2

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Mike H-R
  • 7,726
  • 5
  • 43
  • 65
  • Not sure if this is the problem, but your `eval-after-load` is insufficiently quoted. Write it like `(eval-after-load 'coffee-mode '(setq coffee-command "coffee"))` (extra single quote before `setq`) or use `with-eval-after-load` if your Emacs is new enough. – legoscia May 15 '14 at 13:31
  • @legoscia Thank you. I tried quoting the it as you said but unfortunately that didn't help, (thanks for showing me how it should be done) should I be quoting the other lines as well? EDIT: it seems that quoting the other lines doesn't really do anything. – Mike H-R May 15 '14 at 13:35

1 Answers1

1

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.

event_jr
  • 17,467
  • 4
  • 47
  • 62
  • I suspect you'd need to pass a non-nil third argument to `add-hook`, to put this function after `prelude-coffee-mode-defaults` in the hook variable. – legoscia May 15 '14 at 13:49
  • Hmm... this doesn't appear to be working for me either. @legoscia could you expand on what you mean here? and good point on fixing prelude I'll figure out how to test for existence and then put it into a PR for them. – Mike H-R May 15 '14 at 13:58
  • 2
    `add-hook` by default adds the new hook at the front of the hook variable, in this case `prelude-coffee-mode-hook`. That is, `prelude-coffee-mode-defaults` will be executed _after_ the function that sets the correct value, and thus undo its work. If you pass `t` as the third argument to `add-hook` (i.e. `(add-hook 'prelude-coffee-mode-hook (lambda () (setq coffee-command "coffee")) t)`), then it will add the new function last, which should ensure that it overrides the prelude function. – legoscia May 15 '14 at 14:06
  • @legoscia Hmmm... that didn't seem to work either, oh well I've made the change to prelude and am submitting the PR now so I guess it doesn't matter much. – Mike H-R May 15 '14 at 14:23
  • 1
    Of course, the actual problem with this code is that there are `setq` is a hook. No idea how this got into Prelude, but as I don't use coffeescript I guess I didn't pay much attention when it was originally submitted or something like that. I'll clean up the code. – Bozhidar Batsov May 15 '14 at 14:44
  • if anyone is curious, this issue was fixed [here](https://github.com/bbatsov/prelude/issues/535#issuecomment-43222486) however I have not been able to figure out how one would override the setq from the personal file. – Mike H-R May 15 '14 at 16:06