查找文件:获取由包含文本的过滤器指定的文件的重复缓冲区

发布于 2024-08-18 03:00:57 字数 310 浏览 8 评论 0原文

这似乎是一个非常典型的用例,但如果我能弄清楚的话,我就该死了。我一定缺少一些基本的东西。

find-dired 基本上是 find 命令的前端,它生成结果的 dired 缓冲区

find-grep-dired 似乎比 find 更像是 grep 的前端。并产生一个 dired-buffer,但它搜索目录树中的所有文件。

我想要的是能够从给定路径开始并搜索 *.css 中的 #some-id 并让它为我提供一个 dired-buffer 以供进一步处理。

似乎所有的部分都在那里,但我还没弄清楚。所以我认为这是我可能错过的一些基本的东西。

This seems like a pretty typical use case, but I'll be damned if I can figure it out. There must be something fundamental I'm missing.

find-dired is basically a front end to the find command that yields a dired-buffer of results

find-grep-dired seems to be more of a front end to grep more so than find. and yields a dired-buffer but it searches all files in the directory tree.

What I would like is the ability to start at a given path and search *.css for #some-id and have it give me a dired-buffer for further processing.

Seems all the pieces are there but I haven't figured it out. So I'm thinking it's something fundamental I may have missed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

叹倦 2024-08-25 03:00:57

听起来您正在寻找的功能是 grep< /a>.它将使用您提供的表达式调用 grep 实用程序,并将输出收集在交互式缓冲区中。您可以选择缓冲区中的任何匹配行来跳转到匹配所在文件中的该行。

例如,如果您运行 Mx grep,您应该在迷你缓冲区中收到以下提示:

运行 grep (like this): grep -n

然后添加正则表达式以及要传递给 grep 的 glob 模式:

运行 grep (如下所示):grep -n #some-id *.css

它应该为您提供 #some 的匹配列表-id 在当前目录中所有与 *.css 匹配的文件中。如果你想递归子目录,那么你需要使用 rgrep 而不是 grep。这听起来像您正在寻找的东西,还是我完全误解了您的要求?

It sounds like the function you are looking for is grep. It will call the grep utility with the expression you give it, and collect the output in an interactive buffer. You may select any of the match lines in the buffer to jump to that line in the file that the match is from.

For example, if you run M-x grep, you should get the following prompt in the mini-buffer:

Run grep (like this): grep -n

Then you add the regexp and glob pattern that you want to pass to grep:

Run grep (like this): grep -n #some-id *.css

And it should give you a list of matches for #some-id in all the files matching *.css in the current directory. If you want to recurse through sub-directories, then you need to use rgrep instead of grep. Does this sound like what you are looking for, or have I completely misunderstood your request?

冷情 2024-08-25 03:00:57

这有点晚了,但这是我经常使用的 emacs-lisp 函数:

(defun find-iname-grep-dired (dir pattern regexp)
  (interactive
   "DFind-name (directory): \nsFind-name (filename wildcard): \nsFind-grep (grep regexp): ")
  (find-dired dir (concat "-iname " (shell-quote-argument pattern) " "
                          "-type f -exec " grep-program " " find-grep-options " -e "
                          (shell-quote-argument regexp) " "
                          (shell-quote-argument "{}") " "
                          (shell-quote-argument ";"))))

它将 find-grep-diredfind-name-dired 与不区分大小写的文件结合在一起名称匹配。

This is a bit late, but here is the emacs-lisp function I use regularly:

(defun find-iname-grep-dired (dir pattern regexp)
  (interactive
   "DFind-name (directory): \nsFind-name (filename wildcard): \nsFind-grep (grep regexp): ")
  (find-dired dir (concat "-iname " (shell-quote-argument pattern) " "
                          "-type f -exec " grep-program " " find-grep-options " -e "
                          (shell-quote-argument regexp) " "
                          (shell-quote-argument "{}") " "
                          (shell-quote-argument ";"))))

It combines find-grep-dired and find-name-dired with case-insensitive file name matching.

菊凝晚露 2024-08-25 03:00:57

我会把功劳归功于 A. Levy。但我想我已经明白了。看来 find-dired 确实是完成这项工作的工具,但在我的 Windows 机器上,它不会用“-exec grep”预先填充参数,而且我并没有意识到要这样做。然而,我的 Linux 机器确实用 grep 预先填充了它。

所以....

  #on Linux
  M-x find-dired
  Run Find in Directory: <current_path> 
  Run find(with args): -type f -exec grep -q -e \{\} \; 

  #on windows
  M-x find-dired
  Run Find in Directory: <current_path> 
  Run find(with args): 

  #Solution
  M-x find-dired
  Run Find in Directory: <current_path> 
  Run find(with args): -type f -iname "*.css" -exec grep -q -e #some-id \{\} \; 

I'll give A. Levy credit. But I think I figured it out. It seems that find-dired is indeed the tool for the job, but on my windows machine it doesn't pre-fill the args with "-exec grep" and it didn't dawn on me to do that. My linux machine however does pre-fill it with grep.

So....

  #on Linux
  M-x find-dired
  Run Find in Directory: <current_path> 
  Run find(with args): -type f -exec grep -q -e \{\} \; 

  #on windows
  M-x find-dired
  Run Find in Directory: <current_path> 
  Run find(with args): 

  #Solution
  M-x find-dired
  Run Find in Directory: <current_path> 
  Run find(with args): -type f -iname "*.css" -exec grep -q -e #some-id \{\} \; 
つ可否回来 2024-08-25 03:00:57

你说(在评论中):

唯一缺少的是输出到一个可怕的缓冲区,这样我就可以一次选择/移动/复制所有这些文件

抱歉,直到现在我才看到这个问题。该功能可通过 Dired+ 获得。命令 diredp-grepped-files-other-windowgrep 命中指示的文件上打开 Dired。 (它也适用于从 compilation-mode 派生的任何其他模式。)

You said (in a comment):

the only thing missing is outputting to a dired buffer so I can do things like select/move/copy all those files at once

Sorry I didn't see this question until now. That feature is available with Dired+. Command diredp-grepped-files-other-window opens Dired on the files indicated by grep hits. (It also works for any other mode derived from compilation-mode.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文