You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于emacs-helm-ag的项目文件名直接搜索Elisp函数开发需求

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 or M-x.
  • We pass "-g" as the third argument to helm-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-ag configuration (like --hidden, .git ignores, 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:32:36