Emacs编译模式不会看到bash别名

BBD*_*Sys 16 emacs emacs23

Emacs Mx编译没有看到.bashrc中设置的任何别名.如果我使用Mx shell然后键入别名,它没关系.我尝试从/ etc/profile,从〜/ .profile,〜/ bash_env采购.bashrc,我能想到的任何东西都无济于事.

我在Emacs 23和Ubuntu 11上.我使用/ usr/bin/emacs%F从桌面按钮启动emacs.

Kei*_*wer 18

Emacs从父进程继承其环境.你是如何从命令行或其他方式调用Emacs的?

如果您:

M-x编译RET C-a C-kbash -i -c your_alias RET

将bash作为交互式shell(-i选项)调用应该读取.bashrc别名.

编辑:我认为M-xshell-command和M-x编译通过call-process在劣质shell中执行命令.在.emacs中尝试以下内容(或仅评估):

(setq shell-file-name "bash")
(setq shell-command-switch "-ic")
Run Code Online (Sandbox Code Playgroud)

我注意到在评估了上述内容之后,.bashrc别名被M-xshell-command和M-xcompile使用,即

M-x编译RET your_alias RET

应该工作.

我的环境:Emacs 24.1(预测试rc1),OSX 10.7.3


dsh*_*erd 7

Keith Flower的答案有效,但由于.bashrc在其他地方被不必要地加载(可能很多次,我的计算机不完全不足,但是当尝试使用autocomplete.el时,emacs几乎无法使用)会导致一些速度减慢.

另一种方法是shell-command-switch仅针对需要它的函数进行本地修改.这可以使用emacs的"建议"功能来创建围绕这些功能的包装器.这是一个修改的示例compile:

;; Define + active modification to compile that locally sets
;; shell-command-switch to "-ic".
(defadvice compile (around use-bashrc activate)
  "Load .bashrc in any calls to bash (e.g. so we can use aliases)"
  (let ((shell-command-switch "-ic"))
    ad-do-it))
Run Code Online (Sandbox Code Playgroud)

您需要为要使用的每个函数编写类似的"建议".bashrc(例如,我还需要为其定义相同的建议recompile),只需复制上面的内容并compile在上面用另一个函数名替换.