auctex-devel
[Top][All Lists]

## Re: [AUCTeX-devel] Improve LaTeX macro definition argument prompts

 From: Mosè Giordano Subject: Re: [AUCTeX-devel] Improve LaTeX macro definition argument prompts Date: Tue, 15 Mar 2016 22:23:45 +0100

```Hi Matt,

2016-03-15 21:16 GMT+01:00 Matthew Leach <address@hidden>:
> Hi all,
>
> When inserting a \newcommand macro with AUCTeX, I've found a couple of
> small annoyances and have attached a patch to try and mitigate them.
>
> First, the user is prompted for the number of arguments that a macro
> should take.  If a '0' entered at the prompt, then '[0]' is added at the
> point.  However, when no input is provided and the user just presses RET
> at the prompt, nothing is inserted.  I'm not sure if there is semantic
> difference between
>
> \newcommand{\foo}[0]{Foobar}
>
> and
>
> \newcommand{\foo}{Foobar}
>
> so this may be a stylistic preference for the user.  I think we should
> be consistent, though.

I've never noticed such problem, probably because I never enter "0" as
number of arguments, I just press RET.  AUCTeX does the right thing by
not prompting for the next optional argument only with the default
settings.

The behavior of `TeX-insert-macro' is controlled by
`TeX-insert-macro-default-style'.  By default, after an empty optional
argument AUCTeX doesn't prompt for further optional arguments, but if
one sets it to `show-all-optional-args' he/she will be always prompted
for the default value of the possible optional arguments with the
a real problem, even though `TeX-insert-macro-default-style' probably
isn't one of the most known options.

To be honest this is the first time I see

\newcommand{\foo}[0]{Foobar}

I've always seen and used the version without optional arguments when
the new macro has no argument.  This is probably the reason why I
never enter "0" at the "Number of arguments" prompt.

> Secondly, if a '0' is passed at the prompt of the Number of arguments,
> we are still prompted for the default value of the first argument.  I
> think this is an error as there is no first argument to have a default
> value.

Your patch actually swaps the nuisance: now the useless prompt occurs
when `no-args' is an empty string ;-)  A comment regarding the name of
this variable: "no-args" to me means "no arguments".  It took me a few
seconds to figure out that "no" stands for "number", I think that
using "no" as a shorthand for something different from "no" is at
least misleading.  But I'm not a native English speaker, :-)

> The attached patch creates two new TeX-arg-* functions.
> TeX-arg-define-macro-arguments replaces "Number of arguments" in
> TeX-add-symbols for the macro definition LaTeX commands.  This function
> will prompt the the number of arguments and check the return value and
> if it is equal to "0" or there is no input, nothing is inserted.  If
> anything else is inserted the user is prompted for the default value for
> the first argument, as before.

As I said before, the patch is well-grounded, but please consider my
suggestion(s) above.

Bye,
Mosè

```