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: Sun, 28 Oct 2018 03:14:39 +0000 Message-ID: <87h8h6iwyo.fsf@tcd.ie> References: <20181015100626.2344-1-dme@dme.org> <87r2go2opq.fsf@tcd.ie> <87pnw7fskz.fsf@tcd.ie> <83h8h7ojly.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1540696386 25794 195.159.176.226 (28 Oct 2018 03:13:06 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 28 Oct 2018 03:13:06 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: 33043@debbugs.gnu.org, dme@dme.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Oct 28 04:13:02 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 1gGbVd-0006Zg-J2 for geb-bug-gnu-emacs@m.gmane.org; Sun, 28 Oct 2018 04:13:01 +0100 Original-Received: from localhost ([::1]:38576 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gGbXk-0003Fs-0o for geb-bug-gnu-emacs@m.gmane.org; Sat, 27 Oct 2018 23:15:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60268) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gGbXd-0003Fl-By for bug-gnu-emacs@gnu.org; Sat, 27 Oct 2018 23:15:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gGbXa-0004dM-5v for bug-gnu-emacs@gnu.org; Sat, 27 Oct 2018 23:15:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:41876) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gGbXa-0004dA-1P for bug-gnu-emacs@gnu.org; Sat, 27 Oct 2018 23:15:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gGbXZ-0003qk-S8 for bug-gnu-emacs@gnu.org; Sat, 27 Oct 2018 23:15:01 -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: Sun, 28 Oct 2018 03:15:01 +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.154069648914767 (code B ref 33043); Sun, 28 Oct 2018 03:15:01 +0000 Original-Received: (at 33043) by debbugs.gnu.org; 28 Oct 2018 03:14:49 +0000 Original-Received: from localhost ([127.0.0.1]:46134 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gGbXM-0003q6-L3 for submit@debbugs.gnu.org; Sat, 27 Oct 2018 23:14:48 -0400 Original-Received: from mail-ed1-f42.google.com ([209.85.208.42]:37908) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gGbXL-0003pv-HC for 33043@debbugs.gnu.org; Sat, 27 Oct 2018 23:14:48 -0400 Original-Received: by mail-ed1-f42.google.com with SMTP id c1-v6so4426250ede.5 for <33043@debbugs.gnu.org>; Sat, 27 Oct 2018 20:14:47 -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=SqZqhqAuTfJI5MnzVyrsZRdGG5F08708JKknu5sMrpE=; b=v2Mh9Z1hcIKWGt/x+s23Z8Zmkr4HbSinbke1W6lpta7juhr9/6y55KBBcEPCBC+5Y6 0VL1IhcbjZfPeX4kHH25352dVmBXX/32tmFEGT7Ov+ErlXbFFvBmSdjkVLZfiHqIJH6m 8kVIYqw6kBEdcN4ypnCY2Qe7sJ1w3GOfCCbU3oW8fRS8/kVTB+aylLYjemeOfefVOwro v2xjeBTgoC+IsuV/28jPNvlUL0p82r/KhCcSbQMTMbzCrRb4Eh0ic2qlwIHeEvxnGqp9 wYaXCg7qIiE8K+c28V3vc7f21/urKFEThkqGqO7WEfAXF66MsnNvPZrqpBuWWgTiyJob NV0Q== 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=SqZqhqAuTfJI5MnzVyrsZRdGG5F08708JKknu5sMrpE=; b=cI8nbJxkhApyUtU0xCuiWPcFP4cAn8FE/u9rx3eKOyBPLV9DCvkhEJX9bWhccV24Ao /gtPYnnxzrtwRfnYNfd0RH4gbp+PKPgX+pufan52tpFLDLrZU6jby6g2vtsEzR44XD0k U8ZdnIdb3tTePHCFxE0//ZR4MXP9QIT4LOL8Sd6BsMpi/AxMWbCYh8mIV175eXmFUQsE 1/9nhlnJGidIlctea2VoPTU9si7SVo7zFukKHatr9rB+u8S2lZaxNy2KP5Qe8w/T56vC YgWHYvIrEqjm4zwO+E9G/QQvByaTrZ6FbKCI56urm/0twEorNOY4P9yvK0YehxYCsUcC jgxA== X-Gm-Message-State: AGRZ1gLkhfgNbAzc8obfzMoo9q3bo7Xl7kyHRfVmTEDfxR730vS57dxg UnL8P+/Do5WpoCFesg7aGHw0BtiwGQM= X-Google-Smtp-Source: AJdET5fOjJvv8nkofesvqhbzDU2YTaRNmm0CPCyTtsbP4TjH1gUxfFtQz0dw2pD9l/5VXB+ZO4v3tQ== X-Received: by 2002:a50:f4ac:: with SMTP id s41-v6mr8764169edm.269.1540696481804; Sat, 27 Oct 2018 20:14:41 -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 n3-v6sm2950671eje.26.2018.10.27.20.14.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 27 Oct 2018 20:14:40 -0700 (PDT) In-Reply-To: <83h8h7ojly.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 27 Oct 2018 11:54:17 +0300") 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:151730 Archived-At: --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Add-URL-truncation-support-to-rcirc-bug-33043.patch >From 76dc7ed5d5b9c6273e99a2659ba304e9e7eb8e03 Mon Sep 17 00:00:00 2001 From: David Edmondson Date: Sun, 28 Oct 2018 03:11:21 +0000 Subject: [PATCH 1/2] Add URL truncation support to rcirc (bug#33043) * lisp/net/rcirc.el (rcirc-url-max-length): New user option controlling extent of URL truncation, defaulting to none. (rcirc-markup-urls): Use it. --- lisp/net/rcirc.el | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el index fe9c71a21c..50e4d8ffb2 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) @@ -2491,6 +2499,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. -- 2.19.1 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0002-Reuse-URL-truncation-function-in-rcirc-bug-33043.patch >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 --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: "Basil L. Contovounesios" >> Date: Thu, 18 Oct 2018 11:38:04 +0100 >> Cc: 33043@debbugs.gnu.org >> >> > 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: > > If you two are in agreement wrt what should be installed, I'd need a > full changeset from Basil to push. 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? Thanks, -- Basil --=-=-=--