Emacs is ignoring my path when it runs a compile command

后端 未结 8 1640
盖世英雄少女心
盖世英雄少女心 2020-12-05 11:24

I\'m trying to get a compile command (rake cucumber) to run with a specific ruby version on my Mac OS X system, I use rvm to do this currently in the terminal. My ~/.MacOSX/

相关标签:
8条回答
  • 2020-12-05 12:24

    As far as I observed, Emacs takes the path variable from the shell it is launched from, so one solution is to change $PATH in the shell before you launch Emacs.

    One other approach I used, which is more flexible, is to use a Makefile and append a "source ~/script_that_set_path" in front of each make commands you have.

    0 讨论(0)
  • 2020-12-05 12:28

    A small modification to the solution by sanityinc (couldn't find a way to enter it in the comments above -- is that just me?)

    • I use -l option to the shell to force a login shell (which reads .profile or .bash_profile), rather than an interactive shell (which only reads .bashrc).
    • I do some string trimming on the returned path (as inspection shows a newline sneaking in).

    Modified code:

    (defun set-exec-path-from-shell-PATH ()
      (let ((path-from-shell 
          (replace-regexp-in-string "[[:space:]\n]*$" "" 
            (shell-command-to-string "$SHELL -l -c 'echo $PATH'"))))
        (setenv "PATH" path-from-shell)
        (setq exec-path (split-string path-from-shell path-separator))))
    (when (equal system-type 'darwin) (set-exec-path-from-shell-PATH))
    
    0 讨论(0)
提交回复
热议问题