From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.help Subject: Re: emacs and xdg-open Date: Wed, 11 Jan 2012 13:00:10 +0800 Message-ID: <874nw2hm05.fsf@ericabrahamsen.net> References: <8739bp5gkn.fsf@ericabrahamsen.net> <87vcokms1v.fsf@nzebook.haselwarter.org> <87obuc45nf.fsf@ericabrahamsen.net> <87ipkjmk44.fsf@nzebook.haselwarter.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1326258031 12023 80.91.229.12 (11 Jan 2012 05:00:31 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 11 Jan 2012 05:00:31 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Jan 11 06:00:27 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RkqIV-0001gP-74 for geh-help-gnu-emacs@m.gmane.org; Wed, 11 Jan 2012 06:00:27 +0100 Original-Received: from localhost ([::1]:45989 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RkqIU-0005Pk-O4 for geh-help-gnu-emacs@m.gmane.org; Wed, 11 Jan 2012 00:00:26 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:39664) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RkqIP-0005Pf-Pq for help-gnu-emacs@gnu.org; Wed, 11 Jan 2012 00:00:22 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RkqIO-000228-Ex for help-gnu-emacs@gnu.org; Wed, 11 Jan 2012 00:00:21 -0500 Original-Received: from lo.gmane.org ([80.91.229.12]:58913) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RkqIO-000220-3d for help-gnu-emacs@gnu.org; Wed, 11 Jan 2012 00:00:20 -0500 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1RkqIN-0001cy-AK for help-gnu-emacs@gnu.org; Wed, 11 Jan 2012 06:00:19 +0100 Original-Received: from 114.250.131.43 ([114.250.131.43]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 11 Jan 2012 06:00:19 +0100 Original-Received: from eric by 114.250.131.43 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 11 Jan 2012 06:00:19 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 74 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: 114.250.131.43 User-Agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.92 (gnu/linux) Cancel-Lock: sha1:QFTR7G8wEWYODDEPtekAH69IVPA= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 80.91.229.12 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:83450 Archived-At: On Wed, Jan 11 2012, Philipp Haselwarter wrote: > Eric Abrahamsen writes: > >> On Tue, Jan 10 2012, Philipp Haselwarter wrote: >> >>> Eric Abrahamsen writes: >>> > ---8<---[snipped 13 lines]---8<--- >> [...] >>> Some programs (eg. mplayer) exit uncleanly when their stderr and stdout >>> are closed, which causes xdg-open to reopen the file with the default >>> application for unknown mime types, as it appears. >>> And allocating a buffer to every started program.... >>> > remains unsolved I've never really seen this problem, so I'm not sure how to address it… [...] > > The only annoyance left is that opening multiple files calls the program > several times as xdg-open accepts only one file. I'd glad to hear ideas > how to solve this! I think the only solution here is to look inside xdg-open and see what it uses to determine the proper default applications. Then, inside emacsclient-wrapper, don't use xdg-open itself, but do what it does to figure out the proper application, and then pass multiple files directly to that application. I'll admit it never even occurred to me to open multiple files this way (though it should have!), so I hadn't thought about it. Assuming you have no desktop environment, the relevant function inside xdg-open is open_generic_xdg_mime, which starts at line 408 in my installation. The following lines make it work: # get the mime type, and the .desktop file of the program that # should open it --8<---------------cut here---------------start------------->8--- filetype=`xdg-mime query filetype "$1" | sed "s/;.*//"` default=`xdg-mime query default "$filetype"` --8<---------------cut here---------------end--------------->8--- # then it finds the .desktop file, puts it in $file, and gets the actual # executable from it, this is why the command line flags are dropped! --8<---------------cut here---------------start------------->8--- command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`" command_exec=`which $command 2>/dev/null` --8<---------------cut here---------------end--------------->8--- # execute command --8<---------------cut here---------------start------------->8--- $command_exec "$1" --8<---------------cut here---------------end--------------->8--- So you could use any or all of the above bits to make a shell script which does basically what xdg-open does, except which can also handle multiple files (and can also preserve command line flags for the executable). Hope that's useful, Eric -- GNU Emacs 24.0.92.2 (i686-pc-linux-gnu, GTK+ Version 2.24.8) of 2012-01-04 on pellet