2

So I'm on my first day at my new job, and on the server we use, the default emacs is X-windows based. I much prefer using it in the good old terminal, and I'd like to be able to make the command emacs foo.txt be read as emacs --no-window-system foo.txt.

I tried to do this by adding the line function emacs() { emacs --no-window-system "$@" ;} to my ~/.profile, and then ran source ~/.profile, but the system is unresponsive to emacs foo.txt.

Am I doing this wrong? As an alternative, I would like to know if what I want to do is completely backwards, and it turns out that there is a far simpler solution.

2 Answers 2

1

This would be better as an alias.

Put this in your .profile or .bashrc

alias emacs='emacs -nw'
5
  • Thanks, unfortunately I'm not getting good results with this either. I tried this in both .profile and .bashrc, ran source .profile or source .bashrc beforehand, and then ran emacs foo.txt, but both times nothing happens until I type Ctrl+D, at which point it returns to the prompt. Jun 3, 2013 at 15:58
  • 2
    @FrankHarris What happens when you just emacs -nw foo.txt? I've never seen an Emacs build which was X-only, but I suppose such a thing is theoretically possible. Jun 3, 2013 at 16:03
  • @AaronMiller, the problem has been resolved after I logged out and in again. I was under the impression that source .profile would achieve the same thing, so not sure why it didn't work then! It might've been a completely unrelated error, but the point is that it works now. Thanks for your help! Jun 3, 2013 at 16:20
  • @AaronMiller I want to vote you up but I'm new and apparently need more reputation. I'll try to remember to do so when I get it; you've been a big help. Jun 3, 2013 at 16:21
  • @FrankHarris Thanks, and no worries! Glad to be of help. Jun 3, 2013 at 16:55
0

I believe that the problem with your original solution is that the call to emacs inside your emacs function is a recursive call to the emacs function. You can call the emacs program instead of your emacs function by using the bash builtin command.

function emacs() { command emacs --no-window-system "$@" ;}

I have kind of the opposite desire: I want to automatically background emacs when I'm running under a window system. I have the following in my .bashrc:

if [ -n "$DISPLAY" ]; then
    function emacs() { (command emacs "$@" &) }
fi

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .