emacs之配置gtags

~/emacsConfig/gtags-setting.el

 1 (if (eq system-type 'darwin)
 2     (add-to-list 'load-path "/usr/local/Cellar/global/6.2.9/share/gtags")
 3 )
 4 
 5 (require 'gtags)
 6 
 7 (add-hook 'c-mode-common-hook 'gtags-mode)
 8 (add-hook 'c++-mode-common-hook 'gtags-mode)
 9 (add-hook 'java-mode-common-hook 'gtags-mode)
10 (add-hook 'gtags-select-mode-hook
11       '(lambda ()
12          (setq hl-line-face 'underline)
13          (hl-line-mode 1)))
14 
15 (defvar gtags-src-dir nil)
16 (defvar gtags-saved-tagfile-dir nil)
17 (defvar gtags-language-suffix nil)
18 
19 (setq gtags-suggested-key-mapping t)
20 
21 (defun gtags-update ()
22   "Make GTAGS incremental update"
23   (if
24       (null gtags-src-dir)
25     (message "no tags updated for gtags")
26     (with-temp-buffer
27       (shell-command
28        (concat "cd " gtags-src-dir ";" "global " "-u")
29        (buffer-name))
30     )
31   )
32 )
33 
34 (defun gtags-update-hook ()
35    (gtags-update)
36 )
37 
38 (add-hook 'after-save-hook 'gtags-update-hook)
39 
40 ;gtags生成函数
41 (defun generate-gtags ()
42   "Generate gtag tables."
43   (interactive)
44   (let
45       (
46        (language-suffix "")
47        (src-dir "")
48        (saved-tag-dir "")
49       )
50 
51     (setq src-dir
52           (read-from-minibuffer "source directory for gtags:")
53           
54           language-suffix
55           (read-from-minibuffer "suffix:")
56 
57           saved-tag-dir
58           (read-from-minibuffer "gtags saved path:")
59     )
60         ;设置全局变量保存起来
61     (setf gtags-src-dir src-dir)
62     (setf gtags-language-suffix language-suffix)
63     (setf gtags-saved-tagfile-dir saved-tag-dir)
64 
65 
66     (with-temp-buffer
67       (shell-command
68        (concat "mkdir -p" " " gtags-saved-tagfile-dir " " "2>/dev/null;" "cd " gtags-src-dir ";" "find" " " gtags-src-dir " -name \"" gtags-language-suffix "\" | gtags" " " gtags-saved-tagfile-dir)
69        (buffer-name)))))
70 
71 ;加载gtags
72 (defalias 'load-gtags 'gtags-visit-rootdir)
73 
74 
75 ;光return键在vim模式下不起作用,所以绑定的键是alt+回车
76 (define-key gtags-select-mode-map [(meta return)] 'gtags-select-tag)
77 (define-key gtags-select-mode-map [mouse-1] 'gtags-select-tag)
78 
79 ;查找变量引用:gtags-find-symbol
80 ;查找函数引用:gtags-find-rtag
81 (global-set-key (kbd "C-x v") 'gtags-find-symbol) 
82 (global-set-key (kbd "C-x f") 'gtags-find-rtag) 

 

你可能感兴趣的:(emacs)