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: Wed, 17 Oct 2018 23:27:45 +0100 Message-ID: <87r2go2opq.fsf@tcd.ie> References: <20181015100626.2344-1-dme@dme.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1539815169 31190 195.159.176.226 (17 Oct 2018 22:26:09 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 17 Oct 2018 22:26:09 +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 Thu Oct 18 00:26:05 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 1gCuGR-0007yE-KE for geb-bug-gnu-emacs@m.gmane.org; Thu, 18 Oct 2018 00:26:03 +0200 Original-Received: from localhost ([::1]:39373 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCuIY-0007YW-2g for geb-bug-gnu-emacs@m.gmane.org; Wed, 17 Oct 2018 18:28:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36736) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCuIR-0007YC-Sl for bug-gnu-emacs@gnu.org; Wed, 17 Oct 2018 18:28:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gCuIM-00063H-Sb for bug-gnu-emacs@gnu.org; Wed, 17 Oct 2018 18:28:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:51664) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gCuIM-00061p-Ib for bug-gnu-emacs@gnu.org; Wed, 17 Oct 2018 18:28:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gCuIM-0003me-Cs for bug-gnu-emacs@gnu.org; Wed, 17 Oct 2018 18:28: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: Wed, 17 Oct 2018 22:28: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.153981527414531 (code B ref 33043); Wed, 17 Oct 2018 22:28:02 +0000 Original-Received: (at 33043) by debbugs.gnu.org; 17 Oct 2018 22:27:54 +0000 Original-Received: from localhost ([127.0.0.1]:55922 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gCuIE-0003mI-B0 for submit@debbugs.gnu.org; Wed, 17 Oct 2018 18:27:54 -0400 Original-Received: from mail-ed1-f46.google.com ([209.85.208.46]:44019) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gCuID-0003lz-7W for 33043@debbugs.gnu.org; Wed, 17 Oct 2018 18:27:53 -0400 Original-Received: by mail-ed1-f46.google.com with SMTP id y20-v6so26387424eds.10 for <33043@debbugs.gnu.org>; Wed, 17 Oct 2018 15:27:53 -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=TU90oDWjr1s9JIYE6dsWL6GZENmPmH+mWPOzOb4PqpM=; b=g7c3gczr1Hc/7RPP5IX2rYtQdGxnl/o1U3+O3EIlyApMkQY44PjiqGNJcoyF0mBtp0 kbag+8iOu4ai4rfFmd6YsyWbLw40hfi4smuYGvBGkcPm8QZGULhpt0c0WkW9BM2RO17C 562aQT012ELx1tcIeeOOhr+e8bLm3V+a9kDqp0dtRH6r+uA76CkrFnbG8gZYdps8yyKB BQEaD8s4rWj6cJVOXuSFq3X97/7E/EDmRWs0PIterUqdS8NhI8TDiI6srbu3xl2Qb+yB EQGvwuPhayxY6gaFgMrHyhSduj30tyvbwjz0AUmj9zHca5SbyBteAsNkMrkb4s6fd30D bIgQ== 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=TU90oDWjr1s9JIYE6dsWL6GZENmPmH+mWPOzOb4PqpM=; b=fhPNPN2Xty44vB1wISDSC29hc1HFIN33aNMjuZZFD25WMzriOvPl4Pd9/7wBDVpn7m t5pNi6ZHi63MiJINa+i5LSgH7fNjiwlbsOh7+sYLwf9ybYZL/GzSiPRkyeJrFFg8QBsn AjYrdFkwJBasSAiEzVvGhj9Jw2E7P+OdGnvZqCptEWkclSc3KhA7ecSbAgAeVaMWRoAf TLnW7YLr20TIVjiuuart7tbOFivtXmhk7fLc0UVKbZH5PcX28IA0ifsSMVYfbA3GeSi6 gKND2cZH9hrqqwBQzVWb4IkEAY42hMzoEh5y6gwLLvPY8o6oHlLK+3PwvXjxUJ4nBH3l 9JAQ== X-Gm-Message-State: ABuFfoi9qeV4toYX3JDL6snkVGcFF7w9N9WIqX8+TLNyN0/FXtUe4Rdk guC9HYfLJ4dTKxJeGPOKiTYGdJl3LRo= X-Google-Smtp-Source: ACcGV61QK30dXFjRpSQ1VocVMqXuBmJpKZ83klvEflklYker94Qv7sH8/OQRpfaKgoEcyKPKL7dJPg== X-Received: by 2002:a17:906:a2c4:: with SMTP id by4-v6mr27353714ejb.86.1539815267279; Wed, 17 Oct 2018 15:27:47 -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 k13-v6sm7592014edb.89.2018.10.17.15.27.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 Oct 2018 15:27:46 -0700 (PDT) In-Reply-To: <20181015100626.2344-1-dme@dme.org> (David Edmondson's message of "Mon, 15 Oct 2018 11:06:26 +0100") 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:151357 Archived-At: --=-=-= Content-Type: text/plain Thanks for working on this David, I like the idea. David Edmondson 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: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=rcirc.diff 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") --=-=-= Content-Type: text/plain WDYT? -- Basil --=-=-=--