GNU bug report logs - #38257
27.0.50; ERC does not match or highlight nick surrounded by parens

Previous Next

Package: emacs;

Reported by: Amin Bandali <bandali <at> gnu.org>

Date: Mon, 18 Nov 2019 15:41:02 UTC

Severity: minor

Tags: patch

Merged with 38366

Found in versions 25.1, 27.0.50

Fixed in version 27.1

Done: Amin Bandali <bandali <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Amin Bandali <bandali <at> gnu.org>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 38257 <at> debbugs.gnu.org, Emanuel Berg <moasenwood <at> zoho.eu>
Subject: bug#38257: Acknowledgement (27.0.50; ERC does not match or highlight nick surrounded by parens)
Date: Sat, 28 Dec 2019 23:30:19 -0500
[Message part 1 (text/plain, inline)]
Amin Bandali <bandali <at> gnu.org> writes:

> Lars Ingebrigtsen <larsi <at> gnus.org> writes:
>
> [...]
>>
>> So I think for this to work with erc, I think
>> it would make sense to separate out the URL
>> recognition in erc from other buttons, and
>> base it on browse-url-button-regexp instead,
>> which has worked out these kinks and is
>> pretty DWIM.
>>
>> And then you can change the syntax table to
>> make the other, simpler buttons (for nicks
>> etc) work.
>
> Nice, I think that would make sense.  FWIW, I'm
> not familiar with how ERC does URL recognition
> either, but I'll try to look into it soon-ish.
> In the mean time, if anyone else is familiar
> with this already, your help would be much
> appreciated. :)
>

So I had a bit of time on my hands again, and looked into erc-button per
Lars’s suggestion.  Turns out there’s a C-h v erc-button-url-regexp RET.
Replacing it with C-h v browse-url-button-regexp RET seems to improve
things with surrounding pair of parens.  In particular, the closing
paren isn’t wrongly buttonized anymore, which is nice.

I think the only nice-to-have at this point would be if quotes without a
matching one were buttonized as part of the address, e.g. the one from
Lars’s earlier example.

For instance, currently in all the following examples buttonizing ends
right before the quote (i.e. the t is the last clickable character):

- https://example.org/test"x
- https://example.org/test'x
- https://example.org/test’x
- https://example.org/test"
- https://example.org/test'
- https://example.org/test’

Note that the current behaviour is *not* a side-effect of my patch.

>
> Also, I'll keep on using my patch on my local
> checkout and will report back if I notice any
> serious issues.  So far it's been working
> pretty nicely here, minus the URL buttons.
>

Quick update: I’ve been using my patch every day for the past ~40 days,
and I haven’t had any issues with it so far.

                                 * * *

Finally, the updated patch (against master, but I’m hoping since it
hasn’t diverged from emacs-27 much yet, it should still apply there):

[0001-Improve-ERC-s-matching-of-nicks-and-URLs-bug-38257.patch (text/x-diff, inline)]
From 940d5e41ad5449bf0b0214b941de54ebbd5df546 Mon Sep 17 00:00:00 2001
From: Amin Bandali <bandali <at> gnu.org>
Date: Mon, 18 Nov 2019 10:24:48 -0500
Subject: [PATCH v2] Improve ERC's matching of nicks and URLs (bug#38257)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lisp/erc/erc-{button,match}.el (erc-{button,match}-syntax-table):
Omit (, ), and '; as they're not valid nick characters, per RFC 2812
section 2.3.1.  This enables correct matching/highlighting of nicks
when they’re surrounded by parens, like (nick), and when adjacent to
an apostrophy, like nick's.
* lisp/erc/erc-button.el (erc-button-url-regexp): Use the regexp from
browse-url-button-regexp, which among other things, seems to handle
surrounding pair of parens better.
---
 lisp/erc/erc-button.el | 11 +++--------
 lisp/erc/erc-match.el  |  3 ---
 2 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/lisp/erc/erc-button.el b/lisp/erc/erc-button.el
index ec70260146..ae7a6e6bf3 100644
--- a/lisp/erc/erc-button.el
+++ b/lisp/erc/erc-button.el
@@ -41,6 +41,7 @@
 (require 'erc)
 (require 'wid-edit)
 (require 'erc-fill)
+(require 'browse-url)
 
 ;;; Minor Mode
 
@@ -87,12 +88,9 @@ erc-button-mouse-face
   :type 'face
   :group 'erc-faces)
 
-(defcustom erc-button-url-regexp
-  (concat "\\(www\\.\\|\\(s?https?\\|"
-          "ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\)"
-          "\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?"
-          "[-a-zA-Z0-9_=!?#$@~`%&*+\\/:;.,()]+[-a-zA-Z0-9_=#$@~`%&*+\\/()]")
+(defcustom erc-button-url-regexp browse-url-button-regexp
   "Regular expression that matches URLs."
+  :version "27.1"
   :group 'erc-button
   :type 'regexp)
 
@@ -223,14 +221,11 @@ erc-button-keymap
 
 (defvar erc-button-syntax-table
   (let ((table (make-syntax-table)))
-    (modify-syntax-entry ?\( "w" table)
-    (modify-syntax-entry ?\) "w" table)
     (modify-syntax-entry ?\[ "w" table)
     (modify-syntax-entry ?\] "w" table)
     (modify-syntax-entry ?\{ "w" table)
     (modify-syntax-entry ?\} "w" table)
     (modify-syntax-entry ?` "w" table)
-    (modify-syntax-entry ?' "w" table)
     (modify-syntax-entry ?^ "w" table)
     (modify-syntax-entry ?- "w" table)
     (modify-syntax-entry ?_ "w" table)
diff --git a/lisp/erc/erc-match.el b/lisp/erc/erc-match.el
index e9ed735516..336040a374 100644
--- a/lisp/erc/erc-match.el
+++ b/lisp/erc/erc-match.el
@@ -246,14 +246,11 @@ erc-match-exclude-server-buffer
 ;; just put it in erc.el
 (defvar erc-match-syntax-table
   (let ((table (make-syntax-table)))
-    (modify-syntax-entry ?\( "w" table)
-    (modify-syntax-entry ?\) "w" table)
     (modify-syntax-entry ?\[ "w" table)
     (modify-syntax-entry ?\] "w" table)
     (modify-syntax-entry ?\{ "w" table)
     (modify-syntax-entry ?\} "w" table)
     (modify-syntax-entry ?` "w" table)
-    (modify-syntax-entry ?' "w" table)
     (modify-syntax-entry ?^ "w" table)
     (modify-syntax-entry ?- "w" table)
     (modify-syntax-entry ?_ "w" table)
-- 
2.23.0

[Message part 3 (text/plain, inline)]
-- 
Amin Bandali
Free Software Activist | GNU Maintainer & Webmaster
GPG: BE62 7373 8E61 6D6D 1B3A  08E8 A21A 0202 4881 6103
https://bandali.eu.org
[signature.asc (application/pgp-signature, inline)]

This bug report was last modified 5 years and 116 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.