Is there any package which will allow to run the imenu in all project files of a current mode? More specifically I have a Go project defined by projectile and I would like to search for a symbol in the whole project. I know about imenu-anywhere - but it only searches through symbols in opened buffers.

  • I'd like to be able to do this too -- this is why I seem to have 200 buffers open all the time :) Jun 13, 2020 at 22:32

2 Answers 2


My solution is way too hacky:

A file that you want to have Imenu to access is likely to be tracked by Git.

Use find-file-noselect on all those files (I don't know how to detect binary files with Emacs so limiting on VCS-tracked files is better), and accept the risk of hooks and advices, auto-loading functions, etc.

(defun open-project-files-in-background ()
  "Open/find all source files in the background which are tracked by Git."
  (let ((default-directory (vc-root-dir)))
      (dolist (file (split-string (shell-command-to-string "git ls-files")))
        (unless (find-buffer-visiting file)
          (with-current-buffer (find-file-noselect file)
            (if (equal (get major-mode 'derived-mode-parent) 'prog-mode)

(defun open-project-files-in-background-maybe (&rest _args)
  "Prepare a project-wide `Imenu'."
  ;; 'vc-root-dir returns nil when not tracked, so checking if (not
  ;; that it is in a list that contains nil) is enough for both
  ;; (non-nil and in the list of fully opened projects)
  (defvar fully-opened-projects '(nil) "List of project paths, each has all tracked files opened.")
  (let ((git-dir (vc-root-dir)))
    (unless (member git-dir fully-opened-projects)
      (push git-dir fully-opened-projects))))

(advice-add 'imenu-anywhere :before 'open-project-files-in-background-maybe)

Imenu is for open buffers.

Consider using a command such as find-grep-dired, find-dired, find-name-dired, find-time-dired, or xref-find-definitions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.