leoliu pushed a commit to branch master in repository elpa. commit 1f2e97b967bf6e383c92d19c900af9c11ab74195 Author: Leo Liu <sdl....@gmail.com> Date: Mon Apr 14 22:57:28 2014 +0800
Fix #48: Enhance ggtags-find-tag-dwim to handle new files New functions ggtags-project-relative-file, ggtags-project-file-p and ggtags-update-tags-single. --- ggtags.el | 54 ++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 36 insertions(+), 18 deletions(-) diff --git a/ggtags.el b/ggtags.el index c7a0673..7a93335 100644 --- a/ggtags.el +++ b/ggtags.el @@ -601,6 +601,26 @@ Value is new modtime if updated." (and path (mapcar (apply-partially #'concat (file-remote-p default-directory)) (split-string path (regexp-quote path-separator) t))))) +(defun ggtags-project-relative-file (file) + "Get file name relative to current project root." + (ggtags-check-project) + (if (file-name-absolute-p file) + (file-relative-name file (if (string-prefix-p (ggtags-current-project-root) + file) + (ggtags-current-project-root) + (locate-dominating-file file "GTAGS"))) + file)) + +(defun ggtags-project-file-p (file) + "Return non-nil if FILE is part of current project." + (when (ggtags-find-project) + (with-temp-buffer + (ggtags-with-current-project + (process-file (ggtags-program-path "global") nil t nil + "-vP" (concat "^" (ggtags-project-relative-file file) "$"))) + (goto-char (point-min)) + (not (re-search-forward "^file not found" nil t))))) + (defun ggtags-create-tags (root) "Create tag files (e.g. GTAGS) in directory ROOT. If file .globalrc or gtags.conf exists in ROOT, it will be used @@ -658,6 +678,11 @@ Do nothing if GTAGS exceeds the oversize limit unless FORCE." (setf (ggtags-project-dirty-p (ggtags-find-project)) nil) (setf (ggtags-project-mtime (ggtags-find-project)) (float-time)))))) +(defun ggtags-update-tags-single (file &optional nowait) + (ggtags-with-current-project + (process-file (ggtags-program-path "global") nil (and nowait 0) nil + "--single-update" (ggtags-project-relative-file file)))) + (defun ggtags-delete-tags () "Delete file GTAGS, GRTAGS, GPATH, ID etc. generated by gtags." (interactive (ignore (ggtags-check-project))) @@ -834,28 +859,23 @@ definition tags." (if include (list include 'include) (list (ggtags-read-tag 'definition current-prefix-arg) (and current-prefix-arg 'definition))))) - (ggtags-check-project) ; For `ggtags-current-project-root' below. + (ggtags-check-project) ; For `ggtags-current-project-root' below. (cond ((eq what 'include) (ggtags-find-file name)) ((or (eq what 'definition) (not buffer-file-name) (and (ggtags-find-project) - (not (ggtags-project-has-refs (ggtags-find-project))))) + (not (ggtags-project-has-refs (ggtags-find-project)))) + (not (ggtags-project-file-p buffer-file-name))) (ggtags-find-tag 'definition (shell-quote-argument name))) - (t (ggtags-find-tag - (format "--from-here=%d:%s" - (line-number-at-pos) - (shell-quote-argument - ;; Note `ggtags-global-start' binds default-directory to - ;; project root. - (file-relative-name - buffer-file-name - (if (string-prefix-p (ggtags-current-project-root) - buffer-file-name) - (ggtags-current-project-root) - (locate-dominating-file buffer-file-name "GTAGS"))))) - (shell-quote-argument name))))) + (t (ggtags-find-tag (format "--from-here=%d:%s" + (line-number-at-pos) + (shell-quote-argument + ;; Note `ggtags-global-start' binds + ;; default-directory to project root. + (ggtags-project-relative-file buffer-file-name))) + (shell-quote-argument name))))) (defun ggtags-find-reference (name) (interactive (list (ggtags-read-tag 'reference current-prefix-arg))) @@ -1688,9 +1708,7 @@ commands `next-error' and `previous-error'. ;; When oversize update on a per-save basis. (when (and buffer-file-name (or ggtags-global-always-update (ggtags-project-oversize-p))) - (ggtags-with-current-project - (process-file (ggtags-program-path "global") nil 0 nil "--single-update" - (file-relative-name buffer-file-name)))))) + (ggtags-update-tags-single buffer-file-name 'nowait)))) (defun ggtags-global-output (buffer cmds callback &optional cutoff) "Asynchronously pipe the output of running CMDS to BUFFER.