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

Re: View PDF, PS within emacs



>>>>> In [emacs-w3m : No.10033] David Hansen wrote:

>> I guess we need a Lisp function that downloads the contents into a
>> local file and performs `find-file' on it if `auto-mode-alist'
>> contains the `doc-view-mode' element.

> Ah, OK, I naively thought we just put the file content in a buffer and
> then run the `doc-view-mode' command, but it seems that doc-view
> requires an existing file.

It might be better to implement `doc-view-buffer' in the Emacs
trunk first. ;-)

>> But it might be somewhat troublesome to make emacs-w3m work for a Lisp
>> function (not an external command) which is specified in
>> `w3m-content-type-alist'.

> I think there already is one entry that calls a lisp function (one of
> the browse-url functions for `w3m-view-url-with-external-browser').

I see.  But the functions in `w3m-content-type-alist' might not
be for the internal display.  Instead, now I think modifying
`w3m-goto-url' (as well as it handles ftp, local files, etc.) is
reasonable.  Tsuchiya-san might dislike it, though.

I tried a quick hack.  It works, however it has to be much improved.
--- w3m.el~	2008-02-20 08:08:23 +0000
+++ w3m.el	2008-02-26 10:59:17 +0000
@@ -8246,6 +8246,30 @@
 	 (string-match "\\`ftps?://" url)
 	 (not (string= "text/html" (w3m-local-content-type url))))
     (w3m-goto-ftp-url url))
+   ;; use `doc-view-mode'
+   ((let ((suffix (car (rassq 'doc-view-mode auto-mode-alist)))
+	  temp-file
+	  ;!!! This section should work asynchronously.
+	  w3m-async-exec)
+      (and
+       ;!!! This variable should be implemented as a user option.
+       ;; w3m-use-doc-view-mode
+       suffix
+       (string-match suffix url)
+       (w3m-download
+	url
+	(setq temp-file
+	      (concat (make-temp-name
+		       (expand-file-name "w3mel" w3m-profile-directory))
+		      (match-string 0 url))))
+       (progn
+	 (find-file temp-file)
+	 (while (and doc-view-current-converter-process
+		     (memq (process-status doc-view-current-converter-process)
+			   '(open run)))
+	   (sleep-for 0.1))
+	 (delete-file temp-file)
+	 t))))
    ;; find-file directly
    ((condition-case nil
 	(and (w3m-url-local-p url)