unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* DocView: process ps->pdf changed status to killed.
@ 2014-10-01 17:06 Pierre Lorenzon
  2014-10-02 10:25 ` Tassilo Horn
  0 siblings, 1 reply; 36+ messages in thread
From: Pierre Lorenzon @ 2014-10-01 17:06 UTC (permalink / raw)
  To: help-gnu-emacs


Hi

I get error message in the subject when doing C-c C-c in a
buffer visiting a ps file and I cannot figure out why.


Emacs version is 24.3.1 

When doing C-c C-c I get a message syaing that no conversion to
images can be done since there are no tools to do that on my
system. In fact I am blind and only interested to text. Anyway
normally if you press y key text should be displayed using
first a conversion to pdf and then a conversion to text.

But process dies at first step as shown by the error message.

doc-view-pdftotext-program variable is set to ps2pdf (or
ps2pdf13) but both gives the same result. Even if the two
scripts ps2pdf and ps2pdf13 exist on my system and run
perfectly when launched from the console. 

Does anyone knows where this errror might come from or give me
indications to check more about the process that is meant to
die !

Regards 

Pierre



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  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
                     ` (2 more replies)
  0 siblings, 3 replies; 36+ messages in thread
From: Tassilo Horn @ 2014-10-02 10:25 UTC (permalink / raw)
  To: Pierre Lorenzon; +Cc: help-gnu-emacs

Pierre Lorenzon <devel@pollock-nageoire.net> writes:

Hi Pierre,

> I get error message in the subject when doing C-c C-c in a buffer
> visiting a ps file and I cannot figure out why.
>
> Emacs version is 24.3.1 
>
> When doing C-c C-c I get a message syaing that no conversion to images
> can be done since there are no tools to do that on my system. In fact
> I am blind and only interested to text. Anyway normally if you press y
> key text should be displayed using first a conversion to pdf and then
> a conversion to text.
>
> But process dies at first step as shown by the error message.
>
> doc-view-pdftotext-program variable is set to ps2pdf (or ps2pdf13) but
> both gives the same result.  Even if the two scripts ps2pdf and
> ps2pdf13 exist on my system and run perfectly when launched from the
> console.

