From 43139e7a24b3e917e922f430fc53b3c29ba0a76d Mon Sep 17 00:00:00 2001 From: laurensmiers Date: Tue, 5 Dec 2017 12:34:01 +0100 Subject: [PATCH] Setup ggtags --- custom/setup-gtags.el | 38 ++++++++++---------------------------- custom/setup-helm-gtags.el | 8 -------- 2 files changed, 10 insertions(+), 36 deletions(-) diff --git a/custom/setup-gtags.el b/custom/setup-gtags.el index c3a394d..3ea2ef1 100644 --- a/custom/setup-gtags.el +++ b/custom/setup-gtags.el @@ -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) diff --git a/custom/setup-helm-gtags.el b/custom/setup-helm-gtags.el index 9372ca3..46988fd 100644 --- a/custom/setup-helm-gtags.el +++ b/custom/setup-helm-gtags.el @@ -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)