From 8d7f03b12ccb07cd9ffe953b99d519e289b61df9 Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" Date: Sun, 28 Oct 2018 02:51:18 +0000 Subject: [PATCH 2/2] Reuse URL truncation function in rcirc (bug#33043) * lisp/net/rcirc.el (rcirc-markup-urls): Simplify using url-truncate-url-for-viewing. --- lisp/net/rcirc.el | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el index 50e4d8ffb2..ca707341be 100644 --- a/lisp/net/rcirc.el +++ b/lisp/net/rcirc.el @@ -2493,34 +2493,26 @@ rcirc-markup-my-nick (rcirc-record-activity (current-buffer) 'nick))))) (defun rcirc-markup-urls (_sender _response) - (while (and rcirc-url-regexp ;; nil means disable URL catching + (while (and rcirc-url-regexp ; nil means disable URL catching. (re-search-forward rcirc-url-regexp nil t)) (let* ((start (match-beginning 0)) - (end (match-end 0)) - (url (match-string-no-properties 0)) - (link-text (buffer-substring-no-properties start end))) - ;; Truncate the visible part of URLs if required and necessary. - (when (and rcirc-url-max-length - (> (- end start) rcirc-url-max-length)) - (let* ((ellipsis "...") - (new-end (- (+ start rcirc-url-max-length) - (length ellipsis)))) - (delete-region new-end end) - (goto-char new-end) - (insert ellipsis) - (setq end (point)))) + (url (buffer-substring-no-properties start (point)))) + (when rcirc-url-max-length + ;; Replace match with truncated URL. + (delete-region start (point)) + (insert (url-truncate-url-for-viewing url rcirc-url-max-length))) ;; Add a button for the URL. Note that we use `make-text-button', ;; rather than `make-button', as text-buttons are much faster in ;; large buffers. - (make-text-button start end + (make-text-button start (point) 'face 'rcirc-url 'follow-link t 'rcirc-url url 'action (lambda (button) (browse-url (button-get button 'rcirc-url)))) - ;; record the url if it is not already the latest stored url - (when (not (string= link-text (caar rcirc-urls))) - (push (cons link-text start) rcirc-urls))))) + ;; Record the URL if it is not already the latest stored URL. + (unless (string= url (caar rcirc-urls)) + (push (cons url start) rcirc-urls))))) (defun rcirc-markup-keywords (sender response) (when (and (string= response "PRIVMSG") -- 2.19.1