From: Stefan Kangas Date: Thu, 13 May 2021 10:17:53 +0000 (+0200) Subject: Don't consider obsolete commands for completion in some cases X-Git-Tag: emacs-28.0.90~2487 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=1af91d271e077134e272055407fb8c4312a7579b;p=emacs.git Don't consider obsolete commands for completion in some cases * lisp/simple.el (read-extended-command): Exclude obsolete commands that are either lacking a 'current-name' or were obsoleted in a previous major version (bug#43300). (There's been some back and forth here. Obsolete commands used to be treated normally for completion, and then they were removed. Then they were put back again, but annotated with what they were obsoleting. There was some pushback on this change, so this latest changes is a compromise between the last two states.) --- diff --git a/etc/NEWS b/etc/NEWS index 205f43ce523..18831e052af 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -389,9 +389,10 @@ setting the variable 'auto-save-visited-mode' buffer-locally to nil. description of the properties. Likewise 'button-describe' does the same for a button. -** Obsolete commands are no longer hidden from command completion. +** Obsolete aliases are no longer hidden from command completion. Completion of command names now considers obsolete aliases as -candidates. Invoking a command via an obsolete alias now mentions the +candidates, if they were marked obsolete in the current major version +of Emacs. Invoking a command via an obsolete alias now mentions the obsolescence fact and shows the new name of the command. +++ diff --git a/lisp/simple.el b/lisp/simple.el index b4e34f1e4cb..35bb472be03 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -2006,7 +2006,24 @@ This function uses the `read-extended-command-predicate' user option." '(metadata (affixation-function . read-extended-command--affixation) (category . command)) - (complete-with-action action obarray string pred))) + (let ((pred + (if (memq action '(nil t)) + ;; Exclude from completions obsolete commands + ;; lacking a `current-name', or where `when' is + ;; not the current major version. + (lambda (sym) + (let ((obsolete (get sym 'byte-obsolete-info))) + (and (funcall pred sym) + (or (equal string (symbol-name sym)) + (not obsolete) + (and + ;; Has a current-name. + (functionp (car obsolete)) + ;; when >= emacs-major-version + (>= (car (version-to-list (caddr obsolete))) + emacs-major-version)))))) + pred))) + (complete-with-action action obarray string pred)))) (lambda (sym) (and (commandp sym) (cond ((null read-extended-command-predicate))