[Top][All Lists]

[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: Stefan Monnier
Subject: bug#5805: 23.1; abbrev-insert does not protext itself with save-excursion
Date: Mon, 12 Apr 2010 09:31:17 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

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


> Thanks,
> Andrew
> -----Original Message-----
> From: Stefan Monnier [mailto:address@hidden 
> Sent: 10 April 2010 20:10
> To: Maguire, Andrew (GE Infra, Energy)
> Cc: Chong Yidong; address@hidden
> 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]