GNU bug report logs - #33043
27.0.50; wishlist: rcirc should allow truncation of visible URLs

Previous Next

Package: emacs;

Reported by: David Edmondson <dme <at> dme.org>

Date: Mon, 15 Oct 2018 10:05:02 UTC

Severity: wishlist

Tags: patch

Found in version 27.0.50

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: "Basil L. Contovounesios" <contovob <at> tcd.ie>
To: David Edmondson <dme <at> dme.org>
Cc: 33043 <at> debbugs.gnu.org
Subject: bug#33043: [PATCH v1 1/1] Support for the truncation of displayed URLs
Date: Thu, 18 Oct 2018 11:38:04 +0100
[Message part 1 (text/plain, inline)]
David Edmondson <dme <at> dme.org> writes:

> On Wednesday, 2018-10-17 at 23:27:45 +01, Basil L. Contovounesios wrote:
>
>> 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:
>
> I didn't know about url-truncate-url-for-viewing, no other reason.
>
> I'd be happy with your change, but note that it will always truncate
> URLs that are wider than the current frame - there is no way to have no
> truncation take place.
>
> If a user is most familiar with something like ffap to open URLs then
> this is unfortunate - ffap doesn't see the full URL in the buffer.

Sorry, that was an oversight.  Here's how the last patch can be patched
to support the default of no truncation:

[rcirc.diff (text/x-diff, inline)]
diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el
index de28cdb054..31f0baddc0 100644
--- a/lisp/net/rcirc.el
+++ b/lisp/net/rcirc.el
@@ -2495,7 +2495,9 @@ rcirc-markup-urls
       ;; `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)
+       (if rcirc-url-max-length
+           (url-truncate-url-for-viewing url rcirc-url-max-length)
+         url)
        'face 'rcirc-url
        'follow-link t
        'rcirc-url url
[Message part 3 (text/plain, inline)]
If you prefer to avoid deletion and insertion when rcirc-url-max-length
is nil, you can also write the following:

[rcirc-alt.diff (text/x-diff, inline)]
diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el
index fe9c71a21c..4d62b382a6 100644
--- a/lisp/net/rcirc.el
+++ b/lisp/net/rcirc.el
@@ -2485,24 +2485,27 @@ 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)))
+           (url (buffer-substring-no-properties beg end)))
+      (when rcirc-url-max-length
+        (replace-match (url-truncate-url-for-viewing url rcirc-url-max-length)
+                       t t)
+        (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.
-      (make-text-button start end
+      (make-text-button beg 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)))))
+      ;; 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")
[Message part 5 (text/plain, inline)]
Thanks,

-- 
Basil

This bug report was last modified 6 years and 197 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.