Function: doc-view-set-doc-type
doc-view-set-doc-type is a byte-compiled function defined in
doc-view.el.gz.
Signature
(doc-view-set-doc-type)
Documentation
Figure out the current document type (doc-view-doc-type).
Source Code
;; Defined in /usr/src/emacs/lisp/doc-view.el.gz
(defun doc-view-set-doc-type ()
"Figure out the current document type (`doc-view-doc-type')."
(let ((name-types
(cdr (assoc-string
(file-name-extension
(or buffer-file-name (buffer-name (current-buffer))))
'(
;; DVI
("dvi" dvi)
;; PDF
("pdf" pdf) ("epdf" pdf)
;; EPUB
("epub" epub)
;; PostScript
("ps" ps) ("eps" ps)
;; DjVu
("djvu" djvu)
;; OpenDocument formats.
("odt" odf) ("ods" odf) ("odp" odf) ("odg" odf)
("odc" odf) ("odi" odf) ("odm" odf) ("ott" odf)
("ots" odf) ("otp" odf) ("otg" odf)
;; Microsoft Office formats (also handled by the odf
;; conversion chain).
("doc" odf) ("docx" odf) ("xls" odf) ("xlsx" odf)
("ppt" odf) ("pps" odf) ("pptx" odf) ("rtf" odf)
;; CBZ
("cbz" cbz)
;; FB2
("fb2" fb2)
;; (Open)XPS
("xps" xps) ("oxps" oxps))
t)))
(content-types
(save-excursion
(goto-char (point-min))
(cond
((looking-at "%!") '(ps))
((looking-at "%PDF") '(pdf))
((looking-at "\367\002") '(dvi))
((looking-at "AT&TFORM") '(djvu))
;; The following pattern actually is for recognizing
;; zip-archives, so that this same association is used for
;; cbz files. This is fine, as cbz files should be handled
;; like epub anyway.
((looking-at "PK") '(epub odf cbz))))))
(setq-local
doc-view-doc-type
(car (or (nreverse (seq-intersection name-types content-types #'eq))
(when (and name-types content-types)
(error "Conflicting types: name says %s but content says %s"
name-types content-types))
name-types content-types
(error "Cannot determine the document type"))))))