From: Tassilo Horn <tsdh@gnu.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: help-gnu-emacs@gnu.org
Subject: Re: DocView: process ps->pdf changed status to killed.
Date: Wed, 22 Oct 2014 09:16:15 +0200 [thread overview]
Message-ID: <87y4s8lglc.fsf@thinkpad-t440p.tsdh.org> (raw)
In-Reply-To: <8761fcmyof.fsf@thinkpad-t440p.tsdh.org> (Tassilo Horn's message of "Wed, 22 Oct 2014 08:00:16 +0200")
Tassilo Horn <tsdh@gnu.org> writes:
>> - we change the .txt system so that it displays the text in the
>> original buffer rather than in an auxiliary buffer (and hence we don't
>> switch back to ps-mode).
>
> That's an alternative I've also thought about. I'll see if that's
> feasible...
Ok, here's a patch which does that. `C-c C-t' or saying yes to the
initial "Cannot render; wanna view the text instead?" query replaces the
buffer contents with the text contents of the document and switches to
text-mode + doc-view-minor-mode. The buffer is still read-only so that
you can't modify it because it keeps the file association to the
original file.
With `C-c C-c' you can toggle back to viewing the page images, with
another `C-c C-c' you're back at the original document in its editing
mode (fundamental-mode, ps-mode, or archive-mode for ODF files).
--8<---------------cut here---------------start------------->8---
=== modified file 'lisp/doc-view.el'
--- lisp/doc-view.el 2014-07-28 09:39:09 +0000
+++ lisp/doc-view.el 2014-10-22 07:15:09 +0000
@@ -1396,15 +1396,14 @@
(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)))
- (bname (or buffer-file-name (buffer-name))))
+ (let ((txt (expand-file-name "doc.txt" (doc-view--current-cache-dir))))
(if (file-readable-p txt)
- (let ((name (concat "Text contents of "
- (file-name-nondirectory bname)))
- (dir (or (file-name-directory bname) default-directory)))
- (with-current-buffer (find-file txt)
- (rename-buffer name)
- (setq default-directory dir)))
+ (let ((inhibit-read-only t))
+ (set-buffer-multibyte t)
+ (text-mode)
+ (insert-file-contents txt nil nil nil t)
+ (set-buffer-modified-p nil)
+ (doc-view-minor-mode))
(doc-view-doc->txt txt 'doc-view-open-text)))))
;;;;; Toggle between editing and viewing
@@ -1416,20 +1415,28 @@
(defun doc-view-toggle-display ()
"Toggle between editing a document as text or viewing it."
(interactive)
- (if (eq major-mode 'doc-view-mode)
- ;; Switch to editing mode
- (progn
- (doc-view-kill-proc)
- (setq buffer-read-only nil)
- ;; Switch to the previously used major mode or fall back to
- ;; normal mode.
- (doc-view-fallback-mode)
- (doc-view-minor-mode 1))
+ (cond
+ ((eq major-mode 'doc-view-mode)
+ ;; Switch to editing mode
+ (doc-view-kill-proc)
+ (setq buffer-read-only nil)
+ ;; Switch to the previously used major mode or fall back to
+ ;; normal mode.
+ (doc-view-fallback-mode)
+ (doc-view-minor-mode 1))
+ ((eq major-mode 'text-mode)
+ ;; We're currently viewing the document's text contents, so switch
+ ;; back to doc-view-mode.
+ (setq buffer-read-only nil)
+ (insert-file-contents buffer-file-name nil nil nil t)
+ (doc-view-mode)
+ (set-buffer-modified-p nil))
+ (t
;; Switch to doc-view-mode
(when (and (buffer-modified-p)
(y-or-n-p "The buffer has been modified. Save the changes? "))
(save-buffer))
- (doc-view-mode)))
+ (doc-view-mode))))
;;;; Searching
@@ -1585,11 +1592,11 @@
(concat "No PNG support is available, or some conversion utility for "
(file-name-extension doc-view--buffer-file-name)
" files is missing."))
- (when (and (executable-find doc-view-pdftotext-program)
- (y-or-n-p
- "Unable to render file. View extracted text instead? "))
- (doc-view-open-text))
- (doc-view-toggle-display)))
+ (if (and (executable-find doc-view-pdftotext-program)
+ (y-or-n-p
+ "Unable to render file. View extracted text instead? "))
+ (doc-view-open-text)
+ (doc-view-toggle-display))))
(defvar bookmark-make-record-function)
@@ -1616,7 +1623,7 @@
"Figure out the current document type (`doc-view-doc-type')."
(let ((name-types
(when buffer-file-name
- (cdr (assoc-ignore-case
+ (cdr (assoc-string
(file-name-extension buffer-file-name)
'(
;; DVI
@@ -1634,7 +1641,8 @@
;; Microsoft Office formats (also handled by the odf
;; conversion chain).
("doc" odf) ("docx" odf) ("xls" odf) ("xlsx" odf)
- ("ppt" odf) ("pps" odf) ("pptx" odf))))))
+ ("ppt" odf) ("pps" odf) ("pptx" odf))
+ t))))
(content-types
(save-excursion
(goto-char (point-min))
--8<---------------cut here---------------end--------------->8---
Bye,
Tassilo
next prev parent reply other threads:[~2014-10-22 7:16 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-01 17:06 DocView: process ps->pdf changed status to killed Pierre Lorenzon
2014-10-02 10:25 ` Tassilo Horn
2014-10-02 12:36 ` Stefan Monnier
2014-10-03 15:17 ` Pierre Lorenzon
2014-10-04 8:46 ` Tassilo Horn
2014-10-03 14:48 ` Pierre Lorenzon
2014-10-03 15:09 ` Pierre Lorenzon
2014-10-03 18:34 ` Tassilo Horn
2014-10-04 3:35 ` Pierre Lorenzon
2014-10-04 3:46 ` Pierre Lorenzon
2014-10-04 3:54 ` Pierre Lorenzon
2014-10-04 8:41 ` Tassilo Horn
2014-10-07 8:25 ` Pierre Lorenzon
2014-10-07 9:07 ` Tassilo Horn
2014-10-18 5:32 ` Pierre Lorenzon
2014-10-19 8:23 ` Tassilo Horn
2014-10-19 19:55 ` Stefan Monnier
2014-10-21 9:02 ` Tassilo Horn
2014-10-21 14:28 ` Stefan Monnier
2014-10-21 14:54 ` Tassilo Horn
[not found] ` <mailman.11640.1413903303.1147.help-gnu-emacs@gnu.org>
2014-10-21 15:36 ` Stefan Monnier
2014-10-21 19:15 ` Tassilo Horn
2014-10-21 20:19 ` Stefan Monnier
2014-10-22 6:00 ` Tassilo Horn
2014-10-22 7:16 ` Tassilo Horn [this message]
2014-10-22 12:34 ` Stefan Monnier
2014-10-22 13:36 ` Tassilo Horn
2014-10-23 5:11 ` Pierre Lorenzon
2014-10-23 6:14 ` Tassilo Horn
2014-10-23 12:01 ` Stefan Monnier
2014-10-23 19:18 ` Tassilo Horn
2014-10-24 6:04 ` Pierre Lorenzon
2014-10-24 6:36 ` Tassilo Horn
2014-10-24 9:10 ` Pierre Lorenzon
2014-10-24 9:24 ` Pierre Lorenzon
2014-10-24 10:26 ` Tassilo Horn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y4s8lglc.fsf@thinkpad-t440p.tsdh.org \
--to=tsdh@gnu.org \
--cc=help-gnu-emacs@gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.