Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.
Bug 154293 - 'Open with "Emacs Text Editor"' does not use emacsclient
Summary: 'Open with "Emacs Text Editor"' does not use emacsclient
Alias: None
Product: Fedora
Classification: Fedora
Component: emacs
Version: rawhide
Hardware: All
OS: Linux
Target Milestone: ---
Assignee: Jens Petersen
QA Contact:
Depends On:
TreeView+ depends on / blocked
Reported: 2005-04-09 03:43 UTC by Darren Brierton
Modified: 2008-04-27 10:36 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Enhancement
Doc Text:
Clone Of:
Last Closed: 2006-02-03 07:54:43 UTC

Attachments (Terms of Use)
emacsclient-plus (deleted)
2005-04-13 05:24 UTC, Jens Petersen
no flags Details
implements behavior described in opening report (deleted)
2008-04-27 04:19 UTC, Brad Walker
no flags Details | Diff
implements behavior described in opening report (deleted)
2008-04-27 04:49 UTC, Brad Walker
no flags Details | Diff

Description Darren Brierton 2005-04-09 03:43:06 UTC
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


and in ~/.bash_profile I have


*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):

How reproducible:

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:

Comment 1 Darren Brierton 2005-04-09 03:44:54 UTC
Why didn't any of my lines wrap???

Do I need to bugzilla this bug report?

Comment 2 Jens Petersen 2005-04-10 04:43:54 UTC
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.

Comment 3 Darren Brierton 2005-04-13 04:10:04 UTC
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?)

Comment 4 Jens Petersen 2005-04-13 05:24:23 UTC
Created attachment 113082 [details]

Sorry here it is extracted from debian's emacs patch.
AFAICT they do not ship it yet though.

Comment 5 Darren Brierton 2005-04-13 12:03:12 UTC
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/ 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 is run from the command line.

Comment 6 Jens Petersen 2005-10-03 08:19:04 UTC
Can't you make Nautilus run emacsclient instead? :)

Comment 7 Darren Brierton 2005-10-03 11:24:23 UTC
(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.

Comment 8 Jens Petersen 2005-10-03 22:43:42 UTC
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.

Comment 10 Jens Petersen 2005-11-22 02:32:09 UTC
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?

Comment 11 Darren Brierton 2005-11-22 02:53:53 UTC
(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.

Comment 12 Jens Petersen 2005-11-22 03:23:35 UTC
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.

Comment 13 Brad Walker 2008-04-27 04:15:20 UTC
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.

Comment 14 Brad Walker 2008-04-27 04:19:33 UTC
Created attachment 303887 [details]
implements behavior described in opening report

Comment 15 Brad Walker 2008-04-27 04:49:51 UTC
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 16 Brad Walker 2008-04-27 10:36:38 UTC
Comment on attachment 303889 [details]
implements behavior described in opening report

Oops, this .desktop doesn't work when initially starting Emacs.

Note You need to log in before you can comment on or make changes to this bug.