diff options
-rw-r--r-- | helm-imenu.el | 39 | ||||
-rw-r--r-- | helm-semantic.el | 70 |
2 files changed, 68 insertions, 41 deletions
diff --git a/helm-imenu.el b/helm-imenu.el index 15544ba5..3b80b4da 100644 --- a/helm-imenu.el +++ b/helm-imenu.el @@ -43,11 +43,6 @@ :group 'helm-imenu :type 'boolean) -(defcustom helm-imenu-fuzzy-match nil - "Enable fuzzy matching in `helm-source-imenu'." - :group 'helm-imenu - :type 'boolean) - ;;; keymap (defvar helm-imenu-map @@ -71,18 +66,26 @@ (make-variable-buffer-local 'helm-cached-imenu-tick) -(defvar helm-source-imenu - (helm-build-sync-source "Imenu" - :candidates'helm-imenu-candidates - :fuzzy-match helm-imenu-fuzzy-match - :candidate-transformer 'helm-imenu-transformer - :persistent-action 'helm-imenu-persistent-action - :persistent-help "Show this entry" - :keymap helm-imenu-map - :mode-line helm-imenu-mode-line - :action 'helm-imenu-action) - "See (info \"(emacs)Imenu\")") +(defvar helm-source-imenu nil "See (info \"(emacs)Imenu\")") +(defclass helm-imenu-source (helm-source-sync) + ((candidates :initform 'helm-imenu-candidates) + (candidate-transformer :initform 'helm-imenu-transformer) + (persistent-action :initform 'helm-imenu-persistent-action) + (persistent-help :initform "Show this entry") + (keymap :initform helm-imenu-map) + (mode-line :initform helm-imenu-mode-line) + (action :initform 'helm-imenu-action))) + +(defcustom helm-imenu-fuzzy-match nil + "Enable fuzzy matching in `helm-source-imenu'." + :group 'helm-imenu + :type 'boolean + :set (lambda (var val) + (set var val) + (setq helm-source-imenu + (helm-make-source "Imenu" 'helm-imenu-source + :fuzzy-match helm-imenu-fuzzy-match)))) (defun helm-imenu-action (candidate) "Default action for `helm-source-imenu'." @@ -156,6 +159,10 @@ (defun helm-imenu () "Preconfigured `helm' for `imenu'." (interactive) + (unless helm-source-imenu + (setq helm-source-imenu + (helm-make-source "Imenu" 'helm-imenu-source + :fuzzy-match helm-imenu-fuzzy-match))) (let ((imenu-auto-rescan t) (str (thing-at-point 'symbol)) (helm-execute-action-at-once-if-one diff --git a/helm-semantic.el b/helm-semantic.el index 614129c7..fc3b4e05 100644 --- a/helm-semantic.el +++ b/helm-semantic.el @@ -28,14 +28,13 @@ (declare-function pulse-momentary-highlight-one-line "pulse.el" (point &optional face)) +(defgroup helm-semantic nil + "Semantic tags related libraries and applications for helm." + :group 'helm) + (defcustom helm-semantic-lynx-style-map t "Use Arrow keys to jump to occurences." - :group 'helm-imenu - :type 'boolean) - -(defcustom helm-semantic-fuzzy-match nil - "Enable fuzzy matching in `helm-source-semantic'." - :group 'helm-imenu + :group 'helm-semantic :type 'boolean) ;;; keymap @@ -112,23 +111,32 @@ (setq helm-cached-imenu-tick tick) (semantic-parse-tree-set-needs-update))))) -(defvar helm-source-semantic - (helm-make-source "Semantic Tags" 'helm-source-sync - :header-name "Semantic Tags" - :init (lambda () - (helm-semantic--maybe-set-needs-update) - (setq helm-semantic--tags-cache (semantic-fetch-tags)) - (with-current-buffer (helm-candidate-buffer 'global) - (helm-semantic--fetch-candidates helm-semantic--tags-cache 0))) - :candidates 'helm-semantic-get-candidates - :fuzzy-match helm-semantic-fuzzy-match - :persistent-help "Show this entry" - :keymap 'helm-semantic-map - :mode-line helm-semantic-mode-line - :persistent-action (lambda (elm) - (helm-semantic-default-action elm t) - (helm-highlight-current-line)) - :action 'helm-semantic-default-action)) +(defvar helm-source-semantic nil) + +(defclass helm-semantic-source (helm-source-sync) + ((init :initform (lambda () + (helm-semantic--maybe-set-needs-update) + (setq helm-semantic--tags-cache (semantic-fetch-tags)) + (with-current-buffer (helm-candidate-buffer 'global) + (helm-semantic--fetch-candidates helm-semantic--tags-cache 0)))) + (candidates :initform 'helm-semantic-get-candidates) + (persistent-help :initform "Show this entry") + (keymap :initform 'helm-semantic-map) + (mode-line :initform helm-semantic-mode-line) + (persistent-action :initform (lambda (elm) + (helm-semantic-default-action elm t) + (helm-highlight-current-line))) + (action :initform 'helm-semantic-default-action))) + +(defcustom helm-semantic-fuzzy-match nil + "Enable fuzzy matching in `helm-source-semantic'." + :group 'helm-semantic + :type 'boolean + :set (lambda (var val) + (set var val) + (setq helm-source-semantic + (helm-make-source "Semantic Tags" 'helm-semantic-source + :fuzzy-match helm-semantic-fuzzy-match)))) ;;;###autoload (defun helm-semantic (arg) @@ -139,6 +147,10 @@ If ARG is supplied, pre-select symbol at point instead of current" (cons (format "\\_<%s\\_>" (car it)) (format "\\_<%s\\_>" (car (semantic-current-tag)))) (format "\\_<%s\\_>" (car (semantic-current-tag)))))) + (unless helm-source-semantic + (setq helm-source-semantic + (helm-make-source "Semantic Tags" 'helm-semantic-source + :fuzzy-match helm-semantic-fuzzy-match))) (helm :sources 'helm-source-semantic :candidate-number-limit 9999 :preselect (if arg @@ -156,9 +168,17 @@ If `semantic-mode' is active in the current buffer, then use semantic for generating tags, otherwise fall back to `imenu'. Fill in the symbol at point by default." (interactive "P") + (unless helm-source-semantic + (setq helm-source-semantic + (helm-make-source "Semantic Tags" 'helm-semantic-source + :fuzzy-match helm-semantic-fuzzy-match))) + (unless helm-source-imenu + (setq helm-source-imenu + (helm-make-source "Imenu" 'helm-imenu-source + :fuzzy-match helm-imenu-fuzzy-match))) (let* ((source (if (semantic-active-p) 'helm-source-semantic - 'helm-source-imenu)) + 'helm-source-imenu)) (imenu-p (eq source 'helm-source-imenu)) (imenu-auto-rescan imenu-p) (helm-execute-action-at-once-if-one @@ -172,7 +192,7 @@ Fill in the symbol at point by default." :candidate-number-limit 9999 :preselect (if (or arg imenu-p) (thing-at-point 'symbol) - tag) + tag) :buffer "*helm semantic/imenu*"))) (provide 'helm-semantic) |