From: Lars Ingebrigtsen Date: Tue, 1 Jun 2021 06:55:06 +0000 (+0200) Subject: Add a new command `mailcap-view-file' X-Git-Tag: emacs-28.0.90~2239 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=85e17196fa2b6333fbce7fdac1e2e17b045b91ae;p=emacs.git 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. --- diff --git a/doc/misc/emacs-mime.texi b/doc/misc/emacs-mime.texi index 0cf5ba96506..7cd3e5f5828 100644 --- a/doc/misc/emacs-mime.texi +++ b/doc/misc/emacs-mime.texi @@ -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 diff --git a/etc/NEWS b/etc/NEWS index 6622861aaf1..351295a2688 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -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. diff --git a/lisp/net/mailcap.el b/lisp/net/mailcap.el index 3097c9a671e..54f7f416aba 100644 --- a/lisp/net/mailcap.el +++ b/lisp/net/mailcap.el @@ -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