How to Use One Instance of Emacs as the Default Text Editor? [Linux]

How to use one instance of emacs as the default text editor? [Linux]

  • remove (start-server) from .emacs
  • use emacsclient "$@" -a "" to start emacs whether it is running or not

If you save emacsclient "$@" -a "" as a script e.g. in editor file then editor -c creates a new frame, editor -t opens new frame in the terminal, and editor FILE visits FILE in an existing frame. It starts emacs server if it is not running.

How to set emacs to open new files in current instance on Ubuntu/Mint?

You want emacs client.

Basically, set emacsclient as your default editor, and add (server-start) somewere in your emacs config.

There needs to be a running Emacs instance for emacsclient to work, but if it's a hassle it's possible to have a headless Emacs launched at login.

How to keep a persistent emacs-server instance running?

Assuming you are using Emacs 23, put

emacs --daemon

in your ~/.xsession (or wherever you place your startup commands).

How can I force emacs (or any editor) to read a file as if it is in ASCII format?

You could edit the file using hexl-mode, which lets you edit the file in hexadecimal. That would let you see precisely what those offending characters are, and remove them.

It sounds like you either got a different line ending in the file (eg: carriage returns on a *nix system) or it got saved in an unexpected encoding.

How to start emacs server only if it is not started?

The emacs daemon can be started automatically in a very simple manner. Just add this to your .bashrc/.zshrc/whatever

export ALTERNATE_EDITOR=""

Now when you invoke emacsclient (using either --tty or --create-frame) the server will be started (with emacs --daemon) if it's not already running.

I also find this shell alias handy:

alias e='emacsclient --tty'

Note that since Emacs 23 this is the preferred way to use Emacs in daemon mode. (start-server) is now mostly deprecated.

Emacs: how to make it an editor in a midnight-commander?

Remove ~/.selected_editor, then when you press F4 next time, MC will prompt for select editor. Or, you may directly change it.

$ cat .selected_editor
# Generated by /usr/bin/select-editor
SELECTED_EDITOR="/usr/bin/vim.basic"

This works on Ubuntu. I have tried any other ways to setup default editor which won't help.

Change the default editor for files opened in the terminal? (e.g. set it to TextEdit/Coda/Textmate)

Most programs will check the $EDITOR environment variable, so you can set that to the path of TextEdit in your bashrc. Git will use this as well.

How to do this:

  • Add the following to your ~/.bashrc file:

    export EDITOR="/Applications/TextEdit.app/Contents/MacOS/TextEdit"
  • or just type the following command into your Terminal:

    echo "export EDITOR=\"/Applications/TextEdit.app/Contents/MacOS/TextEdit\"" >> ~/.bashrc

If you are using zsh, use ~/.zshrc instead of ~/.bashrc.

Linux Open default terminal text editor

If the system is properly configured, editor should do the job.

For instance, on my debian system, editor is configured to use nano.

$ update-alternatives --display editor
editor - auto mode
link currently points to /bin/nano
/bin/nano - priority 40
slave editor.1.gz: /usr/share/man/man1/nano.1.gz
/usr/bin/emacs23 - priority 0
slave editor.1.gz: /usr/share/man/man1/emacs.emacs23.1.gz
/usr/bin/vim.basic - priority 30
slave editor.1.gz: /usr/share/man/man1/vim.1.gz
slave editor.fr.1.gz: /usr/share/man/fr/man1/vim.1.gz
slave editor.it.1.gz: /usr/share/man/it/man1/vim.1.gz
slave editor.pl.1.gz: /usr/share/man/pl/man1/vim.1.gz
slave editor.ru.1.gz: /usr/share/man/ru/man1/vim.1.gz
/usr/bin/vim.tiny - priority 10
slave editor.1.gz: /usr/share/man/man1/vim.1.gz
slave editor.fr.1.gz: /usr/share/man/fr/man1/vim.1.gz
slave editor.it.1.gz: /usr/share/man/it/man1/vim.1.gz
slave editor.pl.1.gz: /usr/share/man/pl/man1/vim.1.gz
slave editor.ru.1.gz: /usr/share/man/ru/man1/vim.1.gz
Current 'best' version is '/bin/nano'.

I was expecting it to use the environnement variable EDITOR, but obviously it's not the case, at least on Debian.



Related Topics



Leave a reply



Submit