问题
Is it possible to use ido-mode completion to find definitions in a TAGS file? I suspect that ido-completing-read is part of the answer. Here's my non-working code, which shows an unpopulated ido-mode minibuffer:
(defun ido-choose-from-tags ()
"Use ido to select tags "
(interactive)
(etags-tags-apropos
(ido-completing-read "Tags: " nil t)))
回答1:
Kind of inefficient, but how about:
(defun my-ido-find-tag ()
"Find a tag using ido"
(interactive)
(tags-completion-table)
(let (tag-names)
(mapc (lambda (x)
(unless (integerp x)
(push (prin1-to-string x t) tag-names)))
tags-completion-table)
(find-tag (ido-completing-read "Tag: " tag-names))))
回答2:
To find definitions i use CEDET's command semantic-ia-fast-jump, that together with gtags from GNU Global gives proper and quick navigation through source files.
回答3:
Of course it's possible, this is EMACS. What does the non-working code do that tells you it isn't working?
My first suspicion is that it might work better if you used tags-apropos
(see about line 1885 in etags.el), seeing as etags-tags-apropos
isn't defined and all.
回答4:
See also, as an alternative: http://www.emacswiki.org/emacs/Icicles_-_Emacs_Tags_Enhancements
回答5:
An expansion of scottfrazer's solution:
(defun my-ido-find-tag ()
"Find a tag using ido"
(interactive)
(tags-completion-table)
(let* ((initial-input
(funcall (or find-tag-default-function
(get major-mode 'find-tag-default-function)
'find-tag-default)))
(initial-input-regex (concat "\\(^\\|::\\)" initial-input "$")))
(find-tag (ido-completing-read
"Tag: "
(sort
(remove nil
(mapcar (lambda (tag) (unless (integerp tag)
(prin1-to-string tag 'noescape)))
tags-completion-table))
;; put those matching initial-input first:
(lambda (a b) (string-match initial-input-regex a)))
nil
'require-match
initial-input))))
This puts tags matching tag-at-point at the head of the list. I guess you could secondarily sort by buffer-file-name if two tags match, but that might not always be what you want. Might be faster to use https://github.com/magnars/s.el#s-ends-with-suffix-s-optional-ignore-case than string-match for really huge tags tables.
来源:https://stackoverflow.com/questions/476887/can-i-get-ido-mode-style-completion-for-searching-tags-in-emacs