Hm, you could try to evaluate the following piece of advice:

  (defadvice doc-view-start-process (before doc-view-show-cmd-line activate)
    (message "doc-view-start-process:\n  %s %s"
              program (mapconcat #'concat args " ")))

That will print the exact command lines doc-view executes in the
*Messages* buffer.  The command that doesn't work should be just before
the error message in the subject.  Then copy the command line and check
if it works indeed in a terminal.

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  2014-10-02 10:25 ` Tassilo Horn
@ 2014-10-02 12:36   ` Stefan Monnier
  2014-10-03 15:17     ` Pierre Lorenzon
  2014-10-03 14:48   ` Pierre Lorenzon
  2014-10-03 15:09   ` Pierre Lorenzon
  2 siblings, 1 reply; 36+ messages in thread
From: Stefan Monnier @ 2014-10-02 12:36 UTC (permalink / raw)
  To: help-gnu-emacs

> Hm, you could try to evaluate the following piece of advice:

>   (defadvice doc-view-start-process (before doc-view-show-cmd-line activate)
>     (message "doc-view-start-process:\n  %s %s"
>               program (mapconcat #'concat args " ")))

I think

   M-x trace-function RET doc-view-start-process RET

is a better version of the above.


        Stefan




^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  2014-10-02 10:25 ` Tassilo Horn
  2014-10-02 12:36   ` Stefan Monnier
@ 2014-10-03 14:48   ` Pierre Lorenzon
  2014-10-03 15:09   ` Pierre Lorenzon
  2 siblings, 0 replies; 36+ messages in thread
From: Pierre Lorenzon @ 2014-10-03 14:48 UTC (permalink / raw)
  To: tsdh; +Cc: help-gnu-emacs


Hi Tassilo 

I am happy that you answer my question since you are the
package maintainer and devlopper and certainly know how it
works. I'll try what you recommand and tell you.

Thanks 

Pierre


From: Tassilo Horn <tsdh@gnu.org>
Subject: Re: DocView: process ps->pdf changed status to killed.
Date: Thu, 02 Oct 2014 12:25:37 +0200

> Pierre Lorenzon <devel@pollock-nageoire.net> writes:
> 
> Hi Pierre,
> 
>> I get error message in the subject when doing C-c C-c in a buffer
>> visiting a ps file and I cannot figure out why.
>>
>> Emacs version is 24.3.1 
>>
>> When doing C-c C-c I get a message syaing that no conversion to images
>> can be done since there are no tools to do that on my system. In fact
>> I am blind and only interested to text. Anyway normally if you press y
>> key text should be displayed using first a conversion to pdf and then
>> a conversion to text.
>>
>> But process dies at first step as shown by the error message.
>>
>> doc-view-pdftotext-program variable is set to ps2pdf (or ps2pdf13) but
>> both gives the same result.  Even if the two scripts ps2pdf and
>> ps2pdf13 exist on my system and run perfectly when launched from the
>> console.
> 
> Hm, you could try to evaluate the following piece of advice:
> 
>   (defadvice doc-view-start-process (before doc-view-show-cmd-line activate)
>     (message "doc-view-start-process:\n  %s %s"
>               program (mapconcat #'concat args " ")))
> 
> That will print the exact command lines doc-view executes in the
> *Messages* buffer.  The command that doesn't work should be just before
> the error message in the subject.  Then copy the command line and check
> if it works indeed in a terminal.
> 
> Bye,
> Tassilo



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  2014-10-02 10:25 ` Tassilo Horn
  2014-10-02 12:36   ` Stefan Monnier
  2014-10-03 14:48   ` Pierre Lorenzon
@ 2014-10-03 15:09   ` Pierre Lorenzon
  2014-10-03 18:34     ` Tassilo Horn
  2 siblings, 1 reply; 36+ messages in thread
From: Pierre Lorenzon @ 2014-10-03 15:09 UTC (permalink / raw)
  To: tsdh; +Cc: help-gnu-emacs


Hi,

From: Tassilo Horn <tsdh@gnu.org>
Subject: Re: DocView: process ps->pdf changed status to killed.
Date: Thu, 02 Oct 2014 12:25:37 +0200

> Pierre Lorenzon <devel@pollock-nageoire.net> writes:
> 
> Hi Pierre,
> 
>> I get error message in the subject when doing C-c C-c in a buffer
>> visiting a ps file and I cannot figure out why.
>>
>> Emacs version is 24.3.1 
>>
>> When doing C-c C-c I get a message syaing that no conversion to images
>> can be done since there are no tools to do that on my system. In fact
>> I am blind and only interested to text. Anyway normally if you press y
>> key text should be displayed using first a conversion to pdf and then
>> a conversion to text.
>>
>> But process dies at first step as shown by the error message.
>>
>> doc-view-pdftotext-program variable is set to ps2pdf (or ps2pdf13) but
>> both gives the same result.  Even if the two scripts ps2pdf and
>> ps2pdf13 exist on my system and run perfectly when launched from the
>> console.
> 
> Hm, you could try to evaluate the following piece of advice:
> 
>   (defadvice doc-view-start-process (before doc-view-show-cmd-line activate)
>     (message "doc-view-start-process:\n  %s %s"
>               program (mapconcat #'concat args " ")))
> 
> That will print the exact command lines doc-view executes in the
> *Messages* buffer.  The command that doesn't work should be just before
> the error message in the subject.  Then copy the command line and check
> if it works indeed in a terminal.
> 

  I get following in mmessage buffer : 

Type C-c C-c to toggle between editing or viewing the document.
No PNG support is available, or some conversion utility for ps files is missing.
Error during redisplay: (eval (number-to-string (doc-view-current-page))) signaled (wrong-type-argument numberp nil) [2 times]
Unable to render file.  View extracted text instead? (y or n)  y
doc-view-start-process:
  ps2pdf -dSAFER /home/devel/test.ps /tmp/docview1001/test.ps-932911a0f86866e1b95b1aaf506a818b/doc.pdf
Error during redisplay: (eval (number-to-string (doc-view-current-page))) signaled (wrong-type-argument numberp nil)
Type C-c C-c to toggle between editing or viewing the document. [2 times]
DocView: process ps->pdf changed status to killed.


Command ps2pdf -dSAFER /home/devel/test.ps
/tmp/docview1001/test.ps-932911a0f86866e1b95b1aaf506a818b/doc.pdf
executed in a console works perfectly ... 

Regards 

Pierre



> Bye,
> Tassilo



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  2014-10-02 12:36   ` Stefan Monnier
@ 2014-10-03 15:17     ` Pierre Lorenzon
  2014-10-04  8:46       ` Tassilo Horn
  0 siblings, 1 reply; 36+ messages in thread
From: Pierre Lorenzon @ 2014-10-03 15:17 UTC (permalink / raw)
  To: monnier; +Cc: help-gnu-emacs


Hi Stefan,

You are certainly right but I never used this emacs feature
trace-function and not able to understand the output in trace
buffer : Here it is. If you can get something from that please
tell me :

======================================================================
1 -> doc-view-start-process: name="ps->pdf" program="ps2pdf" args=("-dSAFER" "/home/devel/test.ps" "/tmp/docview1001/test.ps-932911a0f86866e1b95b1aaf506a818b/doc.pdf") callback=#[0 "\303\302\300\301#\207" ["/tmp/docview1001/test.ps-932911a0f86866e1b95b1aaf506a818b/doc.txt" doc-view-open-text "/tmp/docview1001/test.ps-932911a0f86866e1b95b1aaf506a818b/doc.pdf" doc-view-pdf->txt] 4 "

(fn)"]
1 <- doc-view-start-process: (buffer #<buffer test.ps> callback #[0 "\303\302\300\301#\207" ["/tmp/docview1001/test.ps-932911a0f86866e1b95b1aaf506a818b/doc.txt" doc-view-open-text "/tmp/docview1001/test.ps-932911a0f86866e1b95b1aaf506a818b/doc.pdf" doc-view-pdf->txt] 4 "

(fn)"])



Regards

Pierre


From: Stefan Monnier <monnier@iro.umontreal.ca>
Subject: Re: DocView: process ps->pdf changed status to killed.
Date: Thu, 02 Oct 2014 08:36:58 -0400

>> Hm, you could try to evaluate the following piece of advice:
> 
>>   (defadvice doc-view-start-process (before doc-view-show-cmd-line activate)
>>     (message "doc-view-start-process:\n  %s %s"
>>               program (mapconcat #'concat args " ")))
> 
> I think
> 
>    M-x trace-function RET doc-view-start-process RET
> 
> is a better version of the above.
> 
> 
>         Stefan
> 
> 



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  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
  0 siblings, 2 replies; 36+ messages in thread
From: Tassilo Horn @ 2014-10-03 18:34 UTC (permalink / raw)
  To: Pierre Lorenzon; +Cc: help-gnu-emacs

Pierre Lorenzon <devel@pollock-nageoire.net> writes:

Hi Pierre,

> Command ps2pdf -dSAFER /home/devel/test.ps
> /tmp/docview1001/test.ps-932911a0f86866e1b95b1aaf506a818b/doc.pdf
> executed in a console works perfectly ... 

Ok, I've thought that.  So it works on the command line but not from
lisp.  Could you please try evaluating this expression and tell us what
it messages?

(let ((process (start-process "ps2pdf conversion"
               "ps2pdf conversion output"
               "ps2pdf"
               "-dSAFER"
               "/home/devel/test.ps"
               "/tmp/docview1001/test.ps-932911a0f86866e1b95b1aaf506a818b/doc.pdf")))
  (set-process-sentinel process
                        #'(lambda (proc event)
                            (message "Process: %s had the event `%s'"
                                     proc event))))  ;; C-x C-e here

I guess it'll say something like

  Process: ps2pdf conversion had the event `killed
  '

which wouldn't give me more of a clue than I have right now, though. :-(

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  2014-10-03 18:34     ` Tassilo Horn
@ 2014-10-04  3:35       ` Pierre Lorenzon
  2014-10-04  3:46       ` Pierre Lorenzon
  1 sibling, 0 replies; 36+ messages in thread
From: Pierre Lorenzon @ 2014-10-04  3:35 UTC (permalink / raw)
  To: tsdh; +Cc: help-gnu-emacs


Hi Tassilo

From: Tassilo Horn <tsdh@gnu.org>
Subject: Re: DocView: process ps->pdf changed status to killed.
Date: Fri, 03 Oct 2014 20:34:41 +0200

> Pierre Lorenzon <devel@pollock-nageoire.net> writes:
> 
> Hi Pierre,
> 
>> Command ps2pdf -dSAFER /home/devel/test.ps
>> /tmp/docview1001/test.ps-932911a0f86866e1b95b1aaf506a818b/doc.pdf
>> executed in a console works perfectly ... 
> 
> Ok, I've thought that.  So it works on the command line but not from
> lisp.  Could you please try evaluating this expression and tell us what
> it messages?
> 
> (let ((process (start-process "ps2pdf conversion"
>                "ps2pdf conversion output"
>                "ps2pdf"
>                "-dSAFER"
>                "/home/devel/test.ps"
>                "/tmp/docview1001/test.ps-932911a0f86866e1b95b1aaf506a818b/doc.pdf")))
>   (set-process-sentinel process
>                         #'(lambda (proc event)
>                             (message "Process: %s had the event `%s'"
>                                      proc event))))  ;; C-x C-e here
  Surprisingly it returns process had event finished syaing
  that process completed. And looking in the suitable directory
  one can see that the corresponding pdf file has been
  created. In fact the piece of code above is not very
  different from the doc-view-start-process function. Hence
  it's difficult to understand why this one works since the
  doc-view-start-process seems to fail. 




> 
> I guess it'll say something like
> 
>   Process: ps2pdf conversion had the event `killed
>   '

    No !



> 
> which wouldn't give me more of a clue than I have right now,
> though. :-(

  Regards 

  Pierre



> 
> Bye,
> Tassilo



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  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
  1 sibling, 1 reply; 36+ messages in thread
From: Pierre Lorenzon @ 2014-10-04  3:46 UTC (permalink / raw)
  To: tsdh; +Cc: help-gnu-emacs


Hi Tassilo

I tried what I should have try from the beginning starting
emacs with --no-site-file -q option. In this case your code
works. So it's clear it's one of the multiple codes that are
loadded by my emacs that disturbs your code. I am alone now to
determine which one and why. Anyway thanks for your help !


Pierre


From: Tassilo Horn <tsdh@gnu.org>
Subject: Re: DocView: process ps->pdf changed status to killed.
Date: Fri, 03 Oct 2014 20:34:41 +0200

> Pierre Lorenzon <devel@pollock-nageoire.net> writes:
> 
> Hi Pierre,
> 
>> Command ps2pdf -dSAFER /home/devel/test.ps
>> /tmp/docview1001/test.ps-932911a0f86866e1b95b1aaf506a818b/doc.pdf
>> executed in a console works perfectly ... 
> 
> Ok, I've thought that.  So it works on the command line but not from
> lisp.  Could you please try evaluating this expression and tell us what
> it messages?
> 
> (let ((process (start-process "ps2pdf conversion"
>                "ps2pdf conversion output"
>                "ps2pdf"
>                "-dSAFER"
>                "/home/devel/test.ps"
>                "/tmp/docview1001/test.ps-932911a0f86866e1b95b1aaf506a818b/doc.pdf")))
>   (set-process-sentinel process
>                         #'(lambda (proc event)
>                             (message "Process: %s had the event `%s'"
>                                      proc event))))  ;; C-x C-e here
> 
> I guess it'll say something like
> 
>   Process: ps2pdf conversion had the event `killed
>   '
> 
> which wouldn't give me more of a clue than I have right now, though. :-(
> 
> Bye,
> Tassilo



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  2014-10-04  3:46       ` Pierre Lorenzon
@ 2014-10-04  3:54         ` Pierre Lorenzon
  2014-10-04  8:41           ` Tassilo Horn
  0 siblings, 1 reply; 36+ messages in thread
