[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 74f15ad72d9 1/2: New variable shell-command-guess-dired-optional
From: |
Juri Linkov |
Subject: |
master 74f15ad72d9 1/2: New variable shell-command-guess-dired-optional (bug#18132) |
Date: |
Fri, 24 May 2024 13:58:24 -0400 (EDT) |
branch: master
commit 74f15ad72d937b309dafecba872bccd1a880181e
Author: Juri Linkov <juri@linkov.net>
Commit: Juri Linkov <juri@linkov.net>
New variable shell-command-guess-dired-optional (bug#18132)
* doc/emacs/dired.texi (Shell Command Guessing):
Add dired-guess-shell-alist-optional.
* lisp/dired.el (dired-guess-shell-alist-user):
* lisp/dired-aux.el (dired-do-shell-command):
Add dired-guess-shell-alist-optional to docstring.
(dired-guess-shell-alist-default): Move media commands to
'dired-guess-shell-alist-optional'.
(dired-guess-shell-alist-optional): New variable.
(dired-guess-default): Add 'dired-guess-shell-alist-optional'
to the end after 'dired-guess-shell-alist-user'
and 'dired-guess-shell-alist-default'.
(shell-command-guess-functions): Add more options.
(shell-command-guess-dired): Remove function.
(shell-command-guess-dired-user)
(shell-command-guess-dired-default)
(shell-command-guess-dired-optional): New functions.
---
doc/emacs/dired.texi | 13 ++++++-
etc/NEWS | 4 ++
lisp/dired-aux.el | 101 ++++++++++++++++++++++++++++++++++++---------------
lisp/dired.el | 5 ++-
4 files changed, 89 insertions(+), 34 deletions(-)
diff --git a/doc/emacs/dired.texi b/doc/emacs/dired.texi
index a3a740f9727..898c0bfaade 100644
--- a/doc/emacs/dired.texi
+++ b/doc/emacs/dired.texi
@@ -1167,11 +1167,20 @@ guessing off. The elements of
@code{dired-guess-shell-alist-user}
(defined by the user) will override these rules.
@end defvar
+@defvar dired-guess-shell-alist-optional
+This variable is like @code{dired-guess-shell-alist-default} but
+contains external viewers and players for various media formats.
+Setting this to @code{nil} turns guessing off. The variables
+@code{dired-guess-shell-alist-user} and
+@code{dired-guess-shell-alist-default} will override these rules.
+@end defvar
+
@defvar dired-guess-shell-alist-user
If non-@code{nil}, this variable specifies the user-defined alist of
file regexps and their suggested commands. These rules take
-precedence over the predefined rules in the variable
-@code{dired-guess-shell-alist-default} when
+precedence over the predefined rules in the variables
+@code{dired-guess-shell-alist-default} and
+@code{dired-guess-shell-alist-optional} when
@code{dired-do-shell-command} is run). The default is @code{nil}.
Each element of the alist looks like
diff --git a/etc/NEWS b/etc/NEWS
index a79a5844a22..23c87ca5c8b 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -817,6 +817,10 @@ marked or clicked on files according to the OS
conventions. For
example, on systems supporting XDG, this runs 'xdg-open' on the
files.
+*** New variable 'dired-guess-shell-alist-optional'.
+It contains commands for external viewers and players for various media
+formats, moved to this list from 'dired-guess-shell-alist-default'.
+
*** The default value of 'dired-omit-size-limit' was increased.
After performance improvements to omitting in large directories, the new
default value is 300k, up from 100k. This means 'dired-omit-mode' will
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index d1d5ed9b144..83e71b644b8 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -868,8 +868,8 @@ In a noninteractive call (from Lisp code), you must specify
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 @@ Return the result of `process-file' - zero for success."
;; * `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 @@ Return the result of `process-file' - zero for success."
" " 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,37 @@ Return the result of `process-file' - zero for success."
'("\\.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 such as media players and viewers
+that don't exist on many systems where other alternatives are available.
+
+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 +1301,8 @@ See `dired-guess-shell-alist-user'."
(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 +1336,21 @@ See `dired-guess-shell-alist-user'."
(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 +1371,29 @@ after adding own commands to the composite list."
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))
diff --git a/lisp/dired.el b/lisp/dired.el
index 21085de97f2..2b1db9f6e31 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -443,8 +443,9 @@ is anywhere on its Dired line, except the beginning of the
line."
(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