You are not logged in.

#1 2009-07-25 18:19:55

Allamgir
Member
Registered: 2009-06-11
Posts: 168

[SOLVED] Emacs always run in terminal?

UPDATE: The solution is to install the package "emacs-nox" to replace "emacs". This way, the GUI is never used.

I'm starting to use emacs more and more as my main editor, but I would like to know how to make it always run in the terminal. I currently launch it as "emacs -nw" because I created a bash alias that runs it like that when I type "emacs".

The problem is I can't run "sudo emacs" and get it to run in the terminal. I even edited the root user's .bashrc to have the same emacs='emacs -nw' alias. No luck.

Another problem is that I can't set it as the default editor in my .bashrc. I use midnight commander for file management, and it looks for the default bash editor when I choose to edit a text file. If I set the default editor as "emacs", even when I have an alias set for emacs to run emacs -nw, the program still launches its GUI mode. Attempting to set "EDITOR emacs -nw" returns an error.

How can I get emacs to always launch in the terminal, even when running "sudo emacs"?

Last edited by Allamgir (2009-07-26 00:57:14)


дɭɭɑӎɠїɾ

Offline

#2 2009-07-25 18:25:44

Ashren
Member
From: Denmark
Registered: 2007-06-13
Posts: 1,229
Website

Re: [SOLVED] Emacs always run in terminal?

Why not create an alias that consists of:

alias semacs='sudo emacs -nw'

Can't help with default editor problem.

Offline

#3 2009-07-25 18:37:01

moljac024
Member
From: Serbia
Registered: 2008-01-29
Posts: 2,676

Re: [SOLVED] Emacs always run in terminal?

pacman -Rcsn emacs && pacman -Sy vim

Joking aside, you can as a last resort create a script that would just run emacs -nw, then you can call that script every time...

Last edited by moljac024 (2009-07-25 18:39:17)


The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...

Offline

#4 2009-07-25 18:55:09

andre.ramaciotti
Member
From: Brazil
Registered: 2007-04-06
Posts: 649

Re: [SOLVED] Emacs always run in terminal?

I would suggest you the same thing Ashren did. About the EDITOR environment variable, try adding this to your bashrc

EDITOR="emacs -nw"

It may be the case that you want to run emacs in a terminal, but another one, not the one you're using. In this case, you can use (replace xterm with the terminal you use):

xterm -e emacs -nw

(lambda ())

Offline

#5 2009-07-25 19:59:19

djszapi
Member
From: Cambridge, United Kingdom
Registered: 2009-06-14
Posts: 1,439
Website

Re: [SOLVED] Emacs always run in terminal?

Yeah, and after this setting, you can toogle the state of Options/Configuration/Other Options/Use internal editor/viewer box in Midnight Commander.

Offline

#6 2009-07-25 20:02:37

Allamgir
Member
Registered: 2009-06-11
Posts: 168

Re: [SOLVED] Emacs always run in terminal?

What I'm trying to do is make it so emacs is started when I choose to edit a file from midnight commander, and that emacs with the file is started in the same terminal window.

After putting EDITOR="emacs -nw" or even EDITOR="urxvtc -e emacs -nw", midnight commander just blinks when I try to edit a file (I set midnight commander to not use the internal editor).

Setting the editor to nano or vim works fine. I was considering just using vim for editing files from mc (usually config files), but I use emacs for things like LaTeX, and the switching of keybindings throws me off. Nano has kind of similar keybindings to emacs, but I'd really like to have the power of emacs (plus I have a few customizations in my .emacs).

Also, is there a way to create an alias for a two-word command? For example:

 alias sudo emacs='sudo emacs -nw'

I know that doesn't work, but is there a way to get that desired results? semacs just seems a little weird for some reason.

Last edited by Allamgir (2009-07-25 20:03:30)


дɭɭɑӎɠїɾ

Offline

#7 2009-07-25 20:17:40

djszapi
Member
From: Cambridge, United Kingdom
Registered: 2009-06-14
Posts: 1,439
Website

Re: [SOLVED] Emacs always run in terminal?

It's weird, I've tried with vim and it works for me, so the emacs can't... Why is emacs special in this handling, hm. it's a great work to solve wink

Offline

#8 2009-07-25 20:52:23

andre.ramaciotti
Member
From: Brazil
Registered: 2007-04-06
Posts: 649

Re: [SOLVED] Emacs always run in terminal?

This is weird...

EDITOR=emacs mc # works
EDITOR="emacs -nw" mc # doesn't work
EDITOR="emacsclient" mc # works
EDITOR="emacsclient -c -a emacs" mc # doesn't work

From this, I guess that only one word EDITOR variables can be used with mc.


(lambda ())

Offline

#9 2009-07-25 20:53:28

