0

我使用emacs-helm-ag在项目中搜索文件内容和文件名。我的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直接在项目中搜索文件名,并且只需要最终用户输入文件名。我想要一个交互式函数来搜索项目中的文件名,并能够使用不同的键绑定调用该函数。类似于:-ghelm-do-ag-project-rootemacs-helm-ag

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

1 回答 1

0

根据Reddit 上 DasEwigeLicht的建议,我创建了一个函数,该函数ag -g <pattern>根据我的问题中的要求在项目中搜索文件名。功能是:

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

非常感谢DasEwigeLicht的有用建议!

于 2018-01-27T19:17:00.860 回答