help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: DocView: process ps->pdf changed status to killed.


From: Stefan Monnier
Subject: Re: DocView: process ps->pdf changed status to killed.
Date: Wed, 22 Oct 2014 08:34:19 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

>>> - 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.

I suggest to set a write-buffer hook to try and make extra sure we don't
end up overwriting the 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).

For the case at hand, we can't view images, so the first C-c C-c should
switch right back to ps-mode.

> +       (let ((inhibit-read-only t))
> +         (set-buffer-multibyte t)

I strongly recommend not do use set-buffer-multibyte on a non-empty
buffer (this is a general rule, but is especially true in our case since
we may have a mostly-binary file, in which case (set-buffer-multibyte t)
can have a lot of work to do (and suffered from an O(N^2) behavior not
that long ago, not sure if we fixed it)).
And since we throw away the buffer's content right after anyway, we may
as well `erase-buffer' ourselves first (and do it without preserving the
undo info).

> +   ((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)

buffer-file-name can be nil.  So either we need to "stash" away the
contents of the buffer before we erased it (e.g. we could stash it into
an auxiliary buffer with buffer-swap-text), or simpler: use
doc-view--buffer-file-name.

Other than that, I think it looks good.


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]