From: Juanma Barranquero <lekktu@gmail.com>
To: Emacs developers <emacs-devel@gnu.org>
Subject: doc-view-set-doc-type's generality
Date: Wed, 4 Dec 2019 10:32:47 +0100 [thread overview]
Message-ID: <CAAeL0STwFf2pzgbe8w_vh-r6ZcNB=5Ygsf=3CSGfe3Ei5B8r-g@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 2593 bytes --]
I was perusing doc-view.el and I've been quite puzzled by
doc-view-set-doc-type.
(defun doc-view-set-doc-type ()
"Figure out the current document type (`doc-view-doc-type')."
(let ((name-types
(when buffer-file-name
(cdr (assoc-string
(file-name-extension buffer-file-name)
'(
;; DVI
("dvi" dvi)
;; PDF
("pdf" pdf) ("epdf" pdf)
;; 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))
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))))))
(setq-local
doc-view-doc-type
(car (or (doc-view-intersection name-types content-types)
(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"))))))
It is written as if, for a given document (in a buffer), there could be
more than a name type (but name-types is derived from the file's
extension), and more than one content type (but content-types is derived
from looking at the few first bytes at the beginning of the buffer). And
then there's a function doc-view-intersection whose only use is to detect
cases of the name-types in the content-types' "list".
I mean, I could see the logic if it the code tried to detect cases of one
extension (let's say, ".doc") that could represent different content-types.
But in fact, currently the situation is the opposite: multiple extensions
associated to one content-type (like .ps / .eps, etc.)
Seems to me generality for generality's sake, as the code has only had
minor alteration (adding djvu and some assoc changes) in nine years.
[-- Attachment #2: Type: text/html, Size: 3521 bytes --]
next reply other threads:[~2019-12-04 9:32 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-04 9:32 Juanma Barranquero [this message]
2019-12-04 13:57 ` doc-view-set-doc-type's generality Stefan Monnier
2019-12-04 14:05 ` Juanma Barranquero
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAAeL0STwFf2pzgbe8w_vh-r6ZcNB=5Ygsf=3CSGfe3Ei5B8r-g@mail.gmail.com' \
--to=lekktu@gmail.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).