Skip to content

Instantly share code, notes, and snippets.

@fakedrake
Created December 13, 2012 16:34
Show Gist options
  • Save fakedrake/4277722 to your computer and use it in GitHub Desktop.
Save fakedrake/4277722 to your computer and use it in GitHub Desktop.
wraps gtags-find-tag to use imenu if it looks like a better idea
(defun gtags-wrap-find-tag ()
"Just a simple wrapper for gtags-find-tag. This is needed for
ubiquitous exceptions, but it also tries to use imenu before
actually trying to use gtags. This way if we have a single file
project we do not need gtags to jump around. Also we dont need to
regenerate gtags for local symbols."
(interactive)
(let* ((current-token (gtags-current-token))
(imenu-tokens (mapcar (lambda (x) (car x)) (imenu--make-index-alist)))
(use-imenu (member current-token imenu-tokens)))
(if use-imenu
(progn (gtags-push-context) (call-interactively 'imenu))
(progn
(when (null (gtags-get-rootpath))
(gtags-generate-gtags))
(widen) (gtags-find-tag)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment