all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jacob Gerlach <jacobgerlach@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Adding and running a major mode hook
Date: Sun, 27 Apr 2014 04:56:46 -0700 (PDT)	[thread overview]
Message-ID: <96032cfe-f440-4eca-9d44-07fc14fb7371@googlegroups.com> (raw)
In-Reply-To: <mailman.107.1398568207.1147.help-gnu-emacs@gnu.org>

> If you've got the run-hooks inside the mode declaration, then the hooks
> 
> won't run until the user activates the mode in some particular buffer.
> 
> They will then run *every* time your mode is activated.
> 
> 
> 
> If you've got it at the top level of the file, the hooks will run once,
> 
> *while* the file is being loaded for the first time: ie quite likely
> 
> during emacs startup, possibly before the user's relevant customization
> 
> is loaded, probably before any relevant file are opened.

Ahhh, this is the key piece of information that I was missing. I was confused by the fact that the mode declaration wasn't bothered by the fact that it came before the function definitions further on in the file.

> >From what I can see from your examples above, it might be enough just to
> 
> have:
> [...]
> Then, *every time* the user activates this
> 
> mode, constructs are created out of whatever's in `content-list'.
 
The creation uses add-to-list, which checks for duplicates, so that won't be a problem necessarily, but it does seem like unnecessary overhead that I can get rid of. I will play with some conditionals to see what I can do about this.

> Hope that didn't make it worse,
On the contrary, much clearer now!

To add a wrinkle to this, can someone explain how autoload changes this sequence? I tried to implement autoload by putting something like this in my file:

(autoload 'my-mode "my-name" "My Editing Mode" t)

I copied it from somewhere, but now that I read the documentation more carefully, I think I have two problems with this:

First, "my-name" should actually be the filename: "mymode.el". Does this argument care about paths?
Second, I put this line after the mode definition, but the help says:

If FUNCTION is already defined other than as an autoload,
this does nothing and returns nil.

So I think it's doing nothing (and perhaps that's why it doesn't matter that I didn't include the file name as I should have). It also seems it would be much easier to make the mode autoloaded using a magic comment, which is how I'm fixing it.

With regards to the order of code execution, how does autoloading the mode definition change what Eric already described? Users will still have(require 'my-mode) in their .emacs, which I think executes everything except the mode definition.

Is it then redundant to put autoload on a function definition?


  parent reply	other threads:[~2014-04-27 11:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-26 17:25 Adding and running a major mode hook Jacob Gerlach
2014-04-27  3:12 ` Eric Abrahamsen
2014-04-27  5:15 ` Eric Abrahamsen
     [not found] ` <mailman.107.1398568207.1147.help-gnu-emacs@gnu.org>
2014-04-27 11:56   ` Jacob Gerlach [this message]
2014-04-27 12:10     ` Jacob Gerlach
2014-04-29  0:45     ` Eric Abrahamsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=96032cfe-f440-4eca-9d44-07fc14fb7371@googlegroups.com \
    --to=jacobgerlach@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.