From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.help Subject: Re: DocView: process ps->pdf changed status to killed. Date: Wed, 22 Oct 2014 09:16:15 +0200 Message-ID: <87y4s8lglc.fsf@thinkpad-t440p.tsdh.org> References: <87bnpsi5wc.fsf@thinkpad-t440p.tsdh.org> <20141007.102533.2212875331518577085.devel@pollock-nageoire.net> <87oatouu2y.fsf@thinkpad-t440p.tsdh.org> <20141018.073246.1226955945483316970.devel@pollock-nageoire.net> <87mw8smpse.fsf@thinkpad-t440p.tsdh.org> <87fvehztfs.fsf@thinkpad-t440p.tsdh.org> <8738ahtetm.fsf@thinkpad-t440p.tsdh.org> <8761fcmyof.fsf@thinkpad-t440p.tsdh.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1413962211 17994 80.91.229.3 (22 Oct 2014 07:16:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 22 Oct 2014 07:16:51 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Stefan Monnier Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Oct 22 09:16:44 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Xgq9w-0008HW-QD for geh-help-gnu-emacs@m.gmane.org; Wed, 22 Oct 2014 09:16:41 +0200 Original-Received: from localhost ([::1]:55114 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xgq9w-0001ga-80 for geh-help-gnu-emacs@m.gmane.org; Wed, 22 Oct 2014 03:16:40 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xgq9g-0001gA-B0 for help-gnu-emacs@gnu.org; Wed, 22 Oct 2014 03:16:30 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xgq9a-0004dn-B9 for help-gnu-emacs@gnu.org; Wed, 22 Oct 2014 03:16:24 -0400 Original-Received: from deliver.uni-koblenz.de ([141.26.64.15]:33323) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xgq9a-0004df-1L for help-gnu-emacs@gnu.org; Wed, 22 Oct 2014 03:16:18 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by deliver.uni-koblenz.de (Postfix) with ESMTP id 0F3DC1A8439; Wed, 22 Oct 2014 09:16:17 +0200 (CEST) X-Virus-Scanned: amavisd-new at uni-koblenz.de Original-Received: from deliver.uni-koblenz.de ([127.0.0.1]) by localhost (deliver.uni-koblenz.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id b_-jqmc9ofc9; Wed, 22 Oct 2014 09:16:16 +0200 (CEST) X-CHKRCPT: Envelopesender noch tsdh@gnu.org Original-Received: from thinkpad-t440p.tsdh.org (dhcp211.uni-koblenz.de [141.26.71.211]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by deliver.uni-koblenz.de (Postfix) with ESMTPSA id 8043C1A8431; Wed, 22 Oct 2014 09:16:16 +0200 (CEST) In-Reply-To: <8761fcmyof.fsf@thinkpad-t440p.tsdh.org> (Tassilo Horn's message of "Wed, 22 Oct 2014 08:00:16 +0200") User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/25.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 141.26.64.15 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:100544 Archived-At: Tassilo Horn 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