6

erlang-mode is not a derived prog-mode.

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

Lindydancer
  • 6,095
  • 1
  • 13
  • 25
syl20bnr
  • 2,095
  • 11
  • 21

3 Answers3

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.

jch
  • 5,680
  • 22
  • 39
erikstokes
  • 12,686
  • 2
  • 34
  • 56
  • 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. – syl20bnr Jan 13 '15 at 04: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. – erikstokes Jan 13 '15 at 04: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). – phils Jan 09 '17 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.")

Lindydancer
  • 6,095
  • 1
  • 13
  • 25
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!

Abbrev
  • 41
  • 1