emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 85e1719 1/4: Add a new command `mailcap-view-file'


From: Lars Ingebrigtsen
Subject: master 85e1719 1/4: Add a new command `mailcap-view-file'
Date: Tue, 1 Jun 2021 04:24:40 -0400 (EDT)

branch: master
commit 85e17196fa2b6333fbce7fdac1e2e17b045b91ae
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    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.
---
 doc/misc/emacs-mime.texi |  5 +++++
 etc/NEWS                 |  4 ++++
 lisp/net/mailcap.el      | 23 +++++++++++++++++++++++
 3 files changed, 32 insertions(+)

diff --git a/doc/misc/emacs-mime.texi b/doc/misc/emacs-mime.texi
index 0cf5ba9..7cd3e5f 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 6622861..351295a 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 3097c9a..54f7f41 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]