auctex
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[AUCTeX] make a newcommand and use it immediately


From: Nicolas Richard
Subject: [AUCTeX] make a newcommand and use it immediately
Date: Tue, 21 Feb 2012 17:42:04 +0000 (UTC)
User-agent: Pan/0.136 (I'm far too busy being delicious; GIT 88f18c9 git://git.gnome.org/pan2)

Hello,

I'd like to define an emacs function which would:
- add a \newcommand to define a new macro in the preamble (just before 
\begin{document})
- use the newly defined macro at point (using TeX-insert-macro)

I cannot just use (TeX-insert-macro "newcommand") followed by another
(TeX-insert-macro newmacro) because I don't know which macro was just
created by (TeX-insert-macro "newcommand") : it asks for the name
interactively.

This is what I do now.

(defun LaTeX-create-newcommand (symbol)
  "Define a new macro with \\newcommand in the preamble, and use it at 
point"
  (interactive "sNew command name : \\")
  (save-excursion
    (goto-char (point-min))
    (re-search-forward "\\\\begin{document}")
    (beginning-of-line)
    (insert TeX-esc "newcommand" TeX-grop TeX-esc symbol TeX-grcl)
    (TeX-parse-arguments '(["Number of arguments"] ["Default value for 
first argument"]))
    
    (let
        ((TeX-arg-closing-brace TeX-grcl) (TeX-arg-opening-brace TeX-
grop))
     (TeX-argument-insert (read-string "Definition of the macro (use #1, 
#2, etc. for arguments): ") nil)
      )
    (TeX-normal-mode nil)
    (newline)
    )
  (TeX-insert-macro symbol)
  )


It somehow works, but I thought I would ask for comments and
suggestions. One thing I'd like to know : if I use this function then
change my mind, I wish saying "M-x undo" just once would make the
whole thing disappear, but that won't work. How should I do that ?

-- 
Nico.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]