Making the PATH and other environment variables available in emacs

試著忘記壹切 提交于 2019-12-18 04:47:14

问题


Working with emacs in OSX can some times be troubling.

I interchange with using the Terminal.app application and the emace shell both of these use bash, and both seem to work, I do however have the problem that the environment is not setup identically in both.

I'm running a clean installation of OSX Lion, and emacs 24 from emacs and would like for the environment variables in the emacs shell to make the same as in the Terminal.app under osx. How do I fix that?


回答1:


Just install the awesome little package exec-path-from-shell and you're done! It will automatically set your emacs exec-path to be same as the PATH in your zsh/bash config.

It will also allow you to copy the values of other shell variables like this:

(exec-path-from-shell-copy-env "PYTHONPATH")



回答2:


If your environment variables are being set in ~/.bash_profile, Create a file called ~/.emacs_bash and put in it the following:

. ~/.bash_profile

Don't forget the newline at the end of that line or it won't be executed.

~/.emacs_bash is loaded by emacs when you run bash from within it, such as when using M-x shell or shell-command so you can use it to set any environment variables you want available.




回答3:


Open Emacs.app from within Terminal.app (instead of from Finder):

$ emacs

This works for me using Emacs from Homebrew with Cocoa (brew install emacs --with-cocoa). It launches Emacs.app in a Cocoa GUI window (use emacs -nw to fallback to terminal UI). All the environment variables I have set in my bash environment appeared to be set in Emacs.

I have not tried this with Emacsformacosx. I personally prefer Emacs from Homebrew as I heard Emacsformacosx is not compiled with certain extensions I use such as TLS and Imagemagick... you can compile Emacs with those extensions using brew install emacs --with-XXX.




回答4:


As of 2019, exec-path-from-shell will only pass PATH to Emacs, If you want to pass all environments, you can try:

  • https://github.com/ersiner/osx-env-sync/


来源:https://stackoverflow.com/questions/16676826/making-the-path-and-other-environment-variables-available-in-emacs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!