From: Pierre Lorenzon @ 2014-10-04  3:54 UTC (permalink / raw)
  To: tsdh; +Cc: help-gnu-emacs


Oops sorry ! In fact it does not work better with
--no-site-file and -q. Simply I forgot removing pdf files that
had been manually created and doc-view hence did not launch the
conversion process.

Pierre 


From: Pierre Lorenzon <devel@pollock-nageoire.net>
Subject: Re: DocView: process ps->pdf changed status to killed.
Date: Sat, 04 Oct 2014 05:46:21 +0200 (CEST)

> 
> Hi Tassilo
> 
> I tried what I should have try from the beginning starting
> emacs with --no-site-file -q option. In this case your code
> works. So it's clear it's one of the multiple codes that are
> loadded by my emacs that disturbs your code. I am alone now to
> determine which one and why. Anyway thanks for your help !
> 
> 
> Pierre
> 
> 
> From: Tassilo Horn <tsdh@gnu.org>
> Subject: Re: DocView: process ps->pdf changed status to killed.
> Date: Fri, 03 Oct 2014 20:34:41 +0200
> 
>> Pierre Lorenzon <devel@pollock-nageoire.net> writes:
>> 
>> Hi Pierre,
>> 
>>> Command ps2pdf -dSAFER /home/devel/test.ps
>>> /tmp/docview1001/test.ps-932911a0f86866e1b95b1aaf506a818b/doc.pdf
>>> executed in a console works perfectly ... 
>> 
>> Ok, I've thought that.  So it works on the command line but not from
>> lisp.  Could you please try evaluating this expression and tell us what
>> it messages?
>> 
>> (let ((process (start-process "ps2pdf conversion"
>>                "ps2pdf conversion output"
>>                "ps2pdf"
>>                "-dSAFER"
>>                "/home/devel/test.ps"
>>                "/tmp/docview1001/test.ps-932911a0f86866e1b95b1aaf506a818b/doc.pdf")))
>>   (set-process-sentinel process
>>                         #'(lambda (proc event)
>>                             (message "Process: %s had the event `%s'"
>>                                      proc event))))  ;; C-x C-e here
>> 
>> I guess it'll say something like
>> 
>>   Process: ps2pdf conversion had the event `killed
>>   '
>> 
>> which wouldn't give me more of a clue than I have right now, though. :-(
>> 
>> Bye,
>> Tassilo
> 



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  2014-10-04  3:54         ` Pierre Lorenzon
@ 2014-10-04  8:41           ` Tassilo Horn
  2014-10-07  8:25             ` Pierre Lorenzon
  0 siblings, 1 reply; 36+ messages in thread
From: Tassilo Horn @ 2014-10-04  8:41 UTC (permalink / raw)
  To: Pierre Lorenzon; +Cc: help-gnu-emacs

Pierre Lorenzon <devel@pollock-nageoire.net> writes:

Hi Pierre,

