1

I've been plonking around on mac-emacs, and I've M-x install-package-d coffee-mode. I decided to try out the coffee-compile-file command, but when I ran it, it failed, complaining that it couldn't find the coffee command.

So, I open up terminal, on ZSH and Bash. coffee and node run fine on both. So, split my emacs screen, plink out M-x term, let bash load, and type coffee:

bash-3.2$ coffee 
bash: coffee: command not found

Odd. I tried the same for node and npm.

bash-3.2$ node
bash: node: command not found
bash-3.2$ npm
bash: npm: command not found

My question is, why does this happen only on M-x term, and how can I fix it.

AJF
  • 11,767
  • 2
  • 37
  • 64
  • Presumably you set up paths and things during shell init and that isn't happening for `M-x term`. Where did you set those up? – Etan Reisner Feb 27 '15 at 21:16
  • @Etan Reisner I checked `.zshrc` and `.bashrc`, but there's nothing referring to `node` or `coffee`, only `rhino` and `clojure`. – AJF Feb 27 '15 at 21:18
  • Perhaps you are using different shell interpreters. When you run `M-x term` Emacs asks for you to pick the interpreter. Check if you are using the same in the console outside Emacs. To do so, simply type `ps` on the terminal. – Akira Feb 27 '15 at 21:19
  • What does `which coffee` output (where `coffee` works)? Is `$PATH` different in the emacs shell? – Etan Reisner Feb 27 '15 at 21:24
  • @Akira It's indeed bash, but, interestingly, `/bin/bash` rather than just `bash`. I ran `bash` within it, but it still doesn't find `coffee`. – AJF Feb 27 '15 at 21:24
  • @Etan Reisner There's the problem! `which coffee` tells me it's in `/usr/local/bin`, and `M-x term`'s `$PATH` doesn't include it! How might one add to the term path? – AJF Feb 27 '15 at 21:27
  • The question is where are you already adding that and why isn't the `M-x term` shell doing that. – Etan Reisner Feb 27 '15 at 21:47

1 Answers1

3

I've found a solution with help from @Etan Reisner and @Akira (Thanks guys!), so I'll post it here. I'll also wait for other people who might want to expand on this answer before giving myself all the credit.

Firstly, as one may find using which coffee, coffee is located in /usr/local/bin. For some reason, M-x term's $PATH doesn't include that directory, whereas terminal bash does.

We can add /usr/local/bin to emacs' $PATH by adding this line to our .emacs:

(setenv "PATH" (concat (getenv "PATH") ":/usr/local/bin"))

Now, when I open up M-x term and run coffee, it works fine:

bash-3.2$ coffee
coffee> 

However, I notice that running M-x coffee-repl still fails with 'no such file or directory: coffee'. This can be fixed by adding this to .emacs:

(setq exec-path (append exec-path '("/usr/local/bin")))

Note that doesn't solve the problem of ugly colour escape sequences in the REPL. Ah, well, that's solved elsewhere. Besides, M-x ansi-term works so much better with colour.

Community
  • 1
  • 1
AJF
  • 11,767
  • 2
  • 37
  • 64