Function: doc-view-open-text
doc-view-open-text is an interactive and byte-compiled function
defined in doc-view.el.gz.
Signature
(doc-view-open-text)
Documentation
Display the current doc's contents as text.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/doc-view.el.gz
(defun doc-view-open-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)))
(page (doc-view-current-page)))
(if (file-readable-p txt)
(let ((inhibit-read-only t)
(buffer-undo-list t)
(dv-bfn doc-view--buffer-file-name))
(erase-buffer)
;; FIXME: Replacing the buffer's PDF content with its txt rendering
;; is pretty risky. We should probably use *another*
;; buffer instead, so there's much less risk of
;; overwriting the PDF file with some text rendering.
(set-buffer-multibyte t)
(insert-file-contents txt)
(doc-view--text-view-mode)
(setq-local doc-view--buffer-file-name dv-bfn)
(set-buffer-modified-p nil)
(doc-view-minor-mode)
(goto-char (point-min))
;; Put point at the start of the page the user was
;; reading. Pages are separated by Control-L characters.
(re-search-forward page-delimiter nil t (1- page))
(add-hook 'write-file-functions
(lambda ()
;; FIXME: If the user changes major mode and then
;; saves the buffer, the PDF file will be clobbered
;; with its txt rendering!
(when (eq major-mode 'doc-view--text-view-mode)
(error "Cannot save text contents of document %s"
buffer-file-name)))
nil t))
(doc-view-doc->txt txt 'doc-view-open-text)))))