aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Third2019-12-05 13:14:00 +0000
committerAlan Third2019-12-10 20:38:21 +0000
commit33a37360defdc08a5d8eeabffef96f8571d3b608 (patch)
tree6fe807ff4f3c2cdc644d836f58df228145606b36
parentfbf9fea4fdad467429058077b8087dbd0758b964 (diff)
downloademacs-33a37360defdc08a5d8eeabffef96f8571d3b608.tar.gz
emacs-33a37360defdc08a5d8eeabffef96f8571d3b608.zip
Fix dabbrev-completion (bug#17899)
* lisp/dabbrev.el (dabbrev--check-all-buffers): Add new variable. (dabbrev-completion): Lexical scoping means we can't use let to override global variables, so use setq. (dabbrev--reset-global-variables): Reset new variable. (dabbrev--make-friend-buffer-list): Use new variable. * test/lisp/dabbrev-tests.el (dabbrev-completion-test): (dabbrev-completion-test-with-argument): New tests.
-rw-r--r--lisp/dabbrev.el16
-rw-r--r--test/lisp/dabbrev-tests.el30
2 files changed, 40 insertions, 6 deletions
diff --git a/lisp/dabbrev.el b/lisp/dabbrev.el
index 23abe7ae165..0cb9b0b824a 100644
--- a/lisp/dabbrev.el
+++ b/lisp/dabbrev.el
@@ -323,6 +323,9 @@ this list."
323;; Same as dabbrev-check-other-buffers, but is set for every expand. 323;; Same as dabbrev-check-other-buffers, but is set for every expand.
324(defvar dabbrev--check-other-buffers dabbrev-check-other-buffers) 324(defvar dabbrev--check-other-buffers dabbrev-check-other-buffers)
325 325
326;; Same as dabbrev-check-all-buffers, but is set for every expand.
327(defvar dabbrev--check-all-buffers dabbrev-check-all-buffers)
328
326;; The regexp for recognizing a character in an abbreviation. 329;; The regexp for recognizing a character in an abbreviation.
327(defvar dabbrev--abbrev-char-regexp nil) 330(defvar dabbrev--abbrev-char-regexp nil)
328 331
@@ -380,10 +383,7 @@ If the prefix argument is 16 (which comes from \\[universal-argument] \\[univers
380then it searches *all* buffers." 383then it searches *all* buffers."
381 (interactive "*P") 384 (interactive "*P")
382 (dabbrev--reset-global-variables) 385 (dabbrev--reset-global-variables)
383 (let* ((dabbrev-check-other-buffers (and arg t)) 386 (let* ((abbrev (dabbrev--abbrev-at-point))
384 (dabbrev-check-all-buffers
385 (and arg (= (prefix-numeric-value arg) 16)))
386 (abbrev (dabbrev--abbrev-at-point))
387 (beg (progn (search-backward abbrev) (point))) 387 (beg (progn (search-backward abbrev) (point)))
388 (end (progn (search-forward abbrev) (point))) 388 (end (progn (search-forward abbrev) (point)))
389 (ignore-case-p (dabbrev--ignore-case-p abbrev)) 389 (ignore-case-p (dabbrev--ignore-case-p abbrev))
@@ -420,6 +420,9 @@ then it searches *all* buffers."
420 (t 420 (t
421 (mapcar #'downcase completion-list))))))) 421 (mapcar #'downcase completion-list)))))))
422 (complete-with-action a list s p))))) 422 (complete-with-action a list s p)))))
423 (setq dabbrev--check-other-buffers (and arg t))
424 (setq dabbrev--check-all-buffers
425 (and arg (= (prefix-numeric-value arg) 16)))
423 (completion-in-region beg end table))) 426 (completion-in-region beg end table)))
424 427
425;;;###autoload 428;;;###autoload
@@ -623,7 +626,8 @@ all skip characters."
623 dabbrev--last-buffer-found nil 626 dabbrev--last-buffer-found nil
624 dabbrev--abbrev-char-regexp (or dabbrev-abbrev-char-regexp 627 dabbrev--abbrev-char-regexp (or dabbrev-abbrev-char-regexp
625 "\\sw\\|\\s_") 628 "\\sw\\|\\s_")
626 dabbrev--check-other-buffers dabbrev-check-other-buffers)) 629 dabbrev--check-other-buffers dabbrev-check-other-buffers
630 dabbrev--check-all-buffers dabbrev-check-all-buffers))
627 631
628(defun dabbrev--select-buffers () 632(defun dabbrev--select-buffers ()
629 "Return a list of other buffers to search for a possible abbrev. 633 "Return a list of other buffers to search for a possible abbrev.
@@ -772,7 +776,7 @@ of the start of the occurrence."
772 ;; If dabbrev-check-all-buffers, tack on all the other 776 ;; If dabbrev-check-all-buffers, tack on all the other
773 ;; buffers at the end of the list, except those which are 777 ;; buffers at the end of the list, except those which are
774 ;; specifically to be ignored. 778 ;; specifically to be ignored.
775 (if dabbrev-check-all-buffers 779 (if dabbrev--check-all-buffers
776 (setq list 780 (setq list
777 (append list 781 (append list
778 (dabbrev-filter-elements 782 (dabbrev-filter-elements
diff --git a/test/lisp/dabbrev-tests.el b/test/lisp/dabbrev-tests.el
index a6ab2e7201f..d26362db3d4 100644
--- a/test/lisp/dabbrev-tests.el
+++ b/test/lisp/dabbrev-tests.el
@@ -40,3 +40,33 @@ first expansion being replaced rather than the destination."
40 ;; M-/ SPC M-/ M-/ 40 ;; M-/ SPC M-/ M-/
41 (execute-kbd-macro "\257 \257\257")) 41 (execute-kbd-macro "\257 \257\257"))
42 (should (string= (buffer-string) "ab x\nab y\nab y")))) 42 (should (string= (buffer-string) "ab x\nab y\nab y"))))
43
44(ert-deftest dabbrev-completion-test ()
45 "Test for bug#17899.
46dabbrev-completion should not look for expansions in other
47buffers unless a prefix argument is used."
48 (with-temp-buffer
49 (insert "axy")
50 (with-temp-buffer
51 (insert "abc\na")
52 (goto-char 6)
53 (save-window-excursion
54 (set-window-buffer nil (current-buffer))
55 ;; C-M-/
56 (execute-kbd-macro [201326639]))
57 (should (string= (buffer-string) "abc\nabc")))))
58
59(ert-deftest dabbrev-completion-test-with-argument ()
60 "Test for bug#17899.
61dabbrev-completion should not complete because it has found
62multiple expansions."
63 (with-temp-buffer
64 (insert "axy")
65 (with-temp-buffer
66 (insert "abc\na")
67 (goto-char 6)
68 (save-window-excursion
69 (set-window-buffer nil (current-buffer))
70 ;; C-u C-u C-M-/
71 (execute-kbd-macro [21 21 201326639]))
72 (should (string= (buffer-string) "abc\na")))))