Skip to content

Instantly share code, notes, and snippets.

@ajchemist
Last active December 31, 2015 05:59
Show Gist options
  • Select an option

  • Save ajchemist/7944358 to your computer and use it in GitHub Desktop.

Select an option

Save ajchemist/7944358 to your computer and use it in GitHub Desktop.
;;; Do not use this configuration. It's OBSOLETE!!!
;;; Try current ggtags.el.
;;; That can handles bunch of stuff wisely.
(defvar gtags-create-tags-mask
'("/usr/src/linux/")
"regexp list")
(add-hook 'c-mode-common-hook
#'(lambda ()
(ggtags-mode 1)
(unless (dolist (mask gtags-create-tags-mask)
(string-match mask (expand-file-name default-directory)))
(gtags-create-or-update))
(add-hook 'after-save-hook 'gtags-update-after-save-hook nil t)))
(defun gtags-create-or-update ()
"Returns GTAGS root directory or nil if doesn't exist."
(with-temp-buffer
(if (gtags-root-dir)
(async-shell-command "global -u" nil)
(let ((rootdir (read-directory-name
"gtags: top of source tree:" default-directory)))
(async-shell-command
(concat "gtags " rootdir " && echo 'created tagfile'") nil)))))
(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)))
(defun gtags-update-single (filename)
"Update Gtags database for changes in a single file"
(start-process
"update-gtags" "*update-gtags*" "bash" "-c"
(concat "gtags --single-update " filename)))
(defun gtags-update-current-file ()
(interactive)
(let ((filename (buffer-file-name (current-buffer))))
(gtags-update-single filename)
(message "Gtags updated for %s" filename)))
(defun gtags-update-after-save-hook()
"Update GTAGS file incrementally upon saving a file"
(when ggtags-mode
(when (gtags-root-dir)
(gtags-update-current-file))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment