unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "J.P." <jp@neverwas.me>
To: 50005@debbugs.gnu.org
Subject: bug#50005: 28.0.50; silence a couple byte-compiler warnings in ERC
Date: Sun, 12 Sep 2021 05:03:40 -0700	[thread overview]
Message-ID: <87fsuavw4j.fsf@neverwas.me> (raw)
In-Reply-To: <87v94cjd89.fsf@neverwas.me> (J. P.'s message of "Wed, 11 Aug 2021 06:57:26 -0700")

[-- 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


  parent reply	other threads:[~2021-09-12 12:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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. [this message]
2021-09-16 13:25   ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fsuavw4j.fsf@neverwas.me \
    --to=jp@neverwas.me \
    --cc=50005@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).