aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Edmondson2018-10-28 03:11:21 +0000
committerEli Zaretskii2018-11-03 11:08:06 +0200
commit4a344bcab50e688db76c9e123fb7725796cb260b (patch)
treefec33b96340f42b239b63b79bdef2d0be27aa49e
parent484b99a1a83f5e56c917a20de1d46ba1110d5ca2 (diff)
downloademacs-4a344bcab50e688db76c9e123fb7725796cb260b.tar.gz
emacs-4a344bcab50e688db76c9e123fb7725796cb260b.zip
Add URL truncation support to rcirc (bug#33043)
Suggested by David Edmondson <dme@dme.org>. * lisp/net/rcirc.el (rcirc-url-max-length): New user option controlling extent of URL truncation, defaulting to none. (rcirc-markup-urls): Use it. * etc/NEWS: Announce it.
-rw-r--r--etc/NEWS7
-rw-r--r--lisp/net/rcirc.el26
2 files changed, 25 insertions, 8 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 51e3da07d47..1020a2a0ea5 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -775,6 +775,13 @@ Tramp for some look-alike remote file names.
775*** For some connection methods, like "su" or "sudo", the host name in 775*** For some connection methods, like "su" or "sudo", the host name in
776ad-hoc multi-hop file names must match the previous hop. 776ad-hoc multi-hop file names must match the previous hop.
777 777
778** Rcirc
779
780---
781*** New user option 'rcirc-url-max-length'.
782Setting this option to an integer causes URLs displayed in Rcirc
783buffers to be truncated to that many characters.
784
778** Register 785** Register
779--- 786---
780*** The return value of method 'register-val-describe' includes the 787*** The return value of method 'register-val-describe' includes the
diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el
index fe9c71a21c2..ca707341be4 100644
--- a/lisp/net/rcirc.el
+++ b/lisp/net/rcirc.el
@@ -168,6 +168,14 @@ underneath each nick."
168 (string :tag "Prefix text")) 168 (string :tag "Prefix text"))
169 :group 'rcirc) 169 :group 'rcirc)
170 170
171(defcustom rcirc-url-max-length nil
172 "Maximum number of characters in displayed URLs.
173If nil, no maximum is applied."
174 :version "27.1"
175 :type '(choice (const :tag "No maximum" nil)
176 (integer :tag "Number of characters"))
177 :group 'rcirc)
178
171(defvar rcirc-ignore-buffer-activity-flag nil 179(defvar rcirc-ignore-buffer-activity-flag nil
172 "If non-nil, ignore activity in this buffer.") 180 "If non-nil, ignore activity in this buffer.")
173(make-variable-buffer-local 'rcirc-ignore-buffer-activity-flag) 181(make-variable-buffer-local 'rcirc-ignore-buffer-activity-flag)
@@ -2485,24 +2493,26 @@ If ARG is given, opens the URL in a new browser window."
2485 (rcirc-record-activity (current-buffer) 'nick))))) 2493 (rcirc-record-activity (current-buffer) 'nick)))))
2486 2494
2487(defun rcirc-markup-urls (_sender _response) 2495(defun rcirc-markup-urls (_sender _response)
2488 (while (and rcirc-url-regexp ;; nil means disable URL catching 2496 (while (and rcirc-url-regexp ; nil means disable URL catching.
2489 (re-search-forward rcirc-url-regexp nil t)) 2497 (re-search-forward rcirc-url-regexp nil t))
2490 (let* ((start (match-beginning 0)) 2498 (let* ((start (match-beginning 0))
2491 (end (match-end 0)) 2499 (url (buffer-substring-no-properties start (point))))
2492 (url (match-string-no-properties 0)) 2500 (when rcirc-url-max-length
2493 (link-text (buffer-substring-no-properties start end))) 2501 ;; Replace match with truncated URL.
2502 (delete-region start (point))
2503 (insert (url-truncate-url-for-viewing url rcirc-url-max-length)))
2494 ;; Add a button for the URL. Note that we use `make-text-button', 2504 ;; Add a button for the URL. Note that we use `make-text-button',
2495 ;; rather than `make-button', as text-buttons are much faster in 2505 ;; rather than `make-button', as text-buttons are much faster in
2496 ;; large buffers. 2506 ;; large buffers.
2497 (make-text-button start end 2507 (make-text-button start (point)
2498 'face 'rcirc-url 2508 'face 'rcirc-url
2499 'follow-link t 2509 'follow-link t
2500 'rcirc-url url 2510 'rcirc-url url
2501 'action (lambda (button) 2511 'action (lambda (button)
2502 (browse-url (button-get button 'rcirc-url)))) 2512 (browse-url (button-get button 'rcirc-url))))
2503 ;; record the url if it is not already the latest stored url 2513 ;; Record the URL if it is not already the latest stored URL.
2504 (when (not (string= link-text (caar rcirc-urls))) 2514 (unless (string= url (caar rcirc-urls))
2505 (push (cons link-text start) rcirc-urls))))) 2515 (push (cons url start) rcirc-urls)))))
2506 2516
2507(defun rcirc-markup-keywords (sender response) 2517(defun rcirc-markup-keywords (sender response)
2508 (when (and (string= response "PRIVMSG") 2518 (when (and (string= response "PRIVMSG")