Improve doc-type determination in doc-view
authorAndrew G Cohen <cohen@andy.bu.edu>
Fri, 6 Oct 2023 06:34:28 +0000 (14:34 +0800)
committerAndrew G Cohen <cohen@andy.bu.edu>
Fri, 10 May 2024 00:25:48 +0000 (08:25 +0800)
* lisp/doc-view.el (doc-view-set-doc-type): If buffer-file-name is not
set try the buffer-name to identify the doc type.

lisp/doc-view.el

index c4b384c35c610aa983af44ec4277da914d203a6c..4ae9a5e6629a516e2d7785929c160661940c488d 100644 (file)
@@ -2092,35 +2092,35 @@ GOTO-PAGE-FN other than `doc-view-goto-page'."
 (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)
-                   ;; 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))))
+         (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))