From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: "Basil L. Contovounesios" Newsgroups: gmane.emacs.bugs Subject: bug#33043: [PATCH v1 1/1] Support for the truncation of displayed URLs Date: Mon, 29 Oct 2018 18:27:54 +0000 Message-ID: <87tvl4ip5h.fsf@tcd.ie> References: <20181015100626.2344-1-dme@dme.org> <87r2go2opq.fsf@tcd.ie> <87pnw7fskz.fsf@tcd.ie> <83h8h7ojly.fsf@gnu.org> <87h8h6iwyo.fsf@tcd.ie> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1540837630 24636 195.159.176.226 (29 Oct 2018 18:27:10 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 29 Oct 2018 18:27:10 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: 33043@debbugs.gnu.org To: David Edmondson Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Oct 29 19:27:06 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gHCFl-0006Jt-GW for geb-bug-gnu-emacs@m.gmane.org; Mon, 29 Oct 2018 19:27:05 +0100 Original-Received: from localhost ([::1]:48204 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHCHr-0005oZ-NG for geb-bug-gnu-emacs@m.gmane.org; Mon, 29 Oct 2018 14:29:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54474) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHCHi-0005oU-Vo for bug-gnu-emacs@gnu.org; Mon, 29 Oct 2018 14:29:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHCHe-0000ot-M1 for bug-gnu-emacs@gnu.org; Mon, 29 Oct 2018 14:29:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:47944) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHCHe-0000oj-GR for bug-gnu-emacs@gnu.org; Mon, 29 Oct 2018 14:29:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gHCHe-0004yA-DN for bug-gnu-emacs@gnu.org; Mon, 29 Oct 2018 14:29:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "Basil L. Contovounesios" Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 29 Oct 2018 18:29:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 33043 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 33043-submit@debbugs.gnu.org id=B33043.154083768519036 (code B ref 33043); Mon, 29 Oct 2018 18:29:02 +0000 Original-Received: (at 33043) by debbugs.gnu.org; 29 Oct 2018 18:28:05 +0000 Original-Received: from localhost ([127.0.0.1]:52202 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gHCGj-0004wy-Bw for submit@debbugs.gnu.org; Mon, 29 Oct 2018 14:28:05 -0400 Original-Received: from mail-ed1-f48.google.com ([209.85.208.48]:44627) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gHCGg-0004wT-VS for 33043@debbugs.gnu.org; Mon, 29 Oct 2018 14:28:03 -0400 Original-Received: by mail-ed1-f48.google.com with SMTP id z21-v6so8191233edb.11 for <33043@debbugs.gnu.org>; Mon, 29 Oct 2018 11:28:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=ruGuAY69ENpkwf1FVneCxhg8m5iCvgu4LEKdH9v5RzA=; b=nSEYHxIcK/d2ih0gpIOFthwyr5r67bdKSUOFXXdY0W+2qPum3c5M4j/XRNoeb6I4yT jMykSV94laXqhzarbq1I9W4a1VzJ9dG8dQNH/ndsLnzMTvIdDmAYk+TJyaZDgUFZn5+M IHoyy5dLuueKSU4e2/c7f0IqBh9YW5knJG+gFMGA+NENKqoF6XDNk2nd/JijQViDoZN9 wuIoG9/RR+x1y/PrxbJ8u3ppBJzVY2FYRowfh83TooVvVz/OrJASdmt8msVD7x6QcbQC 5CfA/pWGmDvJH0xcwhBQbfGBZtKTsUvu5r8ArxKUMOdIpxZSSYenkk3EH0xTalSOn9dn JWig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=ruGuAY69ENpkwf1FVneCxhg8m5iCvgu4LEKdH9v5RzA=; b=lQwEehbUz0tXaMZc77nNfJwxseX0spm4OvIg/gfkv/yHr0ylTF86/eYmEu37rfuzA7 KH+iRc6r9ACJkgTTwVBMGxEDRFB38ZmfvSFLmThREDTM8vsKXFArr9M/fKI7A4wbQFzj fz4nX+TbkIYL7J5b4CktlCtE9OTF5cbHzTfa/sdIDEMVHsZU5+n+cjZVxsqcpY17Ru+8 p16+r9pmxpNQFJ5QbFwTVhDxFZ96TC5YxMhLKsepcIF49NR/AKutj1rmCRN6B0PX8d1V i0fyakaKeujv8ge0U0eRigg76GCjgCZirpw1qUep5HmXrtBel4uQjaimv5yRXsmJ+Wki 5/cA== X-Gm-Message-State: AGRZ1gIl8AtMOmpZEQEutaPzbV8ayyCFhKgXJolBipegdAWY+NpTpAOR D4FaRpIp7ofCeGM5/qYI13xilw== X-Google-Smtp-Source: AJdET5eeZDBf4vWzORBHbxrsgtObs51nfiWXNrQUdcH7h9EYC7Egqtd+qHfRuRLtXFaUlJBcBqEujA== X-Received: by 2002:a17:906:6616:: with SMTP id b22-v6mr10490673ejp.184.1540837677150; Mon, 29 Oct 2018 11:27:57 -0700 (PDT) Original-Received: from localhost (51-171-243-2-dynamic.agg2.clk.blp-srl.eircom.net. [51.171.243.2]) by smtp.gmail.com with ESMTPSA id m15-v6sm3828519ejq.24.2018.10.29.11.27.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 29 Oct 2018 11:27:56 -0700 (PDT) In-Reply-To: (David Edmondson's message of "Mon, 29 Oct 2018 16:01:04 +0000") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:151782 Archived-At: --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Add-URL-truncation-support-to-rcirc-bug-33043.patch >From 41d7f52984e6220123b8ccc7da1b1d56a9a7eb49 Mon Sep 17 00:00:00 2001 From: David Edmondson Date: Sun, 28 Oct 2018 03:11:21 +0000 Subject: [PATCH] Add URL truncation support to rcirc (bug#33043) Suggested by David Edmondson . * 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. --- etc/NEWS | 7 +++++++ lisp/net/rcirc.el | 26 ++++++++++++++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 226ae1e135..f7fdd0add9 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -758,6 +758,13 @@ Tramp for some look-alike remote file names. *** For some connection methods, like "su" or "sudo", the host name in ad-hoc multi-hop file names must match the previous hop. +** Rcirc + +--- +*** New user option 'rcirc-url-max-length'. +Setting this option to an integer causes URLs displayed in Rcirc +buffers to be truncated to that many characters. + ** Register --- *** The return value of method 'register-val-describe' includes the diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el index fe9c71a21c..ca707341be 100644 --- a/lisp/net/rcirc.el +++ b/lisp/net/rcirc.el @@ -168,6 +168,14 @@ rcirc-fill-prefix (string :tag "Prefix text")) :group 'rcirc) +(defcustom rcirc-url-max-length nil + "Maximum number of characters in displayed URLs. +If nil, no maximum is applied." + :version "27.1" + :type '(choice (const :tag "No maximum" nil) + (integer :tag "Number of characters")) + :group 'rcirc) + (defvar rcirc-ignore-buffer-activity-flag nil "If non-nil, ignore activity in this buffer.") (make-variable-buffer-local 'rcirc-ignore-buffer-activity-flag) @@ -2485,24 +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))) + (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 --=-=-= Content-Type: text/plain David Edmondson writes: > On Sunday, 2018-10-28 at 03:14:39 +00, Basil L. Contovounesios wrote: > >> I attach two patches. The first comprises David's original patch, but >> with an added :version tag and reworded commit message. The second >> switches to reusing url-truncate-url-for-viewing. WDYT? > > It would be simpler just to smash them together. I don't care about the > credit or anything. I don't either. How's the attached patch, which additionally announces the new user option in etc/NEWS? Thanks, -- Basil --=-=-=--