unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#50005: 28.0.50; silence a couple byte-compiler warnings in ERC
@ 2021-08-11 13:57 J.P.
  2021-08-12  8:15 ` Mattias Engdegård
  2021-09-12 12:03 ` J.P.
  0 siblings, 2 replies; 7+ messages in thread
From: J.P. @ 2021-08-11 13:57 UTC (permalink / raw)
  To: 50005

[-- Attachment #1: Type: text/plain, Size: 4321 bytes --]

Tags: patch

Hi, the commit log for this bug mentions two warnings. The one
concerning regexp-opt.el doesn't actually show up in make output
currently, but it's emitted under fairly mundane circumstances.
Moreover, the actual offending function, `erc-lurker-maybe-trim',
doesn't really behave as advertised, so I've tried tackling that here
as well.

As for `erc-with-all-buffers-of-server': out of deference to existing
code, I've left the "eval only once" stuff in play, even though a quick
survey of use cases at various call sites shows it's not really needed.
I also didn't bother with other possible tweaks, like (for example)
using `macroexp-copyable-p' for the `macroexp-let2' test param, which
would omit the superfluous let-binding of symbol expressions (variables)
in expanded code.

I guess I figured if we're going that far, we might as well replace the
call to `erc-buffer-filter' with a `dolist' or similar or even redo the
filter itself (and friends) completely. But if you buy into any of the
nonsense I've been spewing in other bugs [1], then you'll agree all of
that can wait because ERC has more pressing concerns. Thanks.

P.S. I also snuck in a tweak to an existing ERC test so it'll play nicer
with others; hope that's okay.


[1] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=48598
    https://debbugs.gnu.org/cgi/bugreport.cgi?bug=49860


In GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.30, cairo version 1.17.4)
 of 2021-08-09 built on localhost
Repository revision: aeec97fae0ccfcc4dc406a5e0e4c0a94b834cac4
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: Fedora 34 (Workstation Edition)

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NOTIFY
INOTIFY PDUMPER PNG RSVG SECCOMP SOUND THREADS TIFF TOOLKIT_SCROLL_BARS
X11 XDBE XIM XPM GTK3 ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs
rfc822 mml mml-sec epa derived epg epg-config gnus-util rmail
rmail-loaddefs auth-source cl-seq eieio eieio-core cl-macs
eieio-loaddefs password-cache json map text-property-search time-date
subr-x seq byte-opt gv bytecomp byte-compile cconv mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader cl-loaddefs
cl-lib sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils
iso-transl tooltip eldoc electric uniquify ediff-hook vc-hooks
lisp-float-type mwheel term/x-win x-win term/common-win x-dnd tool-bar
dnd fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode elisp-mode lisp-mode prog-mode register page tab-bar menu-bar
rfn-eshadow isearch easymenu timer select scroll-bar mouse jit-lock
font-lock syntax font-core term/tty-colors frame minibuffer cl-generic
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese composite charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray
cl-preloaded nadvice button loaddefs faces cus-face macroexp files
window text-properties overlay sha1 md5 base64 format env code-pages
mule custom widget hashtable-print-readable backquote threads dbusbind
inotify lcms2 dynamic-setting system-font-setting font-render-setting
cairo move-toolbar gtk x-toolkit x multi-tty make-network-process emacs)

Memory information:
((conses 16 51538 6355)
 (symbols 48 6607 1)
 (strings 32 18255 1368)
 (string-bytes 1 616656)
 (vectors 16 14292)
 (vector-slots 8 185252 10153)
 (floats 8 21 47)
 (intervals 56 205 0)
 (buffers 992 10))

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-mistake-in-test-for-erc-ring-previous-command.patch --]
[-- Type: text/x-patch, Size: 1633 bytes --]

From 88475f43ed983a348f9ae3c4e143745e04919065 Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <jp@neverwas.me>
Date: Thu, 13 May 2021 02:27:08 -0700
Subject: [PATCH 1/2] Fix mistake in test for erc-ring-previous-command

