From 020e69d992c98fd852e835c9bd707a8d137090f2 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Wed, 13 Mar 2019 18:22:57 -0400 Subject: [PATCH] * lisp/doc-view.el (doc-view--text-view-mode): Derive from text-mode. --- lisp/doc-view.el | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lisp/doc-view.el b/lisp/doc-view.el index 53ae351abd8..a7069072603 100644 --- a/lisp/doc-view.el +++ b/lisp/doc-view.el @@ -1480,10 +1480,9 @@ For now these keys are useful: ;; 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." @@ -1496,6 +1495,10 @@ For now these keys are useful: (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) @@ -1504,6 +1507,9 @@ For now these keys are useful: (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))) -- 2.39.2