GNU bug report logs - #26096
11.90.0; Inversion of macro arguments with active region

Previous Next

Package: auctex;

Reported by: Didier Verna <didier <at> didierverna.net>

Date: Tue, 14 Mar 2017 14:13:01 UTC

Severity: normal

Tags: notabug

Found in version 11.90.0

Done: Arash Esbati <arash <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 26096 in the body.
You can then email your comments to 26096 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-auctex <at> gnu.org:
bug#26096; Package auctex. (Tue, 14 Mar 2017 14:13:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Didier Verna <didier <at> didierverna.net>:
New bug report received and forwarded. Copy sent to bug-auctex <at> gnu.org. (Tue, 14 Mar 2017 14:13:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Didier Verna <didier <at> didierverna.net>
To: bug-auctex <at> gnu.org
Subject: 11.90.0; Inversion of macro arguments with active  region
Date: Tue, 14 Mar 2017 15:11:45 +0100
  Hello,

I'm trying to define a macro using the active region (when available) as
its second argument. There is no general facility for using the active
region as an argument value (to the best of my knowledge, there's only
the -1 specification, but it encompasses the macro name itself).

I found the function TeX-insert-braces which looked like it could do
what I was looking for. So I tried this:

(TeX-add-symbols '("foo" t TeX-insert-braces))

This works as expected when the region is not active, but otherwise, I
get the two arguments swapped: the contents of the active region appears
first, and then the empty pair of braces with the point inside.

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). 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!




Emacs  : GNU Emacs 25.2.50.1 (x86_64-apple-darwin16.3.0, NS appkit-1504.76 Version 10.12.2 (Build 16C67))
 of 2017-01-21
Package: 11.90.0

current state:
==============
(setq
 AUCTeX-date "2017-01-11"
 window-system 'ns
 LaTeX-version "2e"
 TeX-style-path '("/usr/local/var/auctex/"
		  "/usr/local/share/emacs/emacs-packages/auctex-11.90.0/style"
		  "~/var/auctex/" "~/etc/auctex/" ".auto/" "style")
 TeX-auto-save t
 TeX-parse-self t
 TeX-master nil
 TeX-command-list '(("TeX"
		     "%(PDF)%(tex) %(file-line-error) %(extraopts) %`%S%(PDFout)%(mode)%' %t"
		     TeX-run-TeX nil
		     (plain-tex-mode ams-tex-mode texinfo-mode) :help
		     "Run plain TeX")
		    ("LaTeX" "%`%l%(mode)%' %t" TeX-run-TeX nil
		     (latex-mode doctex-mode) :help "Run LaTeX")
		    ("Makeinfo" "makeinfo %(extraopts) %t" TeX-run-compile nil
		     (texinfo-mode) :help "Run Makeinfo with Info output")
		    ("Makeinfo HTML" "makeinfo %(extraopts) --html %t"
		     TeX-run-compile nil (texinfo-mode) :help
		     "Run Makeinfo with HTML output")
		    ("AmSTeX" "amstex %(PDFout) %(extraopts) %`%S%(mode)%' %t"
		     TeX-run-TeX nil (ams-tex-mode) :help "Run AMSTeX")
		    ("ConTeXt"
		     "%(cntxcom) --once --texutil %(extraopts) %(execopts)%t"
		     TeX-run-TeX nil (context-mode) :help "Run ConTeXt once")
		    ("ConTeXt Full" "%(cntxcom) %(extraopts) %(execopts)%t"
		     TeX-run-TeX nil (context-mode) :help
		     "Run ConTeXt until completion")
		    ("BibTeX" "bibtex %s" TeX-run-BibTeX nil t :help
		     "Run BibTeX")
		    ("Biber" "biber %s" TeX-run-Biber nil t :help "Run Biber")
		    ("View" "%V" TeX-run-discard-or-function t t :help
		     "Run Viewer")
		    ...)
 )


-- 
Resistance is futile. You will be jazzimilated.

Lisp, Jazz, Aïkido: http://www.didierverna.info




Information forwarded to bug-auctex <at> gnu.org:
bug#26096; Package auctex. (Wed, 15 Mar 2017 13:47:01 GMT) Full text and rfc822 format available.

Message #8 received at 26096 <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: Didier Verna <didier <at> didierverna.net>
Cc: 26096 <at> debbugs.gnu.org
Subject: Re: bug#26096: 11.90.0;
 Inversion of macro arguments with active  region
Date: Wed, 15 Mar 2017 14:45:38 +0100
Didier Verna <didier <at> didierverna.net> 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




Information forwarded to bug-auctex <at> gnu.org:
bug#26096; Package auctex. (Wed, 15 Mar 2017 14:04:02 GMT) Full text and rfc822 format available.

