bug-auctex
[Top][All Lists]
Advanced

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

bug#26096: 11.90.0; Inversion of macro arguments with active region


From: Arash Esbati
Subject: bug#26096: 11.90.0; Inversion of macro arguments with active region
Date: Wed, 15 Mar 2017 14:45:38 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2

Didier Verna <address@hidden> writes:

Hi Didier,

> I'm not sure this is a bug, because I'm not sure TeX-insert-braces can
> actually be used as a hook (it would probably break when enclosed within
> square brackets).

Indeed, `TeX-insert-braces' is not meant to be used inside a hook.
Those functions have by convention a name like `TeX-arg-...'.

> However, I'm supposed to be allowed to define my own hook, so here it
> is:
>
> (defun LaTeX-fixme-active-region (optional)
>   (TeX-argument-insert (if (TeX-active-mark)
>                          (prog1 (buffer-substring (point) (mark))
>                            (delete-region (point) (mark))
>                            (deactivate-mark))
>                        "")
>                      optional))
>
>
> Now defining my macro as follows:
>
> (TeX-add-symbols `("foo" t LaTeX-fixme-active-region))
>
> will entail the same behavior as with TeX-insert-braces, so I'm enclined
> to call that a bug (saving the excursion won't change anything BTW).
>
> Any comment appreciated, thanks!

The way I understand the code the behavior you describe is by design:
AUCTeX puts the region in the first argument when it parses t.  You can
check the function `TeX-parse-argument' in tex.el, line 3523, ((eq arg
t) ...)  So you have to write your own function, but avoid the t in the
style hook.  You can set the exit-mark in you function to get the same
effect as with t, e.g.:

(defun LaTeX-fixme-arg (optional)
  (insert TeX-grop)
  (set-marker exit-mark (point))
  (insert TeX-grcl)
  (TeX-argument-insert (prog1 (buffer-substring (point) (mark))
                         (delete-region (point) (mark))
                         (TeX-deactivate-mark))
                       optional))

(TeX-add-style-hook "fixme"
  (lambda ()

    (TeX-add-symbols
     '("foo" (TeX-arg-conditional (TeX-active-mark)
                                  (LaTeX-fixme-arg)
                                (t nil)))))
  LaTeX-dialect)

HTH.

Best, Arash





reply via email to

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