0

On Macs, defining environment variables in the environment.plist will allow you to use environment variables in Emacs.app. On Linux, is there such an equivalent?

I don't want to use the environment variables in one of the shell or terminal emulators but also for find-file (C-x C-f), shell-command (C-!), etc. and I have a lot of paths defined as environment variables that would be helpful here. For instance, finding a file with find-file can be $WORK/projectname and so on.

I suppose the most straightforward way is to use setenv within .emacs, but as I have a lot of such variables it would be better if I could define it once in an external file and have Emacs read it in.

Edit: Sorry for the confusion. This question is specifically addressing issue of Emacs access, as variables defined in ~/.bashrc is not available to Emacs until shell, eshell, or term is invoked.

4

4 回答 4

3

这里是一个脚本,它定义了几个环境变量,由 Emacs 以批处理模式读取

http://bazaar.launchpad.net/~python-mode-devs/python-mode/python-mode/view/head:/test/python-mode-tests.sh

从 lisp 获取 $HOME 例如使用 (getenv "HOME")

于 2012-08-10T12:20:18.180 回答
2

为了能够访问您的变量,您.bashrc需要从 bash shell 启动 emacs。如果您只是单击一个图标,.bashrc则不会读取该图标,并且您将无权访问您的变量。

如果您绝对无法从 bash shell 启动 emacs,请找到一个由您的桌面环境加载的 init 文件。就我而言,它是.xsession。我在其中导出的任何变量都可用于 emacs。

要访问环境变量,请使用getenv.

于 2012-08-10T12:31:41.330 回答
1

如果您在 ~/.bashrc 中定义环境变量,则它们在用户 shell 中可用于所有命令。正确的语法是:

export VARIABLE="value"
于 2012-08-10T10:42:41.553 回答
1

您可以.bashrc在您的主目录中编辑您的,您可以在其中添加您自己的别名、定义环境变量并为您的自定义脚本添加路径。

于 2012-08-10T10:43:25.307 回答