unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Juanma Barranquero <lekktu@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Emacs developers <emacs-devel@gnu.org>
Subject: Re: doc-view-set-doc-type's generality
Date: Wed, 4 Dec 2019 15:05:08 +0100	[thread overview]
Message-ID: <CAAeL0SQyAqXKO9Uxao2q98Tn_MB6AQWLRk8wAzCcA3R2TZENaw@mail.gmail.com> (raw)
In-Reply-To: <jwvpnh46vqu.fsf-monnier+emacs@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 3358 bytes --]

Well, yes, that's what it does. But it doesn't need to build a list of
name-types
based on just one file name and it does not need to build a list of
content-types
based on the beginning of just one buffer...

I mean, AFAICS this would do the same and would not require
`doc-view-intersection',
just eq'ing two symbols.

diff --git i/lisp/doc-view.el w/lisp/doc-view.el
index e5f0e89a36..58f8535328 100644
--- i/lisp/doc-view.el
+++ w/lisp/doc-view.el
@@ -1753,4 +1753,5 @@ doc-view-clone-buffer-hook

 (defun doc-view-intersection (l1 l2)
+  (declare (obsolete nil "28.1"))
   (let ((l ()))
     (dolist (x l1) (if (memq x l2) (push x l)))
@@ -1759,5 +1760,5 @@ doc-view-intersection
 (defun doc-view-set-doc-type ()
   "Figure out the current document type (`doc-view-doc-type')."
-  (let ((name-types
+  (let ((name-type
  (when buffer-file-name
    (cdr (assoc-string
@@ -1765,36 +1766,36 @@ doc-view-set-doc-type
                  '(
                    ;; DVI
-                   ("dvi" dvi)
+                   ("dvi" . dvi)
                    ;; PDF
-                   ("pdf" pdf) ("epdf" pdf)
+                   ("pdf" . pdf) ("epdf" . pdf)
                    ;; PostScript
-                   ("ps" ps) ("eps" ps)
+                   ("ps" . ps) ("eps" . ps)
                    ;; DjVu
-                   ("djvu" 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)
+                   ("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))
+                   ("doc" . odf) ("docx" . odf) ("xls" . odf) ("xlsx" .
odf)
+                   ("ppt" . odf) ("pps" . odf) ("pptx" . odf) ("rtf" .
odf))
  t))))
- (content-types
+ (content-type
  (save-excursion
    (goto-char (point-min))
    (cond
-    ((looking-at "%!") '(ps))
-    ((looking-at "%PDF") '(pdf))
-    ((looking-at "\367\002") '(dvi))
-    ((looking-at "AT&TFORM") '(djvu))))))
+    ((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"))))))
+     (or (and (eq name-type content-type) name-type)
+         (when (and name-type content-type)
+           (error "Conflicting types: name says %s but content says %s"
+                  name-type content-type))
+         name-type content-type
+         (error "Cannot determine the document type")))))

 (defun doc-view-set-up-single-converter ()

[-- Attachment #2: Type: text/html, Size: 4962 bytes --]

      reply	other threads:[~2019-12-04 14:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-04  9:32 doc-view-set-doc-type's generality Juanma Barranquero
2019-12-04 13:57 ` Stefan Monnier
2019-12-04 14:05   ` Juanma Barranquero [this message]

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=CAAeL0SQyAqXKO9Uxao2q98Tn_MB6AQWLRk8wAzCcA3R2TZENaw@mail.gmail.com \
    --to=lekktu@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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).