summaryrefslogtreecommitdiff
path: root/helm-semantic.el
diff options
context:
space:
mode:
authorTu Do <tu.h.do@dektech.com.au>2014-10-22 15:47:13 +0700
committerTu Do <tu.h.do@dektech.com.au>2014-10-22 15:47:13 +0700
commit89947e34c258d6c7c61c2d7c1a2a3d56211c22a5 (patch)
tree5c575b03bd170ae3028f2958ac4afa958dae3416 /helm-semantic.el
parentab3a583f38d7510ffb9d6e5cca69e3242cae9097 (diff)
Fix a bug where Semantic buffer is empty
When a buffer is modified, it has to be re-parsed by Semantic to get a new list of tags. This needs to be done when helm-source-semantic is at "init" phase - to do this in current buffer - then pass the result to "candidate" phase. When helm-source-semantic gets to "candidate" phase, we are already in a Helm buffer and re-parsing at this stage is late. If we modify a large portion of buffer and re-parse at "candidate" stage, we only get an empty helm-semantic buffer. For example, to reproduce this issue: - "C-x h" to mark all helm.el content. - Paste the same content into the same helm.el buffer. - Run helm-semantic-or-imenu and see an empty buffer. For this reason, add back helm-semantic--maybe-set-needs-update and perform tag fetching at "init" phase. "candidates" should only get processed candidates
Diffstat (limited to 'helm-semantic.el')
-rw-r--r--helm-semantic.el25
1 files changed, 18 insertions, 7 deletions
diff --git a/helm-semantic.el b/helm-semantic.el
index 8c275b65..28399049 100644
--- a/helm-semantic.el
+++ b/helm-semantic.el
@@ -91,19 +91,30 @@
(unless persistent
(pulse-momentary-highlight-one-line (point))))))
+(defvar helm-semantic-tags nil)
+
(defun helm-semantic-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")))
+ (split-string (with-temp-buffer
+ (helm-semantic-init-candidates helm-semantic-tags 0)
+ (buffer-string)) "\n"))
+
+(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)))))
(defvar helm-source-semantic
(helm-make-source "Semantic Tags" 'helm-source-sync
:header-name "Semantic Tags"
- :candidates (lambda ()
- (with-helm-current-buffer
- (helm-semantic-get-candidates)))
+ :init (lambda ()
+ (helm-semantic--maybe-set-needs-update)
+ (setq helm-semantic-tags (semantic-fetch-tags))
+ (with-current-buffer (helm-candidate-buffer 'global)
+ (helm-semantic-init-candidates helm-semantic-tags 0)))
+ :candidates 'helm-semantic-get-candidates
:persistent-help "Show this entry"
:keymap 'helm-semantic-map
:mode-line helm-semantic-mode-line