开发者

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

开发者 https://www.devze.com 2023-01-26 09:20 出处:网络
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?

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开发者_如何学C 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


Try etags-select


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)))))


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号