From 4c49e410b1c7050674bcfdabba1006fe375b32d5 Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Thu, 6 Mar 2025 17:46:49 +0100 Subject: 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. --- llama.el | 27 +++++++++------------------ 1 file 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) -- cgit v1.0