Message #11 received at 26096 <at> debbugs.gnu.org (full text, mbox):

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: Didier Verna <didier <at> didierverna.net>
Cc: 26096 <at> debbugs.gnu.org
Subject: Re: bug#26096: 11.90.0;
 Inversion of macro arguments with active region
Date: Wed, 15 Mar 2017 23:03:28 +0900
Hi Didier,

> I'm trying to define a macro using the active region (when available) as
> its second argument. There is no general facility for using the active
> region as an argument value (to the best of my knowledge, there's only
> the -1 specification, but it encompasses the macro name itself).

(snip)

> (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!

How about this one?  With very breif testing, it seems to work:

(defun LaTeX-fixme-active-region (optional)
  (TeX-argument-insert "" nil)
  (TeX-parse-argument optional nil))

(TeX-add-symbols '("foo" LaTeX-fixme-active-region))

The idea is very crude and ad hoc, but it does the required job anyway,
at the cost that it looks as if the macro "foo" took only one argument.

Regards,
Ikumi Keita




Information forwarded to bug-auctex <at> gnu.org:
bug#26096; Package auctex. (Mon, 04 Mar 2024 22:21:02 GMT) Full text and rfc822 format available.

Message #14 received at 26096 <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: 26096 <at> debbugs.gnu.org, Didier Verna <didier <at> didierverna.net>
Subject: Re: bug#26096: 11.90.0; Inversion of macro arguments with active
 region
Date: Mon, 04 Mar 2024 23:19:53 +0100
Ikumi Keita <ikumi <at> ikumi.que.jp> writes:

> Hi Didier,
>
>> I'm trying to define a macro using the active region (when available) as
>> its second argument. There is no general facility for using the active
>> region as an argument value (to the best of my knowledge, there's only
>> the -1 specification, but it encompasses the macro name itself).
>
> (snip)
>
>> (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!
>
> How about this one?  With very breif testing, it seems to work:
>
> (defun LaTeX-fixme-active-region (optional)
>   (TeX-argument-insert "" nil)
>   (TeX-parse-argument optional nil))
>
> (TeX-add-symbols '("foo" LaTeX-fixme-active-region))
>
> The idea is very crude and ad hoc, but it does the required job anyway,
> at the cost that it looks as if the macro "foo" took only one argument.

(I'm going through old bug reports that unfortunately weren't resolved
at the time.)

Bonjour Didier,

there were 2 responses to your query.  Is there anything else we can do,
or can we mark this report as done close it?

Best, Arash




Information forwarded to bug-auctex <at> gnu.org:
bug#26096; Package auctex. (Thu, 21 Mar 2024 18:35:03 GMT) Full text and rfc822 format available.

Message #17 received at 26096 <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: Didier Verna <didier <at> didierverna.net>
Cc: 26096 <at> debbugs.gnu.org
Subject: Re: bug#26096: 11.90.0; Inversion of macro arguments with active
 region
Date: Thu, 21 Mar 2024 19:25:32 +0100
Arash Esbati <arash <at> gnu.org> writes:

> Ikumi Keita <ikumi <at> ikumi.que.jp> writes:
>
>> Hi Didier,
>>
>>> I'm trying to define a macro using the active region (when available) as
>>> its second argument. There is no general facility for using the active
>>> region as an argument value (to the best of my knowledge, there's only
>>> the -1 specification, but it encompasses the macro name itself).
>>
>> (snip)
>>
>>> (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!
>>
>> How about this one?  With very breif testing, it seems to work:
>>
>> (defun LaTeX-fixme-active-region (optional)
>>   (TeX-argument-insert "" nil)
>>   (TeX-parse-argument optional nil))
>>
>> (TeX-add-symbols '("foo" LaTeX-fixme-active-region))
>>
>> The idea is very crude and ad hoc, but it does the required job anyway,
>> at the cost that it looks as if the macro "foo" took only one argument.
>
> (I'm going through old bug reports that unfortunately weren't resolved
> at the time.)
>
> Bonjour Didier,
>
> there were 2 responses to your query.  Is there anything else we can do,
> or can we mark this report as done close it?

No further comments, therefore I'm closing this.

Best, Arash




Added tag(s) notabug. Request was from Arash Esbati <arash <at> gnu.org> to control <at> debbugs.gnu.org. (Thu, 21 Mar 2024 18:35:04 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 26096 <at> debbugs.gnu.org and Didier Verna <didier <at> didierverna.net> Request was from Arash Esbati <arash <at> gnu.org> to control <at> debbugs.gnu.org. (Thu, 21 Mar 2024 18:35:04 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 19 Apr 2024 11:24:25 GMT) Full text and rfc822 format available.

This bug report was last modified 98 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.