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

Re: opening local files with arbitrary extensions as HTML



>>>>> In [emacs-w3m : No.09547] Shinichiro HIDA wrote:

>>>>>> In [emacs-w3m : No.09546]
>>>>>>	"Eduardo Ochs" <eduardoochs@xxxxxxxxx> wrote:

>> what is the recommended way to force w3m to open a local file as HTML?
>> Here's an example: the first call to w3m below works, but the second
>> one treats the local file as plain text and does not invoke w3m to
>> render it as HTML...

>>  (let ((w3m-async-exec nil))
>>    (w3m "file:///usr/share/doc/galeon-common/FAQ.html"))

>>  (let ((w3m-async-exec nil))
>>    (w3m "file:///usr/share/doc/apache2-doc/manual/howto/cgi.html.en"))

> If your apache working, it might be better to access to
> http://localhost/doc/apache2-doc/manual/howto/index.html.en

> ;; On debian, I'm using this way.

I use neither Debian nor Apache, but the problem is that we don't
have a means to detect the content type of a local file other than
checking a file name extension, isn't it?  If you have the version
of the `file' command that returns a content type of a file
regardless of a file name extension, i.e.,

$ file /usr/share/doc/apache2-doc/manual/howto/cgi.html.en
/usr/share/doc/apache2-doc/manual/howto/cgi.html.en: text/html

, how about using of this?

--8<---------------cut here---------------start------------->8---
(defadvice w3m-goto-url (around open-local-html-file activate)
  "Open a local html file regardless of a file name extension."
  (let ((w3m-local-find-file-function
	 (lambda (file)
	   (if (with-temp-buffer
		 (call-process "file" nil t nil "-i" file)
		 (goto-char (point-min))
		 (re-search-forward
		  (concat "^" (regexp-quote file) ": text/html[\n;]")
		  nil t))
	       (let ((wcp (symbol-function 'w3m-create-page)))
		 (setq w3m-local-find-file-function nil)
		 (fset 'w3m-create-page
		       (lambda (url type charset page-buffer)
			 (funcall wcp url "text/html" charset page-buffer)))
		 (unwind-protect
		     ad-do-it
		   (fset 'w3m-create-page wcp)))
	     (if (w3m-popup-frame-p)
		 (find-file-other-frame file)
	       (find-file-other-window file))))))
    ad-do-it))
--8<---------------cut here---------------end--------------->8---

I'd like to install a similar code to the emacs-w3m CVS trunk.