From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: David Edmondson Newsgroups: gmane.emacs.bugs Subject: bug#33043: [PATCH v1 1/1] Support for the truncation of displayed URLs Date: Thu, 18 Oct 2018 11:50:22 +0100 Message-ID: References: <20181015100626.2344-1-dme@dme.org> <87r2go2opq.fsf@tcd.ie> <87pnw7fskz.fsf@tcd.ie> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1539859746 5132 195.159.176.226 (18 Oct 2018 10:49:06 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 18 Oct 2018 10:49:06 +0000 (UTC) Cc: 33043@debbugs.gnu.org To: "Basil L. Contovounesios" Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Oct 18 12:49: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 1gD5rS-0001CE-5Z for geb-bug-gnu-emacs@m.gmane.org; Thu, 18 Oct 2018 12:49:02 +0200 Original-Received: from localhost ([::1]:41599 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gD5tY-0007fM-Ie for geb-bug-gnu-emacs@m.gmane.org; Thu, 18 Oct 2018 06:51:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59783) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gD5tR-0007f6-KP for bug-gnu-emacs@gnu.org; Thu, 18 Oct 2018 06:51:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gD5tO-0000sa-9Z for bug-gnu-emacs@gnu.org; Thu, 18 Oct 2018 06:51:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:51895) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gD5tO-0000sI-4H for bug-gnu-emacs@gnu.org; Thu, 18 Oct 2018 06:51:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gD5tO-0004Wd-1f for bug-gnu-emacs@gnu.org; Thu, 18 Oct 2018 06:51:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: David Edmondson Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 18 Oct 2018 10:51: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.153985983617353 (code B ref 33043); Thu, 18 Oct 2018 10:51:01 +0000 Original-Received: (at 33043) by debbugs.gnu.org; 18 Oct 2018 10:50:36 +0000 Original-Received: from localhost ([127.0.0.1]:56153 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gD5sv-0004Vn-J7 for submit@debbugs.gnu.org; Thu, 18 Oct 2018 06:50:33 -0400 Original-Received: from mail-wm1-f51.google.com ([209.85.128.51]:33290) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gD5ss-0004VW-Ir for 33043@debbugs.gnu.org; Thu, 18 Oct 2018 06:50:31 -0400 Original-Received: by mail-wm1-f51.google.com with SMTP id y140-v6so1578100wmd.0 for <33043@debbugs.gnu.org>; Thu, 18 Oct 2018 03:50:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dme-org.20150623.gappssmtp.com; s=20150623; h=to:cc:subject:in-reply-to:references:from:date:message-id :mime-version; bh=WHT61lS+QlyEQ9YMcnF6+77OwZUsMVENIrsL+9KW1ic=; b=hS4AAbwNTk9An5lqrsAdOhyb5Alhq7xcHOFsMCynrVx+E919z03rUK1NrpHVMgke7A zHWwu0dL7oh/hPkKio7MTRxJGvggWLQ8v5OChpNmxB2gy2EUlj3HOB97bzY5bC3sz9Gp 5MrnaVuzYNglhXg7NdbPOYDlhUgWXWY9Qn1tDdxj8ntmhL+X3r+Bbzl+Ai6BsTGIFw8A Wwa5fTilRvKdthfPFoHhrwxZKsxYs+813TwAHAN7Wr9ULdTOi37NffabWk5IRMJY4CVQ mFqKlFIHIyXGwukgSod8Tvk/BEozybetI8k3XeNkjcx1i+52rpkx1PrDLuxqd8KueR7y r8Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:subject:in-reply-to:references:from:date :message-id:mime-version; bh=WHT61lS+QlyEQ9YMcnF6+77OwZUsMVENIrsL+9KW1ic=; b=dD6BglbGxo9zIqhrSXjcGBFsnZ6zwz6ZZE/3gPIzCe9alWiRQo9PV1aIOPXSOQbZAZ PNxcEtH8q8pql3+HdELFLh+HG7OuZQoTM7fqPTVHX/SPvSnfy+2BZYFhG9OpKhUDNvp8 txmUqSjbniYmnKTsubSWuqGELdGQhCP7bSDgeqMlLMyd30x0fiNbN9m3jCSHgMA6lEtL JY8UAyH63YzttnrwRFE4koJE8TKdzIO1Qy09H0X7Ud9/c7ixJ71E/Yu8KSt5RsqMKq22 AMZEUe/iiwskcq/+eFS4Y46Mh9NAgCUyCHabHfI4ligcl8Kw2ta0MJMpZwbDbaNg0keU tC4A== X-Gm-Message-State: ABuFfojWAkpfPpCDfjWe+VPGUmZFp2jQy+6ECUhDsqSLJkMHlD2UrDSX pc2qxGCCFl5UZ2c+GpVfRLhT5w== X-Google-Smtp-Source: ACcGV62pqy28w1vWoLfNsj9qoM+HlX86z0tQNvSzqpuH+HJsct/C+fZ4y4v6Wh4qIkNf95k2kWc58w== X-Received: by 2002:a1c:e08a:: with SMTP id x132-v6mr7143910wmg.60.1539859824555; Thu, 18 Oct 2018 03:50:24 -0700 (PDT) Original-Received: from disaster-area.hh.sledj.net (disaster-area.hh.sledj.net. [81.149.164.25]) by smtp.gmail.com with ESMTPSA id t13-v6sm11554764wrn.22.2018.10.18.03.50.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 03:50:23 -0700 (PDT) Original-Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 92c85286; Thu, 18 Oct 2018 10:50:22 +0000 (UTC) In-Reply-To: <87pnw7fskz.fsf@tcd.ie> X-HGTTG: disaster-area 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:151369 Archived-At: On Thursday, 2018-10-18 at 11:38:04 +0100, Basil L. Contovounesios wrote: > David Edmondson 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: Either of your versions looks fine to me, thanks for looking into it. > 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 > > If you prefer to avoid deletion and insertion when rcirc-url-max-length > is nil, you can also write the following: > > 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") > > Thanks, > > -- > Basil dme. -- Does everyone stare the way I do?