summaryrefslogtreecommitdiff
path: root/lisp/net/mailcap.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/net/mailcap.el')
-rw-r--r--lisp/net/mailcap.el44
1 files changed, 42 insertions, 2 deletions
diff --git a/lisp/net/mailcap.el b/lisp/net/mailcap.el
index b95cd0febcd..5473ba7e697 100644
--- a/lisp/net/mailcap.el
+++ b/lisp/net/mailcap.el
@@ -332,7 +332,7 @@ whose car is a symbol, it is `eval'uated to yield the validity. If it
is a string or list of strings, it represents a shell command to run
to return a true or false shell value for the validity.
-The last matching entry in this structure takes presedence over
+The last matching entry in this structure takes precedence over
preceding entries.")
(put 'mailcap-mime-data 'risky-local-variable t)
@@ -1075,7 +1075,7 @@ For instance, \"foo.png\" will result in \"image/png\"."
(dolist (data mailcap--computed-mime-data)
(dolist (info (cdr data))
(setq type (cdr (assq 'type (cdr info))))
- (unless (string-match-p "\\*" type)
+ (unless (string-search "*" type)
(push type res))))
(nreverse res)))))
@@ -1156,6 +1156,46 @@ 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))
+ ;; Handlers such as "gio open" and kde-open5 start viewer in background
+ ;; and exit immediately. Avoid `start-process' since it assumes
+ ;; :connection-type `pty' and kills children processes with SIGHUP
+ ;; when temporary terminal session is finished (Bug#44824).
+ ;; An alternative is `process-connection-type' let-bound to nil for
+ ;; `start-process-shell-command' call (with no chance to report failure).
+ (make-process
+ :name "mailcap-view-file"
+ :connection-type 'pipe
+ :buffer nil ; "*Messages*" may be suitable for debugging
+ :sentinel (lambda (proc event)
+ (when (and (memq (process-status proc) '(exit signal))
+ (/= (process-exit-status proc) 0))
+ (message
+ "Command %s: %s."
+ (mapconcat #'identity (process-command proc) " ")
+ (substring event 0 -1))))
+ :command (list shell-file-name shell-command-switch command))))
+
(provide 'mailcap)
;;; mailcap.el ends here