From affd2a0cee901404251ea1d2ef01bfb618f5213a Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Sat, 9 Mar 2019 22:05:38 +0100 Subject: [PATCH] Make doc-view work with text-mode as default major-mode (bug#34451) * lisp/doc-view.el (doc-view--text-view-mode): New alias for view-mode. (doc-view-open-text): Use it. (doc-view-toggle-display): Use it. --- lisp/doc-view.el | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lisp/doc-view.el b/lisp/doc-view.el index 7ae7c6a96cd..53ae351abd8 100644 --- a/lisp/doc-view.el +++ b/lisp/doc-view.el @@ -1476,6 +1476,15 @@ For now these keys are useful: (interactive) (tooltip-show (doc-view-current-info))) +;; We define an own major mode for DocView's text display so that we +;; 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 () + "View mode used in DocView's text buffers." + (view-mode) + (setq major-mode 'doc-view--text-view-mode)) + (defun doc-view-open-text () "Display the current doc's contents as text." (interactive) @@ -1489,13 +1498,13 @@ For now these keys are useful: (erase-buffer) (set-buffer-multibyte t) (insert-file-contents txt) - (text-mode) + (doc-view--text-view-mode) (setq-local doc-view--buffer-file-name dv-bfn) (set-buffer-modified-p nil) (doc-view-minor-mode) (add-hook 'write-file-functions (lambda () - (when (eq major-mode 'text-mode) + (when (eq major-mode 'doc-view--text-view-mode) (error "Cannot save text contents of document %s" buffer-file-name))) nil t)) @@ -1519,7 +1528,7 @@ For now these keys are useful: ;; normal mode. (doc-view-fallback-mode) (doc-view-minor-mode 1)) - ((eq major-mode 'text-mode) + ((eq major-mode 'doc-view--text-view-mode) (let ((buffer-undo-list t)) ;; We're currently viewing the document's text contents, so switch ;; back to . -- 2.39.2