diff options
| author | Tassilo Horn | 2014-10-23 21:17:00 +0200 |
|---|---|---|
| committer | Tassilo Horn | 2014-10-23 21:17:00 +0200 |
| commit | 9e147f750bfc25894c0d14e53f44d4996d441a96 (patch) | |
| tree | aba278d72c1bf5b1622e8044d9e1719720137cad | |
| parent | 894b567b1c8e74a615441147b956263484119702 (diff) | |
| download | emacs-9e147f750bfc25894c0d14e53f44d4996d441a96.tar.gz emacs-9e147f750bfc25894c0d14e53f44d4996d441a96.zip | |
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]
| -rw-r--r-- | doc/emacs/ChangeLog | 5 | ||||
| -rw-r--r-- | doc/emacs/misc.texi | 18 | ||||
| -rw-r--r-- | lisp/ChangeLog | 9 | ||||
| -rw-r--r-- | lisp/doc-view.el | 72 |
4 files changed, 75 insertions, 29 deletions
diff --git a/doc/emacs/ChangeLog b/doc/emacs/ChangeLog index 232330faf1e..2b9a13069d2 100644 --- a/doc/emacs/ChangeLog +++ b/doc/emacs/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2014-10-23 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. [Backport] | ||
| 5 | |||
| 1 | 2014-10-23 Eli Zaretskii <eliz@gnu.org> | 6 | 2014-10-23 Eli Zaretskii <eliz@gnu.org> |
| 2 | 7 | ||
| 3 | * frames.texi (Frame Commands): Document and index | 8 | * frames.texi (Frame Commands): Document and index |
diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi index f77cb993d71..386fd6fdd3b 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. | |||
| 266 | OpenDocument, and Microsoft Office documents. It provides features | 266 | OpenDocument, and Microsoft Office documents. It provides features |
| 267 | such as slicing, zooming, and searching inside documents. It works by | 267 | such as slicing, zooming, and searching inside documents. It works by |
| 268 | converting the document to a set of images using the @command{gs} | 268 | converting 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 |
| 270 | a hard requirement. For DVI files, @code{dvipdf} or @code{dvipdfm} is | 270 | and other external tools @footnote{For PostScript files, GhostScript |
| 271 | needed. For OpenDocument and Microsoft Office documents, the | 271 | is a hard requirement. For DVI files, @code{dvipdf} or @code{dvipdfm} |
| 272 | is 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 |
| 288 | underlying file contents. | 289 | underlying file contents. |
| 289 | 290 | ||
| 291 | @findex doc-view-open-text | ||
| 292 | When you visit a file which would normally be handled by DocView | ||
| 293 | mode but some requirement is not met (e.g., you operate in a terminal | ||
| 294 | frame or emacs has no PNG support), you are queried if you want to | ||
| 295 | view the document's contents as plain text. If you confirm, the | ||
| 296 | buffer is put in text mode and DocView minor mode is activated. Thus, | ||
| 297 | by 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 | ||
| 299 | also 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 |
| 291 | doc-view-mode}. You can toggle DocView minor mode with @code{M-x | 303 | doc-view-mode}. You can toggle DocView minor mode with @code{M-x |
| 292 | doc-view-minor-mode}. | 304 | doc-view-minor-mode}. |
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d32c2772579..67efd558528 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,12 @@ | |||
| 1 | 2014-10-23 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. [Backport] | ||
| 9 | |||
| 1 | 2014-10-23 Eli Zaretskii <eliz@gnu.org> | 10 | 2014-10-23 Eli Zaretskii <eliz@gnu.org> |
| 2 | 11 | ||
| 3 | * startup.el (fancy-about-text): Read the entire tutorial, not | 12 | * startup.el (fancy-about-text): Read the entire tutorial, not |
diff --git a/lisp/doc-view.el b/lisp/doc-view.el index 7d5f1e771d5..4b90a42c498 100644 --- a/lisp/doc-view.el +++ b/lisp/doc-view.el | |||
| @@ -1398,19 +1398,28 @@ For now these keys are useful: | |||
| 1398 | (tooltip-show (doc-view-current-info))) | 1398 | (tooltip-show (doc-view-current-info))) |
| 1399 | 1399 | ||
| 1400 | (defun doc-view-open-text () | 1400 | (defun doc-view-open-text () |
| 1401 | "Open a buffer with the current doc's contents as text." | 1401 | "Display the current doc's contents as text." |
| 1402 | (interactive) | 1402 | (interactive) |
| 1403 | (if doc-view--current-converter-processes | 1403 | (if doc-view--current-converter-processes |
| 1404 | (message "DocView: please wait till conversion finished.") | 1404 | (message "DocView: please wait till conversion finished.") |
| 1405 | (let ((txt (expand-file-name "doc.txt" (doc-view--current-cache-dir))) | 1405 | (let ((txt (expand-file-name "doc.txt" (doc-view--current-cache-dir)))) |
| 1406 | (bname (or buffer-file-name (buffer-name)))) | ||
| 1407 | (if (file-readable-p txt) | 1406 | (if (file-readable-p txt) |
| 1408 | (let ((name (concat "Text contents of " | 1407 | (let ((inhibit-read-only t) |
| 1409 | (file-name-nondirectory bname))) | 1408 | (buffer-undo-list t) |
| 1410 | (dir (or (file-name-directory bname) default-directory))) | 1409 | (dv-bfn doc-view--buffer-file-name)) |
| 1411 | (with-current-buffer (find-file txt) | 1410 | (erase-buffer) |
| 1412 | (rename-buffer name) | 1411 | (set-buffer-multibyte t) |
| 1413 | (setq default-directory dir))) | 1412 | (insert-file-contents txt) |
| 1413 | (text-mode) | ||
| 1414 | (setq-local doc-view--buffer-file-name dv-bfn) | ||
| 1415 | (set-buffer-modified-p nil) | ||
| 1416 | (doc-view-minor-mode) | ||
| 1417 | (add-hook 'write-file-functions | ||
| 1418 | (lambda () | ||
| 1419 | (when (eq major-mode 'text-mode) | ||
| 1420 | (error "Cannot save text contents of document %s" | ||
| 1421 | buffer-file-name))) | ||
| 1422 | nil t)) | ||
| 1414 | (doc-view-doc->txt txt 'doc-view-open-text))))) | 1423 | (doc-view-doc->txt txt 'doc-view-open-text))))) |
| 1415 | 1424 | ||
| 1416 | ;;;;; Toggle between editing and viewing | 1425 | ;;;;; Toggle between editing and viewing |
| @@ -1422,20 +1431,30 @@ For now these keys are useful: | |||
| 1422 | (defun doc-view-toggle-display () | 1431 | (defun doc-view-toggle-display () |
| 1423 | "Toggle between editing a document as text or viewing it." | 1432 | "Toggle between editing a document as text or viewing it." |
| 1424 | (interactive) | 1433 | (interactive) |
| 1425 | (if (eq major-mode 'doc-view-mode) | 1434 | (cond |
| 1426 | ;; Switch to editing mode | 1435 | ((eq major-mode 'doc-view-mode) |
| 1427 | (progn | 1436 | ;; Switch to editing mode |
| 1428 | (doc-view-kill-proc) | 1437 | (doc-view-kill-proc) |
| 1429 | (setq buffer-read-only nil) | 1438 | (setq buffer-read-only nil) |
| 1430 | ;; Switch to the previously used major mode or fall back to | 1439 | ;; Switch to the previously used major mode or fall back to |
| 1431 | ;; normal mode. | 1440 | ;; normal mode. |
| 1432 | (doc-view-fallback-mode) | 1441 | (doc-view-fallback-mode) |
| 1433 | (doc-view-minor-mode 1)) | 1442 | (doc-view-minor-mode 1)) |
| 1443 | ((eq major-mode 'text-mode) | ||
| 1444 | (let ((buffer-undo-list t)) | ||
| 1445 | ;; We're currently viewing the document's text contents, so switch | ||
| 1446 | ;; back to . | ||
| 1447 | (setq buffer-read-only nil) | ||
| 1448 | (insert-file-contents doc-view--buffer-file-name nil nil nil t) | ||
| 1449 | (doc-view-fallback-mode) | ||
| 1450 | (doc-view-minor-mode 1) | ||
| 1451 | (set-buffer-modified-p nil))) | ||
| 1452 | (t | ||
| 1434 | ;; Switch to doc-view-mode | 1453 | ;; Switch to doc-view-mode |
| 1435 | (when (and (buffer-modified-p) | 1454 | (when (and (buffer-modified-p) |
| 1436 | (y-or-n-p "The buffer has been modified. Save the changes? ")) | 1455 | (y-or-n-p "The buffer has been modified. Save the changes? ")) |
| 1437 | (save-buffer)) | 1456 | (save-buffer)) |
| 1438 | (doc-view-mode))) | 1457 | (doc-view-mode)))) |
| 1439 | 1458 | ||
| 1440 | ;;;; Searching | 1459 | ;;;; Searching |
| 1441 | 1460 | ||
| @@ -1591,11 +1610,11 @@ If BACKWARD is non-nil, jump to the previous match." | |||
| 1591 | (concat "No PNG support is available, or some conversion utility for " | 1610 | (concat "No PNG support is available, or some conversion utility for " |
| 1592 | (file-name-extension doc-view--buffer-file-name) | 1611 | (file-name-extension doc-view--buffer-file-name) |
| 1593 | " files is missing.")) | 1612 | " files is missing.")) |
| 1594 | (when (and (executable-find doc-view-pdftotext-program) | 1613 | (if (and (executable-find doc-view-pdftotext-program) |
| 1595 | (y-or-n-p | 1614 | (y-or-n-p |
| 1596 | "Unable to render file. View extracted text instead? ")) | 1615 | "Unable to render file. View extracted text instead? ")) |
| 1597 | (doc-view-open-text)) | 1616 | (doc-view-open-text) |
| 1598 | (doc-view-toggle-display))) | 1617 | (doc-view-toggle-display)))) |
| 1599 | 1618 | ||
| 1600 | (defvar bookmark-make-record-function) | 1619 | (defvar bookmark-make-record-function) |
| 1601 | 1620 | ||
| @@ -1622,7 +1641,7 @@ If BACKWARD is non-nil, jump to the previous match." | |||
| 1622 | "Figure out the current document type (`doc-view-doc-type')." | 1641 | "Figure out the current document type (`doc-view-doc-type')." |
| 1623 | (let ((name-types | 1642 | (let ((name-types |
| 1624 | (when buffer-file-name | 1643 | (when buffer-file-name |
| 1625 | (cdr (assoc (file-name-extension buffer-file-name) | 1644 | (cdr (assoc-ignore-case (file-name-extension buffer-file-name) |
| 1626 | '( | 1645 | '( |
| 1627 | ;; DVI | 1646 | ;; DVI |
| 1628 | ("dvi" dvi) | 1647 | ("dvi" dvi) |
| @@ -1639,7 +1658,8 @@ If BACKWARD is non-nil, jump to the previous match." | |||
| 1639 | ;; Microsoft Office formats (also handled | 1658 | ;; Microsoft Office formats (also handled |
| 1640 | ;; by the odf conversion chain) | 1659 | ;; by the odf conversion chain) |
| 1641 | ("doc" odf) ("docx" odf) ("xls" odf) ("xlsx" odf) | 1660 | ("doc" odf) ("docx" odf) ("xls" odf) ("xlsx" odf) |
| 1642 | ("ppt" odf) ("pptx" odf)))))) | 1661 | ("ppt" odf) ("pptx" odf) |
| 1662 | ("ppt" odf) ("pps" odf) ("pptx" odf)))))) | ||
| 1643 | (content-types | 1663 | (content-types |
| 1644 | (save-excursion | 1664 | (save-excursion |
| 1645 | (goto-char (point-min)) | 1665 | (goto-char (point-min)) |