Pank
Member
From: IT
Registered: 2009-06-13
Posts: 371

Re: [SOLVED] Emacs always run in terminal?

Maybe emacs --daemon and then emacsclient -t will work better for you. This will only work with emacs 23.

I have the following in my .bashrc and it work with yaourt. I haven't tried with MC.

# set Emacsclient as yaourt's default editor
export EDITOR="emacsclient -t"

-Rasmus


Arch x64 on Thinkpad X200s/W530

Offline

#10 2009-07-25 22:59:14

Barrucadu
Member
From: York, England
Registered: 2008-03-30
Posts: 1,158
Website

Re: [SOLVED] Emacs always run in terminal?

Try the emacs-nox package smile

Offline

#11 2009-07-25 23:53:37

andre.ramaciotti
Member
From: Brazil
Registered: 2007-04-06
Posts: 649

Re: [SOLVED] Emacs always run in terminal?

I think it's a bug in mc.

Some one who uses vim and has gvim installed could test it for me? Try running
EDITOR=gvim mc # this should work
and then
EDITOR="vim -g" # but this one shouldn't

I think it's a problem with how mc handles the EDITOR variable. You can see in "my_system" definition (utilsunix.c, line 128) that mc calls execl or execlp, but I the way it's calling it, it won't work if your EDITOR variable has more than one "word". I did this 3 little C program to test it:

#include <unistd.h>

int main(int argc, char *argv[])
{
    execlp("sh", "sh", "emacs -nw", (char *)NULL);
    return 0;
}
#include <unistd.h>

int main(int argc, char *argv[])
{
    execl("sh", "sh", "-c", "emacs -nw", (char *)NULL);
    return 0;
}
#include <unistd.h>

int main(int argc, char *argv[])
{
    execlp("sh", "sh", "-c", "emacs -nw", (char *)NULL);
    return 0;
}

The two first won't work (these are the two ways mcedit calls the EDITOR variable). The last one will work, it was just I test I did.


(lambda ())

Offline

#12 2009-07-26 00:53:22

Allamgir
Member
Registered: 2009-06-11
Posts: 168

Re: [SOLVED] Emacs always run in terminal?

Barrucadu wrote:

Try the emacs-nox package smile

Yes! It works! Thank you!

The problem is that emacs defaults to its GUI mode and requires options to be run in the cli, unlike VIM which defaults to CLI. It must be a limitation of setting the EDITOR in .bashrc that options cannot be used (unless there's another way I'm not aware of), and even if it works, midnight commander gets confused because it's not a one word command.

Installing emacs-nox fixed it. Now running "emacs" runs the program in the cli.


smile


дɭɭɑӎɠїɾ

Offline

#13 2009-07-26 01:09:17

andre.ramaciotti
Member
From: Brazil
Registered: 2007-04-06
Posts: 649

Re: [SOLVED] Emacs always run in terminal?

But I think it still won't work if you need to pass some argument to call your editor, so I'm reporting a bug upstream.


(lambda ())

Offline

#14 2009-08-04 13:40:34

andre.ramaciotti
Member
From: Brazil
Registered: 2007-04-06
Posts: 649

Re: [SOLVED] Emacs always run in terminal?

Ticket #1425 (closed defect: fixed)
External editor won't open if there are spaces in EDITOR variable

http://www.midnight-commander.org/ticket/1425

When version 4.7 is released, this shouldn't be a problem anymore.


(lambda ())

Offline

#15 2009-08-05 00:20:41

ssjlegendx
Member
Registered: 2008-01-01
Posts: 94
Website

Re: [SOLVED] Emacs always run in terminal?

Allamgir wrote:

The problem is I can't run "sudo emacs" and get it to run in the terminal. I even edited the root user's .bashrc to have the same emacs='emacs -nw' alias. No luck.

I know you've found a solution to your problem; however, adding

alias sudo='sudo '

to your ~/.bashrc will allow expansion of aliases following sudo. (This is a feature of BASH: if an alias ends in a space, an alias following it in a command will also be expanded. I'm not certain, but I suppose that this only works for a single following alias.)

In other words, try this:

$ alias sudo='sudo '
$ alias emacs='emacs -nw'

Then, running sudo emacs will essentially run sudo emacs -nw.


Note: Credit for this information goes to one or more sources on these forums.


#!/vim/rocks

Offline

#16 2009-08-05 01:20:43

andre.ramaciotti
Member
From: Brazil
Registered: 2007-04-06
Posts: 649

Re: [SOLVED] Emacs always run in terminal?

I bet this is actually a bug. tongue

If you're using zsh, you can use global aliases and I guess it should work if you put it after sudo:

alias -g emacs='emacs -nw'

(lambda ())

Offline

Board footer

Powered by FluxBB