开发者

Is there a urlview (a la mutt) for gnus? Or just elisp for extracting urls?

I switched from mutt to gn开发者_运维知识库us and would like to extract urls from emails and be able to launch a new buffer that contains all urls in a given email. Urlview does this for mutt as a frame of reference for what I am looking for.


I wrote the following and tested it to work on a couple of articles. Maybe it will be a good starting point for you.

(defun gnus-article-extract-url-into-buffer ()
  (interactive)
  (let ((simple-url-regexp "https?://")
        urls)
    (save-excursion
    ;; collect text URLs
        (while (search-forward-regexp simple-url-regexp nil t)
          (when-let (url (thing-at-point 'url))
            (setq urls (cons url urls))))
        (beginning-of-buffer)
    ;; collect widget URLs
        (while (not (eobp)) 
          (goto-char (next-overlay-change (point)))
          (when-let (link (get-text-property (point) 'gnus-string))
            (and (string-match simple-url-regexp link)
                 (setq urls (cons link urls))))
          (goto-char (next-overlay-change (point)))))
    (when urls
      (switch-to-buffer-other-window "*gnus-article-urls*")
      (dolist (url urls)
        (insert url))
      (beginning-of-buffer))))

I should clarify that this is intended to be run from within the article buffer. Also, I may have missed the point by taking what you said literally about launching a new buffer containing the urls, in which case you can change the last form to:

(when urls
  (dolist (url urls)
    (browse-url url)))

Or, Tyler's approach is simpler if you don't need to parse widget urls.


I don't think that function is built-in. The following code will do what you want. From the summary buffer, call M-x urlview, or bind it to a convenient key. The save-excursion wrapper should drop you back in the summary buffer, but for some reason it leaves you in the article buffer. Just hitting the h key will put you back, but you shouldn't need to do that. Maybe someone else can clarify that part?

(defun urlview ()
  (interactive)
  (save-excursion
    (gnus-summary-select-article-buffer)
    (beginning-of-buffer)
    (while
    (re-search-forward "https?://" nil t)
      (browse-url-at-point))))

Edit: Joseph's answer works for both http and https, which I had overlooked. So I swiped that part of his code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