Subject: bug#16390: 24.3.50; [PATCH] texinfo-mode does not fontify @math{2^{61}} correctly

From: Bastien <[email-masked]>
Date: Wed, 08 Jan 2014 00:32:07 +0100

Glenn Morris <[email-masked]> writes:

> Bastien Guerry wrote:
>
>> The patch fixes this for @math only.
>
> No it doesn't.
> Even if you fix the obvious 2/1 typo that makes it raise an error during
> redisplay, it will make lines like
>
>  @math{e} is used.  If @var{arg} or @var{base} is negative, @code{log}
>
> look awful.

Yes.  Attached is another patch that works, but looks ugly.
Let me know if there is another more elegant way to check for
the optional presence of balanced curly brace.

=== modified file 'lisp/textmodes/texinfo.el'
*** lisp/textmodes/texinfo.el	2014-01-01 07:43:34 +0000
--- lisp/textmodes/texinfo.el	2014-01-07 23:20:40 +0000
***************
*** 366,373 ****
      ;; their arguments frequently include a @@, and we don't want that
      ;; to overwrite the normal fontification of the argument.
      ("@\\(file\\|email\\){\\([^}]+\\)" 2 font-lock-string-face keep)
!     ("@\\(samp\\|code\\|var\\|math\\|env\\|command\\|option\\){\\([^}]+\\)"
       2 font-lock-variable-name-face keep)
      ("@\\(cite\\|x?ref\\|pxref\\|dfn\\|inforef\\){\\([^}]+\\)"
       2 font-lock-constant-face)
      ("@\\(anchor\\){\\([^}]+\\)" 2 font-lock-type-face)
--- 366,375 ----
      ;; their arguments frequently include a @@, and we don't want that
      ;; to overwrite the normal fontification of the argument.
      ("@\\(file\\|email\\){\\([^}]+\\)" 2 font-lock-string-face keep)
!     ("@\\(samp\\|code\\|var\\|env\\|command\\|option\\){\\([^}]+\\)"
       2 font-lock-variable-name-face keep)
+     ;; @math allows nested braces like @math{2^{12}}
+     ("@math{\\([^{}]*{?[^{}]*}?[^{}]*\\)}" 1 font-lock-variable-name-face)
      ("@\\(cite\\|x?ref\\|pxref\\|dfn\\|inforef\\){\\([^}]+\\)"
       2 font-lock-constant-face)
      ("@\\(anchor\\){\\([^}]+\\)" 2 font-lock-type-face)

-- 
 Bastien