unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#63911: Dired Open With
@ 2023-06-05 16:07 Juri Linkov
  2023-06-23 16:27 ` Juri Linkov
  0 siblings, 1 reply; 8+ messages in thread
From: Juri Linkov @ 2023-06-05 16:07 UTC (permalink / raw)
  To: 63911

[-- Attachment #1: Type: text/plain, Size: 93 bytes --]

Tags: patch

As requested in bug#63875, here is a new context submenu "Open With" in Dired:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: dired-open-with.patch --]
[-- Type: text/x-diff, Size: 1951 bytes --]

diff --git a/lisp/dired.el b/lisp/dired.el
index e70467ca53b..a295ece128d 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -2504,17 +2504,33 @@ dired-mode-operate-menu
     ["Delete Image Tag..." image-dired-delete-tag
      :help "Delete image tag from current or marked files"]))
 
+(declare-function mailcap-file-default-commands "mailcap" (files))
+
 (defun dired-context-menu (menu click)
   "Populate MENU with Dired mode commands at CLICK."
   (when (mouse-posn-property (event-start click) 'dired-filename)
     (define-key menu [dired-separator] menu-bar-separator)
-    (let ((easy-menu (make-sparse-keymap "Immediate")))
+    (require 'mailcap nil t)
+    (let* ((filename (save-excursion
+                       (mouse-set-point click)
+                       (dired-get-filename nil t)))
+           (commands (mailcap-file-default-commands (list filename)))
+           (easy-menu (make-sparse-keymap "Immediate")))
       (easy-menu-define nil easy-menu nil
-        '("Immediate"
+        `("Immediate"
           ["Find This File" dired-mouse-find-file
            :help "Edit file at mouse click"]
           ["Find in Other Window" dired-mouse-find-file-other-window
-           :help "Edit file at mouse click in other window"]))
+           :help "Edit file at mouse click in other window"]
+          ,@(when commands
+              (list (cons "Open With"
+                          (mapcar (lambda (command)
+                                    `[,command
+                                      (lambda ()
+                                        (interactive)
+                                        (dired-do-async-shell-command
+                                         ,command nil (list ,filename)))])
+                                  commands))))))
       (dolist (item (reverse (lookup-key easy-menu [menu-bar immediate])))
         (when (consp item)
           (define-key menu (vector (car item)) (cdr item))))))

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-11-27 17:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-05 16:07 bug#63911: Dired Open With Juri Linkov
2023-06-23 16:27 ` Juri Linkov
2023-09-01 22:33   ` Stefan Kangas
2023-09-02 18:40     ` Howard Melman
2023-09-02 19:01       ` Eli Zaretskii
2023-09-23  1:10         ` Björn Bidar via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-23 17:54     ` Juri Linkov
2023-11-27 17:36       ` Juri Linkov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).