Subject: bug#43300: [PATCH] Make M-x show new commands for obsolete aliases

From: Stefan Kangas <[email-masked]>
Date: Wed, 17 Feb 2021 01:52:18 -0800

Lars Ingebrigtsen <[email-masked]> writes:

>> How about showing only obsolete aliases that are new in this major
>> version?  That could give us almost all the benefits without any of the
>> drawbacks.
>
> Hm!  That's a pretty attractive option.  So commands deprecate faster
> than functions...  makes sense to me.

Here's a patch that does that.
From 10715922a84d067b838fef82bd8b3ed8782d65ff Mon Sep 17 00:00:00 2001
From: Stefan Kangas <[email-masked]>
Date: Wed, 17 Feb 2021 10:45:00 +0100
Subject: [PATCH] Don't consider obsolete commands for obsoletion 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)
---
 etc/NEWS       |  5 +++--
 lisp/simple.el | 19 ++++++++++++++++++-
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 943ad6ac59..7b257b9de0 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -323,9 +323,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 215f4399f4..08155c36db 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -1967,7 +1967,24 @@ read-extended-command
 	     '(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 (cadr 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)
               (funcall read-extended-command-predicate sym buffer)))
-- 
2.30.0