summaryrefslogtreecommitdiff
path: root/helm-imenu.el
diff options
context:
space:
mode:
authorThierry Volpiatto <thierry.volpiatto@gmail.com>2017-03-08 20:20:28 +0100
committerThierry Volpiatto <thierry.volpiatto@gmail.com>2017-03-09 06:40:24 +0100
commit9006f050d6c8b48a6a01e1df2dda168230aa8b42 (patch)
treed31b02523018800150b2b15af35b382f5bf5c8cb /helm-imenu.el
parent13cd10eef5320d2ca10d2aba0d204bdb13478702 (diff)
Display helm-imenu-in-all-buffers in separate sources (#1705).
* helm-imenu.el (helm-imenu-in-all-buffers-separate-sources): New user var. (helm-imenu-candidates-in-all-buffers): Take now one optional arg. (helm-imenu-in-all-buffers): Use it.
Diffstat (limited to 'helm-imenu.el')
-rw-r--r--helm-imenu.el69
1 files changed, 45 insertions, 24 deletions
diff --git a/helm-imenu.el b/helm-imenu.el
index 5347c92f..7cad360f 100644
--- a/helm-imenu.el
+++ b/helm-imenu.el
@@ -53,6 +53,12 @@ The alist is bidirectional, i.e no need to add '((foo . bar) (bar . foo))
only '((foo . bar)) is needed."
:type '(alist :key-type symbol :value-type symbol)
:group 'helm-imenu)
+
+(defcustom helm-imenu-in-all-buffers-separate-sources t
+ "Display imenu index of each buffer in its own sources when non-nil."
+ :type 'boolean
+ :group 'helm-imenu)
+
;;; keymap
(defvar helm-imenu-map
@@ -172,23 +178,31 @@ only '((foo . bar)) is needed."
(delete (assoc "*Rescan*" index) index))))
(setq helm-cached-imenu-tick tick))))))
-(defun helm-imenu-candidates-in-all-buffers ()
+(defun helm-imenu-candidates-in-all-buffers (&optional build-sources)
(let* ((lst (buffer-list))
(progress-reporter (make-progress-reporter
"Imenu indexing buffers..." 1 (length lst))))
(prog1
- (cl-loop for b in lst
+ (cl-loop with cur-buf = (if build-sources
+ (current-buffer) helm-current-buffer)
+ for b in lst
for count from 1
- when
- (and (with-current-buffer b
- (derived-mode-p 'prog-mode))
- (with-current-buffer b
- (helm-same-major-mode-p helm-current-buffer
- helm-imenu-all-buffer-assoc)))
- do (progress-reporter-update progress-reporter count)
- and
+ when (and (with-current-buffer b
+ (derived-mode-p 'prog-mode))
+ (with-current-buffer b
+ (helm-same-major-mode-p
+ cur-buf helm-imenu-all-buffer-assoc)))
+ if build-sources
+ collect (helm-make-source
+ (format "Imenu in %s" (buffer-name b))
+ 'helm-imenu-source
+ :candidates (with-current-buffer b
+ (helm-imenu-candidates b))
+ :fuzzy-match helm-imenu-fuzzy-match)
+ else
append (with-current-buffer b
- (helm-imenu-candidates b)))
+ (helm-imenu-candidates b))
+ do (progress-reporter-update progress-reporter count))
(progress-reporter-done progress-reporter))))
(defun helm-imenu--candidates-1 (alist)
@@ -270,22 +284,29 @@ only '((foo . bar)) is needed."
A mode is similar as current if it is the same, it is derived i.e `derived-mode-p'
or it have an association in `helm-imenu-all-buffer-assoc'."
(interactive)
- (unless helm-source-imenu-all
- (setq helm-source-imenu-all
- (helm-make-source "Imenu in all buffers" 'helm-imenu-source
- :init (lambda ()
- ;; Use a cache to avoid repeatedly sending
- ;; progress-reporter message when updating
- ;; (Issue #1704).
- (setq helm-imenu--in-all-buffers-cache
- (helm-imenu-candidates-in-all-buffers)))
- :candidates 'helm-imenu--in-all-buffers-cache
- :fuzzy-match helm-imenu-fuzzy-match)))
+ (unless helm-imenu-in-all-buffers-separate-sources
+ (unless helm-source-imenu-all
+ (setq helm-source-imenu-all
+ (helm-make-source "Imenu in all buffers" 'helm-imenu-source
+ :init (lambda ()
+ ;; Use a cache to avoid repeatedly sending
+ ;; progress-reporter message when updating
+ ;; (Issue #1704).
+ (setq helm-imenu--in-all-buffers-cache
+ (helm-imenu-candidates-in-all-buffers)))
+ :candidates 'helm-imenu--in-all-buffers-cache
+ :fuzzy-match helm-imenu-fuzzy-match))))
(let ((imenu-auto-rescan t)
(str (thing-at-point 'symbol))
(helm-execute-action-at-once-if-one
- helm-imenu-execute-action-at-once-if-one))
- (helm :sources 'helm-source-imenu-all
+ helm-imenu-execute-action-at-once-if-one)
+ (helm--maybe-use-default-as-input
+ (not (null (memq 'helm-source-imenu-all
+ helm-sources-using-default-as-input))))
+ (sources (if helm-imenu-in-all-buffers-separate-sources
+ (helm-imenu-candidates-in-all-buffers 'build-sources)
+ '(helm-source-imenu-all))))
+ (helm :sources sources
:default (list (concat "\\_<" str "\\_>") str)
:preselect (unless (memq 'helm-source-imenu-all
helm-sources-using-default-as-input)