Subject: bug#1797: 23.0.60; completing-read breaks backwards compatibility

From: Ulrich Mueller <[email-masked]>
Date: Tue, 6 Jan 2009 00:53:31 +0100

>>>>> On Mon, 05 Jan 2009, Stefan Monnier wrote:

>> Also, the different behaviour of `completing-read' breaks backwards
>> compatibility. In fact, I stumbled across this because of some lisp
>> code doing "programmed completion", which doesn't work properly
>> with Emacs 23 anymore (because it accounts only for nil, t, and
>> `lambda').

> The intention is for it to 100% backwards compatible. So please
> report this bug.

Here we go.
To reproduce the problem, eval the following code:

(defvar my-keywords '("foo" "bar" "baz" "quux" "quuux"))

(defun my-complete (s pred mode)
  (string-match "^\\(.*\\s-\\)?\\(.*\\)$" s)
  (let* ((s1 (match-string 1 s))
	 (s2 (match-string 2 s))
	 (c2 (funcall
	      (cond ((null mode) 'try-completion)
		    ((eq mode t) 'all-completions)
		    ((eq mode 'lambda)
		     (if (fboundp 'test-completion)
			 'test-completion
		       ;; XEmacs doesn't have test-completion
		       (lambda (&rest args)
			 (eq (apply 'try-completion args) t))))
		    (t 'ignore))
	      s2
	      (mapcar (lambda (x) (list (concat x " ")))
		      my-keywords)
	      pred)))
    (if (stringp c2) (concat s1 c2) c2)))

(completing-read "Type some keywords: " 'my-complete)

Now type at the minibuffer prompt:
   f TAB b TAB TAB

Emacs 21/22 (and XEmacs) behaviour:
   Minibuffer: "Type some keywords: foo ba"
   *Completions* buffer offers "bar" and "baz" as completions.

Emacs 23.0.60 behaviour:
   Minibuffer: "Type some keywords: foo ba [No completions]"
   (and no *Completions* buffer appears)