如何使Emacs识别bash环境变量进行编译? [英] How do I make Emacs recognize bash environment variables for compilation?

查看:189
本文介绍了如何使Emacs识别bash环境变量进行编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过Emacs的编译模式编译u-boot,看起来Emacs不知道如何找到bash环境变量。即使我设置它们,并且可以通过Emacs shell仿真编译,编译模式仍然尝试编译,就好像它们不在那里一样。

I'm trying to compile u-boot via Emacs' compilation mode, and it looks like Emacs doesn't know how to find bash environment variables. Even though I set them, and can compile via Emacs shell emulation, compilation mode still tries to compile as if they aren't there.

我需要做什么

推荐答案

您可以尝试添加类似 .emacs

(let ((path (shell-command-to-string ". ~/.bashrc; echo -n $PATH")))
  (setenv "PATH" path)
  (setq exec-path 
        (append
         (split-string-and-unquote path ":")
         exec-path)))

根据您是否设置了env变量在 .bash_profile .bashrc 中,您可能需要稍微调整此代码段。示例是 PATH 变量,这是一个更特别的(因为你必须设置 exec-path Emacs),但可以扩展为任意变量工作 - 您可以有一个变量列表,必须从 .bashrc 中读取并设置为Emacs。

Depending on whether you've set the env variables in .bash_profile or .bashrc you might need to slightly adjust this snippet. The example is for the PATH variable, which is a bit more special (since you have to set exec-path in Emacs as well), but can be extended to work for arbitrary variables - you could have a list of variables that have to be read from .bashrc and set into Emacs.

我不确定您使用的是OS X还是GNU / Linux。在Linux中从GUI的菜单栏启动Emacs通常会导致Emacs与从命令行启动的Emacs没有相同的 PATH 。这个问题可以追溯到第一个 xdm Xsession脚本,虽然它们相当容易修复(基本上使用 Xsessionwrapper 脚本, exec $ SHELL -c Xsession 所以shell运行用户的Xsession之前运行),没有人有麻烦这样做在很长一段时间(我怀疑任何人都会)。据我所知,这个问题甚至出现在中等xdm后代,例如 kdm gdm

I'm not sure whether you're using OS X or GNU/Linux. Starting Emacs from the GUI's menu-bar in Linux will typically result in an Emacs that does not have the same PATH as one launched from the command line. This problem dates back to the first xdm Xsession scripts, and while they are fairly easy to fix (basically use an Xsessionwrapper script that does exec $SHELL -c Xsession so the shell gets run before running the user's Xsession), nobody has bother to do so in a very long time (and I doubt that anyone will). As far as I know the problem is present even into moder xdm descendants such as kdm and gdm.

在OS X上,env变量的处理是另一个问题,为了获得您的ENV变量,您通常必须从命令行运行Emacs,例如 / Applications /Emacs.app/Contents/MacOS/Emacs 或使用〜/ .MacOSX / environment.plist 玩。

On OS X the handling of the env variables is another problem entirely and to get your ENV variables you typically have to run Emacs from the command line like this /Applications/Emacs.app/Contents/MacOS/Emacs or play with ~/.MacOSX/environment.plist. The code snippet I've provided should cover you in both cases though.

更新

最近,此过程通过 exec-path-from-shell 扩展更容易。它以或多或少的方式设置emacs $ PATH ,但使用扩展通常比自己黑客解决方案更好。

Recently this process was made easier by the exec-path-from-shell extension. It sets the emacs $PATH in more or less the same manner, but using an extension is generally preferable to hacking the solution yourself.

这篇关于如何使Emacs识别bash环境变量进行编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