info-gnus-english
[Top][All Lists]
Advanced

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

Re: Can emacs-w3m open links in browser


From: David Hanak
Subject: Re: Can emacs-w3m open links in browser
Date: Tue, 21 Sep 2004 11:15:27 -0500
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3.50 (windows-nt)

On Mon, 20 Sep 2004, Thamer Mahmoud wrote:

> Just today, I've started using w3m and I'm having a similar problem. I
> want to open all link and image *buttons* rendered by w3m in Firefox.
> I've tried your solution, but for some reason, the w3m-url-at-point
> only works for URL's (i.e http://...) and returns nil for the buttons
> rendered in w3m.

Yes, obviously w3m-url-at-point doesn't return image names and references.

> (require 'w3m)
> (eval-after-load "w3m"
>   '(progn
>      (defun w3m-safe-view-this-url ()
>        (interactive)
>        (if (not (setq url (w3m-url-valid (w3m-anchor))))
>          (setq url (w3m-url-valid (w3m-image))))
>        (if url
>          (browse-url url)
>        (message "No URL at point")))))

Yes, you can do this, but I try to avoid overriding function
definitions unless really necessary.  So I upgraded my function, now it
is capable of displaying both URLs and images in an external browser,
what's more, it can also display cid: images (used by Outlook) in an
external image browser (just in case Emacs can't display them, i.e.,
bmp files under Windows).  Here goes:

(defun my-w3m-browse-url-at-point ()
  (interactive)
  (let ((url (w3m-anchor))
        (img (w3m-image)))
    (cond
     ((w3m-url-valid url)
      (browse-url url))
     ((string-match "\\`cid:" img)
      (catch 'found-handle
        (my-w3m-view-cid-image (concat "<" (substring img (match-end 0)) ">")
                               (with-current-buffer gnus-article-buffer
                                 gnus-article-mime-handles))))
     ((w3m-url-valid img)
      (browse-url img))
     (t
      (message "No URL or image under point.")))))

(defun my-w3m-view-cid-image (img handle)
  (if (mm-multiple-handles handle)
      (dolist (elem handle)
        (my-w3m-view-cid-image img elem))
    (when (and (listp handle)
               (equal img (mm-handle-id handle)))
      (throw 'found-handle (mm-display-part handle)))))

Great!  Now I can view cid: attachments, too!

-- 
David Hanak - Research Engineer
Institute for Software Integrated Systems  |  http://www.isis.vanderbilt.edu
Vanderbilt University                      |      Work phone: (615) 343 1319
Box 1829, Station B, Nashville, TN 37235   |            PGP key ID: 266BC45F

reply via email to

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