bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#33043: [PATCH v1 1/1] Support for the truncation of displayed URLs


From: Basil L. Contovounesios
Subject: bug#33043: [PATCH v1 1/1] Support for the truncation of displayed URLs
Date: Wed, 17 Oct 2018 23:27:45 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Thanks for working on this David, I like the idea.

David Edmondson <dme@dme.org> writes:

> @@ -2491,6 +2498,16 @@ rcirc-markup-urls
>             (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))))
>        ;; 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.

Couldn't we reuse url-truncate-url-for-viewing, which tries to be smart
about where it places the ellipsis, for this?  I think the existing code
can also be cleaned up a little:

diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el
index fe9c71a21c..de28cdb054 100644
--- a/lisp/net/rcirc.el
+++ b/lisp/net/rcirc.el
@@ -2485,24 +2485,25 @@ 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))
+    (let* ((beg (match-beginning 0))
            (end (match-end 0))
-           (url (match-string-no-properties 0))
-           (link-text (buffer-substring-no-properties start end)))
-      ;; 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
-                       '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)))))
+           (url (buffer-substring-no-properties beg end)))
+      (delete-region beg end)
+      ;; Add a button for the URL.  Note that we use
+      ;; `insert-text-button', rather than `insert-button', as text
+      ;; property buttons are much faster in large buffers.
+      (insert-text-button
+       (url-truncate-url-for-viewing url rcirc-url-max-length)
+       '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.
+      (unless (string= url (caar rcirc-urls))
+        (push (cons url beg) rcirc-urls)))))
 
 (defun rcirc-markup-keywords (sender response)
   (when (and (string= response "PRIVMSG")
WDYT?

-- 
Basil

reply via email to

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