Setup ggtags
This commit is contained in:
parent
bdee0e5c46
commit
43139e7a24
2 changed files with 10 additions and 36 deletions
|
|
@ -1,33 +1,15 @@
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
(require 'ggtags)
|
||||||
;; Incremental updates to GTAGS table ;;
|
|
||||||
;; To keep the changes we did in source code synchronized ;;
|
|
||||||
;; in the gtags database ;;
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
|
|
||||||
(defun gtags-root-dir ()
|
;; Update on save of file
|
||||||
"Returns GTAGS root directory or nil if doesn't exist."
|
(setq ggtags-update-on-save t)
|
||||||
(with-temp-buffer
|
|
||||||
(if (zerop (call-process "global" nil t nil "-pr"))
|
|
||||||
(buffer-substring (point-min) (1- (point-max)))
|
|
||||||
nil)))
|
|
||||||
|
|
||||||
(defun gtags-update-single(filename)
|
;; Enable async update
|
||||||
"Update Gtags database for changes in a single file"
|
(setq ggtags-oversize-limit t)
|
||||||
(interactive)
|
|
||||||
(start-process "update-gtags" "update-gtags" "bash" "-c" (concat "cd " (gtags-root-dir) " ; gtags --single-update " filename )))
|
|
||||||
|
|
||||||
(defun gtags-update-current-file()
|
;; Enable ggtags-mode
|
||||||
(interactive)
|
(add-hook 'c-mode-common-hook
|
||||||
(defvar filename)
|
(lambda ()
|
||||||
(setq filename (replace-regexp-in-string (gtags-root-dir) "." (buffer-file-name (current-buffer))))
|
(when (derived-mode-p 'c-mode 'c++-mode 'python-mode 'java-mode 'asm-mode)
|
||||||
(gtags-update-single filename)
|
(ggtags-mode 1))))
|
||||||
(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)
|
|
||||||
|
|
||||||
(provide 'setup-gtags)
|
(provide 'setup-gtags)
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,4 @@
|
||||||
(add-hook 'java-mode-hook 'helm-gtags-mode)
|
(add-hook 'java-mode-hook 'helm-gtags-mode)
|
||||||
(add-hook 'asm-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)
|
(provide 'setup-helm-gtags)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue