From dc4f7e68095110999182f93701bd5dee149e6b00 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Wed, 11 Mar 2026 16:54:00 -0400 Subject: [PATCH] (elisp--shorthand-aware-(f)boundp): Don't allocate * lisp/progmodes/elisp-mode.el (elisp--read-symbol-shorthands): New function, extracted from `elisp--completion-local-symbols`. Remember the longhand symbol in `elisp--longhand` property. (elisp--completion-local-symbols): Use it. (elisp--shorthand-aware-fboundp, elisp--shorthand-aware-boundp): Use the new `elisp--longhand` property. --- lisp/progmodes/elisp-mode.el | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el index 946d3ba10be..bb58e7d382a 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el @@ -1010,6 +1010,22 @@ The cache holds information specific to the current state of the Elisp obarray. If the obarray is modified by any means (such as interning or uninterning a symbol), this variable is set to nil.") +(defun elisp--read-symbol-shorthands (s) + "Return a fresh list of shorthand-ed alternative spellings of symbol S." + (let ((retval ())) + (cl-loop + for (shorthand . longhand) in read-symbol-shorthands + for full-name = (symbol-name s) + when (string-prefix-p longhand full-name) + do (let ((sym (make-symbol + (concat shorthand + (substring full-name + (length longhand)))))) + (put sym 'elisp--longhand s) + (push sym retval) + retval)) + retval)) + (defun elisp--completion-local-symbols () "Compute collections of all Elisp symbols for completion purposes. The return value is compatible with the COLLECTION form described @@ -1018,18 +1034,9 @@ in `completion-at-point-functions' (which see)." (let (retval) (mapatoms (lambda (s) - (push s retval) - (cl-loop - for (shorthand . longhand) in read-symbol-shorthands - for full-name = (symbol-name s) - when (string-prefix-p longhand full-name) - do (let ((sym (make-symbol - (concat shorthand - (substring full-name - (length longhand)))))) - (put sym 'shorthand t) - (push sym retval) - retval)))) + (setq retval + (cons s (nconc (elisp--read-symbol-shorthands s) + retval))))) retval))) (cond ((null read-symbol-shorthands) obarray) ((and obarray-cache @@ -1046,10 +1053,10 @@ in `completion-at-point-functions' (which see)." obarray-cache))))) (defun elisp--shorthand-aware-fboundp (sym) - (fboundp (intern-soft (symbol-name sym)))) + (fboundp (or (get sym 'elisp--longhand) sym))) (defun elisp--shorthand-aware-boundp (sym) - (boundp (intern-soft (symbol-name sym)))) + (boundp (or (get sym 'elisp--longhand) sym))) (defun elisp-completion-at-point () "Function used for `completion-at-point-functions' in `emacs-lisp-mode'.