Setup ggtags
This commit is contained in:
parent
bdee0e5c46
commit
43139e7a24
2 changed files with 10 additions and 36 deletions
|
|
@ -1,33 +1,15 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Incremental updates to GTAGS table ;;
|
||||
;; To keep the changes we did in source code synchronized ;;
|
||||
;; in the gtags database ;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
(require 'ggtags)
|
||||
|
||||
(defun gtags-root-dir ()
|
||||
"Returns GTAGS root directory or nil if doesn't exist."
|
||||
(with-temp-buffer
|
||||
(if (zerop (call-process "global" nil t nil "-pr"))
|
||||
(buffer-substring (point-min) (1- (point-max)))
|
||||
nil)))
|
||||
;; Update on save of file
|
||||
(setq ggtags-update-on-save t)
|
||||
|
||||
(defun gtags-update-single(filename)
|
||||
"Update Gtags database for changes in a single file"
|
||||
(interactive)
|
||||
(start-process "update-gtags" "update-gtags" "bash" "-c" (concat "cd " (gtags-root-dir) " ; gtags --single-update " filename )))
|
||||
;; Enable async update
|
||||
(setq ggtags-oversize-limit t)
|
||||
|
||||
(defun gtags-update-current-file()
|
||||
(interactive)
|
||||
(defvar filename)
|
||||
(setq filename (replace-regexp-in-string (gtags-root-dir) "." (buffer-file-name (current-buffer))))
|
||||
(gtags-update-single filename)
|
||||
(message "Gtags updated for %s" filename))
|
||||
|
||||
(defun gtags-update-hook()
|
||||
"Update GTAGS file incrementally upon saving a file"
|
||||
(when (gtags-root-dir)
|
||||
(gtags-update-current-file)))
|
||||
|
||||
(add-hook 'after-save-hook 'gtags-update-hook)
|
||||
;; Enable ggtags-mode
|
||||
(add-hook 'c-mode-common-hook
|
||||
(lambda ()
|
||||
(when (derived-mode-p 'c-mode 'c++-mode 'python-mode 'java-mode 'asm-mode)
|
||||
(ggtags-mode 1))))
|
||||
|
||||
(provide 'setup-gtags)
|
||||
|
|
|
|||
|
|
@ -7,12 +7,4 @@
|
|||
(add-hook 'java-mode-hook 'helm-gtags-mode)
|
||||
(add-hook 'asm-mode-hook 'helm-gtags-mode)
|
||||
|
||||
;; key bindings
|
||||
(define-key helm-gtags-mode-map (kbd "C-j") 'helm-gtags-select) ; Find tag from here
|
||||
(define-key helm-gtags-mode-map (kbd "M-.") 'helm-gtags-dwim) ; Find by context (inc, ...)
|
||||
(define-key helm-gtags-mode-map (kbd "M-,") 'helm-gtags-pop-stack)
|
||||
(define-key helm-gtags-mode-map (kbd "C-c <") 'helm-gtags-previous-history)
|
||||
(define-key helm-gtags-mode-map (kbd "C-c >") 'helm-gtags-next-history)
|
||||
|
||||
|
||||
(provide 'setup-helm-gtags)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue