From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#18132: Time for a smarter dired-guess-shell-alist-default? (dired-x.el) Date: Sun, 03 Dec 2023 19:04:55 +0200 Organization: LINKOV.NET Message-ID: <86y1eb8bi8.fsf@mail.linkov.net> References: <83ilxn3qpo.fsf@gnu.org> <878ryizwyi.fsf@mail.linkov.net> <86y1eoxtrr.fsf@mail.linkov.net> <83leaofebt.fsf@gnu.org> <86edgfk37h.fsf@mail.linkov.net> <83zfz3dyae.fsf@gnu.org> <86h6l9zorh.fsf@mail.linkov.net> <838r6kby1m.fsf@gnu.org> <86msuz5cft.fsf@mail.linkov.net> <86ttp6j8ax.fsf@mail.linkov.net> <8334wp93ww.fsf@gnu.org> <86v89lt6mk.fsf@mail.linkov.net> <83leag7loj.fsf@gnu.org> <86o7f8ijnd.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36476"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu) Cc: Eli Zaretskii , "18132@debbugs.gnu.org" <18132@debbugs.gnu.org> To: Drew Adams Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Dec 03 18:07:09 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1r9pvx-0009Mq-5p for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 03 Dec 2023 18:07:09 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9pvj-0004mp-Vx; Sun, 03 Dec 2023 12:06:56 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r9pvg-0004lu-A8 for bug-gnu-emacs@gnu.org; Sun, 03 Dec 2023 12:06:52 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9pvg-0000OC-1m for bug-gnu-emacs@gnu.org; Sun, 03 Dec 2023 12:06:52 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r9pvq-0006bm-1W for bug-gnu-emacs@gnu.org; Sun, 03 Dec 2023 12:07:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 03 Dec 2023 17:07:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 18132 X-GNU-PR-Package: emacs Original-Received: via spool by 18132-submit@debbugs.gnu.org id=B18132.170162317625347 (code B ref 18132); Sun, 03 Dec 2023 17:07:02 +0000 Original-Received: (at 18132) by debbugs.gnu.org; 3 Dec 2023 17:06:16 +0000 Original-Received: from localhost ([127.0.0.1]:60733 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r9pv5-0006al-Kk for submit@debbugs.gnu.org; Sun, 03 Dec 2023 12:06:15 -0500 Original-Received: from relay1-d.mail.gandi.net ([2001:4b98:dc4:8::221]:44811) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r9pv1-0006aH-HN for 18132@debbugs.gnu.org; Sun, 03 Dec 2023 12:06:14 -0500 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id E5173240004; Sun, 3 Dec 2023 17:05:53 +0000 (UTC) In-Reply-To: (Drew Adams's message of "Sat, 2 Dec 2023 18:37:24 +0000") X-GND-Sasl: juri@linkov.net X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:275433 Archived-At: --=-=-= Content-Type: text/plain >> 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: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=dired-do-open-2.patch 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 --=-=-=--