diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2011-07-08 10:42:36 -0400 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2011-07-08 10:42:36 -0400 |
commit | 856b2f11d8373374d9ddf7e89f6512b39e4071e3 (patch) | |
tree | 782a4b069af15cfe8a2bbc4b26115069f2cf51b5 /lisp/abbrev.el | |
parent | afae1d6821cbc2bf97c27fe99ec75ca9d40fd458 (diff) | |
download | emacs-856b2f11d8373374d9ddf7e89f6512b39e4071e3.tar.gz |
* lisp/abbrev.el (expand-abbrev): Try to preserve point.
Fixes: debbugs:5805
Diffstat (limited to 'lisp/abbrev.el')
-rw-r--r-- | lisp/abbrev.el | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/lisp/abbrev.el b/lisp/abbrev.el index 2122f43bbad..3795dd46010 100644 --- a/lisp/abbrev.el +++ b/lisp/abbrev.el @@ -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. |