openwith seems to kill replying in
Is there a similar/alternative solution for easy defining default apps per extensions in
Stack Exchange network consists of 181 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.Visit Stack Exchange
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.Sign up to join this community
You might find that dired-launch is of some value. I developed it as a launcher specifically for dired-mode (unlike
openwith... which tries to work in a variety of settings).
dired-launch provides a keybinding (
J) which allows one to launch the default external application corresponding to that file.
On Debian, this is how I do it:
(defun mu-open-in-external-app () "Open the file where point is or the marked files in Dired in external app. The app is chosen from your OS's preference." (interactive) (let* ((file-list (dired-get-marked-files))) (mapc (lambda (file-path) (let ((process-connection-type nil)) (start-process "" nil "xdg-open" file-path))) file-list)))
And then I have this:
(define-key dired-mode-map (kbd "C-<return>") #'mu-open-in-external-app)
You can bind
(define-key dired-mode-map (kbd "RET") #'mu-open-in-external-app)
Yes, vanilla Dired has help for this, and Dired+ provides some more help.
You can use
! on a file (or marked files) to run a shell program on it. Use
M-n to cycle among possible commands. These commands to choose from come from the MIME type of the file (see non-option variable
mailcap-mime-data). They can also come from entries that you make in user option
dired-guess-shell-alist-user (you will need to load standard library
dired-x.el for this).
If you use Emacs on MS Windows and you have both Dired+ and library
w32-browser.el (see Ms Shell Execute) then you can use
M-RET in Dired to open a file or directory using its Windows file association (i.e., its "open" program).
dired-guess-defaultis about. It is used by
dired-guess-shell-commandwhich is used by via
dired-do-shell-command). It just looks through
dired-guess-shell-alist-user anddired-guess-shell-alist-default` for a match for your filename, to get the app. If you know the shell command you want for a given file, then do
(dired-do-shell-command THE-SHELL-COMMAND current-prefix-arg THE-FILES-TO-ACT-ON)in the Emacs command you bind to a key.
I'd like to expand on Manuel Uberti's answer.
I use EWXM, and I don't want to accidentally open another Emacs instance. Before running
xdg-open, I first run
xdg-mime a couple of times to check whether the application that will open the file is Emacs. If it is, skip the current file.
I'm new to Elisp, and I appreciate suggestions for improvement!
;;;###autoload (defun my/open-in-external-app () "Open the file where point is or the marked files in Dired in external app. The app is chosen from your OS's preference." (interactive) (let ((file-list (dired-get-marked-files)) mime-type default-application) (cl-flet ((without-newline (str) (substring str 0 (1- (length str))))) (mapc (lambda (file-path) (setq mime-type (without-newline (shell-command-to-string (concat "xdg-mime query filetype " file-path)))) (setq default-application (without-newline (shell-command-to-string (concat "xdg-mime query default " mime-type)))) (unless (equal default-application "emacs.desktop") (let ((process-connection-type nil)) (start-process "" nil "xdg-open" file-path)))) file-list))))
One more thing: When I attempted to load the
define-key sexp on startup, I got an error about
dired-mode-map being unbound. So I wrapped it with
(with-eval-after-load 'dired (define-key dired-mode-map (kbd "C-<return>") #'my/open-in-external-app))
EDIT: Instead of
with-temp-buffer, the function now uses
shell-command-to-string. Also, I changed
let* at the beginning.
openwithseems to kill replying in
mu4e"? I use both and have no problem with them. Does this problem persist if you start Emacs without your init file (
(add-to-list 'mm-inhibit-file-name-handlers 'openwith-file-handler).