diff options
| author | Stefan Monnier | 2010-02-27 16:21:43 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2010-02-27 16:21:43 -0500 |
| commit | c53b9c3b0ab88ca57fa247c22858e6385f12c0d2 (patch) | |
| tree | 22c42e493615134ea33a00d50df1a54c311e8ab5 | |
| parent | a908c79a8f256b35548a65d14fff11fbecde1c9f (diff) | |
| download | emacs-c53b9c3b0ab88ca57fa247c22858e6385f12c0d2.tar.gz emacs-c53b9c3b0ab88ca57fa247c22858e6385f12c0d2.zip | |
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.
| -rw-r--r-- | lisp/ChangeLog | 10 | ||||
| -rw-r--r-- | lisp/minibuffer.el | 26 |
2 files changed, 26 insertions, 10 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index e743392e5c2..1a51b18cbf5 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,11 +1,17 @@ | |||
| 1 | 2010-02-27 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | Fix in-buffer completion when after-change-functions modify the buffer. | ||
| 4 | * minibuffer.el (completion--replace): New function. | ||
| 5 | (completion--do-completion): Use it and use relative movement. | ||
| 6 | |||
| 1 | 2010-02-27 Chong Yidong <cyd@stupidchicken.com> | 7 | 2010-02-27 Chong Yidong <cyd@stupidchicken.com> |
| 2 | 8 | ||
| 3 | * international/fontset.el (setup-default-fontset): Fix :otf spec. | 9 | * international/fontset.el (setup-default-fontset): Fix :otf spec. |
| 4 | 10 | ||
| 5 | 2010-02-27 Jeremy Whitlock <jcscoobyrs@gmail.com> (tiny change) | 11 | 2010-02-27 Jeremy Whitlock <jcscoobyrs@gmail.com> (tiny change) |
| 6 | 12 | ||
| 7 | * progmodes/python.el (python-pdbtrack-stack-entry-regexp): Allow | 13 | * progmodes/python.el (python-pdbtrack-stack-entry-regexp): |
| 8 | the characters _<> in the stack entry (Bug#5653). | 14 | Allow the characters _<> in the stack entry (Bug#5653). |
| 9 | 15 | ||
| 10 | 2010-02-26 Kenichi Handa <handa@m17n.org> | 16 | 2010-02-26 Kenichi Handa <handa@m17n.org> |
| 11 | 17 | ||
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index d905b9df870..54d155cd510 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el | |||
| @@ -59,6 +59,8 @@ | |||
| 59 | 59 | ||
| 60 | ;; - extend `boundaries' to provide various other meta-data about the | 60 | ;; - extend `boundaries' to provide various other meta-data about the |
| 61 | ;; output of `all-completions': | 61 | ;; output of `all-completions': |
| 62 | ;; - preferred sorting order when displayed in *Completions*. | ||
| 63 | ;; - annotations/text-properties to add when displayed in *Completions*. | ||
| 62 | ;; - quoting/unquoting (so we can complete files names with envvars | 64 | ;; - quoting/unquoting (so we can complete files names with envvars |
| 63 | ;; and backslashes, and all-completion can list names without | 65 | ;; and backslashes, and all-completion can list names without |
| 64 | ;; quoting backslashes and dollars). | 66 | ;; quoting backslashes and dollars). |
| @@ -444,6 +446,17 @@ in the last `cdr'." | |||
| 444 | (if completions 2 0) | 446 | (if completions 2 0) |
| 445 | (if exact 1 0))) | 447 | (if exact 1 0))) |
| 446 | 448 | ||
| 449 | (defun completion--replace (beg end newtext) | ||
| 450 | "Replace the buffer text between BEG and END with NEWTEXT. | ||
| 451 | Moves point to the end of the new text." | ||
| 452 | ;; This should be in subr.el. | ||
| 453 | ;; You'd think this is trivial to do, but details matter if you want | ||
| 454 | ;; to keep markers "at the right place" and be robust in the face of | ||
| 455 | ;; after-change-functions that may themselves modify the buffer. | ||
| 456 | (goto-char beg) | ||
| 457 | (insert newtext) | ||
| 458 | (delete-region (point) (+ (point) (- end beg)))) | ||
| 459 | |||
| 447 | (defun completion--do-completion (&optional try-completion-function) | 460 | (defun completion--do-completion (&optional try-completion-function) |
| 448 | "Do the completion and return a summary of what happened. | 461 | "Do the completion and return a summary of what happened. |
| 449 | M = completion was performed, the text was Modified. | 462 | M = completion was performed, the text was Modified. |
| @@ -486,14 +499,12 @@ E = after completion we now have an Exact match. | |||
| 486 | string nil nil t)))) | 499 | string nil nil t)))) |
| 487 | (unchanged (eq t (compare-strings completion nil nil | 500 | (unchanged (eq t (compare-strings completion nil nil |
| 488 | string nil nil nil)))) | 501 | string nil nil nil)))) |
| 489 | (unless unchanged | 502 | (if unchanged |
| 490 | |||
| 491 | ;; Insert in minibuffer the chars we got. | ||
| 492 | (goto-char end) | 503 | (goto-char end) |
| 493 | (insert completion) | 504 | ;; Insert in minibuffer the chars we got. |
| 494 | (delete-region beg end)) | 505 | (completion--replace beg end completion)) |
| 495 | ;; Move point. | 506 | ;; Move point to its completion-mandated destination. |
| 496 | (goto-char (+ beg comp-pos)) | 507 | (forward-char (- comp-pos (length completion))) |
| 497 | 508 | ||
| 498 | (if (not (or unchanged completed)) | 509 | (if (not (or unchanged completed)) |
| 499 | ;; The case of the string changed, but that's all. We're not sure | 510 | ;; 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'." | |||
| 1813 | (when completions | 1824 | (when completions |
| 1814 | (let* ((re (completion-pcm--pattern->regex pattern '(point))) | 1825 | (let* ((re (completion-pcm--pattern->regex pattern '(point))) |
| 1815 | (case-fold-search completion-ignore-case)) | 1826 | (case-fold-search completion-ignore-case)) |
| 1816 | ;; Remove base-size during mapcar, and add it back later. | ||
| 1817 | (mapcar | 1827 | (mapcar |
| 1818 | (lambda (str) | 1828 | (lambda (str) |
| 1819 | ;; Don't modify the string itself. | 1829 | ;; Don't modify the string itself. |