Is there a way to get emacs tag-search command to output all results to a buffer?

不问归期 提交于 2019-12-10 14:57:27

问题


Is there a way to get Emacs tags-search command to collect all search results in a buffer? Something like the way results from 'grep' and 'tags-apropos' are collected in a compilation buffer?

Using M-, to iterate over the results isn't very effective if there are a large number of hits, so it'd be great if there was a way to browse and search through the results in a buffer.

Thanks,

Benj


回答1:


Try etags-select




回答2:


I misinterpreted your question in my first answer. Here's something that works, but is kind of bad in that it uses synchronous calls to grep so everything blocks while it's working. Improvements are left as an exercise to the reader:

(require 'etags)
(require 'grep)

(defun tags-search-sel (regexp)
  "Search through all files listed in tags table for match for REGEXP.
Show all matches at once."
  (interactive "sTags search (regexp): ")
  ;; Get all unique filenames in TAGS files.
  (let ((keep-going t) files)
    (when (visit-tags-table-buffer)
      (while keep-going
        (save-excursion
          (goto-char (point-min))
          (while (re-search-forward "\f\n\\([^\n]+\\),[0-9]*\n" nil t)
            (add-to-list 'files
                         (expand-file-name
                          (buffer-substring (match-beginning 1) (match-end 1))
                          (file-truename default-directory)))))
        (setq keep-going (visit-tags-table-buffer t))))
    ;; grep through every file for regexp
    (when files
      (grep-compute-defaults)
      (let ((outbuf (get-buffer-create "*tags-search-sel*")))
        (with-current-buffer outbuf
          (setq buffer-read-only nil)
          (erase-buffer)
          (insert "Searching for '" regexp "' in tags files ...\n\n")
          (dolist (file files)
            (call-process-shell-command (concat grep-command regexp " " file) nil t))
          (grep-mode)
          (setq overlay-arrow-position nil)
          (set-buffer-modified-p nil)
          (setq buffer-read-only t)
          (goto-char (point-min)))
        (pop-to-buffer outbuf)))))



回答3:


See icicle-tags-search. It lets you search all source files listed in tags tables for matches for a given regexp.

You see all matches of the regexp in the source-code files, as search hits to visit. All tags in a given tags file are used, including duplicate tags from the same or different source files.

By default, all tags files are used, but if you provide a prefix argument then only the current tag table is used.

Search for matches, with completion, cycling, and search-hit replacement.

After specifying the regexp that defines the search contexts, type input (e.g. regexp or other pattern) to match within the contexts. The contexts that match your input are available as completion candidates. You can use S-SPC to further narrow the candidates, typing additional patterns to match.

By default, candidates are in order of buffer occurrence, but you can sort them in various ways using C-,.

You can alternatively choose to search, not the search contexts as defined by the context regexp you provide, but the non-contexts, that is, the text in the files that does not match the regexp. To do this, use C-M-~ during completion. (This is a toggle, and it affects only future search commands, not the current one.)

See the doc for command icicle-search for more information.



来源:https://stackoverflow.com/questions/4262887/is-there-a-way-to-get-emacs-tag-search-command-to-output-all-results-to-a-buffer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!