Samuel Schaumburg
Samuel Schaumburg

Reputation: 21

Make emacs never open up a new instance

How would you set emacs up to never create any new frame. If I want frames, I will do that from inside emacs.

Annoyingly, whenever I click a file from a file manager outside emacs, this opens up a completely new instance of emacs, with all the long loading time going along with that.

Opening a bunch of files, each taking like 5 seconds to finally load is not very convenient. So what I want to do is this: Whenever I click a file on the file manager, I want that file to be opend up in the one instance of emacs that is already running as a new buffer.

How would I do that?

Using emacs 24.3.1 on Fedora 19 with Gnome 3.8.4

Upvotes: 1

Views: 1869

Answers (2)

abo-abo
abo-abo

Reputation: 20362

Here's what I did. I have Ubuntu, but I'm pretty sure that Gnome also uses /usr/share/applications/.

Here's my /usr/local/share/applications/emacsclient.desktop:

[Desktop Entry]
Name=Emacsclient
GenericName=Text Editor
Comment=View and edit files
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;
Exec=/usr/local/bin/emacsclient %F
Icon=emacs
Type=Application
Terminal=false
Categories=Development;TextEditor;
StartupWMClass=Emacs

Here's my /usr/local/share/applications/emacs.desktop(just for completeness):

[Desktop Entry]
Name=Emacs
GenericName=Text Editor
Comment=Edit text
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;
Exec=emacs %F
Icon=emacs
Type=Application
Terminal=false
Categories=Development;TextEditor;
StartupWMClass=Emacs

The command to update these shortcuts without rebooting is:

sudo update-desktop-database

Now you should have an Emacsclient entry in your file managers "open with" dialog. Make the associations and the files will open in emacs with a click of a mouse. Just make sure to have in your ~/.emacs:

(require 'server)
(or (server-running-p) (server-start))

Upvotes: 2

You want to start one single instance of emacs (which should start a server using (server-start) in your ~/.emacs) and then use emacsclient. You probably should

  export EDITOR=emacsclient

in e.g. your ~/.bashrc

See invoking emacsclient (in Emacs documentation) and EmacsClient (in Emacs Wiki).

Upvotes: 3

Related Questions