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

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

Re: How to shorten urls displayed in text version of mail in Gnus


From: Christian Barthel
Subject: Re: How to shorten urls displayed in text version of mail in Gnus
Date: Sat, 23 May 2020 19:39:38 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (berkeley-unix)

Narendra Joshi <narendraj9@gmail.com> 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 <bch@online.de>



reply via email to

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