Subject: transient.el interns potentially enormous symbols as commands

From: João Távora <[email-masked]>
Date: Thu, 18 Jan 2024 11:50:19 +0000

Hello,

I'd never used a package that made use of "transient.el" before.
I have now, via gptel.el  Takes a bit of getting used to, but I like it
(and can see why people like it in Magit).

Now, immediately after using it, I start noticing that the completion
that Fido mode offers on M-x starts to get weirdly contaminated by these
symbols with enormous symbols names.  This makes my Emacs almost
unusable.  I'd think other completion packages would be similarly
affected unless they special case transient symols some how.

Peeping into the transient source code, we can see that it uses a lot
of 'eval' to define some commands just in time as a user navigates the
menus and submenus.

All these commands seem point to the same actual command, and do not
seem to be meant to be called with M-x at all.  They are generated at
lazily at runtime and only for the submenus being visited.

So they're just temporary artefacts of implementation.  Who know if this
is where the library gets its name.  It's curious, but not going to
argue much on this approach.

Anyway, transient uses 'intern' when I think it could just use
'make-symbol' to avoid polluting the obarray and this whole problem.  It
seems to keep functioning and solves my problem.  Here's the trivial
patch.  Would you look at it, Jonas?

diff --git a/lisp/transient.el b/lisp/transient.el
index f9060f5ba85..249c25262ea 100644
--- a/lisp/transient.el
+++ b/lisp/transient.el
@@ -1127,7 +1127,7 @@ transient--parse-suffix
        ((and (commandp car)
              (not (stringp car)))
         (let ((cmd pop)
-              (sym (intern
+              (sym (make-symbol
                     (format "transient:%s:%s"
                             prefix
                             (let ((desc (plist-get args :description)))
@@ -1156,7 +1156,7 @@ transient--parse-suffix
              (when-let ((shortarg (transient--derive-shortarg arg)))
                (setq args (plist-put args :shortarg shortarg)))
              (setq args (plist-put args :argument arg))))
-          (setq sym (intern (format "transient:%s:%s" prefix arg)))
+          (setq sym (make-symbol (format "transient:%s:%s" prefix arg)))
           (setq args (plist-put
                       args :command
                       `(prog1 ',sym

If some kind of persistent storage for these symbols IS needed I
recommend a separate obarray.  Also, why does the full and potentially
very long description in plain text have to be a part of the symbol
name?  This doesn't matter with the 'make-symbol' approach, but I still
find it curious.

João