diff options
| author | Manuel Giraud | 2024-07-23 16:32:30 +0200 |
|---|---|---|
| committer | Tassilo Horn | 2024-07-25 08:14:00 +0200 |
| commit | 210b98bc9937a86920716ebdf0b0e00a0c79c8fe (patch) | |
| tree | aef887072890dc7d2384f65a8f212b37a0fc4968 | |
| parent | 2f5af5cab3869af426631735f12acf30798136bf (diff) | |
| download | emacs-210b98bc9937a86920716ebdf0b0e00a0c79c8fe.tar.gz emacs-210b98bc9937a86920716ebdf0b0e00a0c79c8fe.zip | |
bug#72241: 31.0.50; [PATCH] Use a dedicated buffer for `doc-view-open-text'
Here is an updated version of this patch. WDYT?
From 6e32534012cafeda1d7e67aab23a8206bc887c9f Mon Sep 17 00:00:00 2001
From: Manuel Giraud <manuel@ledu-giraud.fr>
Date: Sun, 21 Jul 2024 18:52:52 +0200
Subject: [PATCH] Use a dedicated buffer for `doc-view-open-text'
* lisp/doc-view.el (doc-view-open-text): Create a new "text
contents" buffer and switch to it.
(doc-view-toggle-display): Switch back to the document buffer
and kill the "text contents" one.
* etc/NEWS: Mention the change.
| -rw-r--r-- | etc/NEWS | 7 | ||||
| -rw-r--r-- | lisp/doc-view.el | 60 |
2 files changed, 31 insertions, 36 deletions
| @@ -149,6 +149,13 @@ This affects calls to 'warn', 'lwarn', 'display-warning', and | |||
| 149 | In most cases, having it enabled leads to a large amount of false | 149 | In most cases, having it enabled leads to a large amount of false |
| 150 | positives. | 150 | positives. |
| 151 | 151 | ||
| 152 | ** DocView | ||
| 153 | |||
| 154 | --- | ||
| 155 | *** Dedicated buffer for plain text contents. | ||
| 156 | When switching to the plain text contents with 'doc-view-open-text', | ||
| 157 | DocView now creates a dedicated buffer to display it. 'C-c C-c' gets you | ||
| 158 | back to real DocView buffer if it still exists. | ||
| 152 | 159 | ||
| 153 | * New Modes and Packages in Emacs 31.1 | 160 | * New Modes and Packages in Emacs 31.1 |
| 154 | 161 | ||
diff --git a/lisp/doc-view.el b/lisp/doc-view.el index 5a3ec04c165..da9ae991f57 100644 --- a/lisp/doc-view.el +++ b/lisp/doc-view.el | |||
| @@ -1768,34 +1768,25 @@ For now these keys are useful: | |||
| 1768 | (let ((txt (expand-file-name "doc.txt" (doc-view--current-cache-dir))) | 1768 | (let ((txt (expand-file-name "doc.txt" (doc-view--current-cache-dir))) |
| 1769 | (page (doc-view-current-page))) | 1769 | (page (doc-view-current-page))) |
| 1770 | (if (file-readable-p txt) | 1770 | (if (file-readable-p txt) |
| 1771 | (let ((inhibit-read-only t) | 1771 | (let ((dv-bfn doc-view--buffer-file-name) |
| 1772 | (buffer-undo-list t) | 1772 | (dv-text-buffer-name (format "%s/text" (buffer-name)))) |
| 1773 | (dv-bfn doc-view--buffer-file-name)) | 1773 | ;; Prepare the text buffer |
| 1774 | (erase-buffer) | 1774 | (with-current-buffer (get-buffer-create dv-text-buffer-name) |
| 1775 | ;; FIXME: Replacing the buffer's PDF content with its txt rendering | 1775 | (let ((inhibit-read-only t) |
| 1776 | ;; is pretty risky. We should probably use *another* | 1776 | (buffer-undo-list t)) |
| 1777 | ;; buffer instead, so there's much less risk of | 1777 | (erase-buffer) |
| 1778 | ;; overwriting the PDF file with some text rendering. | 1778 | (set-buffer-multibyte t) |
| 1779 | (set-buffer-multibyte t) | 1779 | (insert-file-contents txt) |
| 1780 | (insert-file-contents txt) | 1780 | (doc-view--text-view-mode) |
| 1781 | (doc-view--text-view-mode) | 1781 | (setq-local doc-view--buffer-file-name dv-bfn) |
| 1782 | (setq-local doc-view--buffer-file-name dv-bfn) | 1782 | (set-buffer-modified-p nil) |
| 1783 | (set-buffer-modified-p nil) | 1783 | (doc-view-minor-mode) |
| 1784 | (doc-view-minor-mode) | 1784 | (goto-char (point-min)) |
| 1785 | (goto-char (point-min)) | 1785 | ;; Put point at the start of the page the user was |
| 1786 | ;; Put point at the start of the page the user was | 1786 | ;; reading. Pages are separated by Control-L characters. |
| 1787 | ;; reading. Pages are separated by Control-L characters. | 1787 | (re-search-forward page-delimiter nil t (1- page)))) |
| 1788 | (re-search-forward page-delimiter nil t (1- page)) | 1788 | (switch-to-buffer (get-buffer dv-text-buffer-name))) |
| 1789 | (add-hook 'write-file-functions | 1789 | (doc-view-doc->txt txt 'doc-view-open-text))))) |
| 1790 | (lambda () | ||
| 1791 | ;; FIXME: If the user changes major mode and then | ||
| 1792 | ;; saves the buffer, the PDF file will be clobbered | ||
| 1793 | ;; with its txt rendering! | ||
| 1794 | (when (eq major-mode 'doc-view--text-view-mode) | ||
| 1795 | (error "Cannot save text contents of document %s" | ||
| 1796 | buffer-file-name))) | ||
| 1797 | nil t)) | ||
| 1798 | (doc-view-doc->txt txt 'doc-view-open-text))))) | ||
| 1799 | 1790 | ||
| 1800 | ;;;;; Toggle between editing and viewing | 1791 | ;;;;; Toggle between editing and viewing |
| 1801 | 1792 | ||
| @@ -1816,14 +1807,11 @@ For now these keys are useful: | |||
| 1816 | (doc-view-fallback-mode) | 1807 | (doc-view-fallback-mode) |
| 1817 | (doc-view-minor-mode 1)) | 1808 | (doc-view-minor-mode 1)) |
| 1818 | ((eq major-mode 'doc-view--text-view-mode) | 1809 | ((eq major-mode 'doc-view--text-view-mode) |
| 1819 | (let ((buffer-undo-list t)) | 1810 | ;; We're currently viewing the document's text contents, switch to |
| 1820 | ;; We're currently viewing the document's text contents, so switch | 1811 | ;; the buffer visiting the real document and kill myself. |
| 1821 | ;; back to . | 1812 | (let ((dv-buffer (find-buffer-visiting doc-view--buffer-file-name))) |
| 1822 | (setq buffer-read-only nil) | 1813 | (kill-buffer) |
| 1823 | (insert-file-contents doc-view--buffer-file-name nil nil nil t) | 1814 | (switch-to-buffer dv-buffer))) |
| 1824 | (doc-view-fallback-mode) | ||
| 1825 | (doc-view-minor-mode 1) | ||
| 1826 | (set-buffer-modified-p nil))) | ||
| 1827 | (t | 1815 | (t |
| 1828 | ;; Switch to doc-view-mode | 1816 | ;; Switch to doc-view-mode |
| 1829 | (when (and (buffer-modified-p) | 1817 | (when (and (buffer-modified-p) |