[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 20/38: Teach ggtags-find-tag-dwim to detect #include files
From: |
Leo Liu |
Subject: |
[elpa] 20/38: Teach ggtags-find-tag-dwim to detect #include files |
Date: |
Mon, 24 Mar 2014 09:31:35 +0000 |
leoliu pushed a commit to branch master
in repository elpa.
commit e6f5b3801ec65cb94ae9ad19898e1a3fec191b83
Author: Leo Liu <address@hidden>
Date: Mon Mar 17 11:24:06 2014 +0800
Teach ggtags-find-tag-dwim to detect #include files
New user variable ggtags-include-pattern.
---
ggtags.el | 69 +++++++++++++++++++++++++++++++++++++++++-------------------
1 files changed, 47 insertions(+), 22 deletions(-)
diff --git a/ggtags.el b/ggtags.el
index b5118ad..3f437b6 100644
--- a/ggtags.el
+++ b/ggtags.el
@@ -108,6 +108,16 @@ automatically switches to 'global --single-update'."
number)
:group 'ggtags)
+(defcustom ggtags-include-pattern
+ '("^\\s-*#\\(?:include\\|import\\)\\s-*[\"<]\\(.*?\\)[\">]" . 1)
+ "Pattern used to detect #include files.
+Value can be (REGEXP . SUB) or a function with no arguments."
+ :type '(choice (const :tag "Disable" nil)
+ (cons regexp integer)
+ function)
+ :safe 'stringp
+ :group 'ggtags)
+
(defcustom ggtags-global-always-update nil
"If non-nil always update tags for current file on save."
:safe 'booleanp
@@ -693,31 +703,46 @@ non-nil."
(ggtags-global-start (apply #'ggtags-global-build-command cmd args)))
;;;###autoload
-(defun ggtags-find-tag-dwim (name &optional definition)
+(defun ggtags-find-tag-dwim (name &optional what)
"Find definitions or references of tag NAME by context.
If point is at a definition tag, find references, and vice versa.
-With a prefix arg (non-nil DEFINITION) always find definitions."
- (interactive (list (ggtags-read-tag 'definition current-prefix-arg)
- current-prefix-arg))
+With a prefix arg always find definitions. If point is at a line
+that matches `ggtags-include-pattern', find the include file
+instead."
+ (interactive
+ (let ((include (and (not current-prefix-arg)
+ ggtags-include-pattern
+ (save-excursion
+ (beginning-of-line)
+ (if (functionp ggtags-include-pattern)
+ (funcall ggtags-include-pattern)
+ (and (looking-at (car ggtags-include-pattern))
+ (match-string (cdr
ggtags-include-pattern))))))))
+ (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
- (if (or definition
- (not buffer-file-name)
- (and (ggtags-find-project)
- (not (ggtags-project-has-refs (ggtags-find-project)))))
- (ggtags-find-tag 'definition name)
- (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")))))
- name)))
+ (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)))))
+ (ggtags-find-tag 'definition 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")))))
+ name))))
(defun ggtags-find-reference (name)
(interactive (list (ggtags-read-tag 'reference current-prefix-arg)))
- [elpa] 09/38: Replace ignore-errors with condition-case-unless-debug, (continued)
- [elpa] 09/38: Replace ignore-errors with condition-case-unless-debug, Leo Liu, 2014/03/24
- [elpa] 10/38: Automatically use GTAGSCONF file at project root, Leo Liu, 2014/03/24
- [elpa] 05/38: Improve completion support for all tag types, Leo Liu, 2014/03/24
- [elpa] 11/38: Make last change acutally work, Leo Liu, 2014/03/24
- [elpa] 12/38: Fix compatibility for locate-dominating-file, Leo Liu, 2014/03/24
- [elpa] 14/38: Display project root directory name on mode-line, Leo Liu, 2014/03/24
- [elpa] 22/38: New command ggtags-navigation-isearch-forward, Leo Liu, 2014/03/24
- [elpa] 17/38: Fix ggtags-with-current-project to include GTAGSCONF, Leo Liu, 2014/03/24
- [elpa] 19/38: Use read-only-mode in ggtags-toggle-project-read-only, Leo Liu, 2014/03/24
- [elpa] 18/38: Fix #36: Allow customising path to global's exectuables, Leo Liu, 2014/03/24
- [elpa] 20/38: Teach ggtags-find-tag-dwim to detect #include files,
Leo Liu <=
- [elpa] 25/38: Fix ggtags-find-project to check on the GTAGS file, Leo Liu, 2014/03/24
- [elpa] 23/38: Simplify ggtags-save-to-register by always re-do the search, Leo Liu, 2014/03/24
- [elpa] 21/38: Add new command ggtags-save-to-register for #37, Leo Liu, 2014/03/24
- [elpa] 16/38: Fix ggtags-show-definition to run in current project, Leo Liu, 2014/03/24
- [elpa] 24/38: Fix thinko in "Don't display buffer if ggtags-navigation-mode is exited", Leo Liu, 2014/03/24
- [elpa] 26/38: New macro ignore-errors-unless-debug and use it, Leo Liu, 2014/03/24
- [elpa] 15/38: Small fixes to last change, Leo Liu, 2014/03/24
- [elpa] 32/38: Bind ggtags-save-to-register in ggtags-global-rerun-search-map, Leo Liu, 2014/03/24
- [elpa] 28/38: New helper ggtags-forward-to-line and use it, Leo Liu, 2014/03/24
- [elpa] 27/38: Cosmetic change: Fix indentation, Leo Liu, 2014/03/24