GNU bug report logs - #18132
Time for a smarter dired-guess-shell-alist-default? (dired-x.el)

Previous Next

Package: emacs;

Reported by: Reuben Thomas <rrt <at> sc3d.org>

Date: Mon, 28 Jul 2014 18:27:01 UTC

Severity: wishlist

Fixed in version 30.0.50

Done: Juri Linkov <juri <at> linkov.net>

Bug is archived. No further changes may be made.

Full log


Message #140 received at 18132 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Drew Adams <drew.adams <at> oracle.com>
Cc: Eli Zaretskii <eliz <at> gnu.org>,
 "18132 <at> debbugs.gnu.org" <18132 <at> debbugs.gnu.org>
Subject: Re: [External] : bug#18132: Time for a smarter
 dired-guess-shell-alist-default? (dired-x.el)
Date: Sun, 03 Dec 2023 19:04:55 +0200
[Message part 1 (text/plain, inline)]
>> Here is this new command 'dired-do-open':
>
> Apologies for taking only a cursory look.
>
> 1. It doesn't use the marked files, contrary to the doc.
> 2. On MS Windows, at least, it doesn't work for files
>    with embedded space chars.

You are absolutely right.  The previous version used wrong assumptions.
Please try a better one:

[dired-do-open-2.patch (text/x-diff, inline)]
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index 1a17ed749e8..23c7a9e0027 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -1401,6 +1401,36 @@ shell-command-guess-open
   "Populate COMMANDS by the `open' command."
   (append (ensure-list shell-command-guess-open) commands))
 
+(declare-function w32-shell-execute "w32fns.c")
+
+(defun dired-do-open (&optional arg)
+  "Open the marked files or a file at click/point externally."
+  (interactive "P" dired-mode)
+  (let ((files (if (mouse-event-p last-nonmenu-event)
+                   (save-excursion
+                     (mouse-set-point last-nonmenu-event)
+                     (dired-get-marked-files nil arg))
+                 (dired-get-marked-files nil arg)))
+        (command shell-command-guess-open))
+    (when (and (memq system-type '(windows-nt))
+               (equal command "start"))
+      (setq command "open"))
+    (when command
+      (dolist (file files)
+        (cond
+         ((memq system-type '(gnu/linux))
+          (call-process command nil 0 nil file))
+         ((memq system-type '(ms-dos))
+          (shell-command (concat command " " (shell-quote-argument file))))
+         ((memq system-type '(windows-nt))
+          (w32-shell-execute command (convert-standard-filename file)))
+         ((memq system-type '(cygwin))
+          (call-process command nil nil nil file))
+         ((memq system-type '(darwin))
+          (start-process (concat command " " file) nil command file))
+         (t
+          (error "Open not supported on this system")))))))
+
 
 ;;; Commands that delete or redisplay part of the dired buffer
 
diff --git a/lisp/dired.el b/lisp/dired.el
index 97645c731c8..7f4b96353ee 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -2591,6 +2591,9 @@ dired-mode-operate-menu
     ["Delete Image Tag..." image-dired-delete-tag
      :help "Delete image tag from current or marked files"]))
 
+(declare-function shell-command-guess "dired-aux" (files))
+(defvar shell-command-guess-open)
+
 (defun dired-context-menu (menu click)
   "Populate MENU with Dired mode commands at CLICK."
   (when (mouse-posn-property (event-start click) 'dired-filename)
@@ -2606,6 +2609,9 @@ dired-context-menu
            :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"]
+          ,@(when shell-command-guess-open
+              '(["Open" dired-do-open
+                 :help "Open externally"]))
           ,@(when commands
               (list (cons "Open With"
                           (append

This bug report was last modified 363 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.