Search code examples
emacsemacs23

Emacs compilation mode won't see bash alias


Emacs M-x compile does not see any aliases set in .bashrc. If I use M-x shell then type the alias, it is fine. I tried sourcing .bashrc from /etc/profile, from ~/.profile, ~/bash_env, anything I can think of to no avail.

I am on Emacs 23 and Ubuntu 11. I start emacs using /usr/bin/emacs %F, from a desktop button.


Solution

  • Emacs inherits its environment from the parent process. How are you invoking Emacs - from the command line, or some other way?

    What happens if you:

    M-x compile RET C-a C-k bash -i -c your_alias RET

    Invoking bash as an interactive shell (-i option) should read your .bashrc aliases.

    Edit: I think both M-x shell-command and M-x compile execute commands in an inferior shell via call-process. Try the following in your .emacs (or just evaluate):

    (setq shell-file-name "bash")
    (setq shell-command-switch "-ic")
    

    I notice that after evaluation of the above, .bashrc aliases are picked up for use by both M-x shell-command and M-x compile, i.e

    M-x compile RET your_alias RET

    should then work.

    My environment: Emacs 24.1 (pretest rc1), OSX 10.7.3