emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] emacs-24 r117623: Backport latest doc-view fix


From: Tassilo Horn
Subject: [Emacs-diffs] emacs-24 r117623: Backport latest doc-view fix
Date: Thu, 23 Oct 2014 19:17:22 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 117623
revision-id: address@hidden
parent: address@hidden
committer: Tassilo Horn <address@hidden>
branch nick: emacs-24
timestamp: Thu 2014-10-23 21:17:00 +0200
message:
  Backport latest doc-view fix
  
  * doc/emacs/misc.texi (Document View): Adapt to latest doc-view changes wrt
  viewing the document's plain text contents.  [Backport]
  
  * lisp/doc-view.el (doc-view-open-text): View the document's plain text
  in the current buffer instead of a new one.
  (doc-view-toggle-display): Handle the case where the current
  buffer contains the plain text contents of the document.
  (doc-view-initiate-display): Don't switch to fallback mode if the
  user wants to view the doc's plain text.  [Backport]
modified:
  doc/emacs/ChangeLog            changelog-20091113204419-o5vbwnq5f7feedwu-6227
  doc/emacs/misc.texi            misc.texi-20091113204419-o5vbwnq5f7feedwu-6267
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/doc-view.el               docview.el-20091113204419-o5vbwnq5f7feedwu-6334
=== modified file 'doc/emacs/ChangeLog'
--- a/doc/emacs/ChangeLog       2014-10-23 16:54:25 +0000
+++ b/doc/emacs/ChangeLog       2014-10-23 19:17:00 +0000
@@ -1,3 +1,8 @@
+2014-10-23  Tassilo Horn  <address@hidden>
+
+       * misc.texi (Document View): Adapt to latest doc-view changes wrt
+       viewing the document's plain text contents.  [Backport]
+
 2014-10-23  Eli Zaretskii  <address@hidden>
 
        * frames.texi (Frame Commands): Document and index

=== modified file 'doc/emacs/misc.texi'
--- a/doc/emacs/misc.texi       2014-10-20 22:12:13 +0000
+++ b/doc/emacs/misc.texi       2014-10-23 19:17:00 +0000
@@ -266,9 +266,10 @@
 OpenDocument, and Microsoft Office documents.  It provides features
 such as slicing, zooming, and searching inside documents.  It works by
 converting the document to a set of images using the @command{gs}
-(GhostScript) command and other external tools @address@hidden is
-a hard requirement.  For DVI files, @code{dvipdf} or @code{dvipdfm} is
-needed.  For OpenDocument and Microsoft Office documents, the
+(GhostScript) or @command{mudraw}/@command{pdfdraw} (MuPDF) commands
+and other external tools @footnote{For PostScript files, GhostScript
+is a hard requirement.  For DVI files, @code{dvipdf} or @code{dvipdfm}
+is needed.  For OpenDocument and Microsoft Office documents, the
 @code{unoconv} tool is needed.}, and displaying those images.
 
 @findex doc-view-toggle-display
@@ -287,6 +288,17 @@
 (@code{doc-view-toggle-display}) toggles between DocView and the
 underlying file contents.
 
address@hidden doc-view-open-text
+  When you visit a file which would normally be handled by DocView
+mode but some requirement is not met (e.g., you operate in a terminal
+frame or emacs has no PNG support), you are queried if you want to
+view the document's contents as plain text.  If you confirm, the
+buffer is put in text mode and DocView minor mode is activated.  Thus,
+by typing @kbd{C-c C-c} you switch to the fallback mode.  With another
address@hidden C-c} you return to DocView mode.  The plain text contents can
+also be displayed from within DocView mode by typing @kbd{C-c C-t}
+(@code{doc-view-open-text}).
+
   You can explicitly enable DocView mode with the command @code{M-x
 doc-view-mode}.  You can toggle DocView minor mode with @code{M-x
 doc-view-minor-mode}.

=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2014-10-23 16:32:51 +0000
+++ b/lisp/ChangeLog    2014-10-23 19:17:00 +0000
@@ -1,3 +1,12 @@
+2014-10-23  Tassilo Horn  <address@hidden>
+
+       * doc-view.el (doc-view-open-text): View the document's plain text
+       in the current buffer instead of a new one.
+       (doc-view-toggle-display): Handle the case where the current
+       buffer contains the plain text contents of the document.
+       (doc-view-initiate-display): Don't switch to fallback mode if the
+       user wants to view the doc's plain text.  [Backport]
+
 2014-10-23  Eli Zaretskii  <address@hidden>
 
        * startup.el (fancy-about-text): Read the entire tutorial, not