* test/lisp/erc/erc-tests.el (erc-ring-previous-command):
The variable erc-send-completed-hook was previously set to nil
permanently, which would affect other tests.
---
 test/lisp/erc/erc-tests.el | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index d13397274a..9efcf4a703 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -61,13 +61,16 @@ erc-ring-previous-command
   (with-current-buffer (get-buffer-create "*#fake*")
     (erc-mode)
     (insert "\n\n")
-    (setq erc-input-marker (make-marker) ; these are all local
-          erc-insert-marker (make-marker)
-          erc-send-completed-hook nil)
+    (should-not (local-variable-if-set-p 'erc-send-completed-hook))
+    (set (make-local-variable 'erc-send-completed-hook) nil) ; skip t (globals)
+    (setq erc-input-marker (make-marker)
+          erc-insert-marker (make-marker))
     (set-marker erc-insert-marker (point-max))
     (erc-display-prompt)
     (should (= (point) erc-input-marker))
-    (add-hook 'erc-pre-send-functions #'erc-add-to-input-ring nil t)
+    ;; Just in case erc-ring-mode is already on
+    (setq-local erc-pre-send-functions nil)
+    (add-hook 'erc-pre-send-functions #'erc-add-to-input-ring)
     ;;
     (cl-letf (((symbol-function 'erc-process-input-line)
                (lambda (&rest _)
-- 
2.31.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-Fix-a-couple-byte-compiler-warnings-in-erc.el.patch --]
[-- Type: text/x-patch, Size: 5936 bytes --]

From d54b99bb722616189d1939038b5d2993f9ccfd6f Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <jp@neverwas.me>
Date: Wed, 21 Jul 2021 00:26:38 -0700
Subject: [PATCH 2/2] Fix a couple byte-compiler warnings in erc.el

* lisp/erc/erc.el (erc-lurker-maybe-trim): Prevent warning from
showing up in third party code re library not loaded.  Also make
function do what it claims to. It now only removes trailing chars
typically appended automatically for uniquifying purposes when a
desired nick is already taken.

(erc-with-all-buffers-of-server): Mute byte compiler warning saying
return value unused. Leave possible optimizations for some future
person.
---
 lisp/erc/erc.el            | 25 ++++--------
 test/lisp/erc/erc-tests.el | 79 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 86 insertions(+), 18 deletions(-)

diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 73202016ba..16a08a6823 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -1732,20 +1732,11 @@ erc-with-all-buffers-of-server
 where PRED matches or in all buffers of the server process if PRED is
 nil."
   (declare (indent 1) (debug (form form body)))
-  ;; Make the evaluation have the correct order
-  (let ((pre (make-symbol "pre"))
-        (pro (make-symbol "pro")))
-    `(let* ((,pro ,process)
-            (,pre ,pred)
-            (res (mapcar (lambda (buffer)
-                           (with-current-buffer buffer
-                             ,@forms))
-                         (erc-buffer-list ,pre
-                                          ,pro))))
-       ;; Silence the byte-compiler by binding the result of mapcar to
-       ;; a variable.
-       (ignore res)
-       res)))
+  (macroexp-let2 nil pred pred
+    `(erc-buffer-filter (lambda ()
+                          (when (or (not ,pred) (funcall ,pred))
+                            ,@forms))
+                        ,process)))
 
 (define-obsolete-function-alias 'erc-iswitchb #'erc-switch-to-buffer "25.1")
 (defun erc--switch-to-buffer (&optional arg)
@@ -2572,7 +2563,7 @@ erc-lurker-trim-nicks
 
 (defcustom erc-lurker-ignore-chars "`_"
   "Characters at the end of a nick to strip for activity tracking purposes.
-
+The usual rules regarding ]^\\ and - in \"character alternatives\ apply.
 See also `erc-lurker-trim-nicks'."
   :group 'erc-lurker
   :type 'string)
@@ -2583,9 +2574,7 @@ erc-lurker-maybe-trim
 Returns NICK unmodified unless `erc-lurker-trim-nicks' is
 non-nil."
   (if erc-lurker-trim-nicks
-      (replace-regexp-in-string
-       (regexp-opt-charset (string-to-list erc-lurker-ignore-chars))
-       "" nick)
+      (string-trim-right nick (concat "[" erc-lurker-ignore-chars "]+"))
     nick))
 
 (defcustom erc-lurker-hide-list nil
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 9efcf4a703..b1d2c2a06a 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -47,6 +47,85 @@ erc--read-time-period
   (cl-letf (((symbol-function 'read-string) (lambda (&rest _) "1d")))
     (should (equal (erc--read-time-period "foo: ") 86400))))
 
+(ert-deftest erc-with-all-buffers-of-server ()
+  (let (proc-exnet
+        proc-onet
+        erc-kill-channel-hook erc-kill-server-hook erc-kill-buffer-hook)
+
+    (with-current-buffer (get-buffer-create "OtherNet")
+      (erc-mode)
+      (setq proc-onet (start-process "sleep" (current-buffer) "sleep" "1")
+            erc-server-process proc-onet
+            erc-network 'OtherNet)
+      (set-process-query-on-exit-flag erc-server-process nil))
+
+    (with-current-buffer (get-buffer-create "ExampleNet")
+      (erc-mode)
+      (setq proc-exnet (start-process "sleep" (current-buffer) "sleep" "1")
+            erc-server-process proc-exnet
+            erc-network 'ExampleNet)
+      (set-process-query-on-exit-flag erc-server-process nil))
+
+    (with-current-buffer (get-buffer-create "#foo")
+      (erc-mode)
+      (setq erc-server-process proc-exnet)
+      (setq erc-default-recipients '("#foo")))
+
+    (with-current-buffer (get-buffer-create "#spam")
+      (erc-mode)
+      (setq erc-server-process proc-onet)
+      (setq erc-default-recipients '("#spam")))
+
+    (with-current-buffer (get-buffer-create "#bar")
+      (erc-mode)
+      (setq erc-server-process proc-onet)
+      (setq erc-default-recipients '("#bar")))
+
+    (with-current-buffer (get-buffer-create "#baz")
+      (erc-mode)
+      (setq erc-server-process proc-exnet)
+      (setq erc-default-recipients '("#baz")))
+
+    (should (eq (get-buffer-process "ExampleNet") proc-exnet))
+    (erc-with-all-buffers-of-server (get-buffer-process "ExampleNet")
+      nil
+      (kill-buffer))
+
+    (should-not (get-buffer "ExampleNet"))
+    (should-not (get-buffer "#foo"))
+    (should-not (get-buffer "#baz"))
+    (should (get-buffer "OtherNet"))
+    (should (get-buffer "#bar"))
+    (should (get-buffer "#spam"))
+
+    (let* ((test (lambda () (not (string= (buffer-name) "#spam"))))
+           (calls 0)
+           (get-test (lambda () (cl-incf calls) test)))
+
+      (erc-with-all-buffers-of-server proc-onet
+        (funcall get-test)
+        (kill-buffer))
+
+      (should (= calls 1)))
+
+    (should-not (get-buffer "OtherNet"))
+    (should-not (get-buffer "#bar"))
+    (should (get-buffer "#spam"))
+    (kill-buffer "#spam")))
+
+(ert-deftest erc-lurker-maybe-trim ()
+  (let (erc-lurker-trim-nicks
+        (erc-lurker-ignore-chars "_`"))
+
+    (should (string= "nick`" (erc-lurker-maybe-trim "nick`")))
+
+    (setq erc-lurker-trim-nicks t)
+    (should (string= "nick" (erc-lurker-maybe-trim "nick`")))
+    (should (string= "ni`_ck" (erc-lurker-maybe-trim "ni`_ck__``")))
+
+    (setq erc-lurker-ignore-chars "_-`") ; 95-96
+    (should (string= "nick-" (erc-lurker-maybe-trim "nick-_`")))))
+
 (ert-deftest erc-ring-previous-command-base-case ()
   (ert-info ("Create ring when nonexistent and do nothing")
     (let (erc-input-ring
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* bug#50005: 28.0.50; silence a couple byte-compiler warnings in ERC
  2021-08-11 13:57 bug#50005: 28.0.50; silence a couple byte-compiler warnings in ERC J.P.
@ 2021-08-12  8:15 ` Mattias Engdegård
  2021-08-12 10:56   ` J.P.
  2021-09-12 12:03 ` J.P.
  1 sibling, 1 reply; 7+ messages in thread
From: Mattias Engdegård @ 2021-08-12  8:15 UTC (permalink / raw)
  To: J.P.; +Cc: 50005

>  (defcustom erc-lurker-ignore-chars "`_"
>    "Characters at the end of a nick to strip for activity tracking purposes.
> -
> +The usual rules regarding ]^\\ and - in \"character alternatives\ apply.

Oops (two typos), but thanks for illustrating the problems with:

> +      (string-trim-right nick (concat "[" erc-lurker-ignore-chars "]+"))

Attempting to construct character alternatives by hand is usually a mistake; it's just too error-prone. Better use rx or regexp-opt instead:

 (rx-to-string `(+ (in ,@(string-to-list erc-lurker-ignore-chars))) t)

or

 (concat (regexp-opt (mapcar #'char-to-string erc-lurker-ignore-chars)) "+")






^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#50005: 28.0.50; silence a couple byte-compiler warnings in ERC
  2021-08-12  8:15 ` Mattias Engdegård
@ 2021-08-12 10:56   ` J.P.
  2021-08-12 11:52     ` Mattias Engdegård
  0 siblings, 1 reply; 7+ messages in thread
From: J.P. @ 2021-08-12 10:56 UTC (permalink / raw)
  To: Mattias Engdegård; +Cc: Amin Bandali, 50005

[-- Attachment #1: Type: text/plain, Size: 1804 bytes --]

Mattias Engdegård <mattiase@acm.org> writes:

> Oops (two typos), but thanks for illustrating the problems with:

Thanks, I spotted the weird double-quote mismatch thing earlier, but I
guess I'm still missing something else? Sorry, I'm quite blind/dumb, as
I'm sure you've gathered.

Anyway, I suppose, if we're using `rx-to-string' or `regexp-opt', then
that entire line can just be 86ed.

>  (rx-to-string `(+ (in ,@(string-to-list erc-lurker-ignore-chars))) t)
>
> or
>
>  (concat (regexp-opt (mapcar #'char-to-string erc-lurker-ignore-chars)) "+")

So, I take this to mean there's no problem with requiring (autoloading)
rx.el (or regexp-opt.el), right? I mean, I'd really like to use rx forms
elsewhere in ERC. So if nobody has a problem with it, let's do it! (Cc.
bandali.)

And I guess the `string-to-list' is necessary because

  (rx-to-string '(+ (in "abc")) t)
   ⇒ "[a-c]+"

is still interpreted as a set of character alternatives, whereas

  (rx-to-string '(+ (in ?a ?- ?c)) t)
   ⇒ "[ac-]+"

combines individual character args into just such a set. Thanks for
pointing that out. I'm sure I would have missed that.

Do you use ERC, Mattias? If so, are you available to review more
patches? I'm obviously quite ignorant in the ways of Emacs but am
pushing hard to improve ERC. Some might say that's a recipe for
embarrassment/disaster (though I'm pretty sure I already crossed that
first bridge ages ago).

So what do you say, can you help? I of course would welcome the
experience and obviously don't mind sharing (or even surrendering
complete) credit for anything. (Guess you'd have to weight any potential
cap feathers/plaudits against the indelible smirch of being associated
with the likes of me.) But let me know either way! Thanks.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-mistake-in-test-for-erc-ring-previous-command.patch --]
[-- Type: text/x-patch, Size: 1633 bytes --]

From 552c40c20249bc3d90463e176a623e00a4532c9a Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <jp@neverwas.me>
Date: Thu, 13 May 2021 02:27:08 -0700
Subject: [PATCH 1/2] Fix mistake in test for erc-ring-previous-command

* test/lisp/erc/erc-tests.el (erc-ring-previous-command):
The variable erc-send-completed-hook was previously set to nil
permanently, which would affect other tests.
---
 test/lisp/erc/erc-tests.el | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index d13397274a..9efcf4a703 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -61,13 +61,16 @@ erc-ring-previous-command
   (with-current-buffer (get-buffer-create "*#fake*")
     (erc-mode)
     (insert "\n\n")
-    (setq erc-input-marker (make-marker) ; these are all local
-          erc-insert-marker (make-marker)
-          erc-send-completed-hook nil)
+    (should-not (local-variable-if-set-p 'erc-send-completed-hook))
+    (set (make-local-variable 'erc-send-completed-hook) nil) ; skip t (globals)
+    (setq erc-input-marker (make-marker)
+          erc-insert-marker (make-marker))
     (set-marker erc-insert-marker (point-max))
     (erc-display-prompt)
     (should (= (point) erc-input-marker))
-    (add-hook 'erc-pre-send-functions #'erc-add-to-input-ring nil t)
+    ;; Just in case erc-ring-mode is already on
+    (setq-local erc-pre-send-functions nil)
+    (add-hook 'erc-pre-send-functions #'erc-add-to-input-ring)
     ;;
     (cl-letf (((symbol-function 'erc-process-input-line)
                (lambda (&rest _)
-- 
2.31.1


[-- Attachment #3: 0002-Fix-a-couple-byte-compiler-warnings-in-erc.el.patch --]
[-- Type: text/x-patch, Size: 6083 bytes --]

From e898612de9e2df42c6a769fa88eb02eaeb8b0b78 Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <jp@neverwas.me>
Date: Wed, 21 Jul 2021 00:26:38 -0700
Subject: [PATCH 2/2] Fix a couple byte-compiler warnings in erc.el
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lisp/erc/erc.el (erc-lurker-maybe-trim): Prevent warning from
showing up in third-party code re library not loaded by autoloading
rx.el when needed.  Also make function do what it claims to. It now
only removes trailing chars typically appended automatically for
uniquifying purposes when a desired nick is already taken. Special
thanks to Mattias Engdegård for making this more
respectable. Bug#50005.

(erc-with-all-buffers-of-server): Mute byte compiler warning saying
return value unused. Leave possible optimizations for some future
person.
---
 lisp/erc/erc.el            | 25 ++++--------
 test/lisp/erc/erc-tests.el | 79 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 87 insertions(+), 17 deletions(-)

diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 73202016ba..ec3ed354b6 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -1732,20 +1732,11 @@ erc-with-all-buffers-of-server
 where PRED matches or in all buffers of the server process if PRED is
 nil."
   (declare (indent 1) (debug (form form body)))
-  ;; Make the evaluation have the correct order
-  (let ((pre (make-symbol "pre"))
-        (pro (make-symbol "pro")))
-    `(let* ((,pro ,process)
-            (,pre ,pred)
-            (res (mapcar (lambda (buffer)
-                           (with-current-buffer buffer
-                             ,@forms))
-                         (erc-buffer-list ,pre
-                                          ,pro))))
-       ;; Silence the byte-compiler by binding the result of mapcar to
-       ;; a variable.
-       (ignore res)
-       res)))
+  (macroexp-let2 nil pred pred
+    `(erc-buffer-filter (lambda ()
+                          (when (or (not ,pred) (funcall ,pred))
+                            ,@forms))
+                        ,process)))
 
 (define-obsolete-function-alias 'erc-iswitchb #'erc-switch-to-buffer "25.1")
 (defun erc--switch-to-buffer (&optional arg)
@@ -2583,9 +2574,9 @@ erc-lurker-maybe-trim
 Returns NICK unmodified unless `erc-lurker-trim-nicks' is
 non-nil."
   (if erc-lurker-trim-nicks
-      (replace-regexp-in-string
-       (regexp-opt-charset (string-to-list erc-lurker-ignore-chars))
-       "" nick)
+      (string-trim-right
+       nick (rx-to-string `(+ (in ,@(string-to-list
+                                     erc-lurker-ignore-chars)))))
     nick))
 
 (defcustom erc-lurker-hide-list nil
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 9efcf4a703..d1a1405999 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -47,6 +47,85 @@ erc--read-time-period
   (cl-letf (((symbol-function 'read-string) (lambda (&rest _) "1d")))
     (should (equal (erc--read-time-period "foo: ") 86400))))
 
+(ert-deftest erc-with-all-buffers-of-server ()
+  (let (proc-exnet
+        proc-onet
+        erc-kill-channel-hook erc-kill-server-hook erc-kill-buffer-hook)
+
+    (with-current-buffer (get-buffer-create "OtherNet")
+      (erc-mode)
+      (setq proc-onet (start-process "sleep" (current-buffer) "sleep" "1")
+            erc-server-process proc-onet
+            erc-network 'OtherNet)
+      (set-process-query-on-exit-flag erc-server-process nil))
+
+    (with-current-buffer (get-buffer-create "ExampleNet")
+      (erc-mode)
+      (setq proc-exnet (start-process "sleep" (current-buffer) "sleep" "1")
+            erc-server-process proc-exnet
+            erc-network 'ExampleNet)
+      (set-process-query-on-exit-flag erc-server-process nil))
+
+    (with-current-buffer (get-buffer-create "#foo")
+      (erc-mode)
+      (setq erc-server-process proc-exnet)
+      (setq erc-default-recipients '("#foo")))
+
+    (with-current-buffer (get-buffer-create "#spam")
+      (erc-mode)
+      (setq erc-server-process proc-onet)
+      (setq erc-default-recipients '("#spam")))
+
+    (with-current-buffer (get-buffer-create "#bar")
+      (erc-mode)
+      (setq erc-server-process proc-onet)
+      (setq erc-default-recipients '("#bar")))
+
+    (with-current-buffer (get-buffer-create "#baz")
+      (erc-mode)
+      (setq erc-server-process proc-exnet)
+      (setq erc-default-recipients '("#baz")))
+
+    (should (eq (get-buffer-process "ExampleNet") proc-exnet))
+    (erc-with-all-buffers-of-server (get-buffer-process "ExampleNet")
+      nil
+      (kill-buffer))
+
+    (should-not (get-buffer "ExampleNet"))
+    (should-not (get-buffer "#foo"))
+    (should-not (get-buffer "#baz"))
+    (should (get-buffer "OtherNet"))
+    (should (get-buffer "#bar"))
+    (should (get-buffer "#spam"))
+
+    (let* ((test (lambda () (not (string= (buffer-name) "#spam"))))
+           (calls 0)
+           (get-test (lambda () (cl-incf calls) test)))
+
+      (erc-with-all-buffers-of-server proc-onet
+        (funcall get-test)
+        (kill-buffer))
+
+      (should (= calls 1)))
+
+    (should-not (get-buffer "OtherNet"))
+    (should-not (get-buffer "#bar"))
+    (should (get-buffer "#spam"))
+    (kill-buffer "#spam")))
+
+(ert-deftest erc-lurker-maybe-trim ()
+  (let (erc-lurker-trim-nicks
+        (erc-lurker-ignore-chars "_`"))
+
+    (should (string= "nick`" (erc-lurker-maybe-trim "nick`")))
+
+    (setq erc-lurker-trim-nicks t)
+    (should (string= "nick" (erc-lurker-maybe-trim "nick`")))
+    (should (string= "ni`_ck" (erc-lurker-maybe-trim "ni`_ck__``")))
+
+    (setq erc-lurker-ignore-chars "_-`") ; set of chars, not character alts
+    (should (string= "nick" (erc-lurker-maybe-trim "nick-_`")))))
+
 (ert-deftest erc-ring-previous-command-base-case ()
   (ert-info ("Create ring when nonexistent and do nothing")
     (let (erc-input-ring
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* bug#50005: 28.0.50; silence a couple byte-compiler warnings in ERC
  2021-08-12 10:56   ` J.P.
@ 2021-08-12 11:52     ` Mattias Engdegård
  2021-08-12 13:35       ` J.P.
  0 siblings, 1 reply; 7+ messages in thread
From: Mattias Engdegård @ 2021-08-12 11:52 UTC (permalink / raw)
  To: J.P.; +Cc: Amin Bandali, 50005

12 aug. 2021 kl. 12.56 skrev J.P. <jp@neverwas.me>:

> Thanks, I spotted the weird double-quote mismatch thing earlier, but I
> guess I'm still missing something else?

The string made it look like backslash were a special character inside [...]. It isn't; only ^, ] and - are special, each with their own quirky rules. (Other regexp systems have different rules.)

> So, I take this to mean there's no problem with requiring (autoloading)
> rx.el (or regexp-opt.el), right?

Correct. Your original problem was the use of `regexp-opt-charset` which is not autoloaded (and somewhat of an internal function to regexp-opt.el, but that's debatable). Using plain `regexp-opt` is fine.
Most ordinary uses of rx will not even require rx.el to be loaded at runtime since the macros are expanded during compilation, but `rx-to-string` is a plain function, autoloaded.

> And I guess the `string-to-list' is necessary because
> 
>  (rx-to-string '(+ (in "abc")) t)
>   ⇒ "[a-c]+"
> 
> is still interpreted as a set of character alternatives, whereas
> 
>  (rx-to-string '(+ (in ?a ?- ?c)) t)
>   ⇒ "[ac-]+"
> 
> combines individual character args into just such a set.

If you meant (in "a-c") in your first example then yes, quite right -- the hyphen is special inside strings of the rx `in` construct, but it's not special as a character argument. No other characters are special.

> Do you use ERC, Mattias? If so, are you available to review more
> patches?

I'm afraid I rarely use it and know nothing about its innards so I'm probably not the right person to ask -- only came by to help out with some regexpy things. I have nothing clever to say about your other changes, sorry!

> I'm obviously quite ignorant in the ways of Emacs but am
> pushing hard to improve ERC. Some might say that's a recipe for
> embarrassment/disaster (though I'm pretty sure I already crossed that
> first bridge ages ago).

I'd say it's a good sign! Just dive in.

> So what do you say, can you help?

Wish I could but time probably doesn't permit, sorry. There are much more experienced hands about. Of course I'll be happy to answer specifics about parts that I happen to know something about.






^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#50005: 28.0.50; silence a couple byte-compiler warnings in ERC
  2021-08-12 11:52     ` Mattias Engdegård
@ 2021-08-12 13:35       ` J.P.
  0 siblings, 0 replies; 7+ messages in thread
From: J.P. @ 2021-08-12 13:35 UTC (permalink / raw)
  To: Mattias Engdegård; +Cc: Amin Bandali, 50005

Mattias Engdegård <mattiase@acm.org> writes:

> The string made it look like backslash were a special character inside
> [...]. It isn't;

Thanks, and sorry you had to explain that. Sad as it is, I'm fairly
certain I even read as much in the Info manual only moments before
defiling that doc string:

  You cannot use ‘\’ to escape these three characters, since ‘\’ is not
  special here.

> Most ordinary uses of rx will not even require rx.el to be loaded at
> runtime since the macros are expanded during compilation

Again, thanks. Although I should know this instinctively by now, I too
often forget it when deep in the weeds.

> If you meant (in "a-c") in your first example then yes, quite right

Um, yeah, sure, let's go with that! ;)

> Wish I could but time probably doesn't permit, sorry.

Darn, well I definitely appreciate your insights on this one and the
effort made relating them (frustrating as that might have been).

> Of course I'll be happy to answer specifics about parts that I happen
> to know something about.

You may live to regret those words. (Thanks again.)





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#50005: 28.0.50; silence a couple byte-compiler warnings in ERC
  2021-08-11 13:57 bug#50005: 28.0.50; silence a couple byte-compiler warnings in ERC J.P.
  2021-08-12  8:15 ` Mattias Engdegård
@ 2021-09-12 12:03 ` J.P.
  2021-09-16 13:25   ` Lars Ingebrigtsen
  1 sibling, 1 reply; 7+ messages in thread
From: J.P. @ 2021-09-12 12:03 UTC (permalink / raw)
  To: 50005

[-- Attachment #1: Type: text/plain, Size: 136 bytes --]

v3. Added a missing test dependency.

(Note: the first attachment just shows the changes from the last set and
is not itself a patch.)


[-- Attachment #2: 0000-v2-v3.diff --]
[-- Type: text/x-patch, Size: 2690 bytes --]

From 1b55dcb828093774ebbb83888901644a8c73a67d Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <jp@neverwas.me>
Date: Sun, 12 Sep 2021 02:41:39 -0700
Subject: [PATCH 0/2] *** SUBJECT HERE ***
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

*** BLURB HERE ***

F. Jason Park (2):
  Fix mistake in test for erc-ring-previous-command
  Fix a couple byte-compiler warnings in erc.el

 lisp/erc/erc.el            | 25 ++++-------
 test/lisp/erc/erc-tests.el | 91 ++++++++++++++++++++++++++++++++++++--
 2 files changed, 95 insertions(+), 21 deletions(-)

Range-diff:
-:  ---------- > 1:  d3cbfba5d6 Fix mistake in test for erc-ring-previous-command
1:  8a85439cc7 ! 2:  1b55dcb828 Fix a couple byte-compiler warnings in erc.el
    @@ Commit message
         Fix a couple byte-compiler warnings in erc.el
     
         * lisp/erc/erc.el (erc-lurker-maybe-trim): Prevent warning from
    -    showing up in third-party code re library not loaded by autoloading
    -    rx.el when needed.  Also make function do what it claims to. It now
    -    only removes trailing chars typically appended automatically for
    -    uniquifying purposes when a desired nick is already taken. Special
    -    thanks to Mattias Engdegård for making this more
    -    respectable. Bug#50005.
    +    showing up in third-party code using this function by autoloading
    +    rx.el when needed.  Remove trailing chars appended for uniquifying
    +    purposes when a nick is already taken. Special thanks to Mattias
    +    Engdegård for making this more respectable. Bug#50005.
     
         (erc-with-all-buffers-of-server): Mute byte compiler warning saying
    -    return value unused. Leave possible optimizations for some future
    -    person.
    +    return value unused. Leave optimizations for future contributors.
    +
    +    * test/lisp/erc/erc-tests.el: add tests for the above and require
    +    erc-networks.
     
      ## lisp/erc/erc.el ##
     @@ lisp/erc/erc.el: erc-with-all-buffers-of-server
    @@ lisp/erc/erc.el: erc-lurker-maybe-trim
      (defcustom erc-lurker-hide-list nil
     
      ## test/lisp/erc/erc-tests.el ##
    +@@
    + (require 'ert)
    + (require 'erc)
    + (require 'erc-ring)
    ++(require 'erc-networks)
    + 
    + (ert-deftest erc--read-time-period ()
    +   (cl-letf (((symbol-function 'read-string) (lambda (&rest _) "")))
     @@ test/lisp/erc/erc-tests.el: erc--read-time-period
        (cl-letf (((symbol-function 'read-string) (lambda (&rest _) "1d")))
          (should (equal (erc--read-time-period "foo: ") 86400))))
-- 
2.31.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0001-Fix-mistake-in-test-for-erc-ring-previous-command.patch --]
[-- Type: text/x-patch, Size: 1633 bytes --]

From d3cbfba5d6efe49aa25f7d7dc550e54a36e0d5a1 Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <jp@neverwas.me>
Date: Thu, 13 May 2021 02:27:08 -0700
Subject: [PATCH 1/2] Fix mistake in test for erc-ring-previous-command

* test/lisp/erc/erc-tests.el (erc-ring-previous-command):
The variable erc-send-completed-hook was previously set to nil
permanently, which would affect other tests.
---
 test/lisp/erc/erc-tests.el | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index d13397274a..9efcf4a703 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -61,13 +61,16 @@ erc-ring-previous-command
   (with-current-buffer (get-buffer-create "*#fake*")
     (erc-mode)
     (insert "\n\n")
-    (setq erc-input-marker (make-marker) ; these are all local
-          erc-insert-marker (make-marker)
-          erc-send-completed-hook nil)
+    (should-not (local-variable-if-set-p 'erc-send-completed-hook))
+    (set (make-local-variable 'erc-send-completed-hook) nil) ; skip t (globals)
+    (setq erc-input-marker (make-marker)
+          erc-insert-marker (make-marker))
     (set-marker erc-insert-marker (point-max))
     (erc-display-prompt)
     (should (= (point) erc-input-marker))
-    (add-hook 'erc-pre-send-functions #'erc-add-to-input-ring nil t)
+    ;; Just in case erc-ring-mode is already on
+    (setq-local erc-pre-send-functions nil)
+    (add-hook 'erc-pre-send-functions #'erc-add-to-input-ring)
     ;;
     (cl-letf (((symbol-function 'erc-process-input-line)
                (lambda (&rest _)
-- 
2.31.1


[-- Attachment #4: 0002-Fix-a-couple-byte-compiler-warnings-in-erc.el.patch --]
[-- Type: text/x-patch, Size: 6282 bytes --]

From 1b55dcb828093774ebbb83888901644a8c73a67d Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <jp@neverwas.me>
Date: Wed, 21 Jul 2021 00:26:38 -0700
Subject: [PATCH 2/2] Fix a couple byte-compiler warnings in erc.el
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lisp/erc/erc.el (erc-lurker-maybe-trim): Prevent warning from
showing up in third-party code using this function by autoloading
rx.el when needed.  Remove trailing chars appended for uniquifying
purposes when a nick is already taken. Special thanks to Mattias
Engdegård for making this more respectable. Bug#50005.

(erc-with-all-buffers-of-server): Mute byte compiler warning saying
return value unused. Leave optimizations for future contributors.

* test/lisp/erc/erc-tests.el: add tests for the above and require
erc-networks.
---
 lisp/erc/erc.el            | 25 ++++--------
 test/lisp/erc/erc-tests.el | 80 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 88 insertions(+), 17 deletions(-)

diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index e0fda41f8e..0c1db585b8 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -1732,20 +1732,11 @@ erc-with-all-buffers-of-server
 where PRED matches or in all buffers of the server process if PRED is
 nil."
   (declare (indent 1) (debug (form form body)))
-  ;; Make the evaluation have the correct order
-  (let ((pre (make-symbol "pre"))
-        (pro (make-symbol "pro")))
-    `(let* ((,pro ,process)
-            (,pre ,pred)
-            (res (mapcar (lambda (buffer)
-                           (with-current-buffer buffer
-                             ,@forms))
-                         (erc-buffer-list ,pre
-                                          ,pro))))
-       ;; Silence the byte-compiler by binding the result of mapcar to
-       ;; a variable.
-       (ignore res)
-       res)))
+  (macroexp-let2 nil pred pred
+    `(erc-buffer-filter (lambda ()
+                          (when (or (not ,pred) (funcall ,pred))
+                            ,@forms))
+                        ,process)))
 
 (define-obsolete-function-alias 'erc-iswitchb #'erc-switch-to-buffer "25.1")
 (defun erc--switch-to-buffer (&optional arg)
@@ -2583,9 +2574,9 @@ erc-lurker-maybe-trim
 Returns NICK unmodified unless `erc-lurker-trim-nicks' is
 non-nil."
   (if erc-lurker-trim-nicks
-      (replace-regexp-in-string
-       (regexp-opt-charset (string-to-list erc-lurker-ignore-chars))
-       "" nick)
+      (string-trim-right
+       nick (rx-to-string `(+ (in ,@(string-to-list
+                                     erc-lurker-ignore-chars)))))
     nick))
 
 (defcustom erc-lurker-hide-list nil
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 9efcf4a703..0533d04491 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -24,6 +24,7 @@
 (require 'ert)
 (require 'erc)
 (require 'erc-ring)
+(require 'erc-networks)
 
 (ert-deftest erc--read-time-period ()
   (cl-letf (((symbol-function 'read-string) (lambda (&rest _) "")))
@@ -47,6 +48,85 @@ erc--read-time-period
   (cl-letf (((symbol-function 'read-string) (lambda (&rest _) "1d")))
     (should (equal (erc--read-time-period "foo: ") 86400))))
 
+(ert-deftest erc-with-all-buffers-of-server ()
+  (let (proc-exnet
+        proc-onet
+        erc-kill-channel-hook erc-kill-server-hook erc-kill-buffer-hook)
+
+    (with-current-buffer (get-buffer-create "OtherNet")
+      (erc-mode)
+      (setq proc-onet (start-process "sleep" (current-buffer) "sleep" "1")
+            erc-server-process proc-onet
+            erc-network 'OtherNet)
+      (set-process-query-on-exit-flag erc-server-process nil))
+
+    (with-current-buffer (get-buffer-create "ExampleNet")
+      (erc-mode)
+      (setq proc-exnet (start-process "sleep" (current-buffer) "sleep" "1")
+            erc-server-process proc-exnet
+            erc-network 'ExampleNet)
+      (set-process-query-on-exit-flag erc-server-process nil))
+
+    (with-current-buffer (get-buffer-create "#foo")
+      (erc-mode)
+      (setq erc-server-process proc-exnet)
+      (setq erc-default-recipients '("#foo")))
+
+    (with-current-buffer (get-buffer-create "#spam")
+      (erc-mode)
+      (setq erc-server-process proc-onet)
+      (setq erc-default-recipients '("#spam")))
+
+    (with-current-buffer (get-buffer-create "#bar")
+      (erc-mode)
+      (setq erc-server-process proc-onet)
+      (setq erc-default-recipients '("#bar")))
+
+    (with-current-buffer (get-buffer-create "#baz")
+      (erc-mode)
+      (setq erc-server-process proc-exnet)
+      (setq erc-default-recipients '("#baz")))
+
+    (should (eq (get-buffer-process "ExampleNet") proc-exnet))
+    (erc-with-all-buffers-of-server (get-buffer-process "ExampleNet")
+      nil
+      (kill-buffer))
+
+    (should-not (get-buffer "ExampleNet"))
+    (should-not (get-buffer "#foo"))
+    (should-not (get-buffer "#baz"))
+    (should (get-buffer "OtherNet"))
+    (should (get-buffer "#bar"))
+    (should (get-buffer "#spam"))
+
+    (let* ((test (lambda () (not (string= (buffer-name) "#spam"))))
+           (calls 0)
+           (get-test (lambda () (cl-incf calls) test)))
+
+      (erc-with-all-buffers-of-server proc-onet
+        (funcall get-test)
+        (kill-buffer))
+
+      (should (= calls 1)))
+
+    (should-not (get-buffer "OtherNet"))
+    (should-not (get-buffer "#bar"))
+    (should (get-buffer "#spam"))
+    (kill-buffer "#spam")))
+
+(ert-deftest erc-lurker-maybe-trim ()
+  (let (erc-lurker-trim-nicks
+        (erc-lurker-ignore-chars "_`"))
+
+    (should (string= "nick`" (erc-lurker-maybe-trim "nick`")))
+
+    (setq erc-lurker-trim-nicks t)
+    (should (string= "nick" (erc-lurker-maybe-trim "nick`")))
+    (should (string= "ni`_ck" (erc-lurker-maybe-trim "ni`_ck__``")))
+
+    (setq erc-lurker-ignore-chars "_-`") ; set of chars, not character alts
+    (should (string= "nick" (erc-lurker-maybe-trim "nick-_`")))))
+
 (ert-deftest erc-ring-previous-command-base-case ()
   (ert-info ("Create ring when nonexistent and do nothing")
     (let (erc-input-ring
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* bug#50005: 28.0.50; silence a couple byte-compiler warnings in ERC
  2021-09-12 12:03 ` J.P.
@ 2021-09-16 13:25   ` Lars Ingebrigtsen
  0 siblings, 0 replies; 7+ messages in thread
From: Lars Ingebrigtsen @ 2021-09-16 13:25 UTC (permalink / raw)
  To: J.P.; +Cc: 50005

"J.P." <jp@neverwas.me> writes:

> v3. Added a missing test dependency.

Thanks; applied to Emacs 28.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-09-16 13:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-11 13:57 bug#50005: 28.0.50; silence a couple byte-compiler warnings in ERC J.P.
2021-08-12  8:15 ` Mattias Engdegård
2021-08-12 10:56   ` J.P.
2021-08-12 11:52     ` Mattias Engdegård
2021-08-12 13:35       ` J.P.
2021-09-12 12:03 ` J.P.
2021-09-16 13:25   ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).