Narendra Joshi <[email protected]> writes:

> A lot of mail happens to have very long URLs that I would like to
> shorten while displaying them in the Article buffer. It would be great
> if there is something in Gnus that does this already. Is there any
> function to wash the article buffer and shorten the text displayed for
> URL present in it?

Here are two functions that replace long URLs with the string
"URL" and make them clickable (<ENTER>):

(defun gnus-buttonize-and-shorten ()
  (interactive)
  (progn
    (goto-char (point-min))
    (while (re-search-forward
            "\\(https*://[-~_a-zA-Z0-9][-~_\\.a-zA-Z0-9/]*\\)"
            (point-max) t)
      (let* ((start (match-beginning 0))
             (end (match-end 0)))
        (message "%d %d" start end)
        (goto-char start)
        (let ((thisurl (thing-at-point 'url)))
          (kill-region start end)
          (insert-text-button "URL"
                'url thisurl
                'action (lambda (btn)
                  (browse-url (button-get btn 'url)))
                ))
        (goto-char (+ start 1))))))

(defun gnus-wash-long-urls ()
  (interactive "")
  (gnus-summary-select-article)
  (gnus-eval-in-buffer-window gnus-article-buffer
    (let ((inhibit-read-only t))
      (save-excursion
        (save-restriction
        (gnus-buttonize-and-shorten))))
  (gnus-treat-article nil)))

A better approach would be to use the button mechanism of Gnus
and set the text to something different.  But I did not find [1]
any option to set the button text.

[1] 
https://www.gnu.org/software/emacs/manual/html_node/gnus/Article-Buttons.html
-- 
Christian Barthel <[email protected]>

_______________________________________________
info-gnus-english mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/info-gnus-english

Reply via email to