-
Notifications
You must be signed in to change notification settings - Fork 621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request: filename related functions in readtags expressions #3168
Comments
I assume "resolve relative file name" can be solved easily. |
Maybe it's not that hard ;) Here's a prototype in Elisp: (defun common-prefix-length (str1 str2)
(pcase (compare-strings str1 nil nil
str2 nil nil)
('t (length str1))
((and result (guard (< result 0))) (- -1 result))
((and result (guard (> result 0))) (- result 1))))
(defun file-nearness (start to)
(let* ((start (expand-file-name start))
(to (expand-file-name to))
(common-prefix-length (common-prefix-length start to))
(rest-part (substring start common-prefix-length))
(separators 0))
(if (= common-prefix-length (length start) (length to))
0
(dotimes (i (length rest-part))
(when (memq (aref rest-part i) '(?/ ?\\))
(setq separators (1+ separators))))
(1+ separators))))
(file-nearness "~/path/to/abc.c" "~/path/to/abc.c")
;; => 0
(file-nearness "~/path/to/abc.c" "~/path/to/a.h")
;; => 1
(file-nearness "~/path/to/abc.c" "~/path/to/foo/abc.c")
;; => 1
(file-nearness "~/path/to/abc.c" "~/path/too/abc.c")
;; => 2
(file-nearness "~/path/to/abc.c" "~/foo")
;; => 3 |
I misunderstood the issue; it seems that we have to add an operator. |
Partially close universal-ctags#3168. TODO: * revise code, * update the readtags.1 man page, * consider Windows, and * add test cases. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
I implemented |
Partially close universal-ctags#3168. TODO: * revise code, * update the readtags.1 man page, * consider Windows, and * add test cases. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Partially close universal-ctags#3168. TODO: * revise code, * update the readtags.1 man page, * consider Windows, and * add test cases. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Partially close universal-ctags#3168. TODO: * revise code, * update the readtags.1 man page, * consider Windows, and * add test cases. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Partially close universal-ctags#3168. TODO: * revise code, * update the readtags.1 man page, * consider Windows, and * add test cases. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Partially close universal-ctags#3168. TODO: * revise code, * update the readtags.1 man page, * consider Windows, and * add test cases. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Partially close universal-ctags#3168. TODO: * revise code, * update the readtags.1 man page, * consider Windows, and * add test cases. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Partially close universal-ctags#3168. TODO: * revise code, Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Partially close universal-ctags#3168. TODO: * revise code, Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Partially close universal-ctags#3168. TODO: * revise code, Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Partially close universal-ctags#3168. TODO: * revise code, Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Partially close universal-ctags#3168. TODO: * revise code, Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Partially close universal-ctags#3168. TODO: * revise code, Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Partially close universal-ctags#3168. TODO: * revise code, Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Partially close universal-ctags#3168. TODO: * revise code, Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Partially close universal-ctags#3168. TODO: * revise code, Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Partially close universal-ctags#3168. TODO: * revise code, Signed-off-by: Masatake YAMATO <yamato@redhat.com>
"Sort by nearness" is not solved yet. |
Currently I don't know what exactly is needed, but there are 2 motivations behind this request, I hope they can guide us.
resolve relative file name
When finding definitions, the user may want to exclude file-local symbols that's not in current file. The predicate "not in current file" is actually not a simple one. Here's a one generated by Citre (if you are interested, it's in here)
Suppose the current file is
/path/to/test.el
, andTAG_PROC_CWD
is/path/to/
, then the input field of this file should either betest.el
(when its relative) or/path/to/test.el
(when its absolute). So where does the regexp matching against(^|/)..?/test\\.el$
comes from?This is because a user reported that if you tag the current dir by:
You get tags like this:
I soon realized that the input field can look like anything, e.g., you can feed a path like
../../path/to/
to the ctags command, and it could mean the same as/path/to
.At the end, what I did is: when there's a
/./
or/../
in the input field, and it ends withtest.el
, we think it is the file/path/to/test.el
. This is not correct, but is the best I can do for now.Since there are infinite possibilities, direct matching against the input field simply can't solve the problem. We must somehow transform
$input
to a standard representation, then match against it.Sort by nearness
This is a very nice feature I found in GNU Global. I'll paste its documentation here:
Simply puts it, file that are "near" to the current file is put above those "far" from the current file. This is handy when finding references, but I think readtags could also benefit from this, since:
The text was updated successfully, but these errors were encountered: