summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2025-03-06 17:46:49 +0100
committerJonas Bernoulli <jonas@bernoul.li>2025-03-06 20:19:41 +0100
commit4c49e410b1c7050674bcfdabba1006fe375b32d5 (patch)
tree91339f7f62739d354b9424a5bf2883de7846f61c
parentc1b320d6308a68d8841116745310cc55ac5ce74b (diff)
Use advice on all-completions
Right now the completing-read advice does not cover other places where the empty symbol appears, e.g., `completion-at-point'. Therefore address the problem on a slightly lower level, by using an advice on `all-completions', directly where the completion candidates are generated. This advice is simpler since it removes the empty string from the candidates instead of mutating the obarray.
-rw-r--r--llama.el27
1 files changed, 9 insertions, 18 deletions
diff --git a/llama.el b/llama.el
index 080de93..6476dc5 100644
--- a/llama.el
+++ b/llama.el
@@ -290,8 +290,8 @@ explicitly specified `_%3'."
(string-to-syntax "'")))))
start end)))
-(define-advice completing-read (:around (fn &rest args) llama)
- "Unintern the symbol with the empty name during completion.
+(define-advice all-completions (:around (fn str table &rest rest) llama)
+ "Remove empty symbol from completion results if originating from `llama'.
`##' is the notation for the symbol whose name is the empty string.
(intern \"\") => ##
@@ -303,22 +303,13 @@ it to be used akin to syntax, without actually being new syntax.
alias for `llama', you can access the documentation under that name.)
This advice prevents the empty string from being offered as a completion
-candidate when `obarray' (or a completion table that internally uses
-that) is used as COLLECTION, by `unintern'ing that symbol temporarily."
- (let ((plist (symbol-plist '##))
- (value nil)
- (bound nil))
- (with-no-warnings
- (when (boundp '##)
- (setq bound t)
- (setq value ##)))
- (unwind-protect
- (progn (unintern "" obarray)
- (apply fn args))
- (defalias (intern "") 'llama)
- (setplist (intern "") plist)
- (when bound
- (set (intern "") value)))))
+candidate when `obarray' or a completion table that internally uses
+that is used as TABLE."
+ (let ((result (apply fn str table rest)))
+ (if (and (obarrayp table)
+ (eq (symbol-function (intern-soft "" table)) 'llama))
+ (delete "" result)
+ result)))
(defvar llama-fontify-mode)