How can I define an Elisp function such that it is available only under a specific mode?
(FWIW, at the moment, the mode I want to restrict a function to is comint
.)
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityYou can't. But you can do either of the following:
When the function is invoked, it can test the current mode and do something appropriate. For example, for some modes, or all modes except some modes, it can be a no-op or it can raise an error.
If it is a command, you can ensure that it is not bound to a key in some modes, or in all modes except some modes.
Well, there is a way to make a function or variable essentially invisible in a given context, and that is to put its symbol in a different obarray from the default obarray. You can think of an obarray as a kind of a namespace.
If you are a relative novice then I wouldn't recommend this, but if this is really what you need then go for it. If you want an example of such use, you can take a look at library synonyms.el
(description).