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: Wed, 22 May 2024 09:16:18 +0300 Organization: LINKOV.NET Message-ID: <86v836z8h6.fsf@mail.linkov.net> References: <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> <86y1eb8bi8.fsf@mail.linkov.net> <861qbz9r54.fsf@mail.linkov.net> <86fs0ef372.fsf@mail.linkov.net> <83y1e529a2.fsf@gnu.org> <86sf4db0wf.fsf@mail.linkov.net> <835y1915hl.fsf@gnu.org> <86r0jvbd26.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="40860"; 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 Wed May 22 08:18:27 2024 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 1s9fIw-000AOr-ST for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 22 May 2024 08:18:26 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9fIW-00078r-8H; Wed, 22 May 2024 02:18:00 -0400 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 1s9fIT-00072p-0q for bug-gnu-emacs@gnu.org; Wed, 22 May 2024 02:17:58 -0400 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 1s9fIS-0004y2-O9 for bug-gnu-emacs@gnu.org; Wed, 22 May 2024 02:17:56 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s9fIY-0006cP-4w for bug-gnu-emacs@gnu.org; Wed, 22 May 2024 02:18:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 22 May 2024 06:18: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.171635865025407 (code B ref 18132); Wed, 22 May 2024 06:18:02 +0000 Original-Received: (at 18132) by debbugs.gnu.org; 22 May 2024 06:17:30 +0000 Original-Received: from localhost ([127.0.0.1]:53683 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s9fI1-0006bi-9z for submit@debbugs.gnu.org; Wed, 22 May 2024 02:17:29 -0400 Original-Received: from relay1-d.mail.gandi.net ([217.70.183.193]:44701) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s9fHx-0006bT-PN for 18132@debbugs.gnu.org; Wed, 22 May 2024 02:17:28 -0400 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id 20B2824000A; Wed, 22 May 2024 06:17:13 +0000 (UTC) In-Reply-To: <86r0jvbd26.fsf@mail.linkov.net> (Juri Linkov's message of "Sat, 09 Dec 2023 19:13:13 +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:285577 Archived-At: --=-=-= Content-Type: text/plain >>> https://lists.gnu.org/archive/html/bug-gnu-emacs/2021-10/msg01952.html >> >> This says two things: >> >> . some commands in the list are less capable then others >> . XDG can do the job better >> >> To the first point, my response would be: put the better ones first in >> the list, but leave the worse ones in the list for those users who >> don't have the better alternatives. > > I completely agree. This is what I tried to do, > but couldn't find a way to refactor this amalgamation > in dired-guess-shell-alist-default. We need to split it > to two parts, so users without XDG will have: > > 1. better ones from dired-guess-shell-alist-default > 2. worse ones from dired-guess-shell-alist-default > > And users with XDG should be able to have: > > 1. better ones from dired-guess-shell-alist-default > 2. XDG commands > 3. worse ones from dired-guess-shell-alist-default > > Probably I'll move the worse ones to a new variable > 'dired-guess-shell-alist-default-2'. Ok, here is a new list 'dired-guess-shell-alist-optional' that contains rare commands that don't exist on many systems. So now the default order of a list of commands to select with M-n for M-!, ! in Dired and the Dired context menu with this patch is the following: 1. commands from dired-guess-shell-alist-user 2. commands from dired-guess-shell-alist-default 3. commands found by XDG on user's system 4. commands found by mailcap on user's system 5. rare commands from dired-guess-shell-alist-optional --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=dired-guess-shell-alist-optional.patch diff --git a/lisp/dired.el b/lisp/dired.el index 28ec187e666..b7c42318946 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -443,8 +443,9 @@ dired-guess-shell-case-fold-search (defcustom dired-guess-shell-alist-user nil "User-defined alist of rules for suggested commands. -These rules take precedence over the predefined rules in the variable -`dired-guess-shell-alist-default' (to which they are prepended). +These rules take precedence over the predefined rules in the variables +`dired-guess-shell-alist-default' and `dired-guess-shell-alist-optional' +\(to which they are prepended). Each element of this list looks like diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index 22c6881ae35..58d5a74f269 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el @@ -868,8 +868,8 @@ dired-do-shell-command the list of file names explicitly with the FILE-LIST argument, which can be produced by `dired-get-marked-files', for example. -`dired-guess-shell-alist-default' and -`dired-guess-shell-alist-user' are consulted when the user is +`dired-guess-shell-alist-default', `dired-guess-shell-alist-optional' +and `dired-guess-shell-alist-user' are consulted when the user is prompted for the shell command to use interactively. Also see the `dired-confirm-shell-command' variable." @@ -1068,8 +1068,8 @@ dired-shell-command ;; * `dired-guess-shell-command' calls `dired-guess-default' with list of ;; marked files. ;; -;; * Parse `dired-guess-shell-alist-user' and -;; `dired-guess-shell-alist-default' (in that order) for the first REGEXP +;; * Parse `dired-guess-shell-alist-user', `dired-guess-shell-alist-default', +;; `dired-guess-shell-alist-optional' (in that order) for the first REGEXP ;; that matches the first file in the file list. ;; ;; * If the REGEXP matches all the entries of the file list then evaluate @@ -1219,28 +1219,10 @@ dired-guess-shell-alist-default " " dired-guess-shell-znew-switches)) '("\\.pod\\'" "perldoc" "pod2man * | nroff -man") - '("\\.dvi\\'" "xdvi" "dvips") ; preview and printing - '("\\.au\\'" "play") ; play Sun audiofiles - '("\\.mpe?g\\'\\|\\.avi\\'" "xine -p") - '("\\.ogg\\'" "ogg123") - '("\\.mp3\\'" "mpg123") - '("\\.wav\\'" "play") '("\\.uu\\'" "uudecode") ; for uudecoded files - '("\\.hqx\\'" "mcvert") '("\\.sh\\'" "sh") ; execute shell scripts - '("\\.xbm\\'" "bitmap") ; view X11 bitmaps - '("\\.gp\\'" "gnuplot") - '("\\.p[bgpn]m\\'" "xloadimage") - '("\\.gif\\'" "xloadimage") ; view gif pictures - '("\\.tif\\'" "xloadimage") - '("\\.png\\'" "display") ; xloadimage 4.1 doesn't grok PNG - '("\\.jpe?g\\'" "xloadimage") - '("\\.fig\\'" "xfig") ; edit fig pictures - '("\\.out\\'" "xgraph") ; for plotting purposes. '("\\.tex\\'" "latex" "tex") '("\\.texi\\(nfo\\)?\\'" "makeinfo" "texi2dvi") - '("\\.pdf\\'" "xpdf") - '("\\.doc\\'" "antiword" "strings") '("\\.rpm\\'" "rpm -qilp" "rpm -ivh") '("\\.dia\\'" "dia") '("\\.mgp\\'" "mgp") @@ -1269,7 +1251,39 @@ dired-guess-shell-alist-default '("\\.sign?\\'" "gpg --verify")) "Default alist used for shell command guessing. -See `dired-guess-shell-alist-user'.") +See also `dired-guess-shell-alist-optional' and +`dired-guess-shell-alist-user'.") + +(defvar dired-guess-shell-alist-optional + (list + '("\\.dvi\\'" "xdvi" "dvips") ; preview and printing + '("\\.au\\'" "play") ; play Sun audiofiles + '("\\.mpe?g\\'\\|\\.avi\\'" "xine -p") + '("\\.ogg\\'" "ogg123") + '("\\.mp3\\'" "mpg123") + '("\\.wav\\'" "play") + '("\\.hqx\\'" "mcvert") + '("\\.xbm\\'" "bitmap") ; view X11 bitmaps + '("\\.gp\\'" "gnuplot") + '("\\.p[bgpn]m\\'" "xloadimage") + '("\\.gif\\'" "xloadimage") ; view gif pictures + '("\\.tif\\'" "xloadimage") + '("\\.png\\'" "display") ; xloadimage 4.1 doesn't grok PNG + '("\\.jpe?g\\'" "xloadimage") + '("\\.fig\\'" "xfig") ; edit fig pictures + '("\\.out\\'" "xgraph") ; for plotting purposes. + '("\\.pdf\\'" "xpdf") + '("\\.doc\\'" "antiword" "strings")) + "Optional alist used for shell command guessing. +Unlike `dired-guess-shell-alist-default' that contains mostly the +standard commands that handle the files with corresponding extensions +such as the `tar' command handling the files with the `.tar' extension, +this list contains the commands that don't exist on many systems +where other alternatives are available. So this needs to be in +a separate list not to conflict with existing commands provided +by mailcap and XDG. + +See also `dired-guess-shell-alist-user'.") (defun dired-guess-default (files) "Return a shell command, or a list of commands, appropriate for FILES. @@ -1289,7 +1303,8 @@ dired-guess-default (string-match-p (car elem) file)) files)) (append dired-guess-shell-alist-user - dired-guess-shell-alist-default))) + dired-guess-shell-alist-default + dired-guess-shell-alist-optional))) nil))))) (if (length= programs 1) (car programs) @@ -1323,13 +1338,21 @@ dired-guess-shell-command (if (equal val "") default val)))) (defcustom shell-command-guess-functions - '(shell-command-guess-dired) + '(shell-command-guess-dired-optional + shell-command-guess-mailcap + shell-command-guess-xdg + shell-command-guess-dired-default + shell-command-guess-dired-user) "List of functions that guess shell commands for files. Each function receives a list of commands and a list of file names and should return the same list of commands with changes -such as added new commands." +such as new commands added to the beginning of the list. +In this case the commands from the last entry +will be at the top of the resulted list." :type '(repeat - (choice (function-item shell-command-guess-dired) + (choice (function-item shell-command-guess-dired-user) + (function-item shell-command-guess-dired-default) + (function-item shell-command-guess-dired-optional) (function-item shell-command-guess-mailcap) (function-item shell-command-guess-xdg) (function-item shell-command-guess-open) @@ -1350,9 +1373,29 @@ shell-command-guess nil)) commands)) -(defun shell-command-guess-dired (commands files) - "Populate COMMANDS using `dired-guess-default'." - (append (ensure-list (dired-guess-default files)) commands)) +(defun shell-command-guess-dired-user (commands files) + "Populate COMMANDS using `dired-guess-shell-alist-user'. +This excludes `dired-guess-shell-alist-default' and +`dired-guess-shell-alist-optional'." + (let ((dired-guess-shell-alist-default nil) + (dired-guess-shell-alist-optional nil)) + (append (ensure-list (dired-guess-default files)) commands))) + +(defun shell-command-guess-dired-default (commands files) + "Populate COMMANDS using `dired-guess-shell-alist-default'. +This excludes `dired-guess-shell-alist-user' and +`dired-guess-shell-alist-optional'." + (let ((dired-guess-shell-alist-user nil) + (dired-guess-shell-alist-optional nil)) + (append (ensure-list (dired-guess-default files)) commands))) + +(defun shell-command-guess-dired-optional (commands files) + "Populate COMMANDS using `dired-guess-shell-alist-optional'. +This excludes `dired-guess-shell-alist-user' and +`dired-guess-shell-alist-default'." + (let ((dired-guess-shell-alist-user nil) + (dired-guess-shell-alist-default nil)) + (append (ensure-list (dired-guess-default files)) commands))) (declare-function mailcap-file-default-commands "mailcap" (files)) --=-=-=--