unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Jacob Gerlach <jacobgerlach@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Adding and running a major mode hook
Date: Sat, 26 Apr 2014 10:25:52 -0700 (PDT)	[thread overview]
Message-ID: <ed13f213-3af4-4f7e-b3d8-90543fc5b4b9@googlegroups.com> (raw)

I think that a hook is the right way for me to allow users some customization in my major mode.

I have a list that is used to create font lock constructs, and I'd like to allow users to add to that list before my code processes it into font lock constructs.

What I have now is basically:

(setq content-list...)

(mapc 'create-constructs content-list)

What I've tried to do is

 (setq content-list ...)

 (defvar add-user-content-hook nil)
 (defun add-user-content (input)
   (add-hook 'add-user-content-hook
     (lambda () (add-to-list 'content-list input))))

 (run-hooks 'add-user-content-hook)

 (mapc 'create-constructs content-list)

With the intention that users put something like 

  (add-user-content '("my content"))

in their .emacs

This code doesn't generate any errors, but it doesn't work either.

Reading about hooks in the documentation makes me think that I have a conceptual misunderstanding about the manner and sequence in which code in mymode.el is executed. Specifically, what is the difference between putting (run-hooks... in (define-derived-mode ... vs putting (run-hooks... somewhere in the mode's code (as I have done above)?


             reply	other threads:[~2014-04-26 17:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-26 17:25 Jacob Gerlach [this message]
2014-04-27  3:12 ` Adding and running a major mode hook 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
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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=ed13f213-3af4-4f7e-b3d8-90543fc5b4b9@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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).