> Oops sorry ! In fact it does not work better with --no-site-file and
> -q. Simply I forgot removing pdf files that had been manually created
> and doc-view hence did not launch the conversion process.

Ok, I see.  But is it still true that the `start-process' form of my
last mail worked, i.e., the process finished normally without being
killed?  That would be strange since that's pretty much the same what
doc-view does except that the latter might use a different
`default-directory'.

So if it really worked, please try:

(let* ((default-directory (or (unhandled-file-name-directory
			       default-directory)
			      (expand-file-name "~/")))
       (process (start-process "ps2pdf conversion"
			       "ps2pdf conversion output"
			       "ps2pdf"
			       "-dSAFER"
			       "/home/devel/test.ps"
			       "/tmp/docview1001/test.ps-932911a0f86866e1b95b1aaf506a818b/doc.pdf")))
  (set-process-sentinel process
                        #'(lambda (proc event)
                            (message "Process: %s had the event `%s'"
                                     proc event))))  ;; C-x C-e here

Now that's really exactly what doc-view does.

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  2014-10-03 15:17     ` Pierre Lorenzon
@ 2014-10-04  8:46       ` Tassilo Horn
  0 siblings, 0 replies; 36+ messages in thread
From: Tassilo Horn @ 2014-10-04  8:46 UTC (permalink / raw)
  To: Pierre Lorenzon; +Cc: help-gnu-emacs, monnier

Pierre Lorenzon <devel@pollock-nageoire.net> writes:

Hi Pierre,

> You are certainly right but I never used this emacs feature
> trace-function and not able to understand the output in trace buffer :
> Here it is.

It does basically the same thing as my advice but with standard
facilities (thus it's somewhat better).  It also shows all arguments to
the traced functions (but I've only been interested in the exact ps2pdf
command line doc-view calls).

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  2014-10-04  8:41           ` Tassilo Horn
@ 2014-10-07  8:25             ` Pierre Lorenzon
  2014-10-07  9:07               ` Tassilo Horn
  0 siblings, 1 reply; 36+ messages in thread
From: Pierre Lorenzon @ 2014-10-07  8:25 UTC (permalink / raw)
  To: tsdh; +Cc: help-gnu-emacs

From: Tassilo Horn <tsdh@gnu.org>
Subject: Re: DocView: process ps->pdf changed status to killed.
Date: Sat, 04 Oct 2014 10:41:07 +0200

> Pierre Lorenzon <devel@pollock-nageoire.net> writes:
> 
> Hi Pierre,
> 
>> Oops sorry ! In fact it does not work better with --no-site-file and
>> -q. Simply I forgot removing pdf files that had been manually created
>> and doc-view hence did not launch the conversion process.
> 
> Ok, I see.  But is it still true that the `start-process' form of my
> last mail worked, i.e., the process finished normally without being
> killed?  That would be strange since that's pretty much the same what
> doc-view does except that the latter might use a different
> `default-directory'.
> 
> So if it really worked, please try:
> 
> (let* ((default-directory (or (unhandled-file-name-directory
> 			       default-directory)
> 			      (expand-file-name "~/")))
>        (process (start-process "ps2pdf conversion"
> 			       "ps2pdf conversion output"
> 			       "ps2pdf"
> 			       "-dSAFER"
> 			       "/home/devel/test.ps"
> 			       "/tmp/docview1001/test.ps-932911a0f86866e1b95b1aaf506a818b/doc.pdf")))
>   (set-process-sentinel process
>                         #'(lambda (proc event)
>                             (message "Process: %s had the event `%s'"
>                                      proc event))))  ;; C-x C-e here
> 
> Now that's really exactly what doc-view does.

  Not really exactly as I see in the code since I saw a few
  supplementary things like recording the process in a list etc
  ...

  Anyway the code above gives finished since C-c C-c then y
  still gives killed in buffer test.ps. I will investigate more
  precisely but I have not much time at the moement.

  Thanks 

  Pierre



> 
> Bye,
> Tassilo



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  2014-10-07  8:25             ` Pierre Lorenzon
@ 2014-10-07  9:07               ` Tassilo Horn
  2014-10-18  5:32                 ` Pierre Lorenzon
  0 siblings, 1 reply; 36+ messages in thread
From: Tassilo Horn @ 2014-10-07  9:07 UTC (permalink / raw)
  To: Pierre Lorenzon; +Cc: help-gnu-emacs

Pierre Lorenzon <devel@pollock-nageoire.net> writes:

Hi Pierre,

>> Ok, I see.  But is it still true that the `start-process' form of my
>> last mail worked, i.e., the process finished normally without being
>> killed?  That would be strange since that's pretty much the same what
>> doc-view does except that the latter might use a different
>> `default-directory'.
>> 
>> So if it really worked, please try:
>> 
>> (let* ((default-directory (or (unhandled-file-name-directory
>> 			       default-directory)
>> 			      (expand-file-name "~/")))
>>        (process (start-process "ps2pdf conversion"
>> 			       "ps2pdf conversion output"
>> 			       "ps2pdf"
>> 			       "-dSAFER"
>> 			       "/home/devel/test.ps"
>> 			       "/tmp/docview1001/test.ps-932911a0f86866e1b95b1aaf506a818b/doc.pdf")))
>>   (set-process-sentinel process
>>                         #'(lambda (proc event)
>>                             (message "Process: %s had the event `%s'"
>>                                      proc event))))  ;; C-x C-e here
>> 
>> Now that's really exactly what doc-view does.
>
>   Not really exactly as I see in the code since I saw a few
>   supplementary things like recording the process in a list etc
>   ...

Yes, true.

>   Anyway the code above gives finished since C-c C-c then y
>   still gives killed in buffer test.ps. I will investigate more
>   precisely but I have not much time at the moement.

Ok.  Then let's check if doc-view itself kills the txt conversion
process.  To do that, please do `M-x trace-function RET
doc-view-kill-proc RET' and try opening your document and convert it to
text.

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  2014-10-07  9:07               ` Tassilo Horn
@ 2014-10-18  5:32                 ` Pierre Lorenzon
  2014-10-19  8:23                   ` Tassilo Horn
  0 siblings, 1 reply; 36+ messages in thread
From: Pierre Lorenzon @ 2014-10-18  5:32 UTC (permalink / raw)
  To: tsdh; +Cc: help-gnu-emacs


Hi Tassilo




