all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Bob Nnamtrop <bobnnamtrop@gmail.com>
Cc: 5805-done@debbugs.gnu.org
Subject: bug#5805: 23.3 abbrev-insert needs a limited save-excursion
Date: Fri, 08 Jul 2011 10:43:18 -0400	[thread overview]
Message-ID: <jwvwrfsua6o.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <CAKV0tLOxECeGtoeshQvfN869M9CwiObDAg8Rxb0niLSu4HWqwg@mail.gmail.com> (Bob Nnamtrop's message of "Thu, 7 Jul 2011 08:48:36 -0600")

> --- 23.3/abbrev.el      2011-07-07 08:16:16.000000000 -0600
> +++ 23.3.fix/abbrev.el  2011-07-07 08:43:24.000000000 -0600
> @@ -713,6 +713,7 @@
>      ;; If this abbrev has an expansion, delete the abbrev
>      ;; and insert the expansion.
>      (when (stringp (symbol-value abbrev))
> +      (save-excursion
>        (goto-char wordstart)
>        ;; Insert at beginning so that markers at the end (e.g. point)
>        ;; are preserved.
> @@ -741,7 +742,7 @@
>                (skip-syntax-forward "^w" (1- end))
>                ;; Change just that.
>                (upcase-initials-region (point) (1+ (point)))
> -              (goto-char end))))))
> +              (goto-char end)))))))
>      ;; Now point is at the end of the expansion and the beginning is
>      ;; in last-abbrev-location.

This can't be right, as can be seen in the comment right here: after
this (goto-char end), the rest of the code expects point to be "at the
end of the expansion".

I installed the ugly patch below instead.


        Stefan


=== modified file 'lisp/ChangeLog'
--- lisp/ChangeLog	2011-07-08 14:25:25 +0000
+++ lisp/ChangeLog	2011-07-08 14:41:48 +0000
@@ -5,6 +5,8 @@
 
 2011-07-08  Stefan Monnier  <monnier@iro.umontreal.ca>
 
+	* abbrev.el (expand-abbrev): Try to preserve point (bug#5805).
+
 	* vc/vc-bzr.el (vc-bzr-revision-keywords): Remove svn, it's only
 	provided by a particular plugin.
 

=== modified file 'lisp/abbrev.el'
--- lisp/abbrev.el	2011-07-05 15:31:22 +0000
+++ lisp/abbrev.el	2011-07-08 14:41:16 +0000
@@ -814,6 +814,8 @@
     (destructuring-bind (&optional sym name wordstart wordend)
         (abbrev--before-point)
       (when sym
+        (let ((startpos (copy-marker (point) t))
+              (endmark (copy-marker wordend t)))
         (unless (or ;; executing-kbd-macro
                  noninteractive
                  (window-minibuffer-p (selected-window)))
@@ -826,7 +828,14 @@
         (setq last-abbrev-location wordstart)
         ;; If this abbrev has an expansion, delete the abbrev
         ;; and insert the expansion.
-        (abbrev-insert sym name wordstart wordend)))))
+          (prog1
+              (abbrev-insert sym name wordstart wordend)
+            ;; Yuck!!  If expand-abbrev is called with point slightly
+            ;; further than the end of the abbrev, move point back to
+            ;; where it started.
+            (if (and (> startpos endmark)
+                     (= (point) endmark)) ;Obey skeletons that move point.
+                (goto-char startpos))))))))
 
 (defun unexpand-abbrev ()
   "Undo the expansion of the last abbrev that expanded.






      parent reply	other threads:[~2011-07-08 14:43 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <201003291206.NAA17706@ultimate.Smallworld.co.uk>
2010-03-30 16:33 ` bug#5805: Returned mail: Cannot send message within 3 days Maguire, Andrew (GE Infra, Energy)
2010-04-10 16:04   ` bug#5805: 23.1; abbrev-insert does not protext itself with save-excursion Chong Yidong
2010-04-10 17:06     ` Maguire, Andrew (GE Infra, Energy)
2010-04-10 19:10       ` Stefan Monnier
2010-04-12 11:28         ` Maguire, Andrew (GE Infra, Energy)
2010-04-12 13:31           ` Stefan Monnier
2010-04-12 15:02             ` Maguire, Andrew (GE Infra, Energy)
2010-04-12 18:13               ` Stefan Monnier
2011-07-07 14:48   ` bug#5805: 23.3 abbrev-insert needs a limited save-excursion Bob Nnamtrop
2011-07-07 20:59     ` Stefan Monnier
2011-07-07 21:46       ` Bob Nnamtrop
2011-07-08  0:02         ` Bob Nnamtrop
2011-07-08  1:03           ` Stefan Monnier
2011-07-08 14:43     ` Stefan Monnier [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvwrfsua6o.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=5805-done@debbugs.gnu.org \
    --cc=bobnnamtrop@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.