all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* extending a mode
@ 2017-10-29  1:43 Christopher Howard
  2017-10-29  3:35 ` Dan Hitt
  0 siblings, 1 reply; 3+ messages in thread
From: Christopher Howard @ 2017-10-29  1:43 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org

[-- Attachment #1: Type: text/plain, Size: 502 bytes --]

Hi, I wrote a simple command that I use when in Org mode, and probably
will write a few more in the course of time. I'm not sure if anybody
else besides me would ever use them. However, I want emacs to load
those commands when it enters Org mode. What is the simplest and/or
best way to do this? One trick I learned was that I could (add-hook)
and 'org-mode-hook with a defun in it; however, this causes the command
to be available under other modes as well.

-- 
https://answersingenesis.org/

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: extending a mode
  2017-10-29  1:43 extending a mode Christopher Howard
@ 2017-10-29  3:35 ` Dan Hitt
  2017-10-29  7:00   ` Drew Adams
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Hitt @ 2017-10-29  3:35 UTC (permalink / raw)
  To: Christopher Howard; +Cc: help-gnu-emacs@gnu.org

On Sat, Oct 28, 2017 at 6:43 PM, Christopher Howard
<christopher.howard@qlfiles.net> wrote:
> Hi, I wrote a simple command that I use when in Org mode, and probably
> will write a few more in the course of time. I'm not sure if anybody
> else besides me would ever use them. However, I want emacs to load
> those commands when it enters Org mode. What is the simplest and/or
> best way to do this? One trick I learned was that I could (add-hook)
> and 'org-mode-hook with a defun in it; however, this causes the command
> to be available under other modes as well.
>
> --
> https://answersingenesis.org/


Hi Christopher,

As soon as the defun is executed, i think that will make the function
available everywhere (dynamic scope vs. lexical scope).

So i think that much is expected.

But you should be able to run a piece of code with your add-hook that
will bind the command to some keys, and this binding will only be
available in a particular mode.

But maybe i'm missing your point?

If you post the add-hook think you've done, i think somebody around
here will figure it out though.

dan



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

* RE: extending a mode
  2017-10-29  3:35 ` Dan Hitt
@ 2017-10-29  7:00   ` Drew Adams
  0 siblings, 0 replies; 3+ messages in thread
From: Drew Adams @ 2017-10-29  7:00 UTC (permalink / raw)
  To: Dan Hitt, Christopher Howard; +Cc: help-gnu-emacs

> > I wrote a simple command that I use when in Org mode...
> > however, this causes the command to be available under
> > other modes as well.
> 
> But you should be able to run a piece of code with your add-hook that
> will bind the command to some keys, and this binding will only be
> available in a particular mode.

As Dan said, you can bind the command to a key in the
mode's keymap.  If the command is appropriate only for
the mode then you can also change its code so that if
it is ever invoked outside the mode (usually tested
using `derived-mode-p') then it does nothing, or it
shows a message saying it is only for the mode, or it
raises an error saying the same thing.



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

end of thread, other threads:[~2017-10-29  7:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-29  1:43 extending a mode Christopher Howard
2017-10-29  3:35 ` Dan Hitt
2017-10-29  7:00   ` Drew Adams

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.