;; can easily distinguish when we want to toggle back because
;; text-mode is a likely candidate for a default major-mode
;; (bug#34451).
-(defun doc-view--text-view-mode ()
+(define-derived-mode doc-view--text-view-mode text-mode "DV/Text"
"View mode used in DocView's text buffers."
- (view-mode)
- (setq major-mode 'doc-view--text-view-mode))
+ (view-mode))
(defun doc-view-open-text ()
"Display the current doc's contents as text."
(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)
(doc-view-minor-mode)
(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)))