[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 508e10c 4/6: Implement #99: New user option ggtags-sort-by
From: |
Leo Liu |
Subject: |
[elpa] master 508e10c 4/6: Implement #99: New user option ggtags-sort-by-nearness |
Date: |
Thu, 11 Jun 2015 23:19:43 +0000 |
branch: master
commit 508e10c82a589801759a0b6ce19fac08b7b9b9e8
Author: Leo Liu <address@hidden>
Commit: Leo Liu <address@hidden>
Implement #99: New user option ggtags-sort-by-nearness
---
README.rst | 2 ++
ggtags.el | 31 +++++++++++++++++++++++--------
2 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/README.rst b/README.rst
index e2475b7..28a1cd0 100644
--- a/README.rst
+++ b/README.rst
@@ -318,6 +318,8 @@ NEWS
#. Tags update on save is configurable by ``ggtags-update-on-save``.
#. New command ``ggtags-explain-tags`` to explain how each file is
indexed in current project. Global 6.4+ required.
+#. New user option ``ggtags-sort-by-nearness`` that sorts matched tags
+ by nearness to current directory.
[2015-01-16 Fri] 0.8.9
++++++++++++++++++++++
diff --git a/ggtags.el b/ggtags.el
index 750f3f0..e9f8792 100644
--- a/ggtags.el
+++ b/ggtags.el
@@ -206,6 +206,12 @@ isn't built with sqlite3 support."
:safe 'booleanp
:group 'ggtags)
+(defcustom ggtags-sort-by-nearness nil
+ "Sort tags by nearness to current directory."
+ :type 'boolean
+ :safe #'booleanp
+ :group 'ggtags)
+
(defcustom ggtags-update-on-save t
"Non-nil to update tags for current buffer on saving."
;; It is reported that `global --single-update' can be slow in sshfs
@@ -868,6 +874,10 @@ blocking emacs."
(default (substring-no-properties default))
(t (ggtags-read-tag type t prompt require-match default))))))
+(defun ggtags-sort-by-nearness-p ()
+ (and ggtags-sort-by-nearness
+ (ggtags-process-succeed-p "global" "--nearness" "--help")))
+
(defun ggtags-global-build-command (cmd &rest args)
;; CMD can be definition, reference, symbol, grep, idutils
(let ((xs (append (list (shell-quote-argument (ggtags-program-path "global"))
@@ -878,6 +888,7 @@ blocking emacs."
(ggtags-find-project)
(ggtags-project-has-color (ggtags-find-project))
"--color=always")
+ (and (ggtags-sort-by-nearness-p) "--nearness")
(and (ggtags-find-project)
(ggtags-project-has-path-style
(ggtags-find-project))
"--path-style=shorter")
@@ -939,7 +950,8 @@ blocking emacs."
(defun ggtags-find-tag (cmd &rest args)
(ggtags-check-project)
- (ggtags-global-start (apply #'ggtags-global-build-command cmd args)))
+ (ggtags-global-start (apply #'ggtags-global-build-command cmd args)
+ (and (ggtags-sort-by-nearness-p) default-directory)))
(defun ggtags-include-file ()
"Calculate the include file based on `ggtags-include-pattern'."
@@ -979,13 +991,16 @@ definition tags."
(not (ggtags-project-has-refs (ggtags-find-project)))
(not (ggtags-project-file-p buffer-file-name)))
(ggtags-find-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.
- (ggtags-project-relative-file
buffer-file-name)))
- (shell-quote-argument name)))))
+ (t (ggtags-find-tag
+ (format "--from-here=%d:%s"
+ (line-number-at-pos)
+ (shell-quote-argument
+ ;; Note `ggtags-find-tag' may bind `default-directory'
+ ;; to project root.
+ (funcall (if (ggtags-sort-by-nearness-p)
+ #'file-relative-name
#'ggtags-project-relative-file)
+ buffer-file-name)))
+ (shell-quote-argument name)))))
(defun ggtags-find-tag-mouse (event)
(interactive "e")
- [elpa] master updated (30984c4 -> 1d9cd5e), Leo Liu, 2015/06/11
- [elpa] master b030ebf 1/6: Avoid repeated file-error by eldoc due to missing global, Leo Liu, 2015/06/11
- [elpa] master c626959 2/6: For #85: New variable ggtags-update-on-save, Leo Liu, 2015/06/11
- [elpa] master d0b7f63 3/6: New command ggtags-explain-tags, Leo Liu, 2015/06/11
- [elpa] master 508e10c 4/6: Implement #99: New user option ggtags-sort-by-nearness,
Leo Liu <=
- [elpa] master 9efd5f6 5/6: Doc fix, Leo Liu, 2015/06/11
- [elpa] master 1d9cd5e 6/6: Merge branch 'master' of github.com:leoliu/ggtags, Leo Liu, 2015/06/11