1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 18:40:39 -08:00

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.
This commit is contained in:
Stefan Monnier 2010-02-27 16:21:43 -05:00
parent a908c79a8f
commit c53b9c3b0a
2 changed files with 26 additions and 10 deletions

View file

@ -1,11 +1,17 @@
2010-02-27 Stefan Monnier <monnier@iro.umontreal.ca>
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 <cyd@stupidchicken.com> 2010-02-27 Chong Yidong <cyd@stupidchicken.com>
* international/fontset.el (setup-default-fontset): Fix :otf spec. * international/fontset.el (setup-default-fontset): Fix :otf spec.
2010-02-27 Jeremy Whitlock <jcscoobyrs@gmail.com> (tiny change) 2010-02-27 Jeremy Whitlock <jcscoobyrs@gmail.com> (tiny change)
* progmodes/python.el (python-pdbtrack-stack-entry-regexp): Allow * progmodes/python.el (python-pdbtrack-stack-entry-regexp):
the characters _<> in the stack entry (Bug#5653). Allow the characters _<> in the stack entry (Bug#5653).
2010-02-26 Kenichi Handa <handa@m17n.org> 2010-02-26 Kenichi Handa <handa@m17n.org>

View file

@ -59,6 +59,8 @@
;; - extend `boundaries' to provide various other meta-data about the ;; - extend `boundaries' to provide various other meta-data about the
;; output of `all-completions': ;; 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 ;; - quoting/unquoting (so we can complete files names with envvars
;; and backslashes, and all-completion can list names without ;; and backslashes, and all-completion can list names without
;; quoting backslashes and dollars). ;; quoting backslashes and dollars).
@ -444,6 +446,17 @@ in the last `cdr'."
(if completions 2 0) (if completions 2 0)
(if exact 1 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) (defun completion--do-completion (&optional try-completion-function)
"Do the completion and return a summary of what happened. "Do the completion and return a summary of what happened.
M = completion was performed, the text was Modified. M = completion was performed, the text was Modified.
@ -486,14 +499,12 @@ E = after completion we now have an Exact match.
string nil nil t)))) string nil nil t))))
(unchanged (eq t (compare-strings completion nil nil (unchanged (eq t (compare-strings completion nil nil
string nil nil nil)))) string nil nil nil))))
(unless unchanged (if unchanged
;; Insert in minibuffer the chars we got.
(goto-char end) (goto-char end)
(insert completion) ;; Insert in minibuffer the chars we got.
(delete-region beg end)) (completion--replace beg end completion))
;; Move point. ;; Move point to its completion-mandated destination.
(goto-char (+ beg comp-pos)) (forward-char (- comp-pos (length completion)))
(if (not (or unchanged completed)) (if (not (or unchanged completed))
;; The case of the string changed, but that's all. We're not sure ;; The case of the string changed, but that's all. We're not sure
@ -1813,7 +1824,6 @@ PATTERN is as returned by `completion-pcm--string->pattern'."
(when completions (when completions
(let* ((re (completion-pcm--pattern->regex pattern '(point))) (let* ((re (completion-pcm--pattern->regex pattern '(point)))
(case-fold-search completion-ignore-case)) (case-fold-search completion-ignore-case))
;; Remove base-size during mapcar, and add it back later.
(mapcar (mapcar
(lambda (str) (lambda (str)
;; Don't modify the string itself. ;; Don't modify the string itself.