=== modified file 'lisp/doc-view.el'
--- a/lisp/doc-view.el  2014-07-28 09:32:25 +0000
+++ b/lisp/doc-view.el  2014-10-23 19:17:00 +0000
@@ -1398,19 +1398,28 @@
   (tooltip-show (doc-view-current-info)))
 
 (defun doc-view-open-text ()
-  "Open a buffer with the current doc's contents as text."
+  "Display the current doc's contents as text."
   (interactive)
   (if doc-view--current-converter-processes
       (message "DocView: please wait till conversion finished.")
-    (let ((txt (expand-file-name "doc.txt" (doc-view--current-cache-dir)))
-         (bname (or buffer-file-name (buffer-name))))
+    (let ((txt (expand-file-name "doc.txt" (doc-view--current-cache-dir))))
       (if (file-readable-p txt)
-         (let ((name (concat "Text contents of "
-                             (file-name-nondirectory bname)))
-               (dir (or (file-name-directory bname) default-directory)))
-           (with-current-buffer (find-file txt)
-             (rename-buffer name)
-             (setq default-directory dir)))
+         (let ((inhibit-read-only t)
+               (buffer-undo-list t)
+               (dv-bfn doc-view--buffer-file-name))
+           (erase-buffer)
+           (set-buffer-multibyte t)
+           (insert-file-contents txt)
+           (text-mode)
+           (setq-local doc-view--buffer-file-name dv-bfn)
+           (set-buffer-modified-p nil)
+           (doc-view-minor-mode)
+           (add-hook 'write-file-functions
+                     (lambda ()
+                       (when (eq major-mode 'text-mode)
+                         (error "Cannot save text contents of document %s"
+                                buffer-file-name)))
+                     nil t))
        (doc-view-doc->txt txt 'doc-view-open-text)))))
 
 ;;;;; Toggle between editing and viewing
@@ -1422,20 +1431,30 @@
 (defun doc-view-toggle-display ()
   "Toggle between editing a document as text or viewing it."
   (interactive)
-  (if (eq major-mode 'doc-view-mode)
-      ;; Switch to editing mode
-      (progn
-       (doc-view-kill-proc)
-       (setq buffer-read-only nil)
-       ;; Switch to the previously used major mode or fall back to
-       ;; normal mode.
-       (doc-view-fallback-mode)
-       (doc-view-minor-mode 1))
+  (cond
+   ((eq major-mode 'doc-view-mode)
+    ;; Switch to editing mode
+    (doc-view-kill-proc)
+    (setq buffer-read-only nil)
+    ;; Switch to the previously used major mode or fall back to
+    ;; normal mode.
+    (doc-view-fallback-mode)
+    (doc-view-minor-mode 1))
+   ((eq major-mode 'text-mode)
+    (let ((buffer-undo-list t))
+      ;; We're currently viewing the document's text contents, so switch
+      ;; back to .
+      (setq buffer-read-only nil)
+      (insert-file-contents doc-view--buffer-file-name nil nil nil t)
+      (doc-view-fallback-mode)
+      (doc-view-minor-mode 1)
+      (set-buffer-modified-p nil)))
+   (t
     ;; Switch to doc-view-mode
     (when (and (buffer-modified-p)
               (y-or-n-p "The buffer has been modified.  Save the changes? "))
       (save-buffer))
-    (doc-view-mode)))
+    (doc-view-mode))))
 
 ;;;; Searching
 
@@ -1591,11 +1610,11 @@
      (concat "No PNG support is available, or some conversion utility for "
             (file-name-extension doc-view--buffer-file-name)
             " files is missing."))
-    (when (and (executable-find doc-view-pdftotext-program)
-              (y-or-n-p
-               "Unable to render file.  View extracted text instead? "))
-      (doc-view-open-text))
-    (doc-view-toggle-display)))
+    (if (and (executable-find doc-view-pdftotext-program)
+            (y-or-n-p
+             "Unable to render file.  View extracted text instead? "))
+       (doc-view-open-text)
+      (doc-view-toggle-display))))
 
 (defvar bookmark-make-record-function)
 
@@ -1622,7 +1641,7 @@
   "Figure out the current document type (`doc-view-doc-type')."
   (let ((name-types
         (when buffer-file-name
-          (cdr (assoc (file-name-extension buffer-file-name)
+          (cdr (assoc-ignore-case (file-name-extension buffer-file-name)
                       '(
                         ;; DVI
                         ("dvi" dvi)
@@ -1639,7 +1658,8 @@
                         ;; Microsoft Office formats (also handled
                         ;; by the odf conversion chain)
                         ("doc" odf) ("docx" odf) ("xls" odf) ("xlsx" odf)
-                        ("ppt" odf) ("pptx" odf))))))
+                        ("ppt" odf) ("pptx" odf)
+                        ("ppt" odf) ("pps" odf) ("pptx" odf))))))
        (content-types
         (save-excursion
           (goto-char (point-min))


reply via email to

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