all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Make function callable from some specific major-mode
@ 2022-10-20  0:59 Heime via Users list for the GNU Emacs text editor
  2022-10-20  1:26 ` Stefan Monnier via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 2+ messages in thread
From: Heime via Users list for the GNU Emacs text editor @ 2022-10-20  0:59 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor

How can I make a function callable only whilst in some specific major-mode?

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Make function callable from some specific major-mode
  2022-10-20  0:59 Make function callable from some specific major-mode Heime via Users list for the GNU Emacs text editor
@ 2022-10-20  1:26 ` Stefan Monnier via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2022-10-20  1:26 UTC (permalink / raw)
  To: help-gnu-emacs

Heime via Users list for the GNU Emacs text editor [2022-10-20 00:59:33] wrote:
> How can I make a function callable only whilst in some specific major-mode?

Usually: you don't (most of the time, it's a pointless effort: if the
users go through the trouble to call your function, then better presume
that they actually have a good reason to do so).

If that answer doesn't work, then the second answer: you don't, and
instead you test for a specific property on which your code depends (so
it will still be useful in a buffer using another mode, as long as your code
still makes sense there).

If you're still not satisfied because you really want to prevent users
from using your function even if it could be useful, then you test
(derived-mode-p '<THEMODE>) and signal an error if the test fails.

Another way is to add (declare (modes <THEMODES>)) to your function
definition: this won't prevent the function from being used elsewhere,
but it will tell `M-x` not to bother proposing this function if you're
not in one of the listed modes.


        Stefan




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-20  1:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-20  0:59 Make function callable from some specific major-mode Heime via Users list for the GNU Emacs text editor
2022-10-20  1:26 ` Stefan Monnier via Users list for the GNU Emacs text editor

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.