emacs-devel
[Top][All Lists]
Advanced

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

extract URLs from an emacs (especially gnus) buffer


From: Sam Steingold
Subject: extract URLs from an emacs (especially gnus) buffer
Date: Thu, 20 Feb 2014 16:18:40 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (darwin)

Hi,
How do I extract all URLs from an emacs buffer?
(I am especially interested in gnus *Article* buffers).
E.g., the slashdot articles contain _buttons_, not actual urls, so what
I need to do is:

--8<---------------cut here---------------start------------->8---
    (let ((urls ()) (pos (point-min)))
      (while (setq pos (next-single-property-change pos 'follow-link))
        (push (get-char-property pos 'shr-url) urls)
        (setq pos (next-single-property-change pos 'follow-link)))
       urls)
--8<---------------cut here---------------end--------------->8---

On the other hand, raw URLs in other articles (e.g., in this group) have
to be collected by

--8<---------------cut here---------------start------------->8---
    (let ((urls ()) (pos (point-min)))
      (while (setq pos (next-single-property-change pos 'button))
        (let ((widget (get-char-property pos 'button)))
          (push (buffer-substring-no-properties
                  (widget-get widget :from)
                  (widget-get widget :to))
                urls))
        (setq pos (next-single-property-change pos 'button)))
      urls)
--8<---------------cut here---------------end--------------->8---

Maybe there are other ways for other modes?

So, how do I automate the following algorithm in elisp:

1. (goto-char (point-min))
2. until eobp
3.  find next clickable area
4.  if the click target is a url, click on it

Thanks.

-- 
Sam Steingold (http://sds.podval.org/) on darwin Ns 10.3.1265
http://www.childpsy.net/ http://truepeace.org http://iris.org.il
http://palestinefacts.org http://memri.org http://ffii.org
Nothing is as important as you think it is when you are thinking about it.




reply via email to

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