From Bugzilla Helper: User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.6) Gecko/20050323 Firefox/1.0.2 Fedora/1.0.2-1.3.1 Description of problem: I know this may be more of an RFE than anything else, but I thought it was worth having it in bugzilla. I don't know if this should be fixed upstream or if the FC packages need tweaking. Anyway, I'm very unclear on how the new MIME system in GNOME works, but it is still the case, as it has been forever, that there is no way to open a file from Nautilus in an existing running Emacs. In my ~/.emacs.el I have (server-start) and in ~/.bash_profile I have EDITOR=emacsclient *If* I have Emacs running, then anything I start from a shell which needs an editor, such as "svn commit" opens an svn-commit.tmp buffer in my already running Emacs. Of course, if I don't have a running Emacs it just craps out completely. In Nautilus, whether I have a running Emacs or not, if I right-click on a file and select 'Open with "Emacs Text Editor" it starts a new instance of Emacs. Both behaviours are crappy. The ideal situation would be that if Emacs with (server-start) is running, the existing Emacs should be used, and if no Emacs is running, or one is without (server-start), then a new instance of Emacs should be started. Is it all possible to write a shell script which does exactly that, and have *that* registered (and only that) as a MIME handler? If I could write such a script and submit it as a patch believe me I would, but is light years beyond my abilities. I do know that the Emacs devels seem to be aware of this problem, but they seem to have bigger fish to fry. I suspect it can't be solved at the distribution level either (otherwise it probably would have been), but perhaps this could stay in bugzilla as a reminder that this behaviour isn't desirable and needs fixing at some point. Version-Release number of selected component (if applicable): emacs-21.3.50-0.20041210 How reproducible: Always Steps to Reproduce: 1. Start Emacs with emacs server running 2. Right click on a file in Nautilus and select 'Open with "Emacs Text Editor"' Actual Results: A new instance of Emacs is started Expected Results: File open is running Emacs Additional info:
Why didn't any of my lines wrap??? Do I need to bugzilla this bug report?
Debian's emacs patch contains a script called emacsclient-plus which seems to be for what you want - I haven't tested it yet though... Perhaps you can give it a try and report your findings.
Jens, I've tried googling and all the links to emacsclient-plus give me a 404. Do you know where I can find this script so I can try it out and report my findings? (Will this wrap this time?)
Created attachment 113082 [details] emacsclient-plus Sorry here it is extracted from debian's emacs patch. AFAICT they do not ship it yet though.
Thanks Jens. I'm afraid it doesn't work at all well for me, neither from a terminal or from within Nautilus. Right-clicking on a text file in Nautilus and choosing "Open With" -> "Open with Other Application" and selecting ~/bin/emacs-client-plus.pl open a new instance of Emacs regardless of whether one was running already or not, and the new instance does NOT have the file right clicked on as an open buffer, although if there was a previously running instance of Emacs then that one does. Exact same behaviour if emacsclient-plus.pl is run from the command line.
Can't you make Nautilus run emacsclient instead? :)
(In reply to comment #6) > Can't you make Nautilus run emacsclient instead? :) Presumably, but that wasn't the point of the bug report. If emacs isn't already running then trying to open a file with emacsclient doesn't work. What I was suggesting was needed was *one* way of opening a file in Emacs which uses an existng instance of emacs if one exists and otherwise starts one. There currently doesn't seem to be a way of doing that.
Ok, I guess a wrapper is needed which tries to call emacsclient first, if that fails forks an emacs and then tries emacsclient again. However since emacs is rather slow to start up I'm not sure how to implement this easily with a shell script. Probably it would be better implemented as an extension of emacsclient. Any ideas? Probably it is better to propose this upstream on emacs-devel list.
I received the following response to my posting "emacsclient wrapper to launch emacs server if none running?" on emacs-devel: | From the Emacs manual: | | | The option `--alternate-editor=COMMAND' is useful when running | `emacsclient' in a script. It specifies a command to run if | `emacsclient' fails to contact Emacs. For example, the following | setting for the EDITOR environment variable will always give you an | editor, even if no Emacs server is running: | | EDITOR="emacsclient --alternate-editor emacs +%d %s" Does that help?
(In reply to comment #10) Ah, that does look good. I'll put that in my ~/.bash_profile and report back. I can't report back immediately because logging out (or shutting down emacs) would be a royal pain in the arse, but as soon as it is convenient I'll check it out. If this works, how hard would it be to add something like this as the emacs MIME handler so that simply installing the emacs RPM would give the desired behaviour from a Nautilus right-click? Obviously I'm delighted to solve my own personal problems but I put this in bugzilla with the hope of making ordinary users' interactions with emacs less painful. Thanks again for being so diligent with something that was simply filed as an RFE.
I guess it would need EDITOR set as above in the desktop environment, but I'm not sure everybody would want that be default: at least I'm pretty used to running separate invocations of emacs processes.
Changing emacs.desktop to Exec 'emacsclient -a emacs %f' would only affect users if they have (server-start) in their .emacs. Without (server-start), 'emacsclient -a emacs %f' will always open a new emacs process. With (server-start) it'll open the file in one main emacs process. Changing emacs.desktop to Exec 'emacsclient -a emacs %f' while leaving /etc/skel/.emacs without (server-start) would be optimal.
Created attachment 303887 [details] implements behavior described in opening report
Created attachment 303889 [details] implements behavior described in opening report emacs and emacsclient can accept a list of files, so resubmitting with %F instead of %f in Exec
Comment on attachment 303889 [details] implements behavior described in opening report Oops, this .desktop doesn't work when initially starting Emacs.