Emacs Lisp: opening media files straight from GNU Emacs Dired mode by using xdg-open
This is my personal GNU Emacs Dired setup on the V key that helps me to quickly open media files or external viewers by using xdg-open and EMMS the Emacs Multimedia System.
Simply bind the “V” key to this function and then within Dired you use V to view the file. It will remap the Dired-x function which I never used. This way I can easily open videos and other files by using
xdg-open and if I wish to use GNU Emacs built-in functions to view the file I still have the lowercase
v for that.
defun rcd/dired-view () ("View files, either as HTML or media" (interactive)let* ((files (dired-get-marked-files)) (length files)) (how-many (mapcar 'file-name-extension files)) (extensions (mapcar 'downcase extensions))) (extensions (cond ((member "html" extensions) (eww-open-file (car files))) (member "mp4" extensions) (emms-play-dired)) ((member "mp3" extensions) (emms-play-dired)) ((member "ogg" extensions) (emms-play-dired)) ((t (if (> how-many 1) (xdg-open-files files) (car files) t)))))) (xdg-open ( defun xdg-open (file &optional async) ("Opens file with xdg-open. Without optional argument ASYNC, it will wait for the file to finish playing or review." let ((command (format "xdg-open '%s'" file))) (if async ( (async-shell-command command) (shell-command command)))) defun xdg-open-files (files) ("Opens list of files with xdg-open one by one, waiting for each to finish." dolist (file files) ( (xdg-open file))) ;; Finally mapping the key V to dired-mode-map "V" 'rcd/dired-view)(define-key dired-mode-map
There are many ways to customize GNU Emacs and dired.
Contact GNU.Support now. There is a simple rule at GNU.Support: if we can help you, we do, whenever and wherever necessary, and it's the way we've been doing business since 2002, and the only way we know