Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
109 lines (88 sloc) 3.41 KB
;;; helm-semantic.el --- Helm interface for Semantic
;; Copyright (C) 2012 Daniel Hackney <>
;; Author: Daniel Hackney <>
;; 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
;; 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 <>.
;;; Commentary:
;; Uses `candidates-in-buffer' for speed.
;;; Code:
(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)
(make-string (* depth 2) ?\s)
;; Save the tag for later
(propertize (semantic-format-tag-summarize tag nil t) 'semantic-tag tag)
;; Recurse to children
(semantic-tag-components tag) (1+ depth)))
;; Don't do anything with packages or includes for now
((package include))
;; Catch-all
(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)))
(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)))))
(get-line . buffer-substring)
(persistent-action . (lambda (elm)
(helm-semantic-default-action elm)
(persistent-help . "Show this entry")
(action . helm-semantic-default-action)
"Source to search tags using Semantic from CEDET."))
(defun helm-semantic ()
"Preconfigured `helm' for `semantic'."
(helm :sources 'helm-c-source-semantic
:buffer "*helm semantic*"))
(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."
(let ((source (if (semantic-active-p)
(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
;; byte-compile-dynamic: t
;; End:
;;; helm-semantic.el ends here
Something went wrong with that request. Please try again.