From: Tassilo Horn <tsdh@gnu.org>
Subject: Re: DocView: process ps->pdf changed status to killed.
Date: Tue, 07 Oct 2014 11:07:01 +0200

> Pierre Lorenzon <devel@pollock-nageoire.net> writes:
> 
> Hi Pierre,
> 
>>> Ok, I see.  But is it still true that the `start-process' form of my
>>> last mail worked, i.e., the process finished normally without being
>>> killed?  That would be strange since that's pretty much the same what
>>> doc-view does except that the latter might use a different
>>> `default-directory'.
>>> 
>>> So if it really worked, please try:
>>> 
>>> (let* ((default-directory (or (unhandled-file-name-directory
>>> 			       default-directory)
>>> 			      (expand-file-name "~/")))
>>>        (process (start-process "ps2pdf conversion"
>>> 			       "ps2pdf conversion output"
>>> 			       "ps2pdf"
>>> 			       "-dSAFER"
>>> 			       "/home/devel/test.ps"
>>> 			       "/tmp/docview1001/test.ps-932911a0f86866e1b95b1aaf506a818b/doc.pdf")))
>>>   (set-process-sentinel process
>>>                         #'(lambda (proc event)
>>>                             (message "Process: %s had the event `%s'"
>>>                                      proc event))))  ;; C-x C-e here
>>> 
>>> Now that's really exactly what doc-view does.
>>
>>   Not really exactly as I see in the code since I saw a few
>>   supplementary things like recording the process in a list etc
>>   ...
> 
> Yes, true.
> 
>>   Anyway the code above gives finished since C-c C-c then y
>>   still gives killed in buffer test.ps. I will investigate more
>>   precisely but I have not much time at the moement.
> 
> Ok.  Then let's check if doc-view itself kills the txt conversion
> process.  To do that, please do `M-x trace-function RET
> doc-view-kill-proc RET' and try opening your document and convert it to
> text.

  Here is what I get in the trace buffer : 

======================================================================
1 -> doc-view-kill-proc: 
1 <- doc-view-kill-proc: nil
======================================================================
1 -> doc-view-kill-proc: 
1 <- doc-view-kill-proc: nil



  But I cannot interpret that !


  Pierre
> 
> Bye,
> Tassilo



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  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
  0 siblings, 2 replies; 36+ messages in thread
From: Tassilo Horn @ 2014-10-19  8:23 UTC (permalink / raw)
  To: Pierre Lorenzon; +Cc: help-gnu-emacs

Pierre Lorenzon <devel@pollock-nageoire.net> writes:

Hi Pierre,

>> Ok.  Then let's check if doc-view itself kills the txt conversion
>> process.  To do that, please do `M-x trace-function RET
>> doc-view-kill-proc RET' and try opening your document and convert it
>> to text.
>
>   Here is what I get in the trace buffer : 
>
> ======================================================================
> 1 -> doc-view-kill-proc: 
> 1 <- doc-view-kill-proc: nil
> ======================================================================
> 1 -> doc-view-kill-proc: 
> 1 <- doc-view-kill-proc: nil
>
>   But I cannot interpret that !

It means that some of your emacs' conditions (no image libs) cause
doc-view to kill the PDF to text conversion itself.  Now we need to find
out where that's done.

Could you please eval

  (defadvice doc-view-kill-proc (before debug-dvkp activate)
    (debug))

That will put you in the debugger whenever `doc-view-kill-proc' is
called.  Please post the contents of that *Backtrace* buffer.  In there,
you can resume the program by typing `c' (for continue).

Please find the pdf file again and post the contents of all *Backtrace*
buffers you get in the course of opening that file.

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  2014-10-19  8:23                   ` Tassilo Horn
@ 2014-10-19 19:55                     ` Stefan Monnier
  2014-10-21  9:02                     ` Tassilo Horn
  1 sibling, 0 replies; 36+ messages in thread
From: Stefan Monnier @ 2014-10-19 19:55 UTC (permalink / raw)
  To: help-gnu-emacs

>   (defadvice doc-view-kill-proc (before debug-dvkp activate)
>     (debug))

And this one is done with M-x debug-on-entry RET doc-view-kill-proc RET


        Stefan ;-)




^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  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
  1 sibling, 1 reply; 36+ messages in thread
From: Tassilo Horn @ 2014-10-21  9:02 UTC (permalink / raw)
  To: Pierre Lorenzon; +Cc: help-gnu-emacs, Stefan Monnier

Hi Pierre & Stefan,

you can stop debugging.  I've been able to reproduce the problem
locally.

The problem is that if your emacs doesn't satisfy the doc-view
requirements (PNG support, graphical frame, conversion utilities) but
you have pdf2text installed, then you're asked if you want to view the
document as plain text instead.  If you say yes, then doc-view will
start a process to do the conversion.

But right after starting that process, `doc-view-toggle-display' is
called which will kill all running doc-view processes (including the
conversion to TXT) and put the document's buffer back in its normal
editing mode.  That's why you've got the message that the process was
killed.

To solve that issue, I first tried excluding the processes responsible
to convert the document to text.  However, that didn't work because then
you get different errors because in the meantime the buffer is back to
ps-mode or fundamental-mode and all buffer-local variables that are used
by doc-view are gone.  I've tried to remember those by adding optional
arguments so several functions that could be used to override things
like `doc-view--buffer-file-name' but IMHO that caused too many changes
and complications for the conceptually simple problem we're facing.

So my second try (patch attached) was to just do the document-to-text
conversion synchronously in case (doc-view-mode-p type) is nil.  That
works fine now for PS and PDF documents.  It doesn't work for ODF and
DVI right now because `doc-view-doc->txt' currently assumes that in
those cases the PDF is already there, but that can be fixed easily.

So Stefan, is the attached patch ok, or do you have a better suggestion?

