X-Git-Url: https://code.delx.au/gnu-emacs-elpa/blobdiff_plain/07062a9b12e63b3069d9790149873510e1c64c36..a28e0c3b186c123b158749de2d38815757d20962:/ggtags.el diff --git a/ggtags.el b/ggtags.el index 08f36eb39..d3f13a4ef 100644 --- a/ggtags.el +++ b/ggtags.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2013 Free Software Foundation, Inc. ;; Author: Leo Liu -;; Version: 0.5 +;; Version: 0.6 ;; Keywords: tools, convenience ;; Created: 2013-01-29 ;; URL: https://github.com/leoliu/ggtags @@ -69,12 +69,24 @@ If nil, use Emacs default." (defvar ggtags-current-tag-name nil) +;; Used by ggtags-global-mode +(defvar ggtags-global-error "match" + "Stem of message to print when no matches are found.") + (defmacro ggtags-ignore-file-error (&rest body) (declare (indent 0)) `(condition-case nil (progn ,@body) (file-error nil))) +;; http://thread.gmane.org/gmane.comp.gnu.global.bugs/1518 +(defvar ggtags-global-has-path-style ; introduced in global 6.2.8 + (ggtags-ignore-file-error + (and (string-match-p "^--path-style " + (shell-command-to-string "global --help")) + t)) + "Non-nil if `global' supports --path-style switch.") + (defmacro ggtags-ensure-global-buffer (&rest body) (declare (indent 0)) `(progn @@ -92,6 +104,9 @@ Return -1 if it does not exist." (float-time (nth 5 (file-attributes file))) -1))) +(defun ggtags-get-libpath () + (split-string (or (getenv "GTAGSLIBPATH") "") ":" t)) + (defun ggtags-cache-get (key) (assoc key ggtags-cache)) @@ -142,6 +157,19 @@ Return -1 if it does not exist." (error "%s" (comment-string-strip (buffer-string) t t)))))) (error "Aborted")))) +(defun ggtags-tag-names-1 (root &optional prefix) + (when root + (if (ggtags-cache-stale-p root) + (let* ((default-directory (file-name-as-directory root)) + (tags (with-demoted-errors + (split-string + (with-output-to-string + (call-process "global" nil (list standard-output nil) + nil "-c" (or prefix ""))))))) + (and tags (ggtags-cache-set root tags)) + tags) + (cadr (ggtags-cache-get root))))) + ;;;###autoload (defun ggtags-tag-names (&optional prefix) "Get a list of tag names starting with PREFIX." @@ -150,16 +178,9 @@ Return -1 if it does not exist." (if (zerop (call-process "global" nil nil nil "-u")) (ggtags-cache-mark-dirty root nil) (message "ggtags: error running 'global -u'"))) - (if (ggtags-cache-stale-p root) - (let ((tags (ggtags-ignore-file-error - (split-string - (with-output-to-string - (call-process "global" nil (list standard-output nil) - nil "-cT" (or prefix ""))))))) - (when tags - (ggtags-cache-set root tags)) - tags) - (cadr (ggtags-cache-get root))))) + (apply 'append (mapcar (lambda (r) + (ggtags-tag-names-1 r prefix)) + (cons root (ggtags-get-libpath)))))) (defun ggtags-read-tag (quick) (ggtags-ensure-root-directory) @@ -172,6 +193,11 @@ Return -1 if it does not exist." (format (if default "Tag (default %s): " "Tag: ") default) tags nil t nil nil default))))) +(defvar ggtags-global-options + (concat "-v --result=grep" + (and ggtags-global-has-path-style " --path-style=shorter")) + "Options (as a string) for running `global'.") + ;;;###autoload (defun ggtags-find-tag (name &optional verbose) "Find definitions or references to tag NAME by context. @@ -187,11 +213,13 @@ When called with prefix, ask the name and kind of tag." (default-directory (ggtags-root-directory))) (compilation-start (if verbose - (format "global -v%s --result=grep \"%s\"" + (format "global %s %s \"%s\"" + ggtags-global-options (if (y-or-n-p "Kind (y for definition n for reference)? ") - "" "r") + "" "-r") name) - (format "global -v --result=grep --from-here=%d:%s \"%s\"" + (format "global %s --from-here=%d:%s \"%s\"" + ggtags-global-options (line-number-at-pos) (expand-file-name buffer-file-name) name)) @@ -356,8 +384,7 @@ When called with prefix, ask the name and kind of tag." "Kill all buffers visiting files in the root directory." (interactive "p") (ggtags-check-root-directory) - (let ((gtagslibpath (split-string (or (getenv "GTAGSLIBPATH") "") ":" t)) - (root (ggtags-root-directory)) + (let ((root (ggtags-root-directory)) (count 0) (some (lambda (pred list) (loop for x in list when (funcall pred x) return it)))) @@ -367,7 +394,7 @@ When called with prefix, ask the name and kind of tag." (buffer-file-name buf)))) (when (and file (funcall some (apply-partially #'file-in-directory-p (file-truename file)) - (cons root gtagslibpath))) + (cons root (ggtags-get-libpath)))) (and (kill-buffer buf) (incf count))))) (and interactive @@ -442,10 +469,6 @@ When called with prefix, ask the name and kind of tag." (forward-line (1- line)) (ggtags-move-to-tag name))) -;; NOTE: `ggtags-build-imenu-index' is signficantly faster and more -;; precise than the similar feature provided by cc mode. Tested with -;; ClassFileWriter.java of the rhino project. - ;;;###autoload (defun ggtags-build-imenu-index () "A function suitable for `imenu-create-index-function'."