]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/abbrev.el (expand-abbrev): Try to preserve point.
authorStefan Monnier <monnier@iro.umontreal.ca>
Fri, 8 Jul 2011 14:42:36 +0000 (10:42 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Fri, 8 Jul 2011 14:42:36 +0000 (10:42 -0400)
Fixes: debbugs:5805
lisp/ChangeLog
lisp/abbrev.el

index 0c912db74d9808b8266b5aaddef077459d3b26eb..4a9dd27b8403145e1c40ac27afac672a19c70891 100644 (file)
@@ -1,3 +1,7 @@
+2011-07-08  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+       * abbrev.el (expand-abbrev): Try to preserve point (bug#5805).
+
 2011-07-08  Michael Albinus  <michael.albinus@gmx.de>
 
        * net/tramp-sh.el (tramp-sh-handle-start-file-process): Use a
index 2122f43bbad7e01771fe19a064984975d4a0d307..3795dd46010dc5a821943960c3c035c1b077a644 100644 (file)
@@ -814,19 +814,28 @@ Returns the abbrev symbol, if expansion took place."
     (destructuring-bind (&optional sym name wordstart wordend)
         (abbrev--before-point)
       (when sym
-        (unless (or ;; executing-kbd-macro
-                 noninteractive
-                 (window-minibuffer-p (selected-window)))
-          ;; Add an undo boundary, in case we are doing this for
-          ;; a self-inserting command which has avoided making one so far.
-          (undo-boundary))
-        ;; Now sym is the abbrev symbol.
-        (setq last-abbrev-text name)
-        (setq last-abbrev sym)
-        (setq last-abbrev-location wordstart)
-        ;; If this abbrev has an expansion, delete the abbrev
-        ;; and insert the expansion.
-        (abbrev-insert sym name wordstart wordend)))))
+        (let ((startpos (copy-marker (point) t))
+              (endmark (copy-marker wordend t)))
+          (unless (or ;; executing-kbd-macro
+                   noninteractive
+                   (window-minibuffer-p (selected-window)))
+            ;; Add an undo boundary, in case we are doing this for
+            ;; a self-inserting command which has avoided making one so far.
+            (undo-boundary))
+          ;; Now sym is the abbrev symbol.
+          (setq last-abbrev-text name)
+          (setq last-abbrev sym)
+          (setq last-abbrev-location wordstart)
+          ;; If this abbrev has an expansion, delete the abbrev
+          ;; and insert the expansion.
+          (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.