diff options
author | Tu Do <tu.h.do@dektech.com.au> | 2014-10-21 17:07:40 +0700 |
---|---|---|
committer | Tu Do <tu.h.do@dektech.com.au> | 2014-10-21 17:07:40 +0700 |
commit | babcc655a44e6f70b8462893135c896bb8802166 (patch) | |
tree | 2fb6ecee5060353ccf6ea94bbc752618d31ea9b8 /helm-semantic.el | |
parent | 961f6dcd88d4617c6bbeb9de5fe65d6fdb2744d3 (diff) |
Improve helm-semantic
- helm-semantic and helm-semantic-or-imenu now automatically pre-selects
the semantic tag in context. For example, when cursor is inside a
function like "helm-semantic", invoking the commands will move the
highlighter to that function tag. With this change, effectively the
commands can be used for effective navigation betweens adjacent tags
in buffer.
- With a prefix argument, pre-select symbol at point instead. So, the
original behavior is reserved.
- Pre-selection no longer narrows to a candidate.
- Do not enable using default as input for helm-source-semantic, since
we already handle operation at point.
- Remove helm-semantic--maybe-set-needs-update, since we get tags
directly using semantic-fetch-tags function, and it always gets latest
tags when buffer is modified.
Diffstat (limited to 'helm-semantic.el')
-rw-r--r-- | helm-semantic.el | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/helm-semantic.el b/helm-semantic.el index da3dddba..5aea3a0d 100644 --- a/helm-semantic.el +++ b/helm-semantic.el @@ -91,64 +91,64 @@ (unless persistent (pulse-momentary-highlight-one-line (point)))))) -(defun helm-semantic--maybe-set-needs-update () - (with-helm-current-buffer - (let ((tick (buffer-modified-tick))) - (unless (eq helm-cached-imenu-tick tick) - (setq helm-cached-imenu-tick tick) - (semantic-parse-tree-set-needs-update))))) +(defun helm-semanatic-get-candidates () + "Get a list of candidates in the current buffer." + (let ((tags (semantic-fetch-tags))) + (split-string (with-temp-buffer + (helm-semantic-init-candidates tags 0) + (buffer-string)) "\n"))) (defvar helm-source-semantic - `((name . "Semantic Tags") - (init . (lambda () - (helm-semantic--maybe-set-needs-update) - (let ((tags (semantic-fetch-tags))) - (with-current-buffer (helm-candidate-buffer 'global) - (helm-semantic-init-candidates tags 0))))) - (candidates-in-buffer) - (allow-dups) - (get-line . buffer-substring) - (persistent-action . (lambda (elm) - (helm-semantic-default-action elm t) - (helm-highlight-current-line))) - (persistent-help . "Show this entry") - (keymap . ,helm-semantic-map) - (mode-line . helm-semantic-mode-line) - (action . helm-semantic-default-action) - "Source to search tags using Semantic from CEDET.")) + (helm-make-source "Semantic Tags" 'helm-source-sync + :header-name "Semantic Tags" + :candidates (lambda () + (with-helm-current-buffer + (helm-semanatic-get-candidates))) + :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)) ;;;###autoload -(defun helm-semantic () - "Preconfigured `helm' for `semantic'." +(defun helm-semantic (arg) + "Preconfigured `helm' for `semantic'. +If ARG is supplied, pre-select symbol at point instead of current" (interactive) - (let ((str (thing-at-point 'symbol))) + (let ((tag (semantic-current-tag))) (helm :sources 'helm-source-semantic - :default (list (concat "\\_<" str "\\_>") str) :candidate-number-limit 9999 + :preselect (if arg + (thing-at-point 'symbol) + (concat "\\_<" (car tag) "\\_>")) :buffer "*helm semantic*"))) ;;;###autoload -(defun helm-semantic-or-imenu () +(defun helm-semantic-or-imenu (arg) "Run `helm' with `semantic' or `imenu'. +If ARG is supplied, pre-select symbol at point instead of current +semantic tag in scope. 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) + (interactive "P") (let* ((source (if (semantic-active-p) 'helm-source-semantic 'helm-source-imenu)) (imenu-p (eq source 'helm-source-imenu)) - (str (thing-at-point 'symbol)) (imenu-auto-rescan imenu-p) (helm-execute-action-at-once-if-one (and imenu-p helm-imenu-execute-action-at-once-if-one))) (helm :sources source - :default (list (concat "\\_<" str "\\_>") str) - :buffer "*helm semantic/imenu*" :candidate-number-limit 9999 - :preselect (unless imenu-p (thing-at-point 'symbol))))) + :preselect (if (or arg imenu-p) + (thing-at-point 'symbol) + (concat "\\_<" (car (semantic-current-tag)) "\\_>")) + :buffer "*helm semantic/imenu*"))) (provide 'helm-semantic) |