2

Linux Mint 19, Emacs 26.1 I has different app to show image.Like Drawing, Image Viewer, XnView.

And from Nemo file manager I success open any images by this app. Nice.

But I want to open image in Dired mode. So in my init.el I has this:

(when (require 'openwith nil 'noerror)
  (setq openwith-associations
        (list 
     (list (openwith-make-extension-regexp '("doc" "docx" "rtf")) "word" '(file))
     (list (openwith-make-extension-regexp '("mpg" "mpeg" "mp3" "mp4" "avi" "wmv" "wav" "mov" "mkv")) "vlc" '(file))
     (list (openwith-make-extension-regexp '("pdf")) "FoxitReader" '(file))
     (list (openwith-make-extension-regexp '("bmp" "gif" "jpeg" "jpg" "png" "tif")) "xnview" '(file))
     (list (openwith-make-extension-regexp '("rdp")) "Remote Desctop Connection" '(file))
     (list (openwith-make-extension-regexp '("xls" "xlsx")) "excel" '(file))
         ))
  (openwith-mode 1))

So when I'm in dired mode and press Enter over image file I get the next message and nothing happend:

openwith-file-handler: Opened DEEPSP_little.JPG in external program

I want to open image by external app when I'm in dired mode.

2 Answers 2

1

Just load standard library dired-x.el, customize option dired-guess-shell-alist-user, and use ! in Dired, to open whatever program you want, by default on the marked files or a single file, for whatever image-file extensions you want.

C-x v dired-guess-shell-alist-user:

dired-guess-shell-alist-user is a variable defined in dired-x.el.

Its value is nil

Documentation:

User-defined alist of rules for suggested commands.

These rules take precedence over the predefined rules in the variable dired-guess-shell-alist-default (to which they are prepended).

Each element of this list looks like

(REGEXP COMMAND...)

where each COMMAND can either be a string or a Lisp expression that evaluates to a string. If this expression needs to consult the name of the file for which the shell commands are being requested, it can access that file name as the variable file.

If several COMMANDs are given, the first one will be the default and the rest will be added temporarily to the history and can be retrieved with M-x previous-history-element (M-p) .

The variable dired-guess-shell-case-fold-search controls whether REGEXP is matched case-sensitively.

You can customize this variable.

2
  • Hi @Drew You might be tired of copying and pasting this answer to so many questions :-). Personally, I would like to see an example of application via init.el in addition to the manual entry, preferably on usage of libreoffice, to open xls or doc files from within dired. If you add it to your answer I'd be happy to upvote it.
    – Ajned
    Jul 27, 2021 at 9:18
  • @Ajned: If you find that I've posted the same answer to more than one question then please vote to close the relevant questions a duplicates, or let me know and I'll do so, if you don't have the ability to vote for closing a question. As for your request for an example, please post that as a separate question. Someone will answer it (it's not clear to me what the request/question is).
    – Drew
    Jul 27, 2021 at 18:51
0

I found solution.

I must install app XnView by terminal like this:

sudo apt-get install gdebi

wget http://download.xnview.com/XnViewMP-linux-x64.deb

sudo gdebi XnViewMP-linux-x64.deb

And then image success open in Dired mode. And open image by XnView app.

Nice.

Not need to do any additional setting in init.el

This is enough:

(when (require 'openwith nil 'noerror)
  (setq openwith-associations
        (list 
     (list (openwith-make-extension-regexp '("doc" "docx" "rtf")) "word" '(file))
     (list (openwith-make-extension-regexp '("mpg" "mpeg" "mp3" "mp4" "avi" "wmv" "wav" "mov" "mkv")) "vlc" '(file))
     (list (openwith-make-extension-regexp '("pdf")) "FoxitReader" '(file))
     (list (openwith-make-extension-regexp '("bmp" "gif" "jpeg" "jpg" "png" "tif")) "xnview" '(file))
     (list (openwith-make-extension-regexp '("rdp")) "Remote Desctop Connection" '(file))
     (list (openwith-make-extension-regexp '("xls" "xlsx")) "excel" '(file))
         ))
  (openwith-mode 1))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.