From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jacob Gerlach Newsgroups: gmane.emacs.help Subject: Re: Adding and running a major mode hook Date: Sun, 27 Apr 2014 04:56:46 -0700 (PDT) Message-ID: <96032cfe-f440-4eca-9d44-07fc14fb7371@googlegroups.com> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: ger.gmane.org 1398600031 26434 80.91.229.3 (27 Apr 2014 12:00:31 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 27 Apr 2014 12:00:31 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Apr 27 14:00:24 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 1WeNkt-0001wW-2k for geh-help-gnu-emacs@m.gmane.org; Sun, 27 Apr 2014 14:00:23 +0200 Original-Received: from localhost ([::1]:38946 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WeNkr-0000rG-VE for geh-help-gnu-emacs@m.gmane.org; Sun, 27 Apr 2014 08:00:22 -0400 X-Received: by 10.182.22.133 with SMTP id d5mr10262218obf.27.1398599806281; Sun, 27 Apr 2014 04:56:46 -0700 (PDT) X-Received: by 10.140.94.169 with SMTP id g38mr6035qge.13.1398599806247; Sun, 27 Apr 2014 04:56:46 -0700 (PDT) Original-Path: usenet.stanford.edu!l13no11351645iga.0!news-out.google.com!dz10ni23711qab.1!nntp.google.com!cm18no6785357qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=98.217.114.175; posting-account=Hx-_8AoAAACyMXgs4MCS3wNERNLct_lk Original-NNTP-Posting-Host: 98.217.114.175 User-Agent: G2/1.0 Injection-Date: Sun, 27 Apr 2014 11:56:46 +0000 Original-Xref: usenet.stanford.edu gnu.emacs.help:205127 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:97393 Archived-At: > 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?