[Top][All Lists]

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

Re: emacs and xdg-open

From: Philipp Haselwarter
Subject: Re: emacs and xdg-open
Date: Tue, 10 Jan 2012 20:29:47 +0100
User-agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.92 (gnu/linux)

Eric Abrahamsen <> writes:

> On Tue, Jan 10 2012, Philipp Haselwarter wrote:
>> Eric Abrahamsen <> writes:
---8<---[snipped 13 lines]---8<---
>> What command you use to call `xdg-open'?
> I modified something I found on the internet that originally used
> gnome-open:
> (defun dired-xdg-open-file ()
>   "Opens the current file in a Dired buffer."
>   (interactive)
>   (xdg-open-file (dired-get-file-for-visit)))
> (defun xdg-open-file (filename)
>   "xdg-opens the specified file."
>   (interactive "fFile to open: ")
>   (let ((process-connection-type nil))
>     (start-process "" nil "/usr/bin/xdg-open" filename)))
> ;;'e' usually does 'dired-find-file, same as RET, rebinding it here
> (add-hook 'dired-mode-hook
>         (lambda ()
>           (define-key dired-mode-map (kbd "e") 'dired-xdg-open-file)))
> (setq image-dired-external-viewer "/usr/bin/xdg-open")
>> 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

--8<---------------cut here---------------start------------->8---
(eval-after-load 'dired
    (define-key dired-mode-map "E" 'my-dired-xdg-open)
    (define-key dired-mode-map [tool-bar my-dired-xdg-open]
      `(menu-item "ext" my-dired-xdg-open
                  :help "Open file(s) with xdg-open"
                  :image ,(find-image
                           '((:type xpm :file "right-arrow.xpm")))))))

(defun my-dired-xdg-open (arg)
  "Open files from `dired-get-marked-files' with `my-xdg-open-file'"
  (interactive "P")
  (mapcar 'my-xdg-open-file (dired-get-marked-files nil arg)))

(defun dired-xdg-open-file ()
  "Opens the current file in a Dired buffer."
  (xdg-open-file (dired-get-file-for-visit)))
--8<---------------cut here---------------end--------------->8---

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!

---8<---[snipped 53 lines]---8<---
> Anyway, thanks for getting me the rest of the way there!
> Eric

Glad it works; usually I have {tool,menu,scroll}-bar-mode turned off but
I kind of like them for a file manager.
Here's what I ended up with:

--8<---------------cut here---------------start------------->8---
[ "$1" ] || set "`pwd`"

OPT='((tool-bar-lines . 1) (menu-bar-lines . 1) (vertical-scroll-bars . right))'
emacsclient -n -c -F "$OPT" "$@"
--8<---------------cut here---------------end--------------->8---

Philipp Haselwarter

reply via email to

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