[Top][All Lists]

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

doc-view-set-doc-type's generality

From: Juanma Barranquero
Subject: doc-view-set-doc-type's generality
Date: Wed, 4 Dec 2019 10:32:47 +0100

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))
           (goto-char (point-min))
            ((looking-at "%!") '(ps))
            ((looking-at "%PDF") '(pdf))
            ((looking-at "\367\002") '(dvi))
            ((looking-at "AT&TFORM") '(djvu))))))
     (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.

reply via email to

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