I am trying to understand, what some functions are doing, in order to code something similar.
The following example was copied from the file acro.el
from the AUCTeX package. This is just a random example, as any other style-file from AUCTeX will do.
In acro.el
you will find
...
(TeX-add-symbols
;; Creating New Acronyms
'("DeclareAcronym" LaTeX-arg-define-acro-acronym
(LaTeX-arg-acro-key-val "Definition of acronym (k=v)"
LaTeX-acro-declareacronym-keys))
...)
I do interpret this, that if you want to insert the macro \DeclareAcronym
into your LaTeX-buffer, (by running the command TeX-insert-macro
, bound to CTRL-cCTRL-m) AUCTeX will first run the function LaTeX-arg-define-acro-acronym
.
This---in return---is defined this way:
(defun LaTeX-arg-define-acro-acronym (optional &optional prompt)
"Prompt for an acronym completing with known acronyms.
If OPTIONAL is non-nil, insert the resulting value as an optional
argument, otherwise as a mandatory one. Use PROMPT as the prompt
string."
(LaTeX-arg-acro-acronym optional prompt t))
As far, as I have understood LISP, the function LaTeX-arg-define-acro-acronym
has to be called with one mandatory argument. You may also give it a second, optional argument.
Therefore, calls as this
(LaTeX-arg-define-acro-acronym t)
(LaTeX-arg-define-acro-acronym t "Acronym to define: ")
should be correct. In fact, I can execute those commands in the scratch buffer without error.
But, as you saw above, the function is called without the mandatory argument and even without the parentheses ()
:
LaTeX-arg-define-acro-acronym
Can someone explain to me, why this is working and why emacs is not throwing an error? When I try this in the *scratch*
-buffer, I get an error
Symbol's value as variable is void
When I add parentheses, I get this error message in the minibuffer
Wrong number of arguments
Digging further into the code, I found, that LaTeX-arg-define-acro-acronym
calls the function LaTeX-arg-acro-acronym
. This time, the mandatory OPTIONAL and both optional arguments PROMPT and DEFINITION are handed over. Again, copied from acro.el:
(LaTeX-arg-acro-acronym optional prompt t)
This time the parentheses ()
are used.
I am asking myself, what value OPTIONAL, PROMPT and DEFINITION do get, as they haven't been defined (as far as I can see). (Are there any defaults, I have missed?)