Pārlūkot izejas kodu

Add a workaround for Emacs bug #26997

This bug was fixed in Emacs 26.1, but ido-completing-read+ should
still avoid this error in previous Emacs versions in order to be a
seamless drop-in replacement. This implements the fallback in cases
where the error would be triggered and adds a test for the
functionality.

Fixes ido-ubiquitous bug #119.

https://debbugs.gnu.org/cgi/bugreport.cgi?bug=26997
Ryan C. Thompson 8 gadi atpakaļ
vecāks
revīzija
d1ef2a84bd
2 mainītis faili ar 24 papildinājumiem un 0 dzēšanām
  1. 5 0
      ido-completing-read+.el
  2. 19 0
      test/ido-ubiquitous-test.el

+ 5 - 0
ido-completing-read+.el

@@ -203,6 +203,11 @@ completion for them."
                     '("ido cannot handle COLLECTION being a function"))))
           ;; Expand all possible completions
           (setq collection (all-completions "" collection predicate))
+          ;; Check for a specific bug
+          (when (and (version< emacs-version "26.1")
+                     (member "" collection))
+            (signal 'ido-cr+-fallback
+                    '("ido cannot handle the empty string as an option when `ido-enable-dot-prefix' is non-nil; see https://debbugs.gnu.org/cgi/bugreport.cgi?bug=26997")))
           ;; Check for excessively large collection
           (when (and ido-cr+-max-items
                      (> (length collection) ido-cr+-max-items))

+ 19 - 0
test/ido-ubiquitous-test.el

@@ -558,6 +558,25 @@ Note that although this is a macro, the TAG argument is evaluated normally."
       (with-simulated-input "g C-b x DEL C-b RET"
         (completing-read "Prompt: " '("blue" "yellow" "green")))))))
 
+(ert-deftest ido-ubiquitous-dot-prefix-empty-string ()
+  :tags '(ido ido-ubiquitous)
+  "Test whether ido-ubiquitous successfully works around a bug in ido.
+
+See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=26997 for more
+information on this bug."
+  (with-ido-ubiquitous-standard-env
+    (let ((ido-enable-dot-prefix t))
+      (should
+       (string=
+        ""
+        (with-simulated-input "RET"
+          (completing-read "Pick: " '("" "aaa" "aab" "aac")))))
+      (should
+       (string=
+        "aab"
+        (with-simulated-input "a a b RET"
+          (completing-read "Pick: " '("" "aaa" "aab" "aac"))))))))
+
 (defun ido-ubiquitous-run-all-tests ()
   (interactive)
   (ert "^ido-\\(ubiquitous\\|cr\\+\\)-"))