From: Juri Linkov <juri@linkov.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 18132@debbugs.gnu.org
Subject: bug#18132: Time for a smarter dired-guess-shell-alist-default? (dired-x.el)
Date: Wed, 22 May 2024 09:16:18 +0300 [thread overview]
Message-ID: <86v836z8h6.fsf@mail.linkov.net> (raw)
In-Reply-To: <86r0jvbd26.fsf@mail.linkov.net> (Juri Linkov's message of "Sat, 09 Dec 2023 19:13:13 +0200")
[-- Attachment #1: Type: text/plain, Size: 1490 bytes --]
>>> 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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: dired-guess-shell-alist-optional.patch --]
[-- Type: text/x-diff, Size: 7861 bytes --]
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))
next prev parent reply other threads:[~2024-05-22 6:16 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-28 18:26 bug#18132: Time for a smarter dired-guess-shell-alist-default? (dired-x.el) Reuben Thomas
2014-07-28 18:44 ` bug#18132: Sample code Reuben Thomas
2014-07-29 23:49 ` bug#18132: Time for a smarter dired-guess-shell-alist-default? (dired-x.el) Juri Linkov
2014-07-30 9:12 ` Reuben Thomas
2014-07-30 16:32 ` Juri Linkov
2014-07-30 16:44 ` Reuben Thomas
2014-08-04 23:45 ` Juri Linkov
2014-08-05 9:41 ` Reuben Thomas
2021-10-23 5:25 ` Stefan Kangas
2021-10-23 7:44 ` Eli Zaretskii
2021-10-23 8:16 ` Stefan Kangas
2021-10-23 8:34 ` Eli Zaretskii
2021-10-23 9:48 ` Stefan Kangas
2021-10-23 11:48 ` Eli Zaretskii
2021-10-23 13:06 ` Reuben Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-23 13:20 ` Eli Zaretskii
2021-10-23 13:01 ` Reuben Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-23 13:56 ` Stefan Kangas
2021-10-23 14:03 ` Reuben Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-23 15:45 ` Stefan Kangas
2021-10-23 17:17 ` Gregory Heytings
2021-10-23 20:53 ` Reuben Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-24 6:02 ` Eli Zaretskii
2021-10-24 7:56 ` Juri Linkov
2023-11-23 17:49 ` Juri Linkov
2023-11-23 19:40 ` Eli Zaretskii
2023-11-24 7:51 ` Juri Linkov
2023-11-24 14:24 ` Eli Zaretskii
2023-11-25 18:10 ` Juri Linkov
2023-11-26 10:37 ` Eli Zaretskii
2023-11-27 17:32 ` Juri Linkov
2023-11-28 17:05 ` Juri Linkov
2023-11-28 17:35 ` Eli Zaretskii
2023-11-29 7:09 ` Juri Linkov
2023-11-29 13:07 ` Eli Zaretskii
2023-12-02 17:44 ` Juri Linkov
2023-12-02 18:37 ` Drew Adams
2023-12-03 17:04 ` Juri Linkov
2023-12-03 21:16 ` Drew Adams
2023-12-06 17:28 ` Juri Linkov
2023-12-07 17:33 ` Juri Linkov
2023-12-07 17:48 ` Eli Zaretskii
2023-12-08 7:37 ` Juri Linkov
2023-12-08 8:08 ` Eli Zaretskii
2023-12-09 17:13 ` Juri Linkov
2024-05-22 6:16 ` Juri Linkov [this message]
2024-05-22 12:42 ` Eli Zaretskii
2024-05-23 6:19 ` Juri Linkov
2024-05-23 7:16 ` Eli Zaretskii
2024-05-23 17:31 ` Juri Linkov
2024-05-23 18:15 ` Eli Zaretskii
2024-05-24 6:44 ` Juri Linkov
2024-05-24 7:31 ` Eli Zaretskii
2024-05-24 17:56 ` Juri Linkov
2021-10-23 17:57 ` Howard Melman
2021-10-23 18:29 ` Juri Linkov
2021-10-23 19:22 ` bug#18132: [External] : " Drew Adams
2021-10-24 16:35 ` Howard Melman
2021-10-24 19:08 ` Juri Linkov
2021-10-24 5:10 ` Thierry Volpiatto
2014-07-30 3:56 ` Eli Zaretskii
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86v836z8h6.fsf@mail.linkov.net \
--to=juri@linkov.net \
--cc=18132@debbugs.gnu.org \
--cc=eliz@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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).