From: Eshel Yaron Date: Thu, 28 Mar 2024 18:24:02 +0000 (+0100) Subject: Support choosing between multiple narrow-completions-functions X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=6bb81ba1ea14c1a2f75b8d6af60796a7b678e31b;p=emacs.git Support choosing between multiple narrow-completions-functions --- diff --git a/lisp/help-fns.el b/lisp/help-fns.el index 25979bc3909..faa0ab20746 100644 --- a/lisp/help-fns.el +++ b/lisp/help-fns.el @@ -222,13 +222,26 @@ type specifier when available." (get sym prop))) (format "with property %s" prop)))) +(defun help--symbol-narrow-by-file () + (let ((file (completing-read "Symbol file: " + (mapcar #'file-name-base (mapcar #'car load-history))))) + (cons (lambda (cand &rest _) + (let ((sym (if (symbolp cand) cand + (intern (if (stringp cand) cand (car cand)))))) + (when-let ((sf (symbol-file sym))) + (equal file (file-name-base sf))))) + (format "file=%s" file)))) + (defun help--symbol-completion-table (string pred action) (if (eq action 'metadata) `(metadata ,@(when completions-detailed '((affixation-function . help--symbol-completion-table-affixation))) (category . symbol-help) - (narrow-completions-function . help--symbol-narrow-by-property)) + (sort-function . minibuffer-sort-alphabetically) + (narrow-completions-function + . ((?p "property" "Symbol property" help--symbol-narrow-by-property) + (?f "file" "Symbol file" help--symbol-narrow-by-file)))) (when help-enable-completion-autoload (let ((prefixes (radix-tree-prefixes (help-definition-prefixes) string))) (help--load-prefixes prefixes))) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 121994f1a18..f337cda3183 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -5702,10 +5702,14 @@ DESC is a string describing predicate PRED." (interactive "" minibuffer-mode) (let* ((enable-recursive-minibuffers t) (filter-desc - (funcall (or (completion-metadata-get - (completion--field-metadata (minibuffer-prompt-end)) - 'narrow-completions-function) - minibuffer-narrow-completions-function)))) + (funcall + (or (when-let ((fun (completion-metadata-get + (completion--field-metadata + (minibuffer-prompt-end)) + 'narrow-completions-function))) + (if (functionp fun) fun + (nth 3 (read-multiple-choice "Narrow completions by:" fun)))) + minibuffer-narrow-completions-function)))) (minibuffer--add-completions-predicate (car filter-desc) (cdr filter-desc)))) (defun minibuffer-narrow-completions-by-regexp ()