From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.help Subject: Re: Adding and running a major mode hook Date: Tue, 29 Apr 2014 08:45:55 +0800 Message-ID: <87vbttq7y4.fsf@ericabrahamsen.net> References: <96032cfe-f440-4eca-9d44-07fc14fb7371@googlegroups.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1398732218 6923 80.91.229.3 (29 Apr 2014 00:43:38 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 29 Apr 2014 00:43:38 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Apr 29 02:43:31 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Wew8t-00047k-Bi for geh-help-gnu-emacs@m.gmane.org; Tue, 29 Apr 2014 02:43:27 +0200 Original-Received: from localhost ([::1]:46647 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wew8t-0006ff-12 for geh-help-gnu-emacs@m.gmane.org; Mon, 28 Apr 2014 20:43:27 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wew8a-0006OK-4t for help-gnu-emacs@gnu.org; Mon, 28 Apr 2014 20:43:15 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wew8S-0007gA-KK for help-gnu-emacs@gnu.org; Mon, 28 Apr 2014 20:43:08 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:38549) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wew8S-0007g3-Do for help-gnu-emacs@gnu.org; Mon, 28 Apr 2014 20:43:00 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1Wew8N-0003Vk-J8 for help-gnu-emacs@gnu.org; Tue, 29 Apr 2014 02:42:55 +0200 Original-Received: from 114.248.18.67 ([114.248.18.67]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 29 Apr 2014 02:42:55 +0200 Original-Received: from eric by 114.248.18.67 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 29 Apr 2014 02:42:55 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 84 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 114.248.18.67 User-Agent: Gnus/5.13001 (Ma Gnus v0.10) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:YrEGWeDZCUiC5fFJqAfZEeusDYQ= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:97439 Archived-At: Jacob Gerlach writes: >> 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? `autoload' uses `load', which searches for files in your 'load-path. If the file you want to load isn't in your load-path, you can give an absolute path, but that's probably a bad idea. You don't need the ".el" suffix -- load will try with ".el", ".elc" and no suffix. (see 'load-suffixes) > 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? It's redundant to have an autoload for a function that is defined in the same file, yes. autoloads should be put elsewhere, either in the user's configuration or in other libraries that might theoretically depend on your library. Users will either use require, or autoload, but not both. Require means "load it now" (ie the whole file is executed, probably at emacs startup), and autoload means "load it the first time I try to use it", which probably happens as a relevant file is being opened. Practically speaking that's the only difference. HTH, Eric