bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#5805: 23.1; abbrev-insert does not protext itself with save-excursio


From: Maguire, Andrew (GE Infra, Energy)
Subject: bug#5805: 23.1; abbrev-insert does not protext itself with save-excursion
Date: Mon, 12 Apr 2010 17:02:30 +0200

The workaround I have locally is using advice to place a save-excursion
around the non-interactive function abbrev-insert.
Please check to see whether abbrev-insert should be allowed to not
preserve point.

;; Emacs 23 has a lisp implementation for abbrevs.
(if (fboundp 'abbrev-insert)
    (defadvice abbrev-insert (around
save-excursion-around-advice-insertion activate)
      "Lisp implementation of advice insertion does not save point
location afterwards."
      (save-excursion
        ad-do-it)))

Thanks for your prompt replies :-)
Andrew

-----Original Message-----
From: Stefan Monnier [mailto:monnier@iro.umontreal.ca] 
Sent: 12 April 2010 14:31
To: Maguire, Andrew (GE Infra, Energy)
Cc: Chong Yidong; 5805@debbugs.gnu.org
Subject: Re: bug#5805: 23.1; abbrev-insert does not protext itself with
save-excursion

> I do appreciate the need for some abbrevs to move point and that I am
> reporting a perceived change in behaviour.
> However, the question is whether the change in behaviour is deliberate
> or not.

The change was not deliberate, no.

> If a user wishes to create an abbrev that requires point to move
> presumably they have to create the abbrev in a certain way.
> The example you give below would still require user code to move point
> to between the LaTeX statements.
> i.e If I created a simple global abbrev to expand "begi" point would
be
> left after the \end{itemize}^

Yes, the abbrev would need to be defined differently, but the
point-movement would be done by the abbrev itself, i.e. the caller would
still just call expand-abbrev.

> So how should I fix my code that uses expand-abbrev to work in Emacs
23?
> It currently works as is in Emacs 20, 21 and 22.

I think you need to add a save-excursion around the call to
expand-abbrev to make it clear that you don't want this call to
move point.
This will also save you in the case where the user has setup an abbrev
like "begi", which is a case that could also happen in previous Emacsen.

But that really depends on what behavior you expect in the case where
your code encounters a "begi"-like abbrev.


        Stefan


> Thanks,
> Andrew
> -----Original Message-----
> From: Stefan Monnier [mailto:monnier@iro.umontreal.ca] 
> Sent: 10 April 2010 20:10
> To: Maguire, Andrew (GE Infra, Energy)
> Cc: Chong Yidong; 5805@debbugs.gnu.org
> Subject: Re: bug#5805: 23.1; abbrev-insert does not protext itself
with
> save-excursion

>> Create a global abbrev, abbrv => abbrev
>> Type the following, ^ indicating point location.

>> abbrv ()
>> ^
>> Then press C-x ' to expand the abbrev on the line.
>> abbrev ()
>> ^
>> Observe that point ^ is now before the ()s.

> Right.  The question now is: why is that a problem?

> I ask because for some abbrevs, moving point isa feature, e.g. an
abbrev
> that uses skeletons to expand

>     begi
>         ^
> into

>     \begin{itemize}  \end{itemize}
>                     ^

> so maybe the problem is that your code makes unwarranted assumptions
> about what abbrevs can do, or maybe your code knows that it won't
> encounter such abbreviations or that it wouldn't care about their
> point-placement feature, so it could/should use save-excursion.

>> ;; Emacs 23 has a lisp implementation for abbrevs.

> BTW, the problem is not that the implementation is in Lisp, but that
it
> behaves differently.


>         Stefan






reply via email to

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