[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Functions which are mode dependent
From: |
Heime |
Subject: |
Re: Functions which are mode dependent |
Date: |
Tue, 20 Aug 2024 21:49:14 +0000 |
On Monday, August 19th, 2024 at 9:14 AM, Heime <heimeborgia@protonmail.com>
wrote:
> I need some help understanding how to automatically enable some functionality
> when loading a file with some major mode.
>
> For instance I have a function that sets
>
>
> (defun expr-elisp ()
>
> (setq imenu-generic-expression
> `( ("defun" ,(concat "^\\s-*"
> "(\\(defun\\|define-minor-mode\\)\\s-+"
> "\\(\\(\\sw\\|\\s_\\)+\\)") 2) )) )
>
>
> (defun expr-selector ()
>
> (cond
> ((eq major-mode 'emacs-lisp-mode) (expr-elisp))
> (t (expr-generic)) ))
>
> I have put the code above in a minor mode.
>
> ;;;###autoload
> (define-minor-mode tema-minor-mode
>
> (if tema-minor-mode
> (expr-selector)
> (message "Tema Deactivated")))
>
> with hooks to load the minor mode automatically for specific major modes.
>
> (add-hook emacs-lisp-mode-hook #'tema-minor-mode)
My confusion is whether after making the minor-mode hooked to emacs-lisp-mode,
should I also make a hook to the function as well ?
That is
(add-hook emacs-lisp-mode-hook #'expr-selector)
Is this check the correct way to apply the correct expr-elisp
when emacs-lisp-mode is activated when I load an elisp file ?
(eq major-mode 'emacs-lisp-mode) (expr-elisp)