From: Eshel Yaron Date: Mon, 17 Jun 2024 10:46:14 +0000 (+0200) Subject: Add 'minibuffer-action' to 'imenu' X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=48a1fabeca45cf3649a746f3fd7befc1aeb15c2a;p=emacs.git Add 'minibuffer-action' to 'imenu' --- diff --git a/lisp/imenu.el b/lisp/imenu.el index e9221d33326..54008683529 100644 --- a/lisp/imenu.el +++ b/lisp/imenu.el @@ -958,6 +958,22 @@ function placed in a special index-item." (widen)) (goto-char position)) +(defun imenu-minibuffer-action (string) + (let ((choice (or + ;; FIXME: `completion--replace' leaves stale + ;; `imenu-choice' property on parts of input that it + ;; keeps unchagned, so we can't use the next line ATM. + ;; (get-text-property 0 'imenu-choice string) + (assoc string minibuffer-completion-table)))) + (when (or (imenu--subalist-p choice) (equal choice imenu--rescan-item)) + (user-error "`%s' is not associated with a specific position" string)) + (with-selected-window (minibuffer-selected-window) + (push-mark nil t) + (pcase choice + (`(,name ,pos ,fn . ,args) (apply fn name pos args)) + (`(,name . ,pos) (funcall imenu-default-goto-function name pos))) + (run-hooks 'imenu-after-jump-hook)))) + ;;;###autoload (defun imenu (index-item) "Jump to a place in the buffer chosen using a buffer menu or mouse menu. @@ -976,6 +992,8 @@ for more information." (`(,name . ,pos) (imenu (list name pos imenu-default-goto-function))) (_ (error "Unknown imenu item: %S" index-item))))) +(put 'imenu 'minibuffer-action '(imenu-minibuffer-action . "imenu")) + (defun imenu-flush-cache () "Flush the current imenu cache. This forces a full rescan of the buffer to recreate the index alist