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

Re: w3m-content-type-alist default text/html handler




Thanks.  Ok, back to good old "while" then :)

--- w3m/w3m.el  2011-01-29 13:06:14.000000000 +0100
+++ modified-w3m/w3m.el 2011-01-31 21:16:29.287689195 +0100
@@ -1116,21 +1116,33 @@ (defcustom w3m-content-type-alist
          (if (and (eq system-type 'windows-nt) (w3m-which-command "fiber"))
              'w3m-w32-browser-with-fiber
            (or (when (condition-case nil (require 'browse-url) (error nil))
-                 (if (or (not (boundp 'browse-url-browser-function))
-                         (eq 'w3m-browse-url
-                             (symbol-value 'browse-url-browser-function)))
-                     (cond
-                      ((and (memq system-type '(windows-nt ms-dos cygwin))
-                            (fboundp 'browse-url-default-windows-browser))
-                       'browse-url-default-windows-browser)
-                      ((and (memq system-type '(darwin))
-                            (fboundp 'browse-url-default-macosx-browser))
-                       'browse-url-default-macosx-browser)
-                      ((fboundp 'browse-url-default-browser)
-                       'browse-url-default-browser)
-                      ((fboundp 'browse-url-netscape)
-                       'browse-url-netscape))
-                   (symbol-value 'browse-url-browser-function)))
+                  (let ((default (cond
+                                  ((and (memq system-type '(windows-nt ms-dos cygwin))
+                                        (fboundp 'browse-url-default-windows-browser))
+                                   'browse-url-default-windows-browser)
+                                  ((and (memq system-type '(darwin))
+                                        (fboundp 'browse-url-default-macosx-browser))
+                                   'browse-url-default-macosx-browser)
+                                  ((fboundp 'browse-url-default-browser)
+                                   'browse-url-default-browser)
+                                  ((fboundp 'browse-url-netscape)
+                                   'browse-url-netscape))))
+                    (if (or (not (boundp 'browse-url-browser-function))
+                            (eq 'w3m-browse-url
+                                (symbol-value 'browse-url-browser-function)))
+                        default
+                      (if (symbolp browse-url-browser-function)
+                          (symbol-value 'browse-url-browser-function)
+                        (catch 'browser
+                          (let ((alist browse-url-browser-function))
+                            (while alist
+                              (when (string-match (caar alist) "index.html")
+                                (throw 'browser (cdar alist)))
+                              (setq alist (cdr alist)))
+                            (warn (concat "Found no html handler in "
+                                          "browse-url-browser-function "
+                                          "to put in w3m-content-type-alist."))
+                            default))))))
                (when (w3m-which-command "netscape")
                  (list "netscape" 'url)))))
         (image-viewer (or fiber-viewer


A suggestion for ChangeLog entry:

2011-01-31  Johan Claesson  <johanclaesson@xxxxxxxxxxxx>

	* w3m.el (w3m-content-type-alist): When selecting which
	external html browser to use, handle the case where
	browse-url-browser-function is an alist.


And the context:

(defcustom w3m-content-type-alist
  (let* ((fiber-viewer (when (and (eq system-type 'windows-nt)
				  (w3m-which-command "fiber"))
			 (list "fiber.exe" "-s" 'file)))
	 (external-browser
	  (if (and (eq system-type 'windows-nt) (w3m-which-command "fiber"))
	      'w3m-w32-browser-with-fiber
	    (or (when (condition-case nil (require 'browse-url) (error nil))
                  (let ((default (cond
                                  ((and (memq system-type '(windows-nt ms-dos cygwin))
                                        (fboundp 'browse-url-default-windows-browser))
                                   'browse-url-default-windows-browser)
                                  ((and (memq system-type '(darwin))
                                        (fboundp 'browse-url-default-macosx-browser))
                                   'browse-url-default-macosx-browser)
                                  ((fboundp 'browse-url-default-browser)
                                   'browse-url-default-browser)
                                  ((fboundp 'browse-url-netscape)
                                   'browse-url-netscape))))
                    (if (or (not (boundp 'browse-url-browser-function))
                            (eq 'w3m-browse-url
                                (symbol-value 'browse-url-browser-function)))
                        default
                      (if (symbolp browse-url-browser-function)
                          (symbol-value 'browse-url-browser-function)
                        (catch 'browser
                          (let ((alist browse-url-browser-function))
                            (while alist
                              (when (string-match (caar alist) "index.html")
                                (throw 'browser (cdar alist)))
                              (setq alist (cdr alist)))
                            (warn (concat "Found no html handler in "
                                          "browse-url-browser-function "
                                          "to put in w3m-content-type-alist."))
                            default))))))
		(when (w3m-which-command "netscape")
		  (list "netscape" 'url)))))
	 (image-viewer (or fiber-viewer
			   (when w3m-image-viewer
			     (list w3m-image-viewer 'file))))
	 (video-viewer (or fiber-viewer
			   (when (w3m-which-command "mpeg_play")
			     (list "mpeg_play" 'file))))
	 (dvi-viewer (or fiber-viewer
			 (cond ((w3m-which-command "xdvi") (list "xdvi" 'file))
			       ((w3m-which-command "dvitty")
				(list "dvitty" 'file)))))
	 (ps-viewer (or fiber-viewer
			(cond
			 ((w3m-which-command "gv") (list "gv" 'file))
			 ((w3m-which-command "gs") (list "gs" 'file)))))
	 (pdf-viewer (or fiber-viewer
			 (cond
			  ((w3m-which-command "xpdf") (list "xpdf" 'file))
			  ((w3m-which-command "acroread")
			   (list "acroread" 'file))))))
    `(("text/plain" "\\.\\(?:txt\\|tex\\|el\\)\\'" nil nil)
      ("text/html" "\\.s?html?\\'" ,external-browser nil)
      ("text/sgml" "\\.sgml?\\'" nil "text/plain")
      ("text/xml" "\\.xml\\'" nil "text/plain")
      ("image/jpeg" "\\.jpe?g\\'" ,image-viewer nil)
      ("image/png" "\\.png\\'" ,image-viewer nil)
      ("image/gif" "\\.gif\\'" ,image-viewer nil)
      ("image/tiff" "\\.tif?f\\'" ,image-viewer nil)
      ("image/x-xwd" "\\.xwd\\'" ,image-viewer nil)
      ("image/x-xbm" "\\.xbm\\'" ,image-viewer nil)
      ("image/x-xpm" "\\.xpm\\'" ,image-viewer nil)
      ("image/x-bmp" "\\.bmp\\'" ,image-viewer nil)
      ("video/mpeg" "\\.mpe?g\\'" ,video-viewer nil)
      ("video/quicktime" "\\.mov\\'" ,video-viewer nil)
      ("application/dvi" "\\.dvi\\'" ,dvi-viewer nil)
      ("application/postscript" "\\.e?ps\\'" ,ps-viewer nil)
      ("application/pdf" "\\.pdf\\'" ,pdf-viewer nil)
      ("application/x-pdf" "\\.pdf\\'" ,pdf-viewer nil)
      ("application/xml" "\\.xml\\'" nil w3m-detect-xml-type)
      ("application/rdf+xml" "\\.rdf\\'" nil "text/plain")
      ("application/rss+xml" "\\.rss\\'" nil "text/plain")
      ("application/xhtml+xml" nil nil "text/html")))
  "*Alist of content types, regexps, commands to view, and filters.
Each element is a list which consists of the following data:

1. Content type.

2. Regexp matching a url or a file name.

3. Method to view contents.  The following three types may be used:
   a. Lisp function which takes the url to view as an argument.
   b. (\"COMMAND\" [ARG...]) -- where \"COMMAND\" is the external command
      and ARG's are the arguments passed to the command if any.  The
      symbols `file' and `url' that appear in ARG's will be replaced
      respectively with the name of a temporary file which contains
      the contents and the string of the url to view.
   c. nil which means to download the url into the local file.

4. Content type that overrides the one specified by `1. Content type'.
   Valid values include:
   a. Lisp function that takes three arguments URL, CONTENT-TYPE, and
      CHARSET, and returns a content type.
   b. String that specifies a content type.
   c. nil that means not to override the content type."
  :group 'w3m
  :type '(repeat
	  (group
	   :indent 2
	   (string :format "Type: %v\n" :size 0)
	   (radio :format "%{Regexp%}: %v" :extra-offset 8
		  :sample-face underline
		  (const :tag "Not specified" nil)
		  (regexp :format "String: %v\n" :size 0))
	   (radio :format "%{Viewer%}: %v" :extra-offset 8
		  :sample-face underline
		  (const :tag "Not specified" nil)
		  (cons :tag "External viewer" :extra-offset 2
			(string :format "Command: %v\n" :size 0)
			(repeat :format "Arguments:\n%v%i\n" :extra-offset 2
				(restricted-sexp
				 :format "%v\n"
				 :match-alternatives (stringp 'file 'url)
				 :size 0)))
		  (function :format "%t: %v\n" :size 0))
	   (radio :format "%{Filter%}: %v" :extra-offset 8
		  :sample-face underline
		  (const :tag "Not specified" nil)
		  (string :format "Equivalent type: %v\n" :size 0)
		  (function :format "Function: %v\n" :size 0)))))

Regards,

/Johan

Katsumi Yamaoka <yamaoka@xxxxxxx> writes:

> Johan Claesson <johanclaesson@xxxxxxxxxxxx> wrote:
>> Hi,
>
>> The default value for text/html handler in the w3m-content-type-alist
>> is based among other things on the variable
>> browse-url-browser-function.  It works as expected when
>> browse-url-browser-function is set to a symbol like
>> browse-url-firefox.  But this variable can also have a alist value,
>> for example like this:
>
>> (setq browse-url-browser-function '(("^mailto:"; . browse-url-mail)
>>      				    ("." . browse-url-firefox)))
>
>> In this case the text/html handler will not get a appropriate value.
>> This will make the command w3m-view-url-with-external-browser (bound
>> to M) download the webpage instead of browsing it in a external
>> browser.
>
>> The following patch of w3m.el attempts to remedy this.  It will walk
>> through the alist and select whatever entry that matches the url
>> index.html.
>
> Thanks!  Could you eliminate a cl macro in it?  Normally the use
> of cl macros is ok, but they have to be expanded at the compile
> time since emacs-w3m never uses cl at run-time, like the rest.
> However, macros will not be expanded in defcustom forms, except
> for the recent XEmacs 21.5.  So, an alist value for
> `browse-url-browser-function' will cause the `(void-function loop)'
> error.
>
> In addition, please provide a chengelog entry by yourself.
>
> Regards,