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: Sat, 02 Dec 2023 19:44:38 +0200 Organization: LINKOV.NET Message-ID: <86o7f8ijnd.fsf@mail.linkov.net> References: <83lf2k5gna.fsf@gnu.org> <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> 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="2668"; 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: 18132@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Dec 02 18:50:15 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 1r9U86-0000Yk-Sf for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 02 Dec 2023 18:50:14 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9U7m-0005P2-Mi; Sat, 02 Dec 2023 12:49:54 -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 1r9U7l-0005Oq-Gb for bug-gnu-emacs@gnu.org; Sat, 02 Dec 2023 12:49:53 -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 1r9U7l-0005Is-3l for bug-gnu-emacs@gnu.org; Sat, 02 Dec 2023 12:49:53 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r9U7u-0000PN-7X for bug-gnu-emacs@gnu.org; Sat, 02 Dec 2023 12:50: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: Sat, 02 Dec 2023 17:50: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.17015393841524 (code B ref 18132); Sat, 02 Dec 2023 17:50:02 +0000 Original-Received: (at 18132) by debbugs.gnu.org; 2 Dec 2023 17:49:44 +0000 Original-Received: from localhost ([127.0.0.1]:58588 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r9U7b-0000OT-UN for submit@debbugs.gnu.org; Sat, 02 Dec 2023 12:49:44 -0500 Original-Received: from relay2-d.mail.gandi.net ([2001:4b98:dc4:8::222]:47483) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r9U7Z-0000O7-Ce for 18132@debbugs.gnu.org; Sat, 02 Dec 2023 12:49:42 -0500 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id 8F39740002; Sat, 2 Dec 2023 17:49:24 +0000 (UTC) In-Reply-To: <83leag7loj.fsf@gnu.org> (Eli Zaretskii's message of "Wed, 29 Nov 2023 15:07:08 +0200") 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:275392 Archived-At: --=-=-= Content-Type: text/plain >> Usually context menus on file managers include two items: >> >> "Open" that opens immediately >> "Open With" with a list of commands >> >> So "start" will be used for "Open With" if someone prefers this. >> Then a new command 'dired-do-open' bound to the "Open" menu item >> will hard-code 'w32-shell-execute' call with the "open" command. > > SGTM, thanks. Here is this new command 'dired-do-open': --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=dired-do-open.patch diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index 1a17ed749e8..7887cc358aa 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el @@ -1401,6 +1401,32 @@ 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 at click/point externally." + (interactive "P" dired-mode) + (let ((files (if arg + (dired-get-marked-files nil arg) + (save-excursion + (mouse-set-point last-nonmenu-event) + (list (dired-get-filename nil t))))) + (command shell-command-guess-open)) + (when command + (cond + ((memq system-type '(gnu/linux)) + (apply #'call-process command nil 0 nil files)) + ((memq system-type '(ms-dos)) + (shell-command (concat command " " (mapconcat #'shell-quote-argument files " ")))) + ((memq system-type '(windows-nt)) + (w32-shell-execute (or (and (eq command "start") "open") command) (mapconcat #'convert-standard-filename files " "))) + ((memq system-type '(cygwin)) + (apply #'call-process command nil nil nil files)) + ((memq system-type '(darwin)) + (apply #'start-process (concat command " " files) nil command files)) + (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 --=-=-=--