aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2007-11-16 01:19:13 +0000
committerJuri Linkov2007-11-16 01:19:13 +0000
commit2f8a5963f229a4eff56402bda73d5606a5c47bb7 (patch)
tree44c6a9b01d698286614bd13b7a1a3905ec012c54
parent30971bf9671d0c744be6ee463a0248f4c09d100c (diff)
downloademacs-2f8a5963f229a4eff56402bda73d5606a5c47bb7.tar.gz
emacs-2f8a5963f229a4eff56402bda73d5606a5c47bb7.zip
(dired-read-shell-command-default): New function.
(dired-read-shell-command): Use its return value for DEFAULT arg.
-rw-r--r--lisp/dired-aux.el47
1 files changed, 46 insertions, 1 deletions
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index b9ceb728dbc..321a7f67932 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -463,6 +463,50 @@ with a prefix argument."
463 463
464;;; Shell commands 464;;; Shell commands
465 465
466(defun dired-read-shell-command-default (files)
467 "Return a list of default commands for `dired-read-shell-command'."
468 (require 'mailcap)
469 (mailcap-parse-mailcaps)
470 (mailcap-parse-mimetypes)
471 (let* ((all-mime-type
472 ;; All unique MIME types from file extensions
473 (delete-dups (mapcar (lambda (file)
474 (mailcap-extension-to-mime
475 (file-name-extension file t)))
476 files)))
477 (all-mime-info
478 ;; All MIME info lists
479 (delete-dups (mapcar (lambda (mime-type)
480 (mailcap-mime-info mime-type 'all))
481 all-mime-type)))
482 (common-mime-info
483 ;; Intersection of mime-infos from different mime-types;
484 ;; or just the first MIME info for a single MIME type
485 (if (cdr all-mime-info)
486 (delq nil (mapcar (lambda (mi1)
487 (unless (memq nil (mapcar
488 (lambda (mi2)
489 (member mi1 mi2))
490 (cdr all-mime-info)))
491 mi1))
492 (car all-mime-info)))
493 (car all-mime-info)))
494 (commands
495 ;; Command strings from `viewer' field of the MIME info
496 (delq nil (mapcar (lambda (mime-info)
497 (let ((command (cdr (assoc 'viewer mime-info))))
498 (if (stringp command)
499 (replace-regexp-in-string
500 ;; Replace mailcap's `%s' placeholder
501 ;; with dired's `?' placeholder
502 "%s" "?"
503 (replace-regexp-in-string
504 ;; Remove the final filename placeholder
505 "\s*\\('\\)?%s\\1?\s*\\'" "" command nil t)
506 nil t))))
507 common-mime-info))))
508 commands))
509
466(defun dired-read-shell-command (prompt arg files) 510(defun dired-read-shell-command (prompt arg files)
467;; "Read a dired shell command prompting with PROMPT (using read-string). 511;; "Read a dired shell command prompting with PROMPT (using read-string).
468;;ARG is the prefix arg and may be used to indicate in the prompt which 512;;ARG is the prefix arg and may be used to indicate in the prompt which
@@ -472,7 +516,8 @@ with a prefix argument."
472 nil 'shell files 516 nil 'shell files
473 (function read-string) 517 (function read-string)
474 (format prompt (dired-mark-prompt arg files)) 518 (format prompt (dired-mark-prompt arg files))
475 nil 'shell-command-history)) 519 nil 'shell-command-history
520 (dired-read-shell-command-default files)))
476 521
477;; The in-background argument is only needed in Emacs 18 where 522;; The in-background argument is only needed in Emacs 18 where
478;; shell-command doesn't understand an appended ampersand `&'. 523;; shell-command doesn't understand an appended ampersand `&'.