help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: emacs and xdg-open


From: Eric Abrahamsen
Subject: Re: emacs and xdg-open
Date: Wed, 11 Jan 2012 13:00:10 +0800
User-agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.92 (gnu/linux)

On Wed, Jan 11 2012, Philipp Haselwarter wrote:

> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> On Tue, Jan 10 2012, Philipp Haselwarter wrote:
>>
>>> Eric Abrahamsen <eric@ericabrahamsen.net> 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]