]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix handling of nil PRED2 arg for completion-table-with-predicate
authorRyan C. Thompson <rct@thompsonclan.org>
Wed, 26 Jul 2017 18:09:42 +0000 (11:09 -0700)
committerNoam Postavsky <npostavs@gmail.com>
Wed, 8 Nov 2017 02:25:55 +0000 (21:25 -0500)
* lisp/minibuffer.el (completion-table-with-predicate): Don't act as
if strict is non-nil when pred2 is nil (Bug#27841).
* test/lisp/minibuffer-tests.el
(completion-table-with-predicate-test): Add a test for Bug#27841.

lisp/minibuffer.el
test/lisp/minibuffer-tests.el

index f13f1fa7984a3842eff164953c8d13ec0d6c4579..26861de87b0b12b534afdb8a157f2cc30c053e7f 100644 (file)
@@ -392,7 +392,7 @@ obeys predicates."
                                   (and (funcall pred1 x) (funcall pred2 x)))))
         ;; If completion failed and we're not applying pred1 strictly, try
         ;; again without pred1.
-        (and (not strict) pred1 pred2
+        (and (not strict) pred1
              (complete-with-action action table string pred2))))))
 
 (defun completion-table-in-turn (&rest tables)
index c27b338f7f32fa4f736835ac164cc78b4427d181..2d2ac85e3ff380266e75659b162e5a8bafc65383 100644 (file)
         (should (equal (buffer-string)
                        "test: "))))))
 
+(ert-deftest completion-table-with-predicate-test ()
+  (let ((full-collection
+         '("apple"                      ; Has A.
+           "beet"                       ; Has B.
+           "banana"                     ; Has A & B.
+           "cherry"                     ; Has neither.
+           ))
+        (no-A (lambda (x) (not (string-match-p "a" x))))
+        (no-B (lambda (x) (not (string-match-p "b" x)))))
+    (should
+     (member "cherry"
+             (completion-table-with-predicate
+              full-collection no-A t "" no-B t)))
+    (should-not
+     (member "banana"
+             (completion-table-with-predicate
+              full-collection no-A t "" no-B t)))
+    ;; "apple" should still match when strict is nil.
+    (should (eq t (try-completion
+                   "apple"
+                   (apply-partially
+                    'completion-table-with-predicate
+                    full-collection no-A nil)
+                   no-B)))
+    ;; "apple" should still match when strict is nil and pred2 is nil
+    ;; (Bug#27841).
+    (should (eq t (try-completion
+                   "apple"
+                   (apply-partially
+                    'completion-table-with-predicate
+                    full-collection no-A nil))))))
+
 (provide 'completion-tests)
 ;;; completion-tests.el ends here