1

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

Drew
  • 29,895
  • 7
  • 74
  • 104
  • 1
    Assuming that Basile Starynkevitch's assumption is correct, then your description isn't quite right; you are actually starting multiple Emacs instances (each with a *single* frame), rather than opening new frames (which implies a single instance). As each one takes ~5 seconds to open, then this *is* almost certainly what is happening. (If you are keen, you can undoubtedly also reduce that start time to no more than a second or so, using `eval-after-load` and autoloading where possible. See also http://stackoverflow.com/questions/778716/how-can-i-make-emacs-start-up-faster) – phils Sep 15 '13 at 08:38

2 Answers2

3

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).

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • allright, I have set up things in sever mode with nothing getting better. Not only are my .emacs files ignored whenever I open a file (no customizations loading tell me there is something goin wrong here), I also would have to always right click a file now to open with emacs-client and not with emacs. Even doing that I still get new frames (I don't want frames!!! I want new buffers!!!!) BTW: Speed is not increasing anyhow. Does anybody know sth better?? – Samuel Schaumburg Sep 16 '13 at 15:06
  • Be sure that your desktop is launching `emacsclient` (or `$EDITOR`) not `emacs`; use `ps auxw` or `top` to find out if you have several `emacs` processes.... – Basile Starynkevitch Sep 16 '13 at 16:38
  • OK I got you. But that does not change that the daemon mode is broken and the startup files are ignored. What to do about these?? – Samuel Schaumburg Sep 16 '13 at 18:33
  • emacsclient does not evaluate your init file -- the server instance has *already* done that. Everything which has been loaded and evaluated in the server is available to every client of that server. This is the whole purpose of the emacsclient/server arrangement. – phils Sep 18 '13 at 09:23
  • emacsclient should re-use an existing frame unless you have passed it the `-c` argument to ask it to create a new frame. – phils Sep 18 '13 at 09:25
  • I suggest manually invoking the client on files from the command line to ensure that you understand what should be happening, before trying to replicate the behaviour in any scripted or automated manner; that way you can recognise whether or not the latter config is actually doing the right thing. – phils Sep 18 '13 at 09:33
2

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))
abo-abo
  • 20,038
  • 3
  • 50
  • 71