emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] 07/18: Refactor out ggtags-include-file from ggtags-find-tag-dwim


From: Leo Liu
Subject: [elpa] 07/18: Refactor out ggtags-include-file from ggtags-find-tag-dwim
Date: Sat, 05 Apr 2014 01:25:15 +0000

leoliu pushed a commit to branch master
in repository elpa.

commit 828546825bac86b1ea29875f5e31c5d51f0db7ca
Author: Leo Liu <address@hidden>
Date:   Wed Apr 2 08:44:44 2014 +0800

    Refactor out ggtags-include-file from ggtags-find-tag-dwim
    
    Do not move point to the beginning of line if ggtags-include-pattern
    is a function otherwise it cannot access the value of point.
---
 ggtags.el |   26 +++++++++++++++++---------
 1 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/ggtags.el b/ggtags.el
index 4acf610..dfe7a6e 100644
--- a/ggtags.el
+++ b/ggtags.el
@@ -129,7 +129,8 @@ automatically switches to 'global --single-update'."
 (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."
+Value can be (REGEXP . SUB) or a function with no arguments.
+REGEXP should match from the beginning of line."
   :type '(choice (const :tag "Disable" nil)
                  (cons regexp integer)
                  function)
@@ -761,6 +762,20 @@ Do nothing if GTAGS exceeds the oversize limit unless 
FORCE."
   (ggtags-check-project)
   (ggtags-global-start (apply #'ggtags-global-build-command cmd args)))
 
+(defun ggtags-include-file ()
+  "Calculate the include file based on `ggtags-include-pattern'."
+  (pcase ggtags-include-pattern
+    (`nil nil)
+    ((pred functionp)
+     (funcall ggtags-include-pattern))
+    (`(,re . ,sub)
+     (save-excursion
+       (beginning-of-line)
+       (and (looking-at re) (match-string sub))))
+    (_ (warn "Invalid value for `ggtags-include-pattern':%s"
+             ggtags-include-pattern)
+       nil)))
+
 ;;;###autoload
 (defun ggtags-find-tag-dwim (name &optional what)
   "Find NAME by context.
@@ -771,14 +786,7 @@ the include file instead.
 When called interactively with a prefix arg, always find
 definition tags."
   (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))))))))
+   (let ((include (and (not current-prefix-arg) (ggtags-include-file))))
      (if include (list include 'include)
        (list (ggtags-read-tag 'definition current-prefix-arg)
              (and current-prefix-arg 'definition)))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]