-
-
Notifications
You must be signed in to change notification settings - Fork 389
/
helm-semantic.el
107 lines (87 loc) · 3.38 KB
/
helm-semantic.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
;;; helm-semantic.el --- Helm interface for Semantic
;; Copyright (C) 2012 Daniel Hackney <dan@haxney.org>
;; Author: Daniel Hackney <dan@haxney.org>
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Uses `candidates-in-buffer' for speed.
;;; Code:
(eval-when-compile
(require 'cl))
(require 'semantic)
(require 'helm-imenu)
(defun helm-semantic-init-candidates (tags depth)
"Write the contents of TAGS to the current buffer."
(dolist (tag tags)
(when (listp tag)
(case (semantic-tag-class tag)
((function variable type)
(insert
(make-string (* depth 2) ?\s)
;; Save the tag for later
(propertize (semantic-format-tag-summarize tag nil t) 'semantic-tag tag)
"\n")
;; Recurse to children
(helm-semantic-init-candidates
(semantic-tag-components tag) (1+ depth)))
;; Don't do anything with packages or includes for now
((package include))
;; Catch-all
(t)))))
(defun helm-semantic-default-action (_candidate)
;; By default, helm doesn't pass on the text properties of the selection.
;; Fix this.
(with-current-buffer helm-buffer
(skip-chars-forward " " (point-at-eol))
(let ((tag (get-text-property (point) 'semantic-tag)))
(push-mark)
(semantic-go-to-tag tag))))
(defvar helm-c-source-semantic
'((name . "Semantic Tags")
(init . (lambda ()
(let ((tags (semantic-fetch-tags)))
(with-current-buffer (helm-candidate-buffer 'global)
(helm-semantic-init-candidates tags 0)))))
(candidates-in-buffer)
(get-line . buffer-substring)
(persistent-action . (lambda (elm)
(helm-semantic-default-action elm)
(helm-match-line-color-current-line)))
(persistent-help . "Show this entry")
(action . helm-semantic-default-action)
"Source to search tags using Semantic from CEDET."))
;;;###autoload
(defun helm-semantic ()
"Preconfigured `helm' for `semantic'."
(interactive)
(helm :sources 'helm-c-source-semantic
:buffer "*helm semantic*"))
;;;###autoload
(defun helm-semantic-or-imenu ()
"Run `helm' with `semantic' or `imenu'.
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)
(let ((source (if (semantic-active-p)
'helm-c-source-semantic
'helm-c-source-imenu)))
(push-mark)
(helm :sources source
:buffer "*helm semantic/imenu*"
:preselect (thing-at-point 'symbol))))
(provide 'helm-semantic)
;; Local Variables:
;; byte-compile-warnings: (not cl-functions obsolete)
;; coding: utf-8
;; indent-tabs-mode: nil
;; End:
;;; helm-semantic.el ends here