]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix dabbrev-completion (bug#17899)
authorAlan Third <alan@idiocy.org>
Thu, 5 Dec 2019 13:14:00 +0000 (13:14 +0000)
committerAlan Third <alan@idiocy.org>
Tue, 10 Dec 2019 20:38:21 +0000 (20:38 +0000)
* 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.

lisp/dabbrev.el
test/lisp/dabbrev-tests.el

index 23abe7ae1655ca555e64c3df43619ad01abed2ba..0cb9b0b824a95905ad9b01d8236bd929a73ad264 100644 (file)
@@ -323,6 +323,9 @@ this list."
 ;; Same as dabbrev-check-other-buffers, but is set for every expand.
 (defvar dabbrev--check-other-buffers dabbrev-check-other-buffers)
 
+;; Same as dabbrev-check-all-buffers, but is set for every expand.
+(defvar dabbrev--check-all-buffers dabbrev-check-all-buffers)
+
 ;; The regexp for recognizing a character in an abbreviation.
 (defvar dabbrev--abbrev-char-regexp nil)
 
@@ -380,10 +383,7 @@ If the prefix argument is 16 (which comes from \\[universal-argument] \\[univers
 then it searches *all* buffers."
   (interactive "*P")
   (dabbrev--reset-global-variables)
-  (let* ((dabbrev-check-other-buffers (and arg t))
-        (dabbrev-check-all-buffers
-         (and arg (= (prefix-numeric-value arg) 16)))
-        (abbrev (dabbrev--abbrev-at-point))
+  (let* ((abbrev (dabbrev--abbrev-at-point))
          (beg (progn (search-backward abbrev) (point)))
          (end (progn (search-forward abbrev) (point)))
         (ignore-case-p (dabbrev--ignore-case-p abbrev))
@@ -420,6 +420,9 @@ then it searches *all* buffers."
                            (t
                             (mapcar #'downcase completion-list)))))))
               (complete-with-action a list s p)))))
+    (setq dabbrev--check-other-buffers (and arg t))
+    (setq dabbrev--check-all-buffers
+          (and arg (= (prefix-numeric-value arg) 16)))
     (completion-in-region beg end table)))
 
 ;;;###autoload
@@ -623,7 +626,8 @@ all skip characters."
        dabbrev--last-buffer-found nil
        dabbrev--abbrev-char-regexp (or dabbrev-abbrev-char-regexp
                                        "\\sw\\|\\s_")
-       dabbrev--check-other-buffers dabbrev-check-other-buffers))
+       dabbrev--check-other-buffers dabbrev-check-other-buffers
+        dabbrev--check-all-buffers dabbrev-check-all-buffers))
 
 (defun dabbrev--select-buffers ()
   "Return a list of other buffers to search for a possible abbrev.
@@ -772,7 +776,7 @@ of the start of the occurrence."
       ;; If dabbrev-check-all-buffers, tack on all the other
       ;; buffers at the end of the list, except those which are
       ;; specifically to be ignored.
-      (if dabbrev-check-all-buffers
+      (if dabbrev--check-all-buffers
          (setq list
                (append list
                        (dabbrev-filter-elements
index a6ab2e7201f8ca4e92e2fd6770c80235772842f6..d26362db3d432547db2dda1f31b4c86938c2880c 100644 (file)
@@ -40,3 +40,33 @@ first expansion being replaced rather than the destination."
      ;; M-/ SPC M-/ M-/
      (execute-kbd-macro "\257 \257\257"))
    (should (string= (buffer-string) "ab  x\nab y\nab  y"))))
+
+(ert-deftest dabbrev-completion-test ()
+  "Test for bug#17899.
+dabbrev-completion should not look for expansions in other
+buffers unless a prefix argument is used."
+  (with-temp-buffer
+    (insert "axy")
+    (with-temp-buffer
+      (insert "abc\na")
+      (goto-char 6)
+      (save-window-excursion
+        (set-window-buffer nil (current-buffer))
+        ;; C-M-/
+        (execute-kbd-macro [201326639]))
+      (should (string= (buffer-string) "abc\nabc")))))
+
+(ert-deftest dabbrev-completion-test-with-argument ()
+  "Test for bug#17899.
+dabbrev-completion should not complete because it has found
+multiple expansions."
+  (with-temp-buffer
+    (insert "axy")
+    (with-temp-buffer
+      (insert "abc\na")
+      (goto-char 6)
+      (save-window-excursion
+        (set-window-buffer nil (current-buffer))
+        ;; C-u C-u C-M-/
+        (execute-kbd-macro [21 21 201326639]))
+      (should (string= (buffer-string) "abc\na")))))