[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 882d6c4 161/184: counsel.el (counsel-imenu): Work with :up
From: |
Oleh Krehel |
Subject: |
[elpa] master 882d6c4 161/184: counsel.el (counsel-imenu): Work with :update-fn 'auto |
Date: |
Wed, 16 Oct 2019 13:15:14 -0400 (EDT) |
branch: master
commit 882d6c417c7e73f1dcd7d5c0fce8d15442cabf4f
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
counsel.el (counsel-imenu): Work with :update-fn 'auto
* counsel.el (counsel--imenu-candidates): Extract.
(counsel-imenu-get-candidates-from): Return a proper alist.
(counsel-imenu-action): Simplify.
* ivy.el (ivy-read): Detect alist for :update-fn 'auto.
Fixes #2188
---
counsel.el | 78 ++++++++++++++++++++++++++++++++------------------------------
ivy.el | 9 ++++++--
2 files changed, 47 insertions(+), 40 deletions(-)
diff --git a/counsel.el b/counsel.el
index 967f8f9..48b1214 100644
--- a/counsel.el
+++ b/counsel.el
@@ -4276,28 +4276,40 @@ S will be of the form \"[register]: content\"."
(declare-function imenu--subalist-p "imenu")
(declare-function imenu--make-index-alist "imenu")
+(defun counsel--imenu-candidates ()
+ (unless (featurep 'imenu)
+ (require 'imenu nil t))
+ (let* ((imenu-auto-rescan t)
+ (imenu-auto-rescan-maxout (if current-prefix-arg
+ (buffer-size)
+ imenu-auto-rescan-maxout))
+ (items (imenu--make-index-alist t))
+ (items (delete (assoc "*Rescan*" items) items))
+ (items (counsel-imenu-categorize-functions items)))
+ (counsel-imenu-get-candidates-from items)))
+
(defun counsel-imenu-get-candidates-from (alist &optional prefix)
"Create a list of (key . value) from ALIST.
PREFIX is used to create the key."
- (cl-mapcan (lambda (elm)
- (if (imenu--subalist-p elm)
- (counsel-imenu-get-candidates-from
- (cl-loop for (e . v) in (cdr elm) collect
- (cons e (if (integerp v) (copy-marker v) v)))
- ;; pass the prefix to next recursive call
- (concat prefix (if prefix ".") (car elm)))
- (let ((key (concat
- (when prefix
- (concat
- (propertize prefix 'face 'ivy-grep-info)
- ": "))
- (car elm))))
- (list (cons key
- ;; create a imenu candidate here
- (cons key (if (overlayp (cdr elm))
- (overlay-start (cdr elm))
- (cdr elm))))))))
- alist))
+ (cl-mapcan
+ (lambda (elm)
+ (if (imenu--subalist-p elm)
+ (counsel-imenu-get-candidates-from
+ (cl-loop for (e . v) in (cdr elm) collect
+ (cons e (if (integerp v) (copy-marker v) v)))
+ ;; pass the prefix to next recursive call
+ (concat prefix (if prefix ".") (car elm)))
+ (let ((key (concat
+ (when prefix
+ (concat
+ (propertize prefix 'face 'ivy-grep-info)
+ ": "))
+ (car elm))))
+ (list (cons key
+ (if (overlayp (cdr elm))
+ (overlay-start (cdr elm))
+ (cdr elm)))))))
+ alist))
(defvar counsel-imenu-map
(let ((map (make-sparse-keymap)))
@@ -4312,29 +4324,19 @@ PREFIX is used to create the key."
`(("Functions" ,@fns)))
items)))
+(defun counsel-imenu-action (candidate)
+ (goto-char (cdr candidate)))
+
;;;###autoload
(defun counsel-imenu ()
"Jump to a buffer position indexed by imenu."
(interactive)
- (unless (featurep 'imenu)
- (require 'imenu nil t))
- (let* ((imenu-auto-rescan t)
- (imenu-auto-rescan-maxout (if current-prefix-arg
- (buffer-size)
- imenu-auto-rescan-maxout))
- (items (imenu--make-index-alist t))
- (items (delete (assoc "*Rescan*" items) items))
- (items (counsel-imenu-categorize-functions items)))
- (ivy-read "imenu items: " (counsel-imenu-get-candidates-from items)
- :preselect (thing-at-point 'symbol)
- :require-match t
- :action (lambda (candidate)
- (with-ivy-window
- ;; In org-mode, (imenu candidate) will expand child
node
- ;; after jump to the candidate position
- (imenu (cdr candidate))))
- :keymap counsel-imenu-map
- :caller 'counsel-imenu)))
+ (ivy-read "imenu items: " (counsel--imenu-candidates)
+ :preselect (thing-at-point 'symbol)
+ :require-match t
+ :action #'counsel-imenu-action
+ :keymap counsel-imenu-map
+ :caller 'counsel-imenu))
;;** `counsel-list-processes'
(defun counsel-list-processes-action-delete (x)
diff --git a/ivy.el b/ivy.el
index cb5569d..8411067 100644
--- a/ivy.el
+++ b/ivy.el
@@ -2093,8 +2093,13 @@ customizations apply to the current completion session."
:keymap keymap
:update-fn (if (eq update-fn 'auto)
(lambda ()
- (funcall (ivy--get-action ivy-last)
- (ivy-state-current ivy-last)))
+ (with-ivy-window
+ (funcall
+ (ivy--get-action ivy-last)
+ (if (consp (car-safe (ivy-state-collection
ivy-last)))
+ (assoc (ivy-state-current ivy-last)
+ (ivy-state-collection ivy-last))
+ (ivy-state-current ivy-last)))))
update-fn)
:sort sort
:action (ivy--compute-extra-actions action caller)
- [elpa] master 78dd554 134/184: ivy.el (ivy--exhibit): Handle ivy--reset-state initial call, (continued)
- [elpa] master 78dd554 134/184: ivy.el (ivy--exhibit): Handle ivy--reset-state initial call, Oleh Krehel, 2019/10/16
- [elpa] master c1ea2af 145/184: ivy.el (ivy-read): Fix conflict an existing read-key session, Oleh Krehel, 2019/10/16
- [elpa] master 589e03f 144/184: ivy.el (ivy-configure): Use for ivy-index-functions-alist, Oleh Krehel, 2019/10/16
- [elpa] master 64c0804 163/184: ivy.el (ivy-partial-or-done): Work with completion-cycle-threshold, Oleh Krehel, 2019/10/16
- [elpa] master 6f23c5e 152/184: ivy.el (ivy-occur-press): Re-use ivy-highlight-grep-commands, Oleh Krehel, 2019/10/16
- [elpa] master f46cdad 154/184: counsel.el (counsel-grep): Add :require-match, Oleh Krehel, 2019/10/16
- [elpa] master 2d840b8 157/184: ivy.el (ivy-configure): Add :sort-fn, Oleh Krehel, 2019/10/16
- [elpa] master f0451db 173/184: ivy.el (ivy-occur-revert-buffer): Don't error if the swiper buffer was killed, Oleh Krehel, 2019/10/16
- [elpa] master 3bd1d87 182/184: counsel.el (counsel-locate-cmd-es): Encode command to local codepage, Oleh Krehel, 2019/10/16
- [elpa] master 8b4693c 169/184: counsel.el (counsel-imenu-action and -get-canditates-from): Revert., Oleh Krehel, 2019/10/16
- [elpa] master 882d6c4 161/184: counsel.el (counsel-imenu): Work with :update-fn 'auto,
Oleh Krehel <=
- [elpa] master 1a9002b 168/184: ivy.el: Clean up obsolete aliases, Oleh Krehel, 2019/10/16
- [elpa] master c2d3a4c 184/184: Merge commit 'cd634c6f51458f81898ecf2821ac3169cb65a1eb' from ivy, Oleh Krehel, 2019/10/16
- [elpa] master 12f4771 124/184: ivy.el (ivy-completion-in-region): Add workaround for package-menu-filter, Oleh Krehel, 2019/10/16
- [elpa] master 2b974b4 139/184: ivy.el (ivy-update-fns-alist): New defcustom, Oleh Krehel, 2019/10/16
- [elpa] master 57e0b94 146/184: swiper.el (swiper--action): Set case-fold-search, Oleh Krehel, 2019/10/16
- [elpa] master cdca2fc 141/184: counsel.el (counsel-switch-buffer): Re-use ivy-switch-buffer, Oleh Krehel, 2019/10/16
- [elpa] master a5701a9 159/184: ivy.el (ivy-configure): Add :format-fn, Oleh Krehel, 2019/10/16
- [elpa] master 4d533b2 178/184: counsel.el (counsel-dired): Filter to directories only, Oleh Krehel, 2019/10/16
- [elpa] master ec1ed07 171/184: counsel.el (counsel--find-file-1): Use dired-current-directory for dired, Oleh Krehel, 2019/10/16
- [elpa] master 1d8803e 181/184: Ensure that ripgrep on windows uses '/' as the path-separator, Oleh Krehel, 2019/10/16