all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: 63911@debbugs.gnu.org
Subject: bug#63911: Dired Open With
Date: Mon, 05 Jun 2023 19:07:49 +0300	[thread overview]
Message-ID: <86bkhuney2.fsf@mail.linkov.net> (raw)

[-- 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))))))

             reply	other threads:[~2023-06-05 16:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-05 16:07 Juri Linkov [this message]
2023-06-23 16:27 ` bug#63911: Dired Open With 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86bkhuney2.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=63911@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.