基于emacs-helm-ag的项目文件名直接搜索Elisp函数开发需求
Solution for Dedicated Helm-Ag Filename Search
Got it, let's build that handy filename search function you need—no more manually typing -g every time! Here's how to do it cleanly while reusing your existing helm-do-ag-project-root setup:
Step 1: Create the Interactive Function
Add this Elisp code to your Emacs configuration file:
(defun helm-do-ag-filename-project-root () "Interactive function to search filenames in the project root using helm-ag (auto-inserts -g flag)." (interactive) ;; Call helm-do-ag-project-root with the -g flag pre-filled (helm-do-ag-project-root nil nil "-g"))
How It Works:
- The
(interactive)declaration makes this function callable via keyboard shortcuts orM-x. - We pass
"-g"as the third argument tohelm-do-ag-project-root—this tells helm-ag to switch to filename search mode automatically, so you don't have to type it yourself. - This function inherits all your existing
helm-agconfiguration (like--hidden,.gitignores, etc.) so you don't need to repeat those settings.
Step 2: Bind to Your Preferred Shortcut
Add this line to bind the function to M-s f (or any shortcut you like):
(global-set-key (kbd "M-s f") 'helm-do-ag-filename-project-root)
Step 3: Test It Out
Save your config and restart Emacs (or evaluate the code with C-x C-e for each function/keybinding). Now:
- Press
M-s f - Type the filename (or part of it) you're looking for
- helm-ag will immediately show you matching files in your project root—no extra steps needed!
内容的提问来源于stack exchange,提问作者Volodymyr Prokopyuk
相关产品推荐
相关产品推荐

