emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r99573: Fix in-buffer completion when


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r99573: Fix in-buffer completion when after-change-functions modify the buffer.
Date: Sat, 27 Feb 2010 16:21:43 -0500
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 99573
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Sat 2010-02-27 16:21:43 -0500
message:
  Fix in-buffer completion when after-change-functions modify the buffer.
  * minibuffer.el (completion--replace): New function.
  (completion--do-completion): Use it and use relative movement.
modified:
  lisp/ChangeLog
  lisp/minibuffer.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2010-02-27 15:02:09 +0000
+++ b/lisp/ChangeLog    2010-02-27 21:21:43 +0000
@@ -1,11 +1,17 @@
+2010-02-27  Stefan Monnier  <address@hidden>
+
+       Fix in-buffer completion when after-change-functions modify the buffer.
+       * minibuffer.el (completion--replace): New function.
+       (completion--do-completion): Use it and use relative movement.
+
 2010-02-27  Chong Yidong  <address@hidden>
 
        * international/fontset.el (setup-default-fontset): Fix :otf spec.
 
 2010-02-27  Jeremy Whitlock  <address@hidden>  (tiny change)
 
-       * progmodes/python.el (python-pdbtrack-stack-entry-regexp): Allow
-       the characters _<> in the stack entry (Bug#5653).
+       * progmodes/python.el (python-pdbtrack-stack-entry-regexp):
+       Allow the characters _<> in the stack entry (Bug#5653).
 
 2010-02-26  Kenichi Handa  <address@hidden>
 

=== modified file 'lisp/minibuffer.el'
--- a/lisp/minibuffer.el        2010-02-05 04:21:11 +0000
+++ b/lisp/minibuffer.el        2010-02-27 21:21:43 +0000
@@ -59,6 +59,8 @@
 
 ;; - extend `boundaries' to provide various other meta-data about the
 ;;   output of `all-completions':
+;;   - preferred sorting order when displayed in *Completions*.
+;;   - annotations/text-properties to add when displayed in *Completions*.
 ;;   - quoting/unquoting (so we can complete files names with envvars
 ;;     and backslashes, and all-completion can list names without
 ;;     quoting backslashes and dollars).
@@ -444,6 +446,17 @@
           (if completions 2 0)
           (if exact       1 0)))
 
+(defun completion--replace (beg end newtext)
+  "Replace the buffer text between BEG and END with NEWTEXT.
+Moves point to the end of the new text."
+  ;; This should be in subr.el.
+  ;; You'd think this is trivial to do, but details matter if you want
+  ;; to keep markers "at the right place" and be robust in the face of
+  ;; after-change-functions that may themselves modify the buffer.
+  (goto-char beg)
+  (insert newtext)
+  (delete-region (point) (+ (point) (- end beg))))
+
 (defun completion--do-completion (&optional try-completion-function)
   "Do the completion and return a summary of what happened.
 M = completion was performed, the text was Modified.
@@ -486,14 +499,12 @@
                                                    string nil nil t))))
             (unchanged (eq t (compare-strings completion nil nil
                                               string nil nil nil))))
-        (unless unchanged
-
+        (if unchanged
+          (goto-char end)
           ;; Insert in minibuffer the chars we got.
-          (goto-char end)
-          (insert completion)
-          (delete-region beg end))
-       ;; Move point.
-       (goto-char (+ beg comp-pos))
+          (completion--replace beg end completion))
+       ;; Move point to its completion-mandated destination.
+       (forward-char (- comp-pos (length completion)))
 
         (if (not (or unchanged completed))
           ;; The case of the string changed, but that's all.  We're not sure
@@ -1813,7 +1824,6 @@
   (when completions
     (let* ((re (completion-pcm--pattern->regex pattern '(point)))
            (case-fold-search completion-ignore-case))
-      ;; Remove base-size during mapcar, and add it back later.
       (mapcar
        (lambda (str)
         ;; Don't modify the string itself.


reply via email to

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