emacselispemacs-prelude

How do I override a prelude module hook on coffee-mode?


I have been using prelude for about a year and have developed a nice setup. I started writing coffee-script and tried to use the prelude-coffee module. This contains the line:

(setq coffee-command "~/dev/coffee")

which is incorrect on my machine. I would like to change it to:

(setq coffee-command "coffee")

Now obviously I could simply change this line and be done with it but I like to keep all of my changes in the personal folder in order to facilitate easy updating and keeping my dotfiles in sync on all my machines.

I have tried to override it in the following ways:

(setq coffee-mode "coffee")
(eval-after-load 'coffee-mode
  (setq coffee-command "coffee"))

(add-hook 'prelude-coffee-mode-hook (setq coffee-command "coffee"))
(add-hook 'coffee-mode-hook (setq coffee-command "coffee"))

but none of these work. The change needs to be run after the other file which seems to be run with eval-after-load.

EXTRA INFO I will reproduce the prelude-coffee.el file here, for completeness:

(require 'prelude-programming)

(eval-after-load 'coffee-mode
  '(progn
     (defun prelude-coffee-mode-defaults ()
       "coffee-mode-defaults"

       ;; CoffeeScript uses two spaces.
       (setq coffee-tab-width 2)

       ;; If you don't have js2-mode
       (setq coffee-js-mode 'javascript-mode)

       ;; If you don't want your compiled files to be wrapped
       (setq coffee-args-compile '("-c" "--bare"))

       ;; *Messages* spam
       (setq coffee-debug-mode t)

       ;; Emacs key binding
       (define-key coffee-mode-map [(meta r)] 'coffee-compile-buffer)

       ;; Riding edge.
       (setq coffee-command "~/dev/coffee")

       ;; Compile '.coffee' files on every save
       (and (buffer-file-name)
            (file-exists-p (buffer-file-name))
            (file-exists-p (coffee-compiled-file-name (buffer-file-name)))
            (coffee-cos-mode t)))

     (setq prelude-coffee-mode-hook 'prelude-coffee-mode-defaults)

     (add-hook 'coffee-mode-hook (lambda ()
                                   (run-hooks 'prelude-coffee-mode-hook)))))
(provide 'prelude-coffee)

In summary, how do I override something that is happening on a coffee-mode-hook?


Solution

  • Oh man that is terrible. I would file an issue with prelude. At least it should check for existence before setting coffee-command.

    This line is close

    (add-hook 'prelude-coffee-mode-hook (setq coffee-command "coffee"))
    

    Try this:

    (add-hook 'prelude-coffee-mode-hook (lambda () (setq coffee-command "coffee")))
    

    I found other issues with prelude-coffee.el:

    You can't use setq on a hook and just wipe out all previously added hooks. That's uh uncivilized.