--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-21 08:58:30 +0000
@@ -886,19 +886,24 @@
                   (format ":%s" (car doc-view--current-converter-processes))))
         (funcall (process-get proc 'callback))))))
 
-(defun doc-view-start-process (name program args callback)
+(defun doc-view-start-process (name program args callback &optional sync)
   ;; Make sure the process is started in an existing directory, (rather than
   ;; some file-name-handler-managed dir, for example).
   (let* ((default-directory (or (unhandled-file-name-directory
                                  default-directory)
-			      (expand-file-name "~/")))
-         (proc (apply 'start-process name doc-view-conversion-buffer
-                      program args)))
-    (push proc doc-view--current-converter-processes)
-    (setq mode-line-process (list (format ":%s" proc)))
-    (set-process-sentinel proc 'doc-view-sentinel)
-    (process-put proc 'buffer   (current-buffer))
-    (process-put proc 'callback callback)))
+			      (expand-file-name "~/"))))
+    (if sync
+	(let ((stat (apply 'call-process program nil doc-view-conversion-buffer nil args)))
+	  (if (= 0 stat)
+	      (funcall callback)
+	    (error "Program %s returned exit code %s." program stat)))
+      (let ((proc (apply 'start-process name doc-view-conversion-buffer
+			 program args)))
+	(push proc doc-view--current-converter-processes)
+	(setq mode-line-process (list (format ":%s" proc)))
+	(set-process-sentinel proc 'doc-view-sentinel)
+	(process-put proc 'buffer   (current-buffer))
+	(process-put proc 'callback callback)))))
 
 (defun doc-view-dvi->pdf (dvi pdf callback)
   "Convert DVI to PDF asynchronously and call CALLBACK when finished."
@@ -1039,12 +1044,18 @@
            (doc-view-pdf/ps->png pdf png)))))))
 
 (defun doc-view-pdf->txt (pdf txt callback)
-  "Convert PDF to TXT asynchronously and call CALLBACK when finished."
+  "Convert PDF to TXT and call CALLBACK when finished."
   (or (executable-find doc-view-pdftotext-program)
       (error "You need the `pdftotext' program to convert a PDF to text"))
   (doc-view-start-process "pdf->txt" doc-view-pdftotext-program
                           (list "-raw" pdf txt)
-                          callback))
+                          callback
+			  ;; If we cannot view the doc, do it
+			  ;; synchronously.  In this case, we are just
+			  ;; before switching to the editing mode, so
+			  ;; we need to wait until the conversion is
+			  ;; done.
+			  (not (doc-view-mode-p doc-view-doc-type))))
 
 (defun doc-view-current-cache-doc-pdf ()
   "Return the name of the doc.pdf in the current cache dir.
@@ -1075,7 +1086,7 @@
     (_ (error "DocView doesn't know what to do"))))
 
 (defun doc-view-ps->pdf (ps pdf callback)
-  "Convert PS to PDF asynchronously and call CALLBACK when finished."
+  "Convert PS to PDF and call CALLBACK when finished."
   (or (executable-find doc-view-ps2pdf-program)
       (error "You need the `ps2pdf' program to convert PS to PDF"))
   (doc-view-start-process "ps->pdf" doc-view-ps2pdf-program
@@ -1085,7 +1096,11 @@
                            "-dSAFER"
                            ;; in-file and out-file
                            ps pdf)
-                          callback))
+                          callback
+			  ;; If we cannot view the doc, do it
+			  ;; synchronously.  In this case, this
+			  ;; conversion is followed by pdftotext.
+			  (not (doc-view-mode-p doc-view-doc-type))))
 
 (defun doc-view-active-pages ()
   (let ((pages ()))
@@ -1616,7 +1631,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 +1649,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



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  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>
  0 siblings, 2 replies; 36+ messages in thread
From: Stefan Monnier @ 2014-10-21 14:28 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: help-gnu-emacs

> The problem is that if your emacs doesn't satisfy the doc-view
> requirements (PNG support, graphical frame, conversion utilities) but
> you have pdf2text installed, then you're asked if you want to view the
> document as plain text instead.  If you say yes, then doc-view will
> start a process to do the conversion.
> But right after starting that process, `doc-view-toggle-display' is
> called which will kill all running doc-view processes (including the
> conversion to TXT) and put the document's buffer back in its normal
> editing mode.  That's why you've got the message that the process was
> killed.

It seems like it's an error to put the "put the document's buffer back
in its normal editing mode" if the user agreed to "view the
document as plain text".  IOW the core of the problem might be that we
shouldn't call `doc-view-toggle-display' in that case?

I don't understand why running the process synchronously helps, and it
sounds like a workaround rather than a fix.


        Stefan



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  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>
  1 sibling, 0 replies; 36+ messages in thread
From: Tassilo Horn @ 2014-10-21 14:54 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

Stefan Monnier <monnier@IRO.UMontreal.CA> writes:

>> The problem is that if your emacs doesn't satisfy the doc-view
>> requirements (PNG support, graphical frame, conversion utilities) but
>> you have pdf2text installed, then you're asked if you want to view the
>> document as plain text instead.  If you say yes, then doc-view will
>> start a process to do the conversion.
>> But right after starting that process, `doc-view-toggle-display' is
>> called which will kill all running doc-view processes (including the
>> conversion to TXT) and put the document's buffer back in its normal
>> editing mode.  That's why you've got the message that the process was
>> killed.
>
> It seems like it's an error to put the "put the document's buffer back
> in its normal editing mode" if the user agreed to "view the document
> as plain text".  IOW the core of the problem might be that we
> shouldn't call `doc-view-toggle-display' in that case?

No, I don't think so.  For example, visit a postscript document in a
terminal so that doc-view cannot do its normal workings.  Do M-x
doc-view-mode RET.  Now you're told that this won't work and if you want
to view the doc's text instead.  Say yes.  In the meantime, the original
buffer has switched doc-view-mode which means read-only, no font-lock,
etc.

Since `doc-view-toggle-display' is called, the original buffer will be
switched back to `ps-mode'.  If we'd omit that, the buffer would stay in
doc-view-mode and basically be useless.

> I don't understand why running the process synchronously helps, and it
> sounds like a workaround rather than a fix.

The text contents of the document are opened in a separate buffer, not
in the buffer of the original document.  By doing the conversion
synchronously the switching back from doc-view-mode to, say, ps-mode in
the original buffer is deferred until that conversion has finished (and
thus all the doc-view buffer local variables aren't needed anymore).

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
       [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
  0 siblings, 1 reply; 36+ messages in thread
From: Stefan Monnier @ 2014-10-21 15:36 UTC (permalink / raw)
  To: help-gnu-emacs

> The text contents of the document are opened in a separate buffer, not
> in the buffer of the original document.  By doing the conversion
> synchronously the switching back from doc-view-mode to, say, ps-mode in
> the original buffer is deferred until that conversion has finished (and
> thus all the doc-view buffer local variables aren't needed anymore).

Ah, then it sounds like the problem might be that the pdf2text process
should not be linked to the main buffer but only to the new "text view"
buffer (so that switching back to ps-mode in the main buffer wouldn't
affect the process)


        Stefan


^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  2014-10-21 15:36                           ` Stefan Monnier
@ 2014-10-21 19:15                             ` Tassilo Horn
  2014-10-21 20:19                               ` Stefan Monnier
  0 siblings, 1 reply; 36+ messages in thread
From: Tassilo Horn @ 2014-10-21 19:15 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> The text contents of the document are opened in a separate buffer, not
>> in the buffer of the original document.  By doing the conversion
>> synchronously the switching back from doc-view-mode to, say, ps-mode in
>> the original buffer is deferred until that conversion has finished (and
>> thus all the doc-view buffer local variables aren't needed anymore).
>
> Ah, then it sounds like the problem might be that the pdf2text process
> should not be linked to the main buffer but only to the new "text view"
> buffer (so that switching back to ps-mode in the main buffer wouldn't
> affect the process)

Well, yes, in theory.  The ps/pdftotext conversion works like:

  1. Convert to text by usual doc-view conversion machinery.

  2. (find-file "doc.txt")

Step 1 may involve more than just the pdftotext process, i.e., non-PDF
files have to be converted to PDF first.  We already have the relevant
doc-view-*->pdf functions for that, but all of them (or their sentinels)
access buffer-local doc-view-* variables.  And that's fine except in the
case when we want the process (or chain of processes) to continue
although we're going to switch back the main buffer from doc-view-mode
to whatever mode we've been in before.

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  2014-10-21 19:15                             ` Tassilo Horn
@ 2014-10-21 20:19                               ` Stefan Monnier
  2014-10-22  6:00                                 ` Tassilo Horn
  0 siblings, 1 reply; 36+ messages in thread
From: Stefan Monnier @ 2014-10-21 20:19 UTC (permalink / raw)
  To: help-gnu-emacs

>> Ah, then it sounds like the problem might be that the pdf2text process
>> should not be linked to the main buffer but only to the new "text view"
>> buffer (so that switching back to ps-mode in the main buffer wouldn't
>> affect the process)
> Well, yes, in theory.

So I see 2 possible good fixes:
- we make the practice match the theory by copying all the buffer-local
  vars we need into the .txt buffer and then running all those processes
  in that buffer.
- 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).


        Stefan




^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  2014-10-21 20:19                               ` Stefan Monnier
@ 2014-10-22  6:00                                 ` Tassilo Horn
  2014-10-22  7:16                                   ` Tassilo Horn
  0 siblings, 1 reply; 36+ messages in thread
From: Tassilo Horn @ 2014-10-22  6:00 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> Well, yes, in theory.
>
> So I see 2 possible good fixes:
> - we make the practice match the theory by copying all the buffer-local
>   vars we need into the .txt buffer and then running all those processes
>   in that buffer.

I don't like that idea.  That sounds like much complication for a very
rare special case.

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

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  2014-10-22  6:00                                 ` Tassilo Horn
@ 2014-10-22  7:16                                   ` Tassilo Horn
  2014-10-22 12:34                                     ` Stefan Monnier
  0 siblings, 1 reply; 36+ messages in thread
From: Tassilo Horn @ 2014-10-22  7:16 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

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



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  2014-10-22  7:16                                   ` Tassilo Horn
@ 2014-10-22 12:34                                     ` Stefan Monnier
  2014-10-22 13:36                                       ` Tassilo Horn
  2014-10-23  5:11                                       ` Pierre Lorenzon
  0 siblings, 2 replies; 36+ messages in thread
From: Stefan Monnier @ 2014-10-22 12:34 UTC (permalink / raw)
  To: help-gnu-emacs

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




^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  2014-10-22 12:34                                     ` Stefan Monnier
@ 2014-10-22 13:36                                       ` Tassilo Horn
  2014-10-23  5:11                                       ` Pierre Lorenzon
  1 sibling, 0 replies; 36+ messages in thread
From: Tassilo Horn @ 2014-10-22 13:36 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

Stefan Monnier <monnier@iro.umontreal.ca> writes:

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

Ok, done.

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

I wasn't sure if the "can't view images" or the "can view images but
still wanna look at the plain text contents" is the more common case.
But I guess you're right so I've changed it.

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

Ok, done.

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

Oh, yes.  So now I re-establish that after switching to text-mode so
that it can be used here.

> Other than that, I think it looks good.

Great, I've committed it to the trunk (r118178).

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  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
  1 sibling, 1 reply; 36+ messages in thread
From: Pierre Lorenzon @ 2014-10-23  5:11 UTC (permalink / raw)
  To: monnier; +Cc: help-gnu-emacs


Hi Tassilo and Stefan,


Thanks to take care of this problem ! As you saw I have no time
at the moment to think about this question but I'd be verry
happy that this doc-view works ! So thanks again and I'll wait
until you have fix it !


Pierre



From: Stefan Monnier <monnier@iro.umontreal.ca>
Subject: Re: DocView: process ps->pdf changed status to killed.
Date: Wed, 22 Oct 2014 08:34:19 -0400

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



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  2014-10-23  5:11                                       ` Pierre Lorenzon
@ 2014-10-23  6:14                                         ` Tassilo Horn
  2014-10-23 12:01                                           ` Stefan Monnier
  2014-10-24  6:04                                           ` Pierre Lorenzon
  0 siblings, 2 replies; 36+ messages in thread
From: Tassilo Horn @ 2014-10-23  6:14 UTC (permalink / raw)
  To: Pierre Lorenzon; +Cc: help-gnu-emacs, monnier

Pierre Lorenzon <devel@pollock-nageoire.net> writes:

Hi Pierre,

> Thanks to take care of this problem ! As you saw I have no time
> at the moment to think about this question but I'd be verry
> happy that this doc-view works ! So thanks again and I'll wait
> until you have fix it !

It's already fixed in the bzr trunk meaning it'll be in Emacs 25
(whenever that will be released).

Stefan, should I backport the patch also to the emacs-24 branch?

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  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
  1 sibling, 1 reply; 36+ messages in thread
From: Stefan Monnier @ 2014-10-23 12:01 UTC (permalink / raw)
  To: help-gnu-emacs

> Stefan, should I backport the patch also to the emacs-24 branch?

It would have been better to put it there to start with so as to
avoid backporting.  But if you want to backport it, feel free.


        Stefan




^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  2014-10-23 12:01                                           ` Stefan Monnier
@ 2014-10-23 19:18                                             ` Tassilo Horn
  0 siblings, 0 replies; 36+ messages in thread
From: Tassilo Horn @ 2014-10-23 19:18 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> Stefan, should I backport the patch also to the emacs-24 branch?
>
> It would have been better to put it there to start with so as to avoid
> backporting.  But if you want to backport it, feel free.

Ok, done.

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  2014-10-23  6:14                                         ` Tassilo Horn
  2014-10-23 12:01                                           ` Stefan Monnier
@ 2014-10-24  6:04                                           ` Pierre Lorenzon
  2014-10-24  6:36                                             ` Tassilo Horn
  1 sibling, 1 reply; 36+ messages in thread
From: Pierre Lorenzon @ 2014-10-24  6:04 UTC (permalink / raw)
  To: tsdh; +Cc: help-gnu-emacs, monnier

From: Tassilo Horn <tsdh@gnu.org>
Subject: Re: DocView: process ps->pdf changed status to killed.
Date: Thu, 23 Oct 2014 08:14:09 +0200

> Pierre Lorenzon <devel@pollock-nageoire.net> writes:
> 
> Hi Pierre,
> 
>> Thanks to take care of this problem ! As you saw I have no time
>> at the moment to think about this question but I'd be verry
>> happy that this doc-view works ! So thanks again and I'll wait
>> until you have fix it !
> 
> It's already fixed in the bzr trunk meaning it'll be in Emacs 25
> (whenever that will be released).

  So thanks again !

  Pierre



> 
> Stefan, should I backport the patch also to the emacs-24 branch?
> 
> Bye,
> Tassilo



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  2014-10-24  6:04                                           ` Pierre Lorenzon
@ 2014-10-24  6:36                                             ` Tassilo Horn
  2014-10-24  9:10                                               ` Pierre Lorenzon
  0 siblings, 1 reply; 36+ messages in thread
From: Tassilo Horn @ 2014-10-24  6:36 UTC (permalink / raw)
  To: Pierre Lorenzon; +Cc: help-gnu-emacs

Pierre Lorenzon <devel@pollock-nageoire.net> writes:

Hi Pierre,

>> It's already fixed in the bzr trunk meaning it'll be in Emacs 25
>> (whenever that will be released).
>
>   So thanks again !

You're welcome.  I've also backported it to the emacs-24 branch, so
it'll also be in a possible Emacs 24.5 release.

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  2014-10-24  6:36                                             ` Tassilo Horn
@ 2014-10-24  9:10                                               ` Pierre Lorenzon
  2014-10-24  9:24                                                 ` Pierre Lorenzon
  0 siblings, 1 reply; 36+ messages in thread
From: Pierre Lorenzon @ 2014-10-24  9:10 UTC (permalink / raw)
  To: tsdh; +Cc: help-gnu-emacs


Hi Tassilo,

I downloaded compiled and install the bzr trunk version that is
25.0.50 and in which doc-view seems to work perfectly.


The only thing I yet do not understand is why my .emacs is not
loaded ... If someone has any idea please telle me. Maybe
should the .emacs with this new version no longer be placed in
the home directly or something like that ....


Pierre




From: Tassilo Horn <tsdh@gnu.org>
Subject: Re: DocView: process ps->pdf changed status to killed.
Date: Fri, 24 Oct 2014 08:36:59 +0200

> Pierre Lorenzon <devel@pollock-nageoire.net> writes:
> 
> Hi Pierre,
> 
>>> It's already fixed in the bzr trunk meaning it'll be in Emacs 25
>>> (whenever that will be released).
>>
>>   So thanks again !
> 
> You're welcome.  I've also backported it to the emacs-24 branch, so
> it'll also be in a possible Emacs 24.5 release.
> 
> Bye,
> Tassilo



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  2014-10-24  9:10                                               ` Pierre Lorenzon
@ 2014-10-24  9:24                                                 ` Pierre Lorenzon
  2014-10-24 10:26                                                   ` Tassilo Horn
  0 siblings, 1 reply; 36+ messages in thread
From: Pierre Lorenzon @ 2014-10-24  9:24 UTC (permalink / raw)
  To: tsdh; +Cc: help-gnu-emacs


Oops sorry ! The fact is not that the .emacs file is not loaded
but that it causes an error ... Something probably not
compatible with the new version .... I'll debug that !

Pierre




From: Pierre Lorenzon <devel@pollock-nageoire.net>
Subject: Re: DocView: process ps->pdf changed status to killed.
Date: Fri, 24 Oct 2014 11:10:25 +0200 (CEST)

> 
> Hi Tassilo,
> 
> I downloaded compiled and install the bzr trunk version that is
> 25.0.50 and in which doc-view seems to work perfectly.
> 
> 
> The only thing I yet do not understand is why my .emacs is not
> loaded ... If someone has any idea please telle me. Maybe
> should the .emacs with this new version no longer be placed in
> the home directly or something like that ....
> 
> 
> Pierre
> 
> 
> 
> 
> From: Tassilo Horn <tsdh@gnu.org>
> Subject: Re: DocView: process ps->pdf changed status to killed.
> Date: Fri, 24 Oct 2014 08:36:59 +0200
> 
>> Pierre Lorenzon <devel@pollock-nageoire.net> writes:
>> 
>> Hi Pierre,
>> 
>>>> It's already fixed in the bzr trunk meaning it'll be in Emacs 25
>>>> (whenever that will be released).
>>>
>>>   So thanks again !
>> 
>> You're welcome.  I've also backported it to the emacs-24 branch, so
>> it'll also be in a possible Emacs 24.5 release.
>> 
>> Bye,
>> Tassilo
> 



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: DocView: process ps->pdf changed status to killed.
  2014-10-24  9:24                                                 ` Pierre Lorenzon
@ 2014-10-24 10:26                                                   ` Tassilo Horn
  0 siblings, 0 replies; 36+ messages in thread
From: Tassilo Horn @ 2014-10-24 10:26 UTC (permalink / raw)
  To: Pierre Lorenzon; +Cc: help-gnu-emacs

Pierre Lorenzon <devel@pollock-nageoire.net> writes:

> Oops sorry ! The fact is not that the .emacs file is not loaded
> but that it causes an error ... Something probably not
> compatible with the new version .... I'll debug that !

To do so, start emacs like "emacs --debug-init".

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2014-10-24 10:26 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).