1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Add a new command `mailcap-view-file'

* doc/misc/emacs-mime.texi (mailcap): Document it (bug#12972).

* lisp/net/mailcap.el (mailcap-view-file): New command.
This commit is contained in:
Lars Ingebrigtsen 2021-06-01 08:55:06 +02:00
parent 78f885f370
commit 85e17196fa
3 changed files with 32 additions and 0 deletions

View file

@ -1870,6 +1870,11 @@ A customizable list of viewers that take preference over
Interface functions:
@table @code
@item mailcap-view-file
@findex mailcap-view-file
Prompt for a file name, and start a viewer applicable for the file
type in question.
@item mailcap-parse-mailcaps
@findex mailcap-parse-mailcaps
@vindex mailcap-prefer-mailcap-viewers

View file

@ -1991,6 +1991,10 @@ Shift while typing 'C-a', i.e. 'C-S-a', will now highlight the text.
** Miscellaneous
*** New command 'mailcap-view-file'.
This command will open a viewer based on the file type, as determined
by ~/.mailcap and related files and variables.
+++
*** New command 'C-x C-k Q' to force redisplay in keyboard macros.

View file

@ -1156,6 +1156,29 @@ current buffer after passing its contents to the shell command."
(mailcap--async-shell method file))
(funcall method))))
(defun mailcap-view-file (file)
"View FILE according to rules given by the mailcap system.
This normally involves executing some external program to display
the file.
See \"~/.mailcap\", `mailcap-mime-data' and related files and variables."
(interactive "fOpen file with mailcap: ")
(setq file (expand-file-name file))
(mailcap-parse-mailcaps)
(let ((command (mailcap-mime-info
(mailcap-extension-to-mime (file-name-extension file)))))
(unless command
(error "No viewer for %s" (file-name-extension file)))
;; Remove quotes around the file name - we'll use shell-quote-argument.
(while (string-match "['\"]%s['\"]" command)
(setq command (replace-match "%s" t t command)))
(setq command (replace-regexp-in-string
"%s"
(shell-quote-argument (convert-standard-filename file))
command
nil t))
(start-process-shell-command command nil command)))
(provide 'mailcap)
;;; mailcap.el ends here