使用`emacs-helm-ag`直接搜索文件名的交互式Elisp函数(-g选项)

时间:2018-01-27 09:41:45

标签: emacs ag emacs-helm

我使用Instant来搜索项目中的文件内容和文件名。我的emacs-helm-ag配置是:

; Helm Ag mode
(add-to-list 'load-path "~/.emacs.d/emacs-helm-ag")
(require 'helm-ag)
(custom-set-variables
    '(helm-ag-base-command "ag --nocolor --nogroup")
    '(helm-ag-command-option "--hidden --ignore *~ --ignore .git --ignore .idea"))
(global-set-key (kbd "M-s s") 'helm-do-ag-project-root)

要搜索文件内容(所有项目文件中的一个字词),请按M-s s并输入要搜索的字词。

要搜索文件名(项目所有文件列表中的文件),请按M-s s然后我必须输入-g(我想自动执行)这一步)然后我输入要搜索的文件名。

问题即可。请你帮我提出一个elisp交互式功能,通过自动插入-g命令行选项直接搜索项目中的文件名(最好重用helm-do-ag-project-root来自emacs-helm-ag })并且只需要最终用户输入文件名。我想有一个交互式功能来搜索项目中的文件名,并能够使用不同的键绑定调用该函数。类似于:

(global-set-key (kbd "M-s f") 'helm-do-ag-project-root-file-names)

1 个答案:

答案 0 :(得分:0)

根据DasEwigeLicht on Reddit的建议,我创建了一个函数,根据我的问题的要求,使用(defun helm-do-ag-project-root-search-file-names () "Searches file names in a project using ag -g <pattern> command line tool" (interactive) (let ((helm-ag-command-option (concat helm-ag-command-option " -g"))) (helm-do-ag-project-root))) (global-set-key (kbd "M-s f") 'helm-do-ag-project-root-search-file-names) 在项目中搜索文件名。功能是:

<div class="contentHolder">

<div class="p_img"></div>

<div class="txtHolder">
<p>Hello wordl, this is some dummy text that goes here very nicely and tidy... Enjoy reading me when you can...Hello wordl, this is some dummy text that goes here very nicely and tidy... Enjoy reading me when you can...Hello wordl, this is some dummy text that goes here very nicely and tidy... Enjoy reading me when you can...</p>
</div>

</div>

<div class="cartBtn">
Add to cart
</div>

非常感谢DasEwigeLicht提供了有用的建议!