aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTassilo Horn2014-10-22 15:30:16 +0200
committerTassilo Horn2014-10-22 15:30:16 +0200
commit36749d80256f49ac10860405b95fe319012c3b91 (patch)
treeb69838ad4de84b8bf001a38451a449da6e917072
parent8ae9147a6c6b2e8ebe04610aee4d4aea04d89b2d (diff)
downloademacs-36749d80256f49ac10860405b95fe319012c3b91.tar.gz
emacs-36749d80256f49ac10860405b95fe319012c3b91.zip
Improve viewing plain text contents of document
* doc/emacs/misc.texi (Document View): Adapt to latest doc-view changes wrt viewing the document's plain text contents. * 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. (doc-view-set-doc-type): Use assoc-string instead of assoc-ignore-case.
-rw-r--r--doc/emacs/ChangeLog5
-rw-r--r--doc/emacs/misc.texi18
-rw-r--r--lisp/ChangeLog11
-rw-r--r--lisp/doc-view.el72
4 files changed, 77 insertions, 29 deletions
diff --git a/doc/emacs/ChangeLog b/doc/emacs/ChangeLog
index e19b0cf6485..901eaac42c3 100644
--- a/doc/emacs/ChangeLog
+++ b/doc/emacs/ChangeLog
@@ -1,3 +1,8 @@
12014-10-22 Tassilo Horn <tsdh@gnu.org>
2
3 * misc.texi (Document View): Adapt to latest doc-view changes wrt
4 viewing the document's plain text contents.
5
12014-10-20 Glenn Morris <rgm@gnu.org> 62014-10-20 Glenn Morris <rgm@gnu.org>
2 7
3 * Merge in all changes up to 24.4 release. 8 * Merge in all changes up to 24.4 release.
diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi
index af4d21fe180..af5ced77b52 100644
--- a/doc/emacs/misc.texi
+++ b/doc/emacs/misc.texi
@@ -266,9 +266,10 @@ Exit the summary buffer and return to the group buffer.
266OpenDocument, and Microsoft Office documents. It provides features 266OpenDocument, and Microsoft Office documents. It provides features
267such as slicing, zooming, and searching inside documents. It works by 267such as slicing, zooming, and searching inside documents. It works by
268converting the document to a set of images using the @command{gs} 268converting the document to a set of images using the @command{gs}
269(GhostScript) command and other external tools @footnote{@code{gs} is 269(GhostScript) or @command{mudraw}/@command{pdfdraw} (MuPDF) commands
270a hard requirement. For DVI files, @code{dvipdf} or @code{dvipdfm} is 270and other external tools @footnote{For PostScript files, GhostScript
271needed. For OpenDocument and Microsoft Office documents, the 271is a hard requirement. For DVI files, @code{dvipdf} or @code{dvipdfm}
272is needed. For OpenDocument and Microsoft Office documents, the
272@code{unoconv} tool is needed.}, and displaying those images. 273@code{unoconv} tool is needed.}, and displaying those images.
273 274
274@findex doc-view-toggle-display 275@findex doc-view-toggle-display
@@ -287,6 +288,17 @@ mode or DocView minor mode, repeating @kbd{C-c C-c}
287(@code{doc-view-toggle-display}) toggles between DocView and the 288(@code{doc-view-toggle-display}) toggles between DocView and the
288underlying file contents. 289underlying file contents.
289 290
291@findex doc-view-open-text
292 When you visit a file which would normally be handled by DocView
293mode but some requirement is not met (e.g., you operate in a terminal
294frame or emacs has no PNG support), you are queried if you want to
295view the document's contents as plain text. If you confirm, the
296buffer is put in text mode and DocView minor mode is activated. Thus,
297by typing @kbd{C-c C-c} you switch to the fallback mode. With another
298@kbd{C-c C-c} you return to DocView mode. The plain text contents can
299also be displayed from within DocView mode by typing @kbd{C-c C-t}
300(@code{doc-view-open-text}).
301
290 You can explicitly enable DocView mode with the command @code{M-x 302 You can explicitly enable DocView mode with the command @code{M-x
291doc-view-mode}. You can toggle DocView minor mode with @code{M-x 303doc-view-mode}. You can toggle DocView minor mode with @code{M-x
292doc-view-minor-mode}. 304doc-view-minor-mode}.
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index fb516323ee0..3fa382e531b 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,14 @@
12014-10-22 Tassilo Horn <tsdh@gnu.org>
2
3 * doc-view.el (doc-view-open-text): View the document's plain text
4 in the current buffer instead of a new one.
5 (doc-view-toggle-display): Handle the case where the current
6 buffer contains the plain text contents of the document.
7 (doc-view-initiate-display): Don't switch to fallback mode if the
8 user wants to view the doc's plain text.
9 (doc-view-set-doc-type): Use assoc-string instead of
10 assoc-ignore-case.
11
12014-10-21 Stefan Monnier <monnier@iro.umontreal.ca> 122014-10-21 Stefan Monnier <monnier@iro.umontreal.ca>
2 13
3 * subr.el (read-key): Fix clicks on the mode-line. 14 * subr.el (read-key): Fix clicks on the mode-line.
diff --git a/lisp/doc-view.el b/lisp/doc-view.el
index 9458cace74e..37cb2787cca 100644
--- a/lisp/doc-view.el
+++ b/lisp/doc-view.el
@@ -1392,19 +1392,28 @@ For now these keys are useful:
1392 (tooltip-show (doc-view-current-info))) 1392 (tooltip-show (doc-view-current-info)))
1393 1393
1394(defun doc-view-open-text () 1394(defun doc-view-open-text ()
1395 "Open a buffer with the current doc's contents as text." 1395 "Display the current doc's contents as text."
1396 (interactive) 1396 (interactive)
1397 (if doc-view--current-converter-processes 1397 (if doc-view--current-converter-processes
1398 (message "DocView: please wait till conversion finished.") 1398 (message "DocView: please wait till conversion finished.")
1399 (let ((txt (expand-file-name "doc.txt" (doc-view--current-cache-dir))) 1399 (let ((txt (expand-file-name "doc.txt" (doc-view--current-cache-dir))))
1400 (bname (or buffer-file-name (buffer-name))))
1401 (if (file-readable-p txt) 1400 (if (file-readable-p txt)
1402 (let ((name (concat "Text contents of " 1401 (let ((inhibit-read-only t)
1403 (file-name-nondirectory bname))) 1402 (buffer-undo-list t)
1404 (dir (or (file-name-directory bname) default-directory))) 1403 (dv-bfn doc-view--buffer-file-name))
1405 (with-current-buffer (find-file txt) 1404 (erase-buffer)
1406 (rename-buffer name) 1405 (set-buffer-multibyte t)
1407 (setq default-directory dir))) 1406 (insert-file-contents txt)
1407 (text-mode)
1408 (setq-local doc-view--buffer-file-name dv-bfn)
1409 (set-buffer-modified-p nil)
1410 (doc-view-minor-mode)
1411 (add-hook 'write-file-functions
1412 (lambda ()
1413 (when (eq major-mode 'text-mode)
1414 (error "Cannot save text contents of document %s"
1415 buffer-file-name)))
1416 nil t))
1408 (doc-view-doc->txt txt 'doc-view-open-text))))) 1417 (doc-view-doc->txt txt 'doc-view-open-text)))))
1409 1418
1410;;;;; Toggle between editing and viewing 1419;;;;; Toggle between editing and viewing
@@ -1416,20 +1425,30 @@ For now these keys are useful:
1416(defun doc-view-toggle-display () 1425(defun doc-view-toggle-display ()
1417 "Toggle between editing a document as text or viewing it." 1426 "Toggle between editing a document as text or viewing it."
1418 (interactive) 1427 (interactive)
1419 (if (eq major-mode 'doc-view-mode) 1428 (cond
1420 ;; Switch to editing mode 1429 ((eq major-mode 'doc-view-mode)
1421 (progn 1430 ;; Switch to editing mode
1422 (doc-view-kill-proc) 1431 (doc-view-kill-proc)
1423 (setq buffer-read-only nil) 1432 (setq buffer-read-only nil)
1424 ;; Switch to the previously used major mode or fall back to 1433 ;; Switch to the previously used major mode or fall back to
1425 ;; normal mode. 1434 ;; normal mode.
1426 (doc-view-fallback-mode) 1435 (doc-view-fallback-mode)
1427 (doc-view-minor-mode 1)) 1436 (doc-view-minor-mode 1))
1437 ((eq major-mode 'text-mode)
1438 (let ((buffer-undo-list t))
1439 ;; We're currently viewing the document's text contents, so switch
1440 ;; back to .
1441 (setq buffer-read-only nil)
1442 (insert-file-contents doc-view--buffer-file-name nil nil nil t)
1443 (doc-view-fallback-mode)
1444 (doc-view-minor-mode 1)
1445 (set-buffer-modified-p nil)))
1446 (t
1428 ;; Switch to doc-view-mode 1447 ;; Switch to doc-view-mode
1429 (when (and (buffer-modified-p) 1448 (when (and (buffer-modified-p)
1430 (y-or-n-p "The buffer has been modified. Save the changes? ")) 1449 (y-or-n-p "The buffer has been modified. Save the changes? "))
1431 (save-buffer)) 1450 (save-buffer))
1432 (doc-view-mode))) 1451 (doc-view-mode))))
1433 1452
1434;;;; Searching 1453;;;; Searching
1435 1454
@@ -1585,11 +1604,11 @@ If BACKWARD is non-nil, jump to the previous match."
1585 (concat "No PNG support is available, or some conversion utility for " 1604 (concat "No PNG support is available, or some conversion utility for "
1586 (file-name-extension doc-view--buffer-file-name) 1605 (file-name-extension doc-view--buffer-file-name)
1587 " files is missing.")) 1606 " files is missing."))
1588 (when (and (executable-find doc-view-pdftotext-program) 1607 (if (and (executable-find doc-view-pdftotext-program)
1589 (y-or-n-p 1608 (y-or-n-p
1590 "Unable to render file. View extracted text instead? ")) 1609 "Unable to render file. View extracted text instead? "))
1591 (doc-view-open-text)) 1610 (doc-view-open-text)
1592 (doc-view-toggle-display))) 1611 (doc-view-toggle-display))))
1593 1612
1594(defvar bookmark-make-record-function) 1613(defvar bookmark-make-record-function)
1595 1614
@@ -1616,7 +1635,7 @@ If BACKWARD is non-nil, jump to the previous match."
1616 "Figure out the current document type (`doc-view-doc-type')." 1635 "Figure out the current document type (`doc-view-doc-type')."
1617 (let ((name-types 1636 (let ((name-types
1618 (when buffer-file-name 1637 (when buffer-file-name
1619 (cdr (assoc-ignore-case 1638 (cdr (assoc-string
1620 (file-name-extension buffer-file-name) 1639 (file-name-extension buffer-file-name)
1621 '( 1640 '(
1622 ;; DVI 1641 ;; DVI
@@ -1634,7 +1653,8 @@ If BACKWARD is non-nil, jump to the previous match."
1634 ;; Microsoft Office formats (also handled by the odf 1653 ;; Microsoft Office formats (also handled by the odf
1635 ;; conversion chain). 1654 ;; conversion chain).
1636 ("doc" odf) ("docx" odf) ("xls" odf) ("xlsx" odf) 1655 ("doc" odf) ("docx" odf) ("xls" odf) ("xlsx" odf)
1637 ("ppt" odf) ("pps" odf) ("pptx" odf)))))) 1656 ("ppt" odf) ("pps" odf) ("pptx" odf))
1657 t))))
1638 (content-types 1658 (content-types
1639 (save-excursion 1659 (save-excursion
1640 (goto-char (point-min)) 1660 (goto-char (point-min))