forked from redguardtoo/emacs.d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-gtags.el
40 lines (37 loc) · 1.6 KB
/
init-gtags.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
;; @see http://emacs-fu.blogspot.com.au/2008/01/navigating-through-source-code-using.html
(defun djcb-gtags-create-or-update ()
"create or update the gnu global tag file"
(interactive)
(if (not (= 0 (call-process "global" nil nil nil " -p"))) ; tagfile doesn't exist?
(let ((olddir default-directory)
(topdir (read-directory-name
"gtags: top of source tree:" default-directory)))
(cd topdir)
(shell-command "gtags && echo 'created tagfile'")
(cd olddir)) ; restore
;; tagfile already exists; update it
(shell-command "global -u && echo 'updated tagfile'"))
)
(defun add-gtagslibpath (libdir &optional del)
"add external library directory to environment variable GTAGSLIBPATH.\ngtags will can that directory if needed.\nC-u M-x add-gtagslibpath will remove the directory from GTAGSLIBPATH."
(interactive "DDirectory containing GTAGS:\nP")
(let (sl)
(if (not (file-exists-p (concat (file-name-as-directory libdir) "GTAGS")))
;; create tags
(let ((olddir default-directory))
(cd libdir)
(shell-command "gtags && echo 'created tagfile'")
(cd olddir)
)
)
(setq libdir (directory-file-name libdir)) ;remove final slash
(setq sl (split-string (if (getenv "GTAGSLIBPATH") (getenv "GTAGSLIBPATH") "") ":" t))
(if del (setq sl (delete libdir sl)) (add-to-list 'sl libdir t))
(setenv "GTAGSLIBPATH" (mapconcat 'identity sl ":")))
)
(defun print-gtagslibpath ()
"print the GTAGSLIBPATH (for debug purpose)"
(interactive)
(message "GTAGSLIBPATH=%s" (getenv "GTAGSLIBPATH"))
)
(provide 'init-gtags)