6

erlang-mode is not a derived prog-mode.

Is there any way to make it part of the prog-mode-hook ?

3 Answers 3

7

All you have to do is add (run-hooks 'prog-mode-hook) to erlang-mode-hook:

(add-hook 'erlang-mode-hook
          (lambda () (run-hooks 'prog-mode-hook)))

You should place this after anything else you add to erlang-mode-hook to make sure prog-mode-hook gets called before anything else. That way erlang-mode can clobber any settings in prog-mode that it doesn't like.

3
  • I'm not sure to understand when it is better to hook the lambda. My intuition would say "as the very first function hooked to erlang-mode-hook" but your remark seems to say the opposite so I'm confused. Commented Jan 13, 2015 at 4:47
  • 1
    add-hook adds the function to the beginning of the hook (there is an optional third argument that will cause it to append instead). So by adding prog-mode-hook last, it will become the first thing in the hook. I agree that this seems backwards, but it is what it is. Commented Jan 13, 2015 at 4:51
  • The prog-mode body will not run with this approach. A proper derived mode will run that before the erlang-mode body (which is before change-major-mode-after-body-hook runs, which is before the mode hooks run). Commented Jan 9, 2017 at 10:09
5

In addition to answers given by @erikstokes and @Abbrev, you might want to add the following:

(put 'erlang-mode 'derived-mode-parent 'prog-mode)

It ensures that (derived-mode-p 'prog-mode) returns t for Erlang mode. This is useful since there are a number of utilities that are enabled for all modes that inherit from Prog mode.

However, a more permanent solution would be to lobby to the Erlang team to replace the old definition of erlang-mode with the following, more modern version (and drop some of the stuff this provides for free):

(if (fboundp 'prog-mode)
    (defmacro erlang-define-derived-mode (mode &rest args)
      `(define-derived-mode ,mode prog-mode ,@args))
  (defmacro erlang-define-derived-mode (mode &rest args)
    `(define-derived-mode ,mode nil ,@args)))

(erlang-define-derived-mode erlang-mode "Erlang"
  ...)

(Should someone decide to lobby for this, you can say "Anders Lindgren, the author of Erlang mode, suggested this.")

4

erlang-mode probably doesn't inherit prog-mode-abbrev-table correctly, so any abbrevs you create for prog-mode won't work. Fix like so:

(eval-after-load erlang-mode
  (abbrev-table-put erlang-abbrev-table
                    :parents (list prog-mode-abbrev-table)))

This bug is shared by python-mode and lisp-mode, and they ship with Emacs!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.