all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* imenu-generic-expression appropriate for different major modes
@ 2024-07-30 18:49 Heime
  0 siblings, 0 replies; only message in thread
From: Heime @ 2024-07-30 18:49 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor

Would there be more convenient ways to define `imenu-generic-expression'
appropriate for different major modes ?


(defun vodil-imenu-expr ()
  "Set up `imenu` based on the major mode."

  (interactive)
  (setq imenu-generic-expression
        (cond
         ;; For Emacs Lisp modes
         ((derived-mode-p 'emacs-lisp-mode)
          `(("Functions"
             ,(concat "^\\s-*"
                      "(defun"
                      "\\s-+\\([[:word:]-]+\\)") 1)
            ("Variables"
             ,(concat "^\\s-*"
                      "(\\(defvar\\|defvar-local\\|defconst\\)"
                      "\\s-+\\([[:word:]-]+\\)") 2) ))

         ;; For other modes, add custom expressions here
         ;; Example for hypothetical "foo-mode"
         ((derived-mode-p 'foo-mode)
          `(("Foo Functions"
             ,(concat "^\\s-*"
                      "foo-function"
                      "\\s-+\\([[:word:]-]+\\)") 1)
            ("Foo Variables"
             ,(concat "^\\s-*"
                      "foo-variable"
                      "\\s-+\\([[:word:]-]+\\)") 1)))

         ;; Default case if no specific configuration
         (t nil)))




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-07-30 18:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-30 18:49 imenu-generic-expression appropriate for different major modes Heime

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.