2020-08-05 10:27:40 +02:00
|
|
|
;;; erc-tests.el --- Tests for erc. -*- lexical-binding:t -*-
|
|
|
|
|
2023-01-01 05:31:12 -05:00
|
|
|
;; Copyright (C) 2020-2023 Free Software Foundation, Inc.
|
2020-08-05 10:27:40 +02:00
|
|
|
|
|
|
|
;; Author: Lars Ingebrigtsen <larsi@gnus.org>
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2022-03-13 22:39:36 -07:00
|
|
|
(require 'ert-x)
|
2020-08-05 10:27:40 +02:00
|
|
|
(require 'erc)
|
2021-02-27 05:35:40 +01:00
|
|
|
(require 'erc-ring)
|
2020-08-05 10:27:40 +02:00
|
|
|
|
|
|
|
(ert-deftest erc--read-time-period ()
|
|
|
|
(cl-letf (((symbol-function 'read-string) (lambda (&rest _) "")))
|
|
|
|
(should (equal (erc--read-time-period "foo: ") nil)))
|
|
|
|
|
|
|
|
(cl-letf (((symbol-function 'read-string) (lambda (&rest _) " ")))
|
|
|
|
(should (equal (erc--read-time-period "foo: ") nil)))
|
|
|
|
|
|
|
|
(cl-letf (((symbol-function 'read-string) (lambda (&rest _) " 432 ")))
|
|
|
|
(should (equal (erc--read-time-period "foo: ") 432)))
|
|
|
|
|
|
|
|
(cl-letf (((symbol-function 'read-string) (lambda (&rest _) "432")))
|
|
|
|
(should (equal (erc--read-time-period "foo: ") 432)))
|
|
|
|
|
|
|
|
(cl-letf (((symbol-function 'read-string) (lambda (&rest _) "1h")))
|
|
|
|
(should (equal (erc--read-time-period "foo: ") 3600)))
|
|
|
|
|
|
|
|
(cl-letf (((symbol-function 'read-string) (lambda (&rest _) "1h10s")))
|
|
|
|
(should (equal (erc--read-time-period "foo: ") 3610)))
|
|
|
|
|
|
|
|
(cl-letf (((symbol-function 'read-string) (lambda (&rest _) "1d")))
|
|
|
|
(should (equal (erc--read-time-period "foo: ") 86400))))
|
2021-02-27 05:35:40 +01:00
|
|
|
|
2021-09-16 15:25:18 +02:00
|
|
|
(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")))
|
|
|
|
|
2022-11-24 21:03:03 -08:00
|
|
|
(ert-deftest erc-with-server-buffer ()
|
|
|
|
(setq erc-away 1)
|
|
|
|
(erc-tests--set-fake-server-process "sleep" "1")
|
|
|
|
|
|
|
|
(let (calls)
|
|
|
|
(advice-add 'buffer-local-value :after (lambda (&rest r) (push r calls))
|
|
|
|
'((name . erc-with-server-buffer)))
|
|
|
|
|
|
|
|
(should (= 1 (erc-with-server-buffer erc-away)))
|
|
|
|
(should (equal (pop calls) (list 'erc-away (current-buffer))))
|
|
|
|
|
|
|
|
(should (= 1 (erc-with-server-buffer (ignore 'me) erc-away)))
|
|
|
|
(should-not calls)
|
|
|
|
|
|
|
|
(advice-remove 'buffer-local-value 'erc-with-server-buffer)))
|
|
|
|
|
2023-06-30 23:42:01 -07:00
|
|
|
(ert-deftest erc--with-dependent-type-match ()
|
|
|
|
(should (equal (macroexpand-1
|
|
|
|
'(erc--with-dependent-type-match (repeat face) erc-match))
|
2023-08-17 19:18:50 -07:00
|
|
|
'(backquote-list*
|
|
|
|
'repeat :match (lambda (w v)
|
|
|
|
(require 'erc-match)
|
|
|
|
(widget-editable-list-match w v))
|
|
|
|
'(face)))))
|
2023-06-30 23:42:01 -07:00
|
|
|
|
2022-04-05 17:45:00 -07:00
|
|
|
(defun erc-tests--send-prep ()
|
|
|
|
;; Caller should probably shadow `erc-insert-modify-hook' or
|
|
|
|
;; populate user tables for erc-button.
|
|
|
|
(erc-mode)
|
2023-01-23 20:48:24 -08:00
|
|
|
(erc--initialize-markers (point) nil)
|
2022-04-05 17:45:00 -07:00
|
|
|
(should (= (point) erc-input-marker)))
|
|
|
|
|
|
|
|
(defun erc-tests--set-fake-server-process (&rest args)
|
|
|
|
(setq erc-server-process
|
|
|
|
(apply #'start-process (car args) (current-buffer) args))
|
|
|
|
(set-process-query-on-exit-flag erc-server-process nil))
|
|
|
|
|
|
|
|
(ert-deftest erc-hide-prompt ()
|
|
|
|
(let (erc-kill-channel-hook erc-kill-server-hook erc-kill-buffer-hook)
|
|
|
|
|
|
|
|
(with-current-buffer (get-buffer-create "ServNet")
|
|
|
|
(erc-tests--send-prep)
|
|
|
|
(goto-char erc-insert-marker)
|
|
|
|
(should (looking-at-p (regexp-quote erc-prompt)))
|
|
|
|
(erc-tests--set-fake-server-process "sleep" "1")
|
|
|
|
(set-process-sentinel erc-server-process #'ignore)
|
|
|
|
(setq erc-network 'ServNet)
|
|
|
|
(set-process-query-on-exit-flag erc-server-process nil))
|
|
|
|
|
|
|
|
(with-current-buffer (get-buffer-create "#chan")
|
|
|
|
(erc-tests--send-prep)
|
|
|
|
(goto-char erc-insert-marker)
|
|
|
|
(should (looking-at-p (regexp-quote erc-prompt)))
|
|
|
|
(setq erc-server-process (buffer-local-value 'erc-server-process
|
|
|
|
(get-buffer "ServNet"))
|
2023-02-22 06:24:17 -08:00
|
|
|
erc--target (erc--target-from-string "#chan")))
|
2022-04-05 17:45:00 -07:00
|
|
|
|
|
|
|
(with-current-buffer (get-buffer-create "bob")
|
|
|
|
(erc-tests--send-prep)
|
|
|
|
(goto-char erc-insert-marker)
|
|
|
|
(should (looking-at-p (regexp-quote erc-prompt)))
|
|
|
|
(setq erc-server-process (buffer-local-value 'erc-server-process
|
|
|
|
(get-buffer "ServNet"))
|
2023-02-22 06:24:17 -08:00
|
|
|
erc--target (erc--target-from-string "bob")))
|
2022-04-05 17:45:00 -07:00
|
|
|
|
|
|
|
(ert-info ("Value: t (default)")
|
|
|
|
(should (eq erc-hide-prompt t))
|
|
|
|
(with-current-buffer "ServNet"
|
|
|
|
(should (= (point) erc-insert-marker))
|
|
|
|
(erc--hide-prompt erc-server-process)
|
|
|
|
(should (string= ">" (get-text-property (point) 'display))))
|
|
|
|
|
|
|
|
(with-current-buffer "#chan"
|
|
|
|
(goto-char erc-insert-marker)
|
|
|
|
(should (string= ">" (get-text-property (point) 'display)))
|
|
|
|
(should (memq #'erc--unhide-prompt-on-self-insert pre-command-hook))
|
|
|
|
(goto-char erc-input-marker)
|
|
|
|
(ert-simulate-command '(self-insert-command 1 ?/))
|
|
|
|
(goto-char erc-insert-marker)
|
|
|
|
(should-not (get-text-property (point) 'display))
|
|
|
|
(should-not (memq #'erc--unhide-prompt-on-self-insert
|
|
|
|
pre-command-hook)))
|
|
|
|
|
|
|
|
(with-current-buffer "bob"
|
|
|
|
(goto-char erc-insert-marker)
|
|
|
|
(should (string= ">" (get-text-property (point) 'display)))
|
|
|
|
(should (memq #'erc--unhide-prompt-on-self-insert pre-command-hook))
|
|
|
|
(goto-char erc-input-marker)
|
|
|
|
(ert-simulate-command '(self-insert-command 1 ?/))
|
|
|
|
(goto-char erc-insert-marker)
|
|
|
|
(should-not (get-text-property (point) 'display))
|
|
|
|
(should-not (memq #'erc--unhide-prompt-on-self-insert
|
|
|
|
pre-command-hook)))
|
|
|
|
|
|
|
|
(with-current-buffer "ServNet"
|
|
|
|
(should (get-text-property erc-insert-marker 'display))
|
|
|
|
(should (memq #'erc--unhide-prompt-on-self-insert pre-command-hook))
|
|
|
|
(erc--unhide-prompt)
|
|
|
|
(should-not (memq #'erc--unhide-prompt-on-self-insert
|
|
|
|
pre-command-hook))
|
|
|
|
(should-not (get-text-property erc-insert-marker 'display))))
|
|
|
|
|
|
|
|
(ert-info ("Value: server")
|
|
|
|
(setq erc-hide-prompt '(server))
|
|
|
|
(with-current-buffer "ServNet"
|
|
|
|
(erc--hide-prompt erc-server-process)
|
Make erc-fill-wrap work with left-sided stamps
* etc/ERC-NEWS: Remove all mention of option `erc-timestamp-align-to'
supporting a value of `margin', which has been abandoned. Do mention
leading white space before stamps now having stamp-related properties.
* lisp/erc/erc-backend.el (erc--reveal-prompt, erc--conceal-prompt):
New generic functions with default implementations factored out from
`erc--unhide-prompt' and `erc--hide-prompt'.
(erc--prompt-hidden-p): New internal predicate function.
(erc--unhide-prompt): Defer to `erc--reveal-prompt', and set
`erc-prompt' text property to t.
(erc--hide-prompt): Defer to `erc--conceal-prompt', and set
`erc-prompt' text property to `hidden'.
* lisp/erc/erc-compat.el (erc-compat--29-browse-url-irc): Don't
use `function-equal'.
* lisp/erc/erc-fill.el (erc-fill-wrap-margin-width,
erc-fill-wrap-margin-side): New options to control side and initial
width of `fill-wrap' margin.
(erc-fill--wrap-beginning-of-line): Fix bug involving non-string
valued `display' props.
(erc-fill-wrap-toggle-truncate-lines): New command to re-enable
`visual-line-mode' when toggling off `truncate-lines'.
(erc-fill-wrap-mode-map): Remap `toggle-truncate-lines' to
`erc-fill-wrap-toggle-truncate-lines'.
(erc-fill-wrap-mode, erc-fill-wrap-enable, erc-fill-wrap-disable):
Update doc string, persist a few local vars, and conditionally set
`erc-stamp--margin-left-p'. When deactivating, disable
`visual-line-mode' first.
(erc-fill--wrap-continued-message-p): Use `erc-speaker' instead of
heuristics when comparing nicks between consecutive messages.
(erc-fill-wrap-nudge): Update doc string and account for left-sided
stamps.
(erc-timestamp-offset): Add comment regarding conditional guard based
on function-valued option.
* lisp/erc/erc-stamp.el (erc-timestamp-use-align-to): Remove value
variant `margin', which was originally intended to be new in ERC 5.6.
This functionality was all but useless without the internal minor mode
`erc-stamp--display-margin-mode' active.
(erc-stamp-right-margin-width): Remove unused option new in 5.6.
(erc-stamp--display-margin-force): Remove unused function.
(erc-stamp--margin-width, erc-stamp--margin-left-p): New internal
variables.
(erc-stamp--init-margins-on-connect): New function for initializing
mode-managed margin after connecting.
(erc-stamp--adjust-right-margin, erc-stamp--adjust-margin): Rename
function to latter and accommodate left-hand stamps.
(erc-stamp--inherited-props): Move definition higher up in same file.
(erc-stamp--display-margin-mode): Update function name, and adjust
setup and teardown to accommodate left-handed stamps. Don't add
advice around `erc-insert-timestamp-function'.
(erc-stamp--last-prompt, erc-stamp--display-prompt-in-left-margin):
New function and helper var to convert a normal inserted prompt so
that it appears in the left margin.
(erc-stamp--refresh-left-margin-prompt): Helper for other modules to
quickly refresh prompt outside of insert hooks.
(erc--reveal-prompt, erc--conceal-prompt): New implementations for
when `erc-stamp--display-margin-mode' is active.
(erc-insert-timestamp-left): Convert to generic function and provide
implementation for `erc-stamp--display-margin-mode'.
(erc-stamp--omit-properties-on-folded-lines): New variable, an escape
hatch for propertizing white space before right-side stamps folded
over onto another line.
(erc-insert-timestamp-right): Don't expect `erc-timestamp-align-to' to
ever be the symbol `margin'. Move handling for that case to one
contingent on the internal minor mode `erc-stamp--display-margin-mode'
being active. Add text properties preceding stamps that occupy a line
by their lonesome. See related news entry for rationale. This is
arguably a breaking change.
* lisp/erc/erc.el (erc--refresh-prompt-hook): New hook variable for
modules to adjust prompt properties whenever it's refreshed.
(erc--refresh-prompt): Fix bug in which user-defined prompt functions
failed to hide when quitting in server buffers. Run new hook
`erc--refresh-prompt-hook'.
(erc-display-prompt): Add comment noting that the text property
`erc-prompt' now actually matters: it's t while a session is running
and `hidden' when disconnected.
* test/lisp/erc/erc-fill-tests.el (erc-fill--left-hand-stamps): New
test.
* test/lisp/erc/erc-stamp-tests.el
(erc-stamp-tests--use-align-to--nil,
erc-stamp-tests--use-align-to--t): New functions forged from old test
bodies to allow optionally asserting pre-5.6 behavior regarding
leading white space on right-hand stamps that exist on their own line.
(erc-timestamp-use-align-to--nil, erc-timestamp-use-align-to--t):
Parameterize with compatibility flag.
(erc-timestamp-use-align-to--margin,
erc-stamp--display-margin-mode--right): Rename test to latter.
* test/lisp/erc/erc-tests.el (erc-hide-prompt): Add some assertions
for new possible value of `erc-prompt' text property.
* test/lisp/erc/resources/fill/snapshots/stamps-left-01.eld: New test
data file. (Bug#60936)
2023-07-14 06:12:30 -07:00
|
|
|
(should (eq (get-text-property erc-insert-marker 'erc-prompt) 'hidden))
|
2022-04-05 17:45:00 -07:00
|
|
|
(should (string= ">" (get-text-property erc-insert-marker 'display))))
|
|
|
|
|
|
|
|
(with-current-buffer "#chan"
|
|
|
|
(should-not (get-text-property erc-insert-marker 'display)))
|
|
|
|
|
|
|
|
(with-current-buffer "bob"
|
|
|
|
(should-not (get-text-property erc-insert-marker 'display)))
|
|
|
|
|
|
|
|
(with-current-buffer "ServNet"
|
|
|
|
(erc--unhide-prompt)
|
Make erc-fill-wrap work with left-sided stamps
* etc/ERC-NEWS: Remove all mention of option `erc-timestamp-align-to'
supporting a value of `margin', which has been abandoned. Do mention
leading white space before stamps now having stamp-related properties.
* lisp/erc/erc-backend.el (erc--reveal-prompt, erc--conceal-prompt):
New generic functions with default implementations factored out from
`erc--unhide-prompt' and `erc--hide-prompt'.
(erc--prompt-hidden-p): New internal predicate function.
(erc--unhide-prompt): Defer to `erc--reveal-prompt', and set
`erc-prompt' text property to t.
(erc--hide-prompt): Defer to `erc--conceal-prompt', and set
`erc-prompt' text property to `hidden'.
* lisp/erc/erc-compat.el (erc-compat--29-browse-url-irc): Don't
use `function-equal'.
* lisp/erc/erc-fill.el (erc-fill-wrap-margin-width,
erc-fill-wrap-margin-side): New options to control side and initial
width of `fill-wrap' margin.
(erc-fill--wrap-beginning-of-line): Fix bug involving non-string
valued `display' props.
(erc-fill-wrap-toggle-truncate-lines): New command to re-enable
`visual-line-mode' when toggling off `truncate-lines'.
(erc-fill-wrap-mode-map): Remap `toggle-truncate-lines' to
`erc-fill-wrap-toggle-truncate-lines'.
(erc-fill-wrap-mode, erc-fill-wrap-enable, erc-fill-wrap-disable):
Update doc string, persist a few local vars, and conditionally set
`erc-stamp--margin-left-p'. When deactivating, disable
`visual-line-mode' first.
(erc-fill--wrap-continued-message-p): Use `erc-speaker' instead of
heuristics when comparing nicks between consecutive messages.
(erc-fill-wrap-nudge): Update doc string and account for left-sided
stamps.
(erc-timestamp-offset): Add comment regarding conditional guard based
on function-valued option.
* lisp/erc/erc-stamp.el (erc-timestamp-use-align-to): Remove value
variant `margin', which was originally intended to be new in ERC 5.6.
This functionality was all but useless without the internal minor mode
`erc-stamp--display-margin-mode' active.
(erc-stamp-right-margin-width): Remove unused option new in 5.6.
(erc-stamp--display-margin-force): Remove unused function.
(erc-stamp--margin-width, erc-stamp--margin-left-p): New internal
variables.
(erc-stamp--init-margins-on-connect): New function for initializing
mode-managed margin after connecting.
(erc-stamp--adjust-right-margin, erc-stamp--adjust-margin): Rename
function to latter and accommodate left-hand stamps.
(erc-stamp--inherited-props): Move definition higher up in same file.
(erc-stamp--display-margin-mode): Update function name, and adjust
setup and teardown to accommodate left-handed stamps. Don't add
advice around `erc-insert-timestamp-function'.
(erc-stamp--last-prompt, erc-stamp--display-prompt-in-left-margin):
New function and helper var to convert a normal inserted prompt so
that it appears in the left margin.
(erc-stamp--refresh-left-margin-prompt): Helper for other modules to
quickly refresh prompt outside of insert hooks.
(erc--reveal-prompt, erc--conceal-prompt): New implementations for
when `erc-stamp--display-margin-mode' is active.
(erc-insert-timestamp-left): Convert to generic function and provide
implementation for `erc-stamp--display-margin-mode'.
(erc-stamp--omit-properties-on-folded-lines): New variable, an escape
hatch for propertizing white space before right-side stamps folded
over onto another line.
(erc-insert-timestamp-right): Don't expect `erc-timestamp-align-to' to
ever be the symbol `margin'. Move handling for that case to one
contingent on the internal minor mode `erc-stamp--display-margin-mode'
being active. Add text properties preceding stamps that occupy a line
by their lonesome. See related news entry for rationale. This is
arguably a breaking change.
* lisp/erc/erc.el (erc--refresh-prompt-hook): New hook variable for
modules to adjust prompt properties whenever it's refreshed.
(erc--refresh-prompt): Fix bug in which user-defined prompt functions
failed to hide when quitting in server buffers. Run new hook
`erc--refresh-prompt-hook'.
(erc-display-prompt): Add comment noting that the text property
`erc-prompt' now actually matters: it's t while a session is running
and `hidden' when disconnected.
* test/lisp/erc/erc-fill-tests.el (erc-fill--left-hand-stamps): New
test.
* test/lisp/erc/erc-stamp-tests.el
(erc-stamp-tests--use-align-to--nil,
erc-stamp-tests--use-align-to--t): New functions forged from old test
bodies to allow optionally asserting pre-5.6 behavior regarding
leading white space on right-hand stamps that exist on their own line.
(erc-timestamp-use-align-to--nil, erc-timestamp-use-align-to--t):
Parameterize with compatibility flag.
(erc-timestamp-use-align-to--margin,
erc-stamp--display-margin-mode--right): Rename test to latter.
* test/lisp/erc/erc-tests.el (erc-hide-prompt): Add some assertions
for new possible value of `erc-prompt' text property.
* test/lisp/erc/resources/fill/snapshots/stamps-left-01.eld: New test
data file. (Bug#60936)
2023-07-14 06:12:30 -07:00
|
|
|
(should (eq (get-text-property erc-insert-marker 'erc-prompt) t))
|
2022-04-05 17:45:00 -07:00
|
|
|
(should-not (get-text-property erc-insert-marker 'display))))
|
|
|
|
|
|
|
|
(ert-info ("Value: channel")
|
|
|
|
(setq erc-hide-prompt '(channel))
|
|
|
|
(with-current-buffer "ServNet"
|
|
|
|
(erc--hide-prompt erc-server-process)
|
|
|
|
(should-not (get-text-property erc-insert-marker 'display)))
|
|
|
|
|
|
|
|
(with-current-buffer "bob"
|
|
|
|
(should-not (get-text-property erc-insert-marker 'display)))
|
|
|
|
|
|
|
|
(with-current-buffer "#chan"
|
|
|
|
(should (string= ">" (get-text-property erc-insert-marker 'display)))
|
Make erc-fill-wrap work with left-sided stamps
* etc/ERC-NEWS: Remove all mention of option `erc-timestamp-align-to'
supporting a value of `margin', which has been abandoned. Do mention
leading white space before stamps now having stamp-related properties.
* lisp/erc/erc-backend.el (erc--reveal-prompt, erc--conceal-prompt):
New generic functions with default implementations factored out from
`erc--unhide-prompt' and `erc--hide-prompt'.
(erc--prompt-hidden-p): New internal predicate function.
(erc--unhide-prompt): Defer to `erc--reveal-prompt', and set
`erc-prompt' text property to t.
(erc--hide-prompt): Defer to `erc--conceal-prompt', and set
`erc-prompt' text property to `hidden'.
* lisp/erc/erc-compat.el (erc-compat--29-browse-url-irc): Don't
use `function-equal'.
* lisp/erc/erc-fill.el (erc-fill-wrap-margin-width,
erc-fill-wrap-margin-side): New options to control side and initial
width of `fill-wrap' margin.
(erc-fill--wrap-beginning-of-line): Fix bug involving non-string
valued `display' props.
(erc-fill-wrap-toggle-truncate-lines): New command to re-enable
`visual-line-mode' when toggling off `truncate-lines'.
(erc-fill-wrap-mode-map): Remap `toggle-truncate-lines' to
`erc-fill-wrap-toggle-truncate-lines'.
(erc-fill-wrap-mode, erc-fill-wrap-enable, erc-fill-wrap-disable):
Update doc string, persist a few local vars, and conditionally set
`erc-stamp--margin-left-p'. When deactivating, disable
`visual-line-mode' first.
(erc-fill--wrap-continued-message-p): Use `erc-speaker' instead of
heuristics when comparing nicks between consecutive messages.
(erc-fill-wrap-nudge): Update doc string and account for left-sided
stamps.
(erc-timestamp-offset): Add comment regarding conditional guard based
on function-valued option.
* lisp/erc/erc-stamp.el (erc-timestamp-use-align-to): Remove value
variant `margin', which was originally intended to be new in ERC 5.6.
This functionality was all but useless without the internal minor mode
`erc-stamp--display-margin-mode' active.
(erc-stamp-right-margin-width): Remove unused option new in 5.6.
(erc-stamp--display-margin-force): Remove unused function.
(erc-stamp--margin-width, erc-stamp--margin-left-p): New internal
variables.
(erc-stamp--init-margins-on-connect): New function for initializing
mode-managed margin after connecting.
(erc-stamp--adjust-right-margin, erc-stamp--adjust-margin): Rename
function to latter and accommodate left-hand stamps.
(erc-stamp--inherited-props): Move definition higher up in same file.
(erc-stamp--display-margin-mode): Update function name, and adjust
setup and teardown to accommodate left-handed stamps. Don't add
advice around `erc-insert-timestamp-function'.
(erc-stamp--last-prompt, erc-stamp--display-prompt-in-left-margin):
New function and helper var to convert a normal inserted prompt so
that it appears in the left margin.
(erc-stamp--refresh-left-margin-prompt): Helper for other modules to
quickly refresh prompt outside of insert hooks.
(erc--reveal-prompt, erc--conceal-prompt): New implementations for
when `erc-stamp--display-margin-mode' is active.
(erc-insert-timestamp-left): Convert to generic function and provide
implementation for `erc-stamp--display-margin-mode'.
(erc-stamp--omit-properties-on-folded-lines): New variable, an escape
hatch for propertizing white space before right-side stamps folded
over onto another line.
(erc-insert-timestamp-right): Don't expect `erc-timestamp-align-to' to
ever be the symbol `margin'. Move handling for that case to one
contingent on the internal minor mode `erc-stamp--display-margin-mode'
being active. Add text properties preceding stamps that occupy a line
by their lonesome. See related news entry for rationale. This is
arguably a breaking change.
* lisp/erc/erc.el (erc--refresh-prompt-hook): New hook variable for
modules to adjust prompt properties whenever it's refreshed.
(erc--refresh-prompt): Fix bug in which user-defined prompt functions
failed to hide when quitting in server buffers. Run new hook
`erc--refresh-prompt-hook'.
(erc-display-prompt): Add comment noting that the text property
`erc-prompt' now actually matters: it's t while a session is running
and `hidden' when disconnected.
* test/lisp/erc/erc-fill-tests.el (erc-fill--left-hand-stamps): New
test.
* test/lisp/erc/erc-stamp-tests.el
(erc-stamp-tests--use-align-to--nil,
erc-stamp-tests--use-align-to--t): New functions forged from old test
bodies to allow optionally asserting pre-5.6 behavior regarding
leading white space on right-hand stamps that exist on their own line.
(erc-timestamp-use-align-to--nil, erc-timestamp-use-align-to--t):
Parameterize with compatibility flag.
(erc-timestamp-use-align-to--margin,
erc-stamp--display-margin-mode--right): Rename test to latter.
* test/lisp/erc/erc-tests.el (erc-hide-prompt): Add some assertions
for new possible value of `erc-prompt' text property.
* test/lisp/erc/resources/fill/snapshots/stamps-left-01.eld: New test
data file. (Bug#60936)
2023-07-14 06:12:30 -07:00
|
|
|
(should (eq (get-text-property erc-insert-marker 'erc-prompt) 'hidden))
|
2022-04-05 17:45:00 -07:00
|
|
|
(erc--unhide-prompt)
|
Make erc-fill-wrap work with left-sided stamps
* etc/ERC-NEWS: Remove all mention of option `erc-timestamp-align-to'
supporting a value of `margin', which has been abandoned. Do mention
leading white space before stamps now having stamp-related properties.
* lisp/erc/erc-backend.el (erc--reveal-prompt, erc--conceal-prompt):
New generic functions with default implementations factored out from
`erc--unhide-prompt' and `erc--hide-prompt'.
(erc--prompt-hidden-p): New internal predicate function.
(erc--unhide-prompt): Defer to `erc--reveal-prompt', and set
`erc-prompt' text property to t.
(erc--hide-prompt): Defer to `erc--conceal-prompt', and set
`erc-prompt' text property to `hidden'.
* lisp/erc/erc-compat.el (erc-compat--29-browse-url-irc): Don't
use `function-equal'.
* lisp/erc/erc-fill.el (erc-fill-wrap-margin-width,
erc-fill-wrap-margin-side): New options to control side and initial
width of `fill-wrap' margin.
(erc-fill--wrap-beginning-of-line): Fix bug involving non-string
valued `display' props.
(erc-fill-wrap-toggle-truncate-lines): New command to re-enable
`visual-line-mode' when toggling off `truncate-lines'.
(erc-fill-wrap-mode-map): Remap `toggle-truncate-lines' to
`erc-fill-wrap-toggle-truncate-lines'.
(erc-fill-wrap-mode, erc-fill-wrap-enable, erc-fill-wrap-disable):
Update doc string, persist a few local vars, and conditionally set
`erc-stamp--margin-left-p'. When deactivating, disable
`visual-line-mode' first.
(erc-fill--wrap-continued-message-p): Use `erc-speaker' instead of
heuristics when comparing nicks between consecutive messages.
(erc-fill-wrap-nudge): Update doc string and account for left-sided
stamps.
(erc-timestamp-offset): Add comment regarding conditional guard based
on function-valued option.
* lisp/erc/erc-stamp.el (erc-timestamp-use-align-to): Remove value
variant `margin', which was originally intended to be new in ERC 5.6.
This functionality was all but useless without the internal minor mode
`erc-stamp--display-margin-mode' active.
(erc-stamp-right-margin-width): Remove unused option new in 5.6.
(erc-stamp--display-margin-force): Remove unused function.
(erc-stamp--margin-width, erc-stamp--margin-left-p): New internal
variables.
(erc-stamp--init-margins-on-connect): New function for initializing
mode-managed margin after connecting.
(erc-stamp--adjust-right-margin, erc-stamp--adjust-margin): Rename
function to latter and accommodate left-hand stamps.
(erc-stamp--inherited-props): Move definition higher up in same file.
(erc-stamp--display-margin-mode): Update function name, and adjust
setup and teardown to accommodate left-handed stamps. Don't add
advice around `erc-insert-timestamp-function'.
(erc-stamp--last-prompt, erc-stamp--display-prompt-in-left-margin):
New function and helper var to convert a normal inserted prompt so
that it appears in the left margin.
(erc-stamp--refresh-left-margin-prompt): Helper for other modules to
quickly refresh prompt outside of insert hooks.
(erc--reveal-prompt, erc--conceal-prompt): New implementations for
when `erc-stamp--display-margin-mode' is active.
(erc-insert-timestamp-left): Convert to generic function and provide
implementation for `erc-stamp--display-margin-mode'.
(erc-stamp--omit-properties-on-folded-lines): New variable, an escape
hatch for propertizing white space before right-side stamps folded
over onto another line.
(erc-insert-timestamp-right): Don't expect `erc-timestamp-align-to' to
ever be the symbol `margin'. Move handling for that case to one
contingent on the internal minor mode `erc-stamp--display-margin-mode'
being active. Add text properties preceding stamps that occupy a line
by their lonesome. See related news entry for rationale. This is
arguably a breaking change.
* lisp/erc/erc.el (erc--refresh-prompt-hook): New hook variable for
modules to adjust prompt properties whenever it's refreshed.
(erc--refresh-prompt): Fix bug in which user-defined prompt functions
failed to hide when quitting in server buffers. Run new hook
`erc--refresh-prompt-hook'.
(erc-display-prompt): Add comment noting that the text property
`erc-prompt' now actually matters: it's t while a session is running
and `hidden' when disconnected.
* test/lisp/erc/erc-fill-tests.el (erc-fill--left-hand-stamps): New
test.
* test/lisp/erc/erc-stamp-tests.el
(erc-stamp-tests--use-align-to--nil,
erc-stamp-tests--use-align-to--t): New functions forged from old test
bodies to allow optionally asserting pre-5.6 behavior regarding
leading white space on right-hand stamps that exist on their own line.
(erc-timestamp-use-align-to--nil, erc-timestamp-use-align-to--t):
Parameterize with compatibility flag.
(erc-timestamp-use-align-to--margin,
erc-stamp--display-margin-mode--right): Rename test to latter.
* test/lisp/erc/erc-tests.el (erc-hide-prompt): Add some assertions
for new possible value of `erc-prompt' text property.
* test/lisp/erc/resources/fill/snapshots/stamps-left-01.eld: New test
data file. (Bug#60936)
2023-07-14 06:12:30 -07:00
|
|
|
(should (eq (get-text-property erc-insert-marker 'erc-prompt) t))
|
2022-04-05 17:45:00 -07:00
|
|
|
(should-not (get-text-property erc-insert-marker 'display))))
|
|
|
|
|
|
|
|
(ert-info ("Value: query")
|
|
|
|
(setq erc-hide-prompt '(query))
|
|
|
|
(with-current-buffer "ServNet"
|
|
|
|
(erc--hide-prompt erc-server-process)
|
|
|
|
(should-not (get-text-property erc-insert-marker 'display)))
|
|
|
|
|
|
|
|
(with-current-buffer "bob"
|
|
|
|
(should (string= ">" (get-text-property erc-insert-marker 'display)))
|
Make erc-fill-wrap work with left-sided stamps
* etc/ERC-NEWS: Remove all mention of option `erc-timestamp-align-to'
supporting a value of `margin', which has been abandoned. Do mention
leading white space before stamps now having stamp-related properties.
* lisp/erc/erc-backend.el (erc--reveal-prompt, erc--conceal-prompt):
New generic functions with default implementations factored out from
`erc--unhide-prompt' and `erc--hide-prompt'.
(erc--prompt-hidden-p): New internal predicate function.
(erc--unhide-prompt): Defer to `erc--reveal-prompt', and set
`erc-prompt' text property to t.
(erc--hide-prompt): Defer to `erc--conceal-prompt', and set
`erc-prompt' text property to `hidden'.
* lisp/erc/erc-compat.el (erc-compat--29-browse-url-irc): Don't
use `function-equal'.
* lisp/erc/erc-fill.el (erc-fill-wrap-margin-width,
erc-fill-wrap-margin-side): New options to control side and initial
width of `fill-wrap' margin.
(erc-fill--wrap-beginning-of-line): Fix bug involving non-string
valued `display' props.
(erc-fill-wrap-toggle-truncate-lines): New command to re-enable
`visual-line-mode' when toggling off `truncate-lines'.
(erc-fill-wrap-mode-map): Remap `toggle-truncate-lines' to
`erc-fill-wrap-toggle-truncate-lines'.
(erc-fill-wrap-mode, erc-fill-wrap-enable, erc-fill-wrap-disable):
Update doc string, persist a few local vars, and conditionally set
`erc-stamp--margin-left-p'. When deactivating, disable
`visual-line-mode' first.
(erc-fill--wrap-continued-message-p): Use `erc-speaker' instead of
heuristics when comparing nicks between consecutive messages.
(erc-fill-wrap-nudge): Update doc string and account for left-sided
stamps.
(erc-timestamp-offset): Add comment regarding conditional guard based
on function-valued option.
* lisp/erc/erc-stamp.el (erc-timestamp-use-align-to): Remove value
variant `margin', which was originally intended to be new in ERC 5.6.
This functionality was all but useless without the internal minor mode
`erc-stamp--display-margin-mode' active.
(erc-stamp-right-margin-width): Remove unused option new in 5.6.
(erc-stamp--display-margin-force): Remove unused function.
(erc-stamp--margin-width, erc-stamp--margin-left-p): New internal
variables.
(erc-stamp--init-margins-on-connect): New function for initializing
mode-managed margin after connecting.
(erc-stamp--adjust-right-margin, erc-stamp--adjust-margin): Rename
function to latter and accommodate left-hand stamps.
(erc-stamp--inherited-props): Move definition higher up in same file.
(erc-stamp--display-margin-mode): Update function name, and adjust
setup and teardown to accommodate left-handed stamps. Don't add
advice around `erc-insert-timestamp-function'.
(erc-stamp--last-prompt, erc-stamp--display-prompt-in-left-margin):
New function and helper var to convert a normal inserted prompt so
that it appears in the left margin.
(erc-stamp--refresh-left-margin-prompt): Helper for other modules to
quickly refresh prompt outside of insert hooks.
(erc--reveal-prompt, erc--conceal-prompt): New implementations for
when `erc-stamp--display-margin-mode' is active.
(erc-insert-timestamp-left): Convert to generic function and provide
implementation for `erc-stamp--display-margin-mode'.
(erc-stamp--omit-properties-on-folded-lines): New variable, an escape
hatch for propertizing white space before right-side stamps folded
over onto another line.
(erc-insert-timestamp-right): Don't expect `erc-timestamp-align-to' to
ever be the symbol `margin'. Move handling for that case to one
contingent on the internal minor mode `erc-stamp--display-margin-mode'
being active. Add text properties preceding stamps that occupy a line
by their lonesome. See related news entry for rationale. This is
arguably a breaking change.
* lisp/erc/erc.el (erc--refresh-prompt-hook): New hook variable for
modules to adjust prompt properties whenever it's refreshed.
(erc--refresh-prompt): Fix bug in which user-defined prompt functions
failed to hide when quitting in server buffers. Run new hook
`erc--refresh-prompt-hook'.
(erc-display-prompt): Add comment noting that the text property
`erc-prompt' now actually matters: it's t while a session is running
and `hidden' when disconnected.
* test/lisp/erc/erc-fill-tests.el (erc-fill--left-hand-stamps): New
test.
* test/lisp/erc/erc-stamp-tests.el
(erc-stamp-tests--use-align-to--nil,
erc-stamp-tests--use-align-to--t): New functions forged from old test
bodies to allow optionally asserting pre-5.6 behavior regarding
leading white space on right-hand stamps that exist on their own line.
(erc-timestamp-use-align-to--nil, erc-timestamp-use-align-to--t):
Parameterize with compatibility flag.
(erc-timestamp-use-align-to--margin,
erc-stamp--display-margin-mode--right): Rename test to latter.
* test/lisp/erc/erc-tests.el (erc-hide-prompt): Add some assertions
for new possible value of `erc-prompt' text property.
* test/lisp/erc/resources/fill/snapshots/stamps-left-01.eld: New test
data file. (Bug#60936)
2023-07-14 06:12:30 -07:00
|
|
|
(should (eq (get-text-property erc-insert-marker 'erc-prompt) 'hidden))
|
2022-04-05 17:45:00 -07:00
|
|
|
(erc--unhide-prompt)
|
Make erc-fill-wrap work with left-sided stamps
* etc/ERC-NEWS: Remove all mention of option `erc-timestamp-align-to'
supporting a value of `margin', which has been abandoned. Do mention
leading white space before stamps now having stamp-related properties.
* lisp/erc/erc-backend.el (erc--reveal-prompt, erc--conceal-prompt):
New generic functions with default implementations factored out from
`erc--unhide-prompt' and `erc--hide-prompt'.
(erc--prompt-hidden-p): New internal predicate function.
(erc--unhide-prompt): Defer to `erc--reveal-prompt', and set
`erc-prompt' text property to t.
(erc--hide-prompt): Defer to `erc--conceal-prompt', and set
`erc-prompt' text property to `hidden'.
* lisp/erc/erc-compat.el (erc-compat--29-browse-url-irc): Don't
use `function-equal'.
* lisp/erc/erc-fill.el (erc-fill-wrap-margin-width,
erc-fill-wrap-margin-side): New options to control side and initial
width of `fill-wrap' margin.
(erc-fill--wrap-beginning-of-line): Fix bug involving non-string
valued `display' props.
(erc-fill-wrap-toggle-truncate-lines): New command to re-enable
`visual-line-mode' when toggling off `truncate-lines'.
(erc-fill-wrap-mode-map): Remap `toggle-truncate-lines' to
`erc-fill-wrap-toggle-truncate-lines'.
(erc-fill-wrap-mode, erc-fill-wrap-enable, erc-fill-wrap-disable):
Update doc string, persist a few local vars, and conditionally set
`erc-stamp--margin-left-p'. When deactivating, disable
`visual-line-mode' first.
(erc-fill--wrap-continued-message-p): Use `erc-speaker' instead of
heuristics when comparing nicks between consecutive messages.
(erc-fill-wrap-nudge): Update doc string and account for left-sided
stamps.
(erc-timestamp-offset): Add comment regarding conditional guard based
on function-valued option.
* lisp/erc/erc-stamp.el (erc-timestamp-use-align-to): Remove value
variant `margin', which was originally intended to be new in ERC 5.6.
This functionality was all but useless without the internal minor mode
`erc-stamp--display-margin-mode' active.
(erc-stamp-right-margin-width): Remove unused option new in 5.6.
(erc-stamp--display-margin-force): Remove unused function.
(erc-stamp--margin-width, erc-stamp--margin-left-p): New internal
variables.
(erc-stamp--init-margins-on-connect): New function for initializing
mode-managed margin after connecting.
(erc-stamp--adjust-right-margin, erc-stamp--adjust-margin): Rename
function to latter and accommodate left-hand stamps.
(erc-stamp--inherited-props): Move definition higher up in same file.
(erc-stamp--display-margin-mode): Update function name, and adjust
setup and teardown to accommodate left-handed stamps. Don't add
advice around `erc-insert-timestamp-function'.
(erc-stamp--last-prompt, erc-stamp--display-prompt-in-left-margin):
New function and helper var to convert a normal inserted prompt so
that it appears in the left margin.
(erc-stamp--refresh-left-margin-prompt): Helper for other modules to
quickly refresh prompt outside of insert hooks.
(erc--reveal-prompt, erc--conceal-prompt): New implementations for
when `erc-stamp--display-margin-mode' is active.
(erc-insert-timestamp-left): Convert to generic function and provide
implementation for `erc-stamp--display-margin-mode'.
(erc-stamp--omit-properties-on-folded-lines): New variable, an escape
hatch for propertizing white space before right-side stamps folded
over onto another line.
(erc-insert-timestamp-right): Don't expect `erc-timestamp-align-to' to
ever be the symbol `margin'. Move handling for that case to one
contingent on the internal minor mode `erc-stamp--display-margin-mode'
being active. Add text properties preceding stamps that occupy a line
by their lonesome. See related news entry for rationale. This is
arguably a breaking change.
* lisp/erc/erc.el (erc--refresh-prompt-hook): New hook variable for
modules to adjust prompt properties whenever it's refreshed.
(erc--refresh-prompt): Fix bug in which user-defined prompt functions
failed to hide when quitting in server buffers. Run new hook
`erc--refresh-prompt-hook'.
(erc-display-prompt): Add comment noting that the text property
`erc-prompt' now actually matters: it's t while a session is running
and `hidden' when disconnected.
* test/lisp/erc/erc-fill-tests.el (erc-fill--left-hand-stamps): New
test.
* test/lisp/erc/erc-stamp-tests.el
(erc-stamp-tests--use-align-to--nil,
erc-stamp-tests--use-align-to--t): New functions forged from old test
bodies to allow optionally asserting pre-5.6 behavior regarding
leading white space on right-hand stamps that exist on their own line.
(erc-timestamp-use-align-to--nil, erc-timestamp-use-align-to--t):
Parameterize with compatibility flag.
(erc-timestamp-use-align-to--margin,
erc-stamp--display-margin-mode--right): Rename test to latter.
* test/lisp/erc/erc-tests.el (erc-hide-prompt): Add some assertions
for new possible value of `erc-prompt' text property.
* test/lisp/erc/resources/fill/snapshots/stamps-left-01.eld: New test
data file. (Bug#60936)
2023-07-14 06:12:30 -07:00
|
|
|
(should (eq (get-text-property erc-insert-marker 'erc-prompt) t))
|
2022-04-05 17:45:00 -07:00
|
|
|
(should-not (get-text-property erc-insert-marker 'display)))
|
|
|
|
|
|
|
|
(with-current-buffer "#chan"
|
|
|
|
(should-not (get-text-property erc-insert-marker 'display))))
|
|
|
|
|
|
|
|
(ert-info ("Value: nil")
|
|
|
|
(setq erc-hide-prompt nil)
|
|
|
|
(with-current-buffer "ServNet"
|
|
|
|
(erc--hide-prompt erc-server-process)
|
|
|
|
(should-not (get-text-property erc-insert-marker 'display)))
|
|
|
|
|
|
|
|
(with-current-buffer "bob"
|
|
|
|
(should-not (get-text-property erc-insert-marker 'display)))
|
|
|
|
|
|
|
|
(with-current-buffer "#chan"
|
|
|
|
(should-not (get-text-property erc-insert-marker 'display))
|
|
|
|
(erc--unhide-prompt) ; won't blow up when prompt already showing
|
|
|
|
(should-not (get-text-property erc-insert-marker 'display))))
|
|
|
|
|
|
|
|
(when noninteractive
|
|
|
|
(kill-buffer "#chan")
|
|
|
|
(kill-buffer "bob")
|
|
|
|
(kill-buffer "ServNet"))))
|
|
|
|
|
2023-05-18 23:47:27 -07:00
|
|
|
(ert-deftest erc--refresh-prompt ()
|
|
|
|
(let* ((counter 0)
|
|
|
|
(erc-prompt (lambda ()
|
|
|
|
(format "%s %d>"
|
|
|
|
(erc-format-target-and/or-network)
|
|
|
|
(cl-incf counter))))
|
|
|
|
erc-accidental-paste-threshold-seconds
|
|
|
|
erc-insert-modify-hook
|
Improve erc-warn-about-blank-lines behavior
* etc/ERC-NEWS: Mention more detailed feedback when option
`erc-warn-about-blank-lines' is non-nil.
* lisp/erc/erc-common.el (erc--input-split): Add `abortp' slot to
allow a premature exit while validating prompt input.
* lisp/erc/erc.el (erc-warn-about-blank-lines): Clarify meaning of
"blank lines" in doc string, and mention interaction with
companion option `erc-send-whitespace-lines'.
(erc-inhibit-multiline-input): Fix inaccurate description in doc
string.
(erc--input-review-functions): Move
`erc--discard-trailing-multiline-nulls' to end of list, after
`erc--run-input-validation-checks' so that the latter doesn't have to
resplit the original input string in order to issue feedback.
(erc--blank-in-multiline-input-p): Remove unused internal function
originally slated to be part of ERC 5.6.
(erc--check-prompt-input-for-something): New trivial validation
function to check if the input is empty.
(erc--count-blank-lines): New function that tallies up the number of
blank and whitespace-only lines in the current input. One downside of
this design is that this function's conclusions aren't shared with
`erc--discard-trailing-multiline-nulls', which must decide on its own
how many lines to strip.
(erc--check-prompt-explanation): New variable.
(erc--check-prompt-input-for-multiline-blanks): Rework significantly
to provide more informative messages and more sensible behavior for
common cases with respect to relevant option values.
(erc--check-prompt-input-functions): Add new validation function
`erc--check-prompt-for-something'.
(erc--run-input-validation-checks): Set `abortp' slot of
`erc--input-split' when hooks return a non-string, rather than
generate an unhelpful fallback message. Also print a message when
the variable `erc--check-prompt-explanation' is non-nil.
(erc-send-current-line): When the `abortp' slot of the current
`erc--input-split' object is non-nil, forgo normal input processing.
This fixes a regression in 5.6-git, which previously emitted an error
message when it should have just exited the command.
(erc--discard-trailing-multiline-nulls): Always run, regardless of
`erc-send-whitespace-lines', and leave a blank line behind when
stripping a message consisting of only blank lines.
(erc--run-send-hooks): Always run hooks and surrounding logic rather
than only when hooks are populated.
* test/lisp/erc/erc-tests.el (erc--refresh-prompt): Add assertion and
use default value for `erc--input-review-functions'.
(erc-ring-previous-command): Use default value for
`erc--input-review-functions' and ensure `erc-current-nick' does not
error.
(erc--blank-in-multiline-input-p): Remove obsolete test.
(erc--check-prompt-input-functions): Update expected message.
(erc--discard-trailing-multiline-nulls, erc--count-blank-lines): New
tests.
(erc-tests--check-prompt-input--expect,
erc-tests--check-prompt-input-messages): New helper variables.
(erc--check-prompt-input-for-multiline-blanks,
erc--check-prompt-input-for-multiline-blanks/explanations): New tests.
(erc-send-whitespace-lines): Expect hook-processing logic to pad empty
lines instead of deferring to `erc-send-input-line-function'.
(Bug#66073)
2023-09-15 06:08:55 -07:00
|
|
|
(erc--input-review-functions erc--input-review-functions)
|
2023-05-18 23:47:27 -07:00
|
|
|
erc-send-completed-hook)
|
|
|
|
|
|
|
|
(ert-info ("Server buffer")
|
|
|
|
(with-current-buffer (get-buffer-create "ServNet")
|
|
|
|
(erc-tests--send-prep)
|
|
|
|
(goto-char erc-insert-marker)
|
|
|
|
(should (looking-at-p "ServNet 3>"))
|
|
|
|
(erc-tests--set-fake-server-process "sleep" "1")
|
|
|
|
(set-process-sentinel erc-server-process #'ignore)
|
|
|
|
(setq erc-network 'ServNet
|
|
|
|
erc-server-current-nick "tester"
|
|
|
|
erc-networks--id (erc-networks--id-create nil)
|
|
|
|
erc-server-users (make-hash-table :test 'equal))
|
|
|
|
(set-process-query-on-exit-flag erc-server-process nil)
|
|
|
|
;; Incoming message redraws prompt
|
|
|
|
(erc-display-message nil 'notice nil "Welcome")
|
Don't insert prompt input before markers in ERC
* etc/ERC-NEWS: Update entry in 5.6 section announcing a persistent
prompt.
* lisp/erc/erc-dcc.el (erc-dcc-chat-setup): Use helper
`erc--initialize-markers' to set up prompt.
* lisp/erc/erc.el (erc--initialize-markers): Change
`erc-insert-marker' type to t. Do this to spare modules that want to
remember the current message location from resorting to workarounds,
like leaving a marker one char before the end of a message, which is
not foolproof.
(erc--refresh-prompt): Temporarily change type of `erc-insert-marker'
when inserting prompt.
(erc-display-line-1): Insert incoming message normally instead of
forcing before markers, thus respecting markers left by third parties.
Strictly speaking, this is a breaking change.
(erc-display-msg): Insert normally instead of calling
`insert-before-markers', which was a regression introduced by 05f6fdb9
"Preserve ERC prompt and its bounding markers".
* test/lisp/erc/erc-dcc-tests.el
(erc-dcc-tests--dcc-handle-ctcp-send,
erc-dcc-tests--erc-dcc-do-GET-command): Use helper to initialize
prompt and markers.
* test/lisp/erc/erc-networks-tests.el
(erc-networks--ensure-announced,
erc-networks--rename-server-buffer--existing--reuse,
erc-networks--rename-server-buffer--existing--noreuse,
erc-networks--rename-server-buffer--reconnecting,
erc-networks--rename-server-buffer--id,
erc-networks--rename-server-buffer--existing--live,
erc-networks--rename-server-buffer--local-match,
erc-networks--rename-server-buffer--local-nomatch): Use helper to
initialize prompt and bounding markers.
* test/lisp/erc/erc-stamp-tests.el (erc-stamp-tests--insert-right):
Use `erc--initialize-markers' for setting up prompt.
* test/lisp/erc/erc-tests.el (erc--refresh-prompt): Adjust assertions
for expected prompt content. (Bug#60936)
2023-06-10 00:17:44 -07:00
|
|
|
(should (looking-at-p (rx "*** Welcome")))
|
|
|
|
(forward-line)
|
2023-05-18 23:47:27 -07:00
|
|
|
(should (looking-at-p "ServNet 4>"))
|
|
|
|
;; Say something
|
Don't insert prompt input before markers in ERC
* etc/ERC-NEWS: Update entry in 5.6 section announcing a persistent
prompt.
* lisp/erc/erc-dcc.el (erc-dcc-chat-setup): Use helper
`erc--initialize-markers' to set up prompt.
* lisp/erc/erc.el (erc--initialize-markers): Change
`erc-insert-marker' type to t. Do this to spare modules that want to
remember the current message location from resorting to workarounds,
like leaving a marker one char before the end of a message, which is
not foolproof.
(erc--refresh-prompt): Temporarily change type of `erc-insert-marker'
when inserting prompt.
(erc-display-line-1): Insert incoming message normally instead of
forcing before markers, thus respecting markers left by third parties.
Strictly speaking, this is a breaking change.
(erc-display-msg): Insert normally instead of calling
`insert-before-markers', which was a regression introduced by 05f6fdb9
"Preserve ERC prompt and its bounding markers".
* test/lisp/erc/erc-dcc-tests.el
(erc-dcc-tests--dcc-handle-ctcp-send,
erc-dcc-tests--erc-dcc-do-GET-command): Use helper to initialize
prompt and markers.
* test/lisp/erc/erc-networks-tests.el
(erc-networks--ensure-announced,
erc-networks--rename-server-buffer--existing--reuse,
erc-networks--rename-server-buffer--existing--noreuse,
erc-networks--rename-server-buffer--reconnecting,
erc-networks--rename-server-buffer--id,
erc-networks--rename-server-buffer--existing--live,
erc-networks--rename-server-buffer--local-match,
erc-networks--rename-server-buffer--local-nomatch): Use helper to
initialize prompt and bounding markers.
* test/lisp/erc/erc-stamp-tests.el (erc-stamp-tests--insert-right):
Use `erc--initialize-markers' for setting up prompt.
* test/lisp/erc/erc-tests.el (erc--refresh-prompt): Adjust assertions
for expected prompt content. (Bug#60936)
2023-06-10 00:17:44 -07:00
|
|
|
(goto-char erc-input-marker)
|
|
|
|
(insert "Howdy")
|
|
|
|
(erc-send-current-line)
|
|
|
|
(save-excursion (forward-line -1)
|
2023-05-18 23:47:27 -07:00
|
|
|
(should (looking-at "No target"))
|
|
|
|
(forward-line -1)
|
|
|
|
(should (looking-at "<tester> Howdy")))
|
Don't insert prompt input before markers in ERC
* etc/ERC-NEWS: Update entry in 5.6 section announcing a persistent
prompt.
* lisp/erc/erc-dcc.el (erc-dcc-chat-setup): Use helper
`erc--initialize-markers' to set up prompt.
* lisp/erc/erc.el (erc--initialize-markers): Change
`erc-insert-marker' type to t. Do this to spare modules that want to
remember the current message location from resorting to workarounds,
like leaving a marker one char before the end of a message, which is
not foolproof.
(erc--refresh-prompt): Temporarily change type of `erc-insert-marker'
when inserting prompt.
(erc-display-line-1): Insert incoming message normally instead of
forcing before markers, thus respecting markers left by third parties.
Strictly speaking, this is a breaking change.
(erc-display-msg): Insert normally instead of calling
`insert-before-markers', which was a regression introduced by 05f6fdb9
"Preserve ERC prompt and its bounding markers".
* test/lisp/erc/erc-dcc-tests.el
(erc-dcc-tests--dcc-handle-ctcp-send,
erc-dcc-tests--erc-dcc-do-GET-command): Use helper to initialize
prompt and markers.
* test/lisp/erc/erc-networks-tests.el
(erc-networks--ensure-announced,
erc-networks--rename-server-buffer--existing--reuse,
erc-networks--rename-server-buffer--existing--noreuse,
erc-networks--rename-server-buffer--reconnecting,
erc-networks--rename-server-buffer--id,
erc-networks--rename-server-buffer--existing--live,
erc-networks--rename-server-buffer--local-match,
erc-networks--rename-server-buffer--local-nomatch): Use helper to
initialize prompt and bounding markers.
* test/lisp/erc/erc-stamp-tests.el (erc-stamp-tests--insert-right):
Use `erc--initialize-markers' for setting up prompt.
* test/lisp/erc/erc-tests.el (erc--refresh-prompt): Adjust assertions
for expected prompt content. (Bug#60936)
2023-06-10 00:17:44 -07:00
|
|
|
(should (looking-back "ServNet 6> "))
|
|
|
|
(should (= erc-input-marker (point)))
|
2023-05-18 23:47:27 -07:00
|
|
|
;; Space after prompt is unpropertized
|
|
|
|
(should (get-text-property (1- erc-input-marker) 'erc-prompt))
|
|
|
|
(should-not (get-text-property erc-input-marker 'erc-prompt))
|
|
|
|
;; No sign of old prompts
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-min))
|
|
|
|
(should-not (search-forward (rx (any "3-5") ">") nil t)))))
|
|
|
|
|
|
|
|
(ert-info ("Channel buffer")
|
|
|
|
(with-current-buffer (get-buffer-create "#chan")
|
|
|
|
(erc-tests--send-prep)
|
|
|
|
(goto-char erc-insert-marker)
|
|
|
|
(should (looking-at-p "#chan 9>"))
|
Don't insert prompt input before markers in ERC
* etc/ERC-NEWS: Update entry in 5.6 section announcing a persistent
prompt.
* lisp/erc/erc-dcc.el (erc-dcc-chat-setup): Use helper
`erc--initialize-markers' to set up prompt.
* lisp/erc/erc.el (erc--initialize-markers): Change
`erc-insert-marker' type to t. Do this to spare modules that want to
remember the current message location from resorting to workarounds,
like leaving a marker one char before the end of a message, which is
not foolproof.
(erc--refresh-prompt): Temporarily change type of `erc-insert-marker'
when inserting prompt.
(erc-display-line-1): Insert incoming message normally instead of
forcing before markers, thus respecting markers left by third parties.
Strictly speaking, this is a breaking change.
(erc-display-msg): Insert normally instead of calling
`insert-before-markers', which was a regression introduced by 05f6fdb9
"Preserve ERC prompt and its bounding markers".
* test/lisp/erc/erc-dcc-tests.el
(erc-dcc-tests--dcc-handle-ctcp-send,
erc-dcc-tests--erc-dcc-do-GET-command): Use helper to initialize
prompt and markers.
* test/lisp/erc/erc-networks-tests.el
(erc-networks--ensure-announced,
erc-networks--rename-server-buffer--existing--reuse,
erc-networks--rename-server-buffer--existing--noreuse,
erc-networks--rename-server-buffer--reconnecting,
erc-networks--rename-server-buffer--id,
erc-networks--rename-server-buffer--existing--live,
erc-networks--rename-server-buffer--local-match,
erc-networks--rename-server-buffer--local-nomatch): Use helper to
initialize prompt and bounding markers.
* test/lisp/erc/erc-stamp-tests.el (erc-stamp-tests--insert-right):
Use `erc--initialize-markers' for setting up prompt.
* test/lisp/erc/erc-tests.el (erc--refresh-prompt): Adjust assertions
for expected prompt content. (Bug#60936)
2023-06-10 00:17:44 -07:00
|
|
|
(goto-char erc-input-marker)
|
2023-05-18 23:47:27 -07:00
|
|
|
(setq erc-server-process (buffer-local-value 'erc-server-process
|
|
|
|
(get-buffer "ServNet"))
|
|
|
|
erc-networks--id (erc-with-server-buffer erc-networks--id)
|
|
|
|
erc--target (erc--target-from-string "#chan")
|
|
|
|
erc-default-recipients (list "#chan")
|
|
|
|
erc-channel-users (make-hash-table :test 'equal))
|
|
|
|
(erc-update-current-channel-member "alice" "alice")
|
|
|
|
(erc-update-current-channel-member "bob" "bob")
|
|
|
|
(erc-update-current-channel-member "tester" "tester")
|
|
|
|
(erc-display-message nil nil (current-buffer)
|
|
|
|
(erc-format-privmessage "alice" "Hi" nil t))
|
Don't insert prompt input before markers in ERC
* etc/ERC-NEWS: Update entry in 5.6 section announcing a persistent
prompt.
* lisp/erc/erc-dcc.el (erc-dcc-chat-setup): Use helper
`erc--initialize-markers' to set up prompt.
* lisp/erc/erc.el (erc--initialize-markers): Change
`erc-insert-marker' type to t. Do this to spare modules that want to
remember the current message location from resorting to workarounds,
like leaving a marker one char before the end of a message, which is
not foolproof.
(erc--refresh-prompt): Temporarily change type of `erc-insert-marker'
when inserting prompt.
(erc-display-line-1): Insert incoming message normally instead of
forcing before markers, thus respecting markers left by third parties.
Strictly speaking, this is a breaking change.
(erc-display-msg): Insert normally instead of calling
`insert-before-markers', which was a regression introduced by 05f6fdb9
"Preserve ERC prompt and its bounding markers".
* test/lisp/erc/erc-dcc-tests.el
(erc-dcc-tests--dcc-handle-ctcp-send,
erc-dcc-tests--erc-dcc-do-GET-command): Use helper to initialize
prompt and markers.
* test/lisp/erc/erc-networks-tests.el
(erc-networks--ensure-announced,
erc-networks--rename-server-buffer--existing--reuse,
erc-networks--rename-server-buffer--existing--noreuse,
erc-networks--rename-server-buffer--reconnecting,
erc-networks--rename-server-buffer--id,
erc-networks--rename-server-buffer--existing--live,
erc-networks--rename-server-buffer--local-match,
erc-networks--rename-server-buffer--local-nomatch): Use helper to
initialize prompt and bounding markers.
* test/lisp/erc/erc-stamp-tests.el (erc-stamp-tests--insert-right):
Use `erc--initialize-markers' for setting up prompt.
* test/lisp/erc/erc-tests.el (erc--refresh-prompt): Adjust assertions
for expected prompt content. (Bug#60936)
2023-06-10 00:17:44 -07:00
|
|
|
(should (looking-back "#chan@ServNet 10> "))
|
|
|
|
(goto-char erc-input-marker)
|
|
|
|
(insert "Howdy")
|
|
|
|
(erc-send-current-line)
|
|
|
|
(save-excursion (forward-line -1)
|
2023-05-18 23:47:27 -07:00
|
|
|
(should (looking-at "<tester> Howdy")))
|
Don't insert prompt input before markers in ERC
* etc/ERC-NEWS: Update entry in 5.6 section announcing a persistent
prompt.
* lisp/erc/erc-dcc.el (erc-dcc-chat-setup): Use helper
`erc--initialize-markers' to set up prompt.
* lisp/erc/erc.el (erc--initialize-markers): Change
`erc-insert-marker' type to t. Do this to spare modules that want to
remember the current message location from resorting to workarounds,
like leaving a marker one char before the end of a message, which is
not foolproof.
(erc--refresh-prompt): Temporarily change type of `erc-insert-marker'
when inserting prompt.
(erc-display-line-1): Insert incoming message normally instead of
forcing before markers, thus respecting markers left by third parties.
Strictly speaking, this is a breaking change.
(erc-display-msg): Insert normally instead of calling
`insert-before-markers', which was a regression introduced by 05f6fdb9
"Preserve ERC prompt and its bounding markers".
* test/lisp/erc/erc-dcc-tests.el
(erc-dcc-tests--dcc-handle-ctcp-send,
erc-dcc-tests--erc-dcc-do-GET-command): Use helper to initialize
prompt and markers.
* test/lisp/erc/erc-networks-tests.el
(erc-networks--ensure-announced,
erc-networks--rename-server-buffer--existing--reuse,
erc-networks--rename-server-buffer--existing--noreuse,
erc-networks--rename-server-buffer--reconnecting,
erc-networks--rename-server-buffer--id,
erc-networks--rename-server-buffer--existing--live,
erc-networks--rename-server-buffer--local-match,
erc-networks--rename-server-buffer--local-nomatch): Use helper to
initialize prompt and bounding markers.
* test/lisp/erc/erc-stamp-tests.el (erc-stamp-tests--insert-right):
Use `erc--initialize-markers' for setting up prompt.
* test/lisp/erc/erc-tests.el (erc--refresh-prompt): Adjust assertions
for expected prompt content. (Bug#60936)
2023-06-10 00:17:44 -07:00
|
|
|
(should (looking-back "#chan@ServNet 11> "))
|
|
|
|
(should (= (point) erc-input-marker))
|
|
|
|
(insert "/query bob")
|
|
|
|
(erc-send-current-line)
|
Improve erc-warn-about-blank-lines behavior
* etc/ERC-NEWS: Mention more detailed feedback when option
`erc-warn-about-blank-lines' is non-nil.
* lisp/erc/erc-common.el (erc--input-split): Add `abortp' slot to
allow a premature exit while validating prompt input.
* lisp/erc/erc.el (erc-warn-about-blank-lines): Clarify meaning of
"blank lines" in doc string, and mention interaction with
companion option `erc-send-whitespace-lines'.
(erc-inhibit-multiline-input): Fix inaccurate description in doc
string.
(erc--input-review-functions): Move
`erc--discard-trailing-multiline-nulls' to end of list, after
`erc--run-input-validation-checks' so that the latter doesn't have to
resplit the original input string in order to issue feedback.
(erc--blank-in-multiline-input-p): Remove unused internal function
originally slated to be part of ERC 5.6.
(erc--check-prompt-input-for-something): New trivial validation
function to check if the input is empty.
(erc--count-blank-lines): New function that tallies up the number of
blank and whitespace-only lines in the current input. One downside of
this design is that this function's conclusions aren't shared with
`erc--discard-trailing-multiline-nulls', which must decide on its own
how many lines to strip.
(erc--check-prompt-explanation): New variable.
(erc--check-prompt-input-for-multiline-blanks): Rework significantly
to provide more informative messages and more sensible behavior for
common cases with respect to relevant option values.
(erc--check-prompt-input-functions): Add new validation function
`erc--check-prompt-for-something'.
(erc--run-input-validation-checks): Set `abortp' slot of
`erc--input-split' when hooks return a non-string, rather than
generate an unhelpful fallback message. Also print a message when
the variable `erc--check-prompt-explanation' is non-nil.
(erc-send-current-line): When the `abortp' slot of the current
`erc--input-split' object is non-nil, forgo normal input processing.
This fixes a regression in 5.6-git, which previously emitted an error
message when it should have just exited the command.
(erc--discard-trailing-multiline-nulls): Always run, regardless of
`erc-send-whitespace-lines', and leave a blank line behind when
stripping a message consisting of only blank lines.
(erc--run-send-hooks): Always run hooks and surrounding logic rather
than only when hooks are populated.
* test/lisp/erc/erc-tests.el (erc--refresh-prompt): Add assertion and
use default value for `erc--input-review-functions'.
(erc-ring-previous-command): Use default value for
`erc--input-review-functions' and ensure `erc-current-nick' does not
error.
(erc--blank-in-multiline-input-p): Remove obsolete test.
(erc--check-prompt-input-functions): Update expected message.
(erc--discard-trailing-multiline-nulls, erc--count-blank-lines): New
tests.
(erc-tests--check-prompt-input--expect,
erc-tests--check-prompt-input-messages): New helper variables.
(erc--check-prompt-input-for-multiline-blanks,
erc--check-prompt-input-for-multiline-blanks/explanations): New tests.
(erc-send-whitespace-lines): Expect hook-processing logic to pad empty
lines instead of deferring to `erc-send-input-line-function'.
(Bug#66073)
2023-09-15 06:08:55 -07:00
|
|
|
;; Last command not inserted
|
|
|
|
(save-excursion (forward-line -1)
|
|
|
|
(should (looking-at "<tester> Howdy")))
|
2023-05-18 23:47:27 -07:00
|
|
|
;; Query does not redraw (nor /help, only message input)
|
Don't insert prompt input before markers in ERC
* etc/ERC-NEWS: Update entry in 5.6 section announcing a persistent
prompt.
* lisp/erc/erc-dcc.el (erc-dcc-chat-setup): Use helper
`erc--initialize-markers' to set up prompt.
* lisp/erc/erc.el (erc--initialize-markers): Change
`erc-insert-marker' type to t. Do this to spare modules that want to
remember the current message location from resorting to workarounds,
like leaving a marker one char before the end of a message, which is
not foolproof.
(erc--refresh-prompt): Temporarily change type of `erc-insert-marker'
when inserting prompt.
(erc-display-line-1): Insert incoming message normally instead of
forcing before markers, thus respecting markers left by third parties.
Strictly speaking, this is a breaking change.
(erc-display-msg): Insert normally instead of calling
`insert-before-markers', which was a regression introduced by 05f6fdb9
"Preserve ERC prompt and its bounding markers".
* test/lisp/erc/erc-dcc-tests.el
(erc-dcc-tests--dcc-handle-ctcp-send,
erc-dcc-tests--erc-dcc-do-GET-command): Use helper to initialize
prompt and markers.
* test/lisp/erc/erc-networks-tests.el
(erc-networks--ensure-announced,
erc-networks--rename-server-buffer--existing--reuse,
erc-networks--rename-server-buffer--existing--noreuse,
erc-networks--rename-server-buffer--reconnecting,
erc-networks--rename-server-buffer--id,
erc-networks--rename-server-buffer--existing--live,
erc-networks--rename-server-buffer--local-match,
erc-networks--rename-server-buffer--local-nomatch): Use helper to
initialize prompt and bounding markers.
* test/lisp/erc/erc-stamp-tests.el (erc-stamp-tests--insert-right):
Use `erc--initialize-markers' for setting up prompt.
* test/lisp/erc/erc-tests.el (erc--refresh-prompt): Adjust assertions
for expected prompt content. (Bug#60936)
2023-06-10 00:17:44 -07:00
|
|
|
(should (looking-back "#chan@ServNet 11> "))
|
2023-05-18 23:47:27 -07:00
|
|
|
;; No sign of old prompts
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-min))
|
|
|
|
(should-not (search-forward (rx (or "9" "10") ">") nil t)))))
|
|
|
|
|
|
|
|
(ert-info ("Query buffer")
|
|
|
|
(with-current-buffer (get-buffer "bob")
|
|
|
|
(goto-char erc-insert-marker)
|
|
|
|
(should (looking-at-p "bob@ServNet 14>"))
|
Don't insert prompt input before markers in ERC
* etc/ERC-NEWS: Update entry in 5.6 section announcing a persistent
prompt.
* lisp/erc/erc-dcc.el (erc-dcc-chat-setup): Use helper
`erc--initialize-markers' to set up prompt.
* lisp/erc/erc.el (erc--initialize-markers): Change
`erc-insert-marker' type to t. Do this to spare modules that want to
remember the current message location from resorting to workarounds,
like leaving a marker one char before the end of a message, which is
not foolproof.
(erc--refresh-prompt): Temporarily change type of `erc-insert-marker'
when inserting prompt.
(erc-display-line-1): Insert incoming message normally instead of
forcing before markers, thus respecting markers left by third parties.
Strictly speaking, this is a breaking change.
(erc-display-msg): Insert normally instead of calling
`insert-before-markers', which was a regression introduced by 05f6fdb9
"Preserve ERC prompt and its bounding markers".
* test/lisp/erc/erc-dcc-tests.el
(erc-dcc-tests--dcc-handle-ctcp-send,
erc-dcc-tests--erc-dcc-do-GET-command): Use helper to initialize
prompt and markers.
* test/lisp/erc/erc-networks-tests.el
(erc-networks--ensure-announced,
erc-networks--rename-server-buffer--existing--reuse,
erc-networks--rename-server-buffer--existing--noreuse,
erc-networks--rename-server-buffer--reconnecting,
erc-networks--rename-server-buffer--id,
erc-networks--rename-server-buffer--existing--live,
erc-networks--rename-server-buffer--local-match,
erc-networks--rename-server-buffer--local-nomatch): Use helper to
initialize prompt and bounding markers.
* test/lisp/erc/erc-stamp-tests.el (erc-stamp-tests--insert-right):
Use `erc--initialize-markers' for setting up prompt.
* test/lisp/erc/erc-tests.el (erc--refresh-prompt): Adjust assertions
for expected prompt content. (Bug#60936)
2023-06-10 00:17:44 -07:00
|
|
|
(goto-char erc-input-marker)
|
2023-05-18 23:47:27 -07:00
|
|
|
(erc-display-message nil nil (current-buffer)
|
|
|
|
(erc-format-privmessage "bob" "Hi" nil t))
|
Don't insert prompt input before markers in ERC
* etc/ERC-NEWS: Update entry in 5.6 section announcing a persistent
prompt.
* lisp/erc/erc-dcc.el (erc-dcc-chat-setup): Use helper
`erc--initialize-markers' to set up prompt.
* lisp/erc/erc.el (erc--initialize-markers): Change
`erc-insert-marker' type to t. Do this to spare modules that want to
remember the current message location from resorting to workarounds,
like leaving a marker one char before the end of a message, which is
not foolproof.
(erc--refresh-prompt): Temporarily change type of `erc-insert-marker'
when inserting prompt.
(erc-display-line-1): Insert incoming message normally instead of
forcing before markers, thus respecting markers left by third parties.
Strictly speaking, this is a breaking change.
(erc-display-msg): Insert normally instead of calling
`insert-before-markers', which was a regression introduced by 05f6fdb9
"Preserve ERC prompt and its bounding markers".
* test/lisp/erc/erc-dcc-tests.el
(erc-dcc-tests--dcc-handle-ctcp-send,
erc-dcc-tests--erc-dcc-do-GET-command): Use helper to initialize
prompt and markers.
* test/lisp/erc/erc-networks-tests.el
(erc-networks--ensure-announced,
erc-networks--rename-server-buffer--existing--reuse,
erc-networks--rename-server-buffer--existing--noreuse,
erc-networks--rename-server-buffer--reconnecting,
erc-networks--rename-server-buffer--id,
erc-networks--rename-server-buffer--existing--live,
erc-networks--rename-server-buffer--local-match,
erc-networks--rename-server-buffer--local-nomatch): Use helper to
initialize prompt and bounding markers.
* test/lisp/erc/erc-stamp-tests.el (erc-stamp-tests--insert-right):
Use `erc--initialize-markers' for setting up prompt.
* test/lisp/erc/erc-tests.el (erc--refresh-prompt): Adjust assertions
for expected prompt content. (Bug#60936)
2023-06-10 00:17:44 -07:00
|
|
|
(should (looking-back "bob@ServNet 15> "))
|
|
|
|
(goto-char erc-input-marker)
|
|
|
|
(insert "Howdy")
|
|
|
|
(erc-send-current-line)
|
|
|
|
(save-excursion (forward-line -1)
|
2023-05-18 23:47:27 -07:00
|
|
|
(should (looking-at "<tester> Howdy")))
|
Don't insert prompt input before markers in ERC
* etc/ERC-NEWS: Update entry in 5.6 section announcing a persistent
prompt.
* lisp/erc/erc-dcc.el (erc-dcc-chat-setup): Use helper
`erc--initialize-markers' to set up prompt.
* lisp/erc/erc.el (erc--initialize-markers): Change
`erc-insert-marker' type to t. Do this to spare modules that want to
remember the current message location from resorting to workarounds,
like leaving a marker one char before the end of a message, which is
not foolproof.
(erc--refresh-prompt): Temporarily change type of `erc-insert-marker'
when inserting prompt.
(erc-display-line-1): Insert incoming message normally instead of
forcing before markers, thus respecting markers left by third parties.
Strictly speaking, this is a breaking change.
(erc-display-msg): Insert normally instead of calling
`insert-before-markers', which was a regression introduced by 05f6fdb9
"Preserve ERC prompt and its bounding markers".
* test/lisp/erc/erc-dcc-tests.el
(erc-dcc-tests--dcc-handle-ctcp-send,
erc-dcc-tests--erc-dcc-do-GET-command): Use helper to initialize
prompt and markers.
* test/lisp/erc/erc-networks-tests.el
(erc-networks--ensure-announced,
erc-networks--rename-server-buffer--existing--reuse,
erc-networks--rename-server-buffer--existing--noreuse,
erc-networks--rename-server-buffer--reconnecting,
erc-networks--rename-server-buffer--id,
erc-networks--rename-server-buffer--existing--live,
erc-networks--rename-server-buffer--local-match,
erc-networks--rename-server-buffer--local-nomatch): Use helper to
initialize prompt and bounding markers.
* test/lisp/erc/erc-stamp-tests.el (erc-stamp-tests--insert-right):
Use `erc--initialize-markers' for setting up prompt.
* test/lisp/erc/erc-tests.el (erc--refresh-prompt): Adjust assertions
for expected prompt content. (Bug#60936)
2023-06-10 00:17:44 -07:00
|
|
|
(should (looking-back "bob@ServNet 16> "))
|
2023-05-18 23:47:27 -07:00
|
|
|
;; No sign of old prompts
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-min))
|
|
|
|
(should-not (search-forward (rx (or "14" "15") ">") nil t)))))
|
|
|
|
|
|
|
|
(when noninteractive
|
|
|
|
(kill-buffer "#chan")
|
|
|
|
(kill-buffer "bob")
|
|
|
|
(kill-buffer "ServNet"))))
|
|
|
|
|
2023-01-23 20:48:24 -08:00
|
|
|
(ert-deftest erc--initialize-markers ()
|
|
|
|
(let ((proc (start-process "true" (current-buffer) "true"))
|
|
|
|
erc-modules
|
|
|
|
erc-connect-pre-hook
|
|
|
|
erc-insert-modify-hook
|
|
|
|
erc-kill-channel-hook erc-kill-server-hook erc-kill-buffer-hook)
|
|
|
|
(set-process-query-on-exit-flag proc nil)
|
|
|
|
(erc-mode)
|
|
|
|
(setq erc-server-process proc
|
|
|
|
erc-networks--id (erc-networks--id-create 'foonet))
|
|
|
|
(erc-open "localhost" 6667 "tester" "Tester" nil
|
|
|
|
"fake" nil "#chan" proc nil "user" nil)
|
|
|
|
(with-current-buffer (should (get-buffer "#chan"))
|
|
|
|
(should (= ?\n (char-after 1)))
|
|
|
|
(should (= ?E (char-after erc-insert-marker)))
|
|
|
|
(should (= 3 (marker-position erc-insert-marker)))
|
|
|
|
(should (= 8 (marker-position erc-input-marker)))
|
|
|
|
(should (= 8 (point-max)))
|
|
|
|
(should (= 8 (point)))
|
|
|
|
;; These prompt properties are a continual source of confusion.
|
|
|
|
;; Including the literal defaults here can hopefully serve as a
|
|
|
|
;; quick reference for anyone operating in that area.
|
|
|
|
(should (equal (buffer-string)
|
|
|
|
#("\n\nERC> "
|
|
|
|
2 6 ( font-lock-face erc-prompt-face
|
|
|
|
rear-nonsticky t
|
|
|
|
erc-prompt t
|
|
|
|
field erc-prompt
|
|
|
|
front-sticky t
|
|
|
|
read-only t)
|
|
|
|
6 7 ( rear-nonsticky t
|
|
|
|
erc-prompt t
|
|
|
|
field erc-prompt
|
|
|
|
front-sticky t
|
|
|
|
read-only t))))
|
|
|
|
|
|
|
|
;; Simulate some activity by inserting some text before and
|
|
|
|
;; after the prompt (multiline).
|
|
|
|
(erc-display-error-notice nil "Welcome")
|
|
|
|
(goto-char (point-max))
|
|
|
|
(insert "Hello\nWorld")
|
|
|
|
(goto-char 3)
|
|
|
|
(should (looking-at-p (regexp-quote "*** Welcome"))))
|
|
|
|
|
|
|
|
(ert-info ("Reconnect")
|
Allow custom display-buffer actions in ERC
* doc/misc/erc.texi: Add new section under "Integrations" chapter
describing `display-buffer' Custom function choice for ERC's many
buffer-display options.
* etc/ERC-NEWS: Mention new function variant for all buffer-display
options.
* lisp/erc/erc-backend.el: Add forward declaration for
`erc--called-as-input-p' and `erc--display-context'.
(erc--server-reconnect-display-timer,
erc--server-last-reconnect-display-reset): Use new name for option
`erc-reconnect-display', now `erc-auto-reconnect-display'.
(erc--server-determine-join-display-context): New generic function to
determine value of `erc--display-context' during JOINs.
(erc-server-JOIN, erc-server-PRIVMSG): Set `erc--display-context' to a
symbol for the handler's IRC command, like `JOIN', for the benefit of
custom `display-buffer'-like functions running in `erc-setup-buffer'.
(erc-server-471, erc-server-471-functions, erc-server-473,
erc-server-473-functions): New handlers for JOIN rejections. Also
remove 471 and 473 from comment at bottom of file.
(erc-server-475): Bind `erc--called-as-input-p' so that `erc-cmd-JOIN'
sets `erc-interactive-display' context.
* lisp/erc/erc-join.el (erc-autojoin-mode, erc-autojoin-enable,
erc-autojoin-disable): Kill local variable
`erc-join--requested-channels'. Add and remove
`erc-join--remove-requested-channels' to/from various server-handler
hooks for JOIN rejection numerics.
(erc-join--requested-channels): New local variable to remember
channels we've attempted to JOIN this session that haven't yet been
confirmed by the server.
(erc-join--remove-requested-channel): New JOIN rejection handler to
stop tracking channel in `erc-join--requested-channels'.
(erc--server-determine-join-display-context): module-specific
implementation of generic function for `erc-autojoin-mode'.
(erc-autojoin--join): Remember channels slated for JOIN'ing.
* lisp/erc/erc.el (erc--buffer-display-choices): New helper constant
for defining common `:type' for all buffer-display options.
(erc-buffer-display, erc-interactive-display,
erc-auto-reconnect-display, erc-receive-query-display): Use helper
`erc--buffer-display-choices' for defining `:type', which
includes a new choice for a `display-buffer'-like function.
(erc-reconnect-display, erc-auto-reconnect-display): Alias former to
latter, now the preferred name.
(erc-reconnect-timeout, erc-auto-reconnect-timeout): Change name from
former to latter. This option is new in ERC 5.6.
(erc-reconnect-display-server-buffers): New option.
(erc-buffer-do): Revise doc string.
(erc--display-context): New variable, an alist of "context tokens" to
be forwarded as the "action alist" to `erc-buffer-display' functions.
(erc-skip-displaying-selected-window-buffer): New variable, deprecated
at birth, to act as an escape hatch for folks who don't want to skip
the displaying of buffers already showing in the selected window.
(erc--display-buffer-overriding-action): Local variable allowing
modules to influence the displaying of new ERC buffers independently
of user options.
(erc-setup-buffer): Do nothing when the selected window already shows
current buffer unless user has provided a custom display function.
Accommodate new Custom choice function values, like `display-buffer'
and `pop-to-buffer'.
(erc-open): Run `erc-setup-buffer' when option
`erc-reconnect-display-server-buffers' is non-nil, even for existing
server buffers. Bind `display-buffer-overriding-action' to the value
of `erc--display-buffer-overriding-action' around calls to
`erc-setup-buffer'.
(erc-select-read-args): Add `erc--display-context' to environment.
(erc, erc-tls): Bind `erc--display-context' around calls to
`erc-select-read-args' and main body.
(erc-cmd-JOIN, erc-cmd-QUERY, erc--cmd-reconnect, erc-handle-irc-url):
Add item for `erc-interactive-display' to `erc--display-context'.
(erc-connection-established): Update name of
`erc-reconnect-display-timeout' to
`erc-auto-reconnect-display-timeout'.
(erc-message-english-s471, erc-message-english-s473): New variables,
format templates for JOIN rejection messages.
* test/lisp/erc/erc-scenarios-base-buffer-display.el
(erc-scenarios-base-buffer-display--defwin-recbury-intbuf,
erc-scenarios-base-buffer-display--defwino-recbury-intbuf,
erc-scenarios-base-buffer-display--count-reset-timeout): Use preferred
name `erc-auto-reconnect-display' for `erc-reconnect-display'.
* test/lisp/erc/erc-scenarios-join-display-context.el: New file.
* test/lisp/erc/erc-tests.el (erc--initialize-markers): Fix
unrealistic call to `erc-open'.
(erc-setup-buffer--custom-action): New test.
(erc-select-read-args, erc-tls, erc--interactive, erc-server-select):
Expect new environment binding for `erc--display-context'.
* test/lisp/erc/resources/join/buffer-display/mode-context.eld: New
file. (Bug#62833)
2023-05-30 23:27:12 -07:00
|
|
|
(with-current-buffer (erc-server-buffer)
|
|
|
|
(erc-open "localhost" 6667 "tester" "Tester" nil
|
|
|
|
"fake" nil "#chan" proc nil "user" nil))
|
2023-01-23 20:48:24 -08:00
|
|
|
(should-not (get-buffer "#chan<2>")))
|
|
|
|
|
|
|
|
(ert-info ("Existing prompt respected")
|
|
|
|
(with-current-buffer (should (get-buffer "#chan"))
|
|
|
|
(should (= ?\n (char-after 1)))
|
|
|
|
(should (= ?E (char-after erc-insert-marker)))
|
|
|
|
(should (= 15 (marker-position erc-insert-marker)))
|
|
|
|
(should (= 20 (marker-position erc-input-marker)))
|
|
|
|
(should (= 3 (point))) ; point restored
|
|
|
|
(should (equal (buffer-string)
|
|
|
|
#("\n\n*** Welcome\nERC> Hello\nWorld"
|
|
|
|
2 13 (font-lock-face erc-error-face)
|
|
|
|
14 18 ( font-lock-face erc-prompt-face
|
|
|
|
rear-nonsticky t
|
|
|
|
erc-prompt t
|
|
|
|
field erc-prompt
|
|
|
|
front-sticky t
|
|
|
|
read-only t)
|
|
|
|
18 19 ( rear-nonsticky t
|
|
|
|
erc-prompt t
|
|
|
|
field erc-prompt
|
|
|
|
front-sticky t
|
|
|
|
read-only t))))
|
|
|
|
(when noninteractive
|
|
|
|
(kill-buffer))))))
|
|
|
|
|
2022-03-13 22:39:36 -07:00
|
|
|
(ert-deftest erc--switch-to-buffer ()
|
|
|
|
(defvar erc-modified-channels-alist) ; lisp/erc/erc-track.el
|
|
|
|
|
|
|
|
(let ((proc (start-process "aNet" (current-buffer) "true"))
|
|
|
|
(erc-modified-channels-alist `(("fake") (,(messages-buffer))))
|
|
|
|
(inhibit-message noninteractive)
|
|
|
|
(completion-fail-discreetly t) ; otherwise ^G^G printed to .log file
|
|
|
|
;;
|
|
|
|
erc-kill-channel-hook erc-kill-server-hook erc-kill-buffer-hook)
|
|
|
|
|
|
|
|
(with-current-buffer (get-buffer-create "server")
|
|
|
|
(erc-mode)
|
|
|
|
(set-process-buffer (setq erc-server-process proc) (current-buffer))
|
2022-03-19 02:33:24 -07:00
|
|
|
(set-process-query-on-exit-flag erc-server-process nil)
|
2022-03-13 22:39:36 -07:00
|
|
|
(with-current-buffer (get-buffer-create "#chan")
|
|
|
|
(erc-mode)
|
|
|
|
(setq erc-server-process proc))
|
|
|
|
(with-current-buffer (get-buffer-create "#foo")
|
|
|
|
(erc-mode)
|
|
|
|
(setq erc-server-process proc))
|
|
|
|
|
|
|
|
(ert-info ("Channel #chan selectable from server buffer")
|
|
|
|
(ert-simulate-keys (list ?# ?c ?h ?a ?n ?\C-m)
|
|
|
|
(should (string= "#chan" (erc--switch-to-buffer))))))
|
|
|
|
|
|
|
|
(ert-info ("Channel #foo selectable from non-ERC buffer")
|
|
|
|
(ert-simulate-keys (list ?# ?f ?o ?o ?\C-m)
|
|
|
|
(should (string= "#foo" (erc--switch-to-buffer)))))
|
|
|
|
|
|
|
|
(ert-info ("Default selectable")
|
|
|
|
(ert-simulate-keys (list ?\C-m)
|
|
|
|
(should (string= "*Messages*" (erc--switch-to-buffer)))))
|
|
|
|
|
|
|
|
(ert-info ("Extant but non-ERC buffer not selectable")
|
|
|
|
(get-buffer-create "#fake") ; not ours
|
|
|
|
(ert-simulate-keys (kbd "#fake C-m C-a C-k C-m")
|
|
|
|
;; Initial query fails ~~~~~~^; clearing input accepts default
|
|
|
|
(should (string= "*Messages*" (erc--switch-to-buffer)))))
|
|
|
|
|
|
|
|
(with-current-buffer (get-buffer-create "other")
|
|
|
|
(erc-mode)
|
2022-03-19 02:33:24 -07:00
|
|
|
(setq erc-server-process (start-process "bNet" (current-buffer) "true"))
|
|
|
|
(set-process-query-on-exit-flag erc-server-process nil))
|
2022-03-13 22:39:36 -07:00
|
|
|
|
|
|
|
(ert-info ("Foreign ERC buffer not selectable")
|
|
|
|
(ert-simulate-keys (kbd "other C-m C-a C-k C-m")
|
|
|
|
(with-current-buffer "server"
|
|
|
|
(should (string= "*Messages*" (erc--switch-to-buffer))))))
|
|
|
|
|
|
|
|
(ert-info ("Any ERC-buffer selectable from non-ERC buffer")
|
|
|
|
(should-not (eq major-mode 'erc-mode))
|
|
|
|
(ert-simulate-keys (list ?o ?t ?h ?e ?r ?\C-m)
|
|
|
|
(should (string= "other" (erc--switch-to-buffer)))))
|
|
|
|
|
|
|
|
(dolist (b '("server" "other" "#chan" "#foo" "#fake"))
|
|
|
|
(kill-buffer b))))
|
|
|
|
|
Allow custom display-buffer actions in ERC
* doc/misc/erc.texi: Add new section under "Integrations" chapter
describing `display-buffer' Custom function choice for ERC's many
buffer-display options.
* etc/ERC-NEWS: Mention new function variant for all buffer-display
options.
* lisp/erc/erc-backend.el: Add forward declaration for
`erc--called-as-input-p' and `erc--display-context'.
(erc--server-reconnect-display-timer,
erc--server-last-reconnect-display-reset): Use new name for option
`erc-reconnect-display', now `erc-auto-reconnect-display'.
(erc--server-determine-join-display-context): New generic function to
determine value of `erc--display-context' during JOINs.
(erc-server-JOIN, erc-server-PRIVMSG): Set `erc--display-context' to a
symbol for the handler's IRC command, like `JOIN', for the benefit of
custom `display-buffer'-like functions running in `erc-setup-buffer'.
(erc-server-471, erc-server-471-functions, erc-server-473,
erc-server-473-functions): New handlers for JOIN rejections. Also
remove 471 and 473 from comment at bottom of file.
(erc-server-475): Bind `erc--called-as-input-p' so that `erc-cmd-JOIN'
sets `erc-interactive-display' context.
* lisp/erc/erc-join.el (erc-autojoin-mode, erc-autojoin-enable,
erc-autojoin-disable): Kill local variable
`erc-join--requested-channels'. Add and remove
`erc-join--remove-requested-channels' to/from various server-handler
hooks for JOIN rejection numerics.
(erc-join--requested-channels): New local variable to remember
channels we've attempted to JOIN this session that haven't yet been
confirmed by the server.
(erc-join--remove-requested-channel): New JOIN rejection handler to
stop tracking channel in `erc-join--requested-channels'.
(erc--server-determine-join-display-context): module-specific
implementation of generic function for `erc-autojoin-mode'.
(erc-autojoin--join): Remember channels slated for JOIN'ing.
* lisp/erc/erc.el (erc--buffer-display-choices): New helper constant
for defining common `:type' for all buffer-display options.
(erc-buffer-display, erc-interactive-display,
erc-auto-reconnect-display, erc-receive-query-display): Use helper
`erc--buffer-display-choices' for defining `:type', which
includes a new choice for a `display-buffer'-like function.
(erc-reconnect-display, erc-auto-reconnect-display): Alias former to
latter, now the preferred name.
(erc-reconnect-timeout, erc-auto-reconnect-timeout): Change name from
former to latter. This option is new in ERC 5.6.
(erc-reconnect-display-server-buffers): New option.
(erc-buffer-do): Revise doc string.
(erc--display-context): New variable, an alist of "context tokens" to
be forwarded as the "action alist" to `erc-buffer-display' functions.
(erc-skip-displaying-selected-window-buffer): New variable, deprecated
at birth, to act as an escape hatch for folks who don't want to skip
the displaying of buffers already showing in the selected window.
(erc--display-buffer-overriding-action): Local variable allowing
modules to influence the displaying of new ERC buffers independently
of user options.
(erc-setup-buffer): Do nothing when the selected window already shows
current buffer unless user has provided a custom display function.
Accommodate new Custom choice function values, like `display-buffer'
and `pop-to-buffer'.
(erc-open): Run `erc-setup-buffer' when option
`erc-reconnect-display-server-buffers' is non-nil, even for existing
server buffers. Bind `display-buffer-overriding-action' to the value
of `erc--display-buffer-overriding-action' around calls to
`erc-setup-buffer'.
(erc-select-read-args): Add `erc--display-context' to environment.
(erc, erc-tls): Bind `erc--display-context' around calls to
`erc-select-read-args' and main body.
(erc-cmd-JOIN, erc-cmd-QUERY, erc--cmd-reconnect, erc-handle-irc-url):
Add item for `erc-interactive-display' to `erc--display-context'.
(erc-connection-established): Update name of
`erc-reconnect-display-timeout' to
`erc-auto-reconnect-display-timeout'.
(erc-message-english-s471, erc-message-english-s473): New variables,
format templates for JOIN rejection messages.
* test/lisp/erc/erc-scenarios-base-buffer-display.el
(erc-scenarios-base-buffer-display--defwin-recbury-intbuf,
erc-scenarios-base-buffer-display--defwino-recbury-intbuf,
erc-scenarios-base-buffer-display--count-reset-timeout): Use preferred
name `erc-auto-reconnect-display' for `erc-reconnect-display'.
* test/lisp/erc/erc-scenarios-join-display-context.el: New file.
* test/lisp/erc/erc-tests.el (erc--initialize-markers): Fix
unrealistic call to `erc-open'.
(erc-setup-buffer--custom-action): New test.
(erc-select-read-args, erc-tls, erc--interactive, erc-server-select):
Expect new environment binding for `erc--display-context'.
* test/lisp/erc/resources/join/buffer-display/mode-context.eld: New
file. (Bug#62833)
2023-05-30 23:27:12 -07:00
|
|
|
(ert-deftest erc-setup-buffer--custom-action ()
|
|
|
|
(erc-mode)
|
|
|
|
(erc-tests--set-fake-server-process "sleep" "1")
|
|
|
|
(setq erc--server-last-reconnect-count 0)
|
|
|
|
(let ((owin (selected-window))
|
|
|
|
(obuf (window-buffer))
|
|
|
|
(mbuf (messages-buffer))
|
|
|
|
calls)
|
|
|
|
(cl-letf (((symbol-function 'switch-to-buffer) ; regression
|
|
|
|
(lambda (&rest r) (push (cons 'switch-to-buffer r) calls)))
|
|
|
|
((symbol-function 'erc--test-fun)
|
|
|
|
(lambda (&rest r) (push (cons 'erc--test-fun r) calls)))
|
|
|
|
((symbol-function 'display-buffer)
|
|
|
|
(lambda (&rest r) (push (cons 'display-buffer r) calls))))
|
|
|
|
|
|
|
|
;; Baseline
|
|
|
|
(let ((erc-join-buffer 'bury))
|
|
|
|
(erc-setup-buffer mbuf)
|
|
|
|
(should-not calls))
|
|
|
|
|
|
|
|
(should-not erc--display-context)
|
|
|
|
|
|
|
|
;; `display-buffer'
|
|
|
|
(let ((erc--display-context '((erc-buffer-display . 1)))
|
|
|
|
(erc-join-buffer 'erc--test-fun))
|
|
|
|
(erc-setup-buffer mbuf)
|
|
|
|
(should (equal `(erc--test-fun ,mbuf (nil (erc-buffer-display . 1)))
|
|
|
|
(pop calls)))
|
|
|
|
(should-not calls))
|
|
|
|
|
|
|
|
;; `pop-to-buffer' with `erc-auto-reconnect-display'
|
|
|
|
(let* ((erc--server-last-reconnect-count 1)
|
|
|
|
(erc--display-context '((erc-buffer-display . 1)))
|
|
|
|
(erc-auto-reconnect-display 'erc--test-fun))
|
|
|
|
(erc-setup-buffer mbuf)
|
|
|
|
(should (equal `(erc--test-fun ,mbuf
|
|
|
|
(nil (erc-auto-reconnect-display . t)
|
|
|
|
(erc-buffer-display . 1)))
|
|
|
|
(pop calls)))
|
|
|
|
(should-not calls)))
|
|
|
|
|
2023-09-10 22:55:16 -07:00
|
|
|
;; Mimic simplistic version of example in "(erc) display-buffer".
|
|
|
|
(when (>= emacs-major-version 29)
|
|
|
|
(let ((proc erc-server-process))
|
|
|
|
(with-temp-buffer
|
|
|
|
(should-not (eq (window-buffer) (current-buffer)))
|
|
|
|
(erc-mode)
|
|
|
|
(setq erc-server-process proc)
|
|
|
|
|
|
|
|
(cl-letf (((symbol-function 'erc--test-fun-p)
|
|
|
|
(lambda (buf action)
|
|
|
|
(should (eql 1 (alist-get 'erc-buffer-display action)))
|
|
|
|
(push (cons 'erc--test-fun-p buf) calls)))
|
|
|
|
((symbol-function 'action-fn)
|
|
|
|
(lambda (buf action)
|
|
|
|
(should (eql 1 (alist-get 'erc-buffer-display action)))
|
|
|
|
(should (eql 42 (alist-get 'foo action)))
|
|
|
|
(push (cons 'action-fn buf) calls)
|
|
|
|
(selected-window))))
|
|
|
|
|
|
|
|
(let ((erc--display-context '((erc-buffer-display . 1)))
|
|
|
|
(display-buffer-alist
|
|
|
|
`(((and (major-mode . erc-mode) erc--test-fun-p)
|
|
|
|
action-fn (foo . 42))))
|
|
|
|
(erc-buffer-display 'display-buffer))
|
|
|
|
|
|
|
|
(erc-setup-buffer (current-buffer))
|
|
|
|
(should (equal 'action-fn (car (pop calls))))
|
|
|
|
(should (equal 'erc--test-fun-p (car (pop calls))))
|
|
|
|
(should-not calls))))))
|
|
|
|
|
Allow custom display-buffer actions in ERC
* doc/misc/erc.texi: Add new section under "Integrations" chapter
describing `display-buffer' Custom function choice for ERC's many
buffer-display options.
* etc/ERC-NEWS: Mention new function variant for all buffer-display
options.
* lisp/erc/erc-backend.el: Add forward declaration for
`erc--called-as-input-p' and `erc--display-context'.
(erc--server-reconnect-display-timer,
erc--server-last-reconnect-display-reset): Use new name for option
`erc-reconnect-display', now `erc-auto-reconnect-display'.
(erc--server-determine-join-display-context): New generic function to
determine value of `erc--display-context' during JOINs.
(erc-server-JOIN, erc-server-PRIVMSG): Set `erc--display-context' to a
symbol for the handler's IRC command, like `JOIN', for the benefit of
custom `display-buffer'-like functions running in `erc-setup-buffer'.
(erc-server-471, erc-server-471-functions, erc-server-473,
erc-server-473-functions): New handlers for JOIN rejections. Also
remove 471 and 473 from comment at bottom of file.
(erc-server-475): Bind `erc--called-as-input-p' so that `erc-cmd-JOIN'
sets `erc-interactive-display' context.
* lisp/erc/erc-join.el (erc-autojoin-mode, erc-autojoin-enable,
erc-autojoin-disable): Kill local variable
`erc-join--requested-channels'. Add and remove
`erc-join--remove-requested-channels' to/from various server-handler
hooks for JOIN rejection numerics.
(erc-join--requested-channels): New local variable to remember
channels we've attempted to JOIN this session that haven't yet been
confirmed by the server.
(erc-join--remove-requested-channel): New JOIN rejection handler to
stop tracking channel in `erc-join--requested-channels'.
(erc--server-determine-join-display-context): module-specific
implementation of generic function for `erc-autojoin-mode'.
(erc-autojoin--join): Remember channels slated for JOIN'ing.
* lisp/erc/erc.el (erc--buffer-display-choices): New helper constant
for defining common `:type' for all buffer-display options.
(erc-buffer-display, erc-interactive-display,
erc-auto-reconnect-display, erc-receive-query-display): Use helper
`erc--buffer-display-choices' for defining `:type', which
includes a new choice for a `display-buffer'-like function.
(erc-reconnect-display, erc-auto-reconnect-display): Alias former to
latter, now the preferred name.
(erc-reconnect-timeout, erc-auto-reconnect-timeout): Change name from
former to latter. This option is new in ERC 5.6.
(erc-reconnect-display-server-buffers): New option.
(erc-buffer-do): Revise doc string.
(erc--display-context): New variable, an alist of "context tokens" to
be forwarded as the "action alist" to `erc-buffer-display' functions.
(erc-skip-displaying-selected-window-buffer): New variable, deprecated
at birth, to act as an escape hatch for folks who don't want to skip
the displaying of buffers already showing in the selected window.
(erc--display-buffer-overriding-action): Local variable allowing
modules to influence the displaying of new ERC buffers independently
of user options.
(erc-setup-buffer): Do nothing when the selected window already shows
current buffer unless user has provided a custom display function.
Accommodate new Custom choice function values, like `display-buffer'
and `pop-to-buffer'.
(erc-open): Run `erc-setup-buffer' when option
`erc-reconnect-display-server-buffers' is non-nil, even for existing
server buffers. Bind `display-buffer-overriding-action' to the value
of `erc--display-buffer-overriding-action' around calls to
`erc-setup-buffer'.
(erc-select-read-args): Add `erc--display-context' to environment.
(erc, erc-tls): Bind `erc--display-context' around calls to
`erc-select-read-args' and main body.
(erc-cmd-JOIN, erc-cmd-QUERY, erc--cmd-reconnect, erc-handle-irc-url):
Add item for `erc-interactive-display' to `erc--display-context'.
(erc-connection-established): Update name of
`erc-reconnect-display-timeout' to
`erc-auto-reconnect-display-timeout'.
(erc-message-english-s471, erc-message-english-s473): New variables,
format templates for JOIN rejection messages.
* test/lisp/erc/erc-scenarios-base-buffer-display.el
(erc-scenarios-base-buffer-display--defwin-recbury-intbuf,
erc-scenarios-base-buffer-display--defwino-recbury-intbuf,
erc-scenarios-base-buffer-display--count-reset-timeout): Use preferred
name `erc-auto-reconnect-display' for `erc-reconnect-display'.
* test/lisp/erc/erc-scenarios-join-display-context.el: New file.
* test/lisp/erc/erc-tests.el (erc--initialize-markers): Fix
unrealistic call to `erc-open'.
(erc-setup-buffer--custom-action): New test.
(erc-select-read-args, erc-tls, erc--interactive, erc-server-select):
Expect new environment binding for `erc--display-context'.
* test/lisp/erc/resources/join/buffer-display/mode-context.eld: New
file. (Bug#62833)
2023-05-30 23:27:12 -07:00
|
|
|
(should (eq owin (selected-window)))
|
|
|
|
(should (eq obuf (window-buffer)))))
|
|
|
|
|
2021-09-16 15:25:18 +02:00
|
|
|
(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-_`")))))
|
|
|
|
|
2023-09-01 20:05:35 -07:00
|
|
|
(ert-deftest erc-parse-user ()
|
|
|
|
(should (equal erc--parse-user-regexp erc--parse-user-regexp-legacy))
|
|
|
|
|
|
|
|
(should (equal '("" "" "") (erc-parse-user "!@")))
|
|
|
|
(should (equal '("" "!" "") (erc-parse-user "!!@")))
|
|
|
|
(should (equal '("" "" "@") (erc-parse-user "!@@")))
|
|
|
|
(should (equal '("" "!" "@") (erc-parse-user "!!@@")))
|
|
|
|
|
|
|
|
(should (equal '("abc" "" "") (erc-parse-user "abc")))
|
|
|
|
(should (equal '("" "123" "fake") (erc-parse-user "!123@fake")))
|
|
|
|
(should (equal '("abc" "" "123") (erc-parse-user "abc!123")))
|
|
|
|
|
|
|
|
(should (equal '("abc" "123" "fake") (erc-parse-user "abc!123@fake")))
|
|
|
|
(should (equal '("abc" "!123" "@xy") (erc-parse-user "abc!!123@@xy")))
|
|
|
|
|
|
|
|
(should (equal '("de" "fg" "xy") (erc-parse-user "abc\nde!fg@xy")))
|
|
|
|
|
|
|
|
(ert-info ("`erc--parse-user-regexp-pedantic'")
|
|
|
|
(let ((erc--parse-user-regexp erc--parse-user-regexp-pedantic))
|
|
|
|
(should (equal '("" "" "") (erc-parse-user "!@")))
|
|
|
|
(should (equal '("" "!" "") (erc-parse-user "!!@")))
|
|
|
|
(should (equal '("" "@" "") (erc-parse-user "!@@")))
|
|
|
|
(should (equal '("" "!@" "") (erc-parse-user "!!@@")))
|
|
|
|
|
|
|
|
(should (equal '("abc" "" "") (erc-parse-user "abc")))
|
|
|
|
(should (equal '("" "123" "fake") (erc-parse-user "!123@fake")))
|
|
|
|
(should (equal '("abc" "" "123") (erc-parse-user "abc!123")))
|
|
|
|
|
|
|
|
(should (equal '("abc" "123" "fake") (erc-parse-user "abc!123@fake")))
|
|
|
|
(should (equal '("abc" "!123@" "xy") (erc-parse-user "abc!!123@@xy")))
|
|
|
|
|
|
|
|
(should (equal '("de" "" "fg@xy") (erc-parse-user "abc\nde!fg@xy"))))))
|
|
|
|
|
2021-08-12 03:10:31 -07:00
|
|
|
(ert-deftest erc--parse-isupport-value ()
|
|
|
|
(should (equal (erc--parse-isupport-value "a,b") '("a" "b")))
|
|
|
|
(should (equal (erc--parse-isupport-value "a,b,c") '("a" "b" "c")))
|
|
|
|
|
|
|
|
(should (equal (erc--parse-isupport-value "abc") '("abc")))
|
|
|
|
(should (equal (erc--parse-isupport-value "\\x20foo") '(" foo")))
|
|
|
|
(should (equal (erc--parse-isupport-value "foo\\x20") '("foo ")))
|
|
|
|
(should (equal (erc--parse-isupport-value "a\\x20b\\x20c") '("a b c")))
|
|
|
|
(should (equal (erc--parse-isupport-value "a\\x20b\\x20c\\x20") '("a b c ")))
|
|
|
|
(should (equal (erc--parse-isupport-value "\\x20a\\x20b\\x20c") '(" a b c")))
|
|
|
|
(should (equal (erc--parse-isupport-value "a\\x20\\x20c") '("a c")))
|
|
|
|
(should (equal (erc--parse-isupport-value "\\x20\\x20\\x20") '(" ")))
|
|
|
|
(should (equal (erc--parse-isupport-value "\\x5Co/") '("\\o/")))
|
|
|
|
(should (equal (erc--parse-isupport-value "\\x7F,\\x19") '("\\x7F" "\\x19")))
|
|
|
|
(should (equal (erc--parse-isupport-value "a\\x2Cb,c") '("a,b" "c"))))
|
|
|
|
|
|
|
|
(ert-deftest erc--get-isupport-entry ()
|
|
|
|
(let ((erc--isupport-params (make-hash-table))
|
|
|
|
(erc-server-parameters '(("FOO" . "1") ("BAR") ("BAZ" . "A,B,C")))
|
|
|
|
(items (lambda ()
|
|
|
|
(cl-loop for k being the hash-keys of erc--isupport-params
|
|
|
|
using (hash-values v) collect (cons k v)))))
|
|
|
|
|
|
|
|
(should-not (erc--get-isupport-entry 'FAKE))
|
|
|
|
(should-not (erc--get-isupport-entry 'FAKE 'single))
|
|
|
|
(should (zerop (hash-table-count erc--isupport-params)))
|
|
|
|
|
|
|
|
(should (equal (erc--get-isupport-entry 'BAR) '(BAR)))
|
|
|
|
(should-not (erc--get-isupport-entry 'BAR 'single))
|
|
|
|
(should (= 1 (hash-table-count erc--isupport-params)))
|
|
|
|
|
|
|
|
(should (equal (erc--get-isupport-entry 'BAZ) '(BAZ "A" "B" "C")))
|
|
|
|
(should (equal (erc--get-isupport-entry 'BAZ 'single) "A"))
|
|
|
|
(should (= 2 (hash-table-count erc--isupport-params)))
|
|
|
|
|
|
|
|
(should (equal (erc--get-isupport-entry 'FOO 'single) "1"))
|
|
|
|
(should (equal (erc--get-isupport-entry 'FOO) '(FOO "1")))
|
|
|
|
|
|
|
|
(should (equal (funcall items)
|
|
|
|
'((BAR . --empty--) (BAZ "A" "B" "C") (FOO "1"))))))
|
|
|
|
|
|
|
|
(ert-deftest erc-server-005 ()
|
|
|
|
(let* ((hooked 0)
|
|
|
|
(verify #'ignore)
|
|
|
|
(hook (lambda (_ _) (funcall verify) (cl-incf hooked)))
|
|
|
|
(erc-server-005-functions (list #'erc-server-005 hook #'ignore))
|
|
|
|
erc-server-parameters
|
|
|
|
erc--isupport-params
|
|
|
|
erc-timer-hook
|
|
|
|
calls
|
|
|
|
args
|
|
|
|
parsed)
|
|
|
|
|
|
|
|
(cl-letf (((symbol-function 'erc-display-message)
|
|
|
|
(lambda (_ _ _ line) (push line calls))))
|
|
|
|
|
|
|
|
(ert-info ("Baseline")
|
|
|
|
(setq args '("tester" "BOT=B" "EXCEPTS" "PREFIX=(ov)@+" "are supp...")
|
|
|
|
parsed (make-erc-response :command-args args :command "005"))
|
|
|
|
|
|
|
|
(setq verify
|
|
|
|
(lambda ()
|
|
|
|
(should (equal erc-server-parameters
|
|
|
|
'(("PREFIX" . "(ov)@+") ("EXCEPTS")
|
|
|
|
("BOT" . "B"))))
|
|
|
|
(should (zerop (hash-table-count erc--isupport-params)))
|
|
|
|
(should (equal "(ov)@+" (erc--get-isupport-entry 'PREFIX t)))
|
|
|
|
(should (equal '(EXCEPTS) (erc--get-isupport-entry 'EXCEPTS)))
|
|
|
|
(should (equal "B" (erc--get-isupport-entry 'BOT t)))
|
|
|
|
(should (string= (pop calls)
|
|
|
|
"BOT=B EXCEPTS PREFIX=(ov)@+ are supp..."))
|
|
|
|
(should (equal args (erc-response.command-args parsed)))))
|
|
|
|
|
|
|
|
(erc-call-hooks nil parsed))
|
|
|
|
|
|
|
|
(ert-info ("Negated, updated")
|
|
|
|
(setq args '("tester" "-EXCEPTS" "-FAKE" "PREFIX=(ohv)@%+" "are su...")
|
|
|
|
parsed (make-erc-response :command-args args :command "005"))
|
|
|
|
|
|
|
|
(setq verify
|
|
|
|
(lambda ()
|
|
|
|
(should (equal erc-server-parameters
|
|
|
|
'(("PREFIX" . "(ohv)@%+") ("BOT" . "B"))))
|
|
|
|
(should (string= (pop calls)
|
|
|
|
"-EXCEPTS -FAKE PREFIX=(ohv)@%+ are su..."))
|
|
|
|
(should (equal "(ohv)@%+" (erc--get-isupport-entry 'PREFIX t)))
|
|
|
|
(should (equal "B" (erc--get-isupport-entry 'BOT t)))
|
|
|
|
(should-not (erc--get-isupport-entry 'EXCEPTS))
|
|
|
|
(should (equal args (erc-response.command-args parsed)))))
|
|
|
|
|
|
|
|
(erc-call-hooks nil parsed))
|
|
|
|
(should (= hooked 2)))))
|
|
|
|
|
2021-10-05 19:03:56 -07:00
|
|
|
(ert-deftest erc-downcase ()
|
|
|
|
(let ((erc--isupport-params (make-hash-table)))
|
|
|
|
|
|
|
|
(puthash 'PREFIX '("(ov)@+") erc--isupport-params)
|
|
|
|
(puthash 'BOT '("B") erc--isupport-params)
|
|
|
|
|
|
|
|
(ert-info ("ascii")
|
|
|
|
(puthash 'CASEMAPPING '("ascii") erc--isupport-params)
|
2022-12-11 19:41:43 -08:00
|
|
|
(should (equal (erc-downcase "ABC 123 ΔΞΩΣ") "abc 123 ΔΞΩΣ"))
|
2021-10-05 19:03:56 -07:00
|
|
|
(should (equal (erc-downcase "Bob[m]`") "bob[m]`"))
|
|
|
|
(should (equal (erc-downcase "Tilde~") "tilde~" ))
|
|
|
|
(should (equal (erc-downcase "\\O/") "\\o/" )))
|
|
|
|
|
|
|
|
(ert-info ("rfc1459")
|
|
|
|
(puthash 'CASEMAPPING '("rfc1459") erc--isupport-params)
|
2022-12-11 19:41:43 -08:00
|
|
|
(should (equal (erc-downcase "ABC 123 ΔΞΩΣ") "abc 123 ΔΞΩΣ"))
|
2021-10-05 19:03:56 -07:00
|
|
|
(should (equal (erc-downcase "Bob[m]`") "bob{m}`" ))
|
|
|
|
(should (equal (erc-downcase "Tilde~") "tilde^" ))
|
|
|
|
(should (equal (erc-downcase "\\O/") "|o/" )))
|
|
|
|
|
|
|
|
(ert-info ("rfc1459-strict")
|
|
|
|
(puthash 'CASEMAPPING '("rfc1459-strict") erc--isupport-params)
|
2022-12-11 19:41:43 -08:00
|
|
|
(should (equal (erc-downcase "ABC 123 ΔΞΩΣ") "abc 123 ΔΞΩΣ"))
|
2021-10-05 19:03:56 -07:00
|
|
|
(should (equal (erc-downcase "Bob[m]`") "bob{m}`"))
|
|
|
|
(should (equal (erc-downcase "Tilde~") "tilde~" ))
|
|
|
|
(should (equal (erc-downcase "\\O/") "|o/" )))))
|
|
|
|
|
2023-02-18 19:32:36 -08:00
|
|
|
(ert-deftest erc-channel-p ()
|
|
|
|
(let ((erc--isupport-params (make-hash-table))
|
|
|
|
erc-server-parameters)
|
|
|
|
|
|
|
|
(should (erc-channel-p "#chan"))
|
|
|
|
(should (erc-channel-p "##chan"))
|
|
|
|
(should (erc-channel-p "&chan"))
|
|
|
|
(should (erc-channel-p "+chan"))
|
|
|
|
(should (erc-channel-p "!chan"))
|
|
|
|
(should-not (erc-channel-p "@chan"))
|
|
|
|
|
|
|
|
(push '("CHANTYPES" . "#&@+!") erc-server-parameters)
|
|
|
|
|
|
|
|
(should (erc-channel-p "!chan"))
|
|
|
|
(should (erc-channel-p "#chan"))
|
|
|
|
|
|
|
|
(with-current-buffer (get-buffer-create "#chan")
|
|
|
|
(setq erc--target (erc--target-from-string "#chan")))
|
|
|
|
(should (erc-channel-p (get-buffer "#chan"))))
|
|
|
|
(kill-buffer "#chan"))
|
|
|
|
|
2021-08-16 05:01:16 -07:00
|
|
|
(ert-deftest erc--valid-local-channel-p ()
|
|
|
|
(ert-info ("Local channels not supported")
|
|
|
|
(let ((erc--isupport-params (make-hash-table)))
|
|
|
|
(puthash 'CHANTYPES '("#") erc--isupport-params)
|
|
|
|
(should-not (erc--valid-local-channel-p "#chan"))
|
|
|
|
(should-not (erc--valid-local-channel-p "&local"))))
|
|
|
|
(ert-info ("Local channels supported")
|
|
|
|
(let ((erc--isupport-params (make-hash-table)))
|
|
|
|
(puthash 'CHANTYPES '("&#") erc--isupport-params)
|
|
|
|
(should-not (erc--valid-local-channel-p "#chan"))
|
|
|
|
(should (erc--valid-local-channel-p "&local")))))
|
|
|
|
|
2023-05-07 19:43:57 -07:00
|
|
|
(ert-deftest erc--restore-initialize-priors ()
|
|
|
|
(should (pcase (macroexpand-1 '(erc--restore-initialize-priors erc-my-mode
|
|
|
|
foo (ignore 1 2 3)
|
2023-10-05 00:16:46 -07:00
|
|
|
bar #'spam
|
|
|
|
baz nil))
|
|
|
|
(`(let* ((,p (or erc--server-reconnecting erc--target-priors))
|
|
|
|
(,q (and ,p (alist-get 'erc-my-mode ,p))))
|
|
|
|
(setq foo (if ,q (alist-get 'foo ,p) (ignore 1 2 3))
|
|
|
|
bar (if ,q (alist-get 'bar ,p) #'spam)
|
|
|
|
baz (if ,q (alist-get 'baz ,p) nil)))
|
2023-05-07 19:43:57 -07:00
|
|
|
t))))
|
|
|
|
|
2021-10-19 22:53:03 -07:00
|
|
|
(ert-deftest erc--target-from-string ()
|
|
|
|
(should (equal (erc--target-from-string "#chan")
|
|
|
|
#s(erc--target-channel "#chan" \#chan)))
|
|
|
|
|
|
|
|
(should (equal (erc--target-from-string "Bob")
|
|
|
|
#s(erc--target "Bob" bob)))
|
|
|
|
|
|
|
|
(let ((erc--isupport-params (make-hash-table)))
|
|
|
|
(puthash 'CHANTYPES '("&#") erc--isupport-params)
|
|
|
|
(should (equal (erc--target-from-string "&Bitlbee")
|
|
|
|
#s(erc--target-channel-local "&Bitlbee" &bitlbee)))))
|
|
|
|
|
2023-01-19 21:07:27 -08:00
|
|
|
(ert-deftest erc--modify-local-map ()
|
|
|
|
(when (and (bound-and-true-p erc-irccontrols-mode)
|
|
|
|
(fboundp 'erc-irccontrols-mode))
|
|
|
|
(erc-irccontrols-mode -1))
|
|
|
|
(when (and (bound-and-true-p erc-match-mode)
|
|
|
|
(fboundp 'erc-match-mode))
|
|
|
|
(erc-match-mode -1))
|
|
|
|
(let* (calls
|
|
|
|
(inhibit-message noninteractive)
|
|
|
|
(cmd-foo (lambda () (interactive) (push 'foo calls)))
|
|
|
|
(cmd-bar (lambda () (interactive) (push 'bar calls))))
|
|
|
|
|
|
|
|
(ert-info ("Add non-existing")
|
|
|
|
(erc--modify-local-map t "C-c C-c" cmd-foo "C-c C-k" cmd-bar)
|
|
|
|
(with-temp-buffer
|
|
|
|
(set-window-buffer (selected-window) (current-buffer))
|
|
|
|
(use-local-map erc-mode-map)
|
|
|
|
(execute-kbd-macro "\C-c\C-c")
|
|
|
|
(execute-kbd-macro "\C-c\C-k"))
|
|
|
|
(should (equal calls '(bar foo))))
|
|
|
|
(setq calls nil)
|
|
|
|
|
|
|
|
(ert-info ("Add existing") ; Attempt to swap definitions fails
|
|
|
|
(erc--modify-local-map t "C-c C-c" cmd-bar "C-c C-k" cmd-foo)
|
|
|
|
(with-temp-buffer
|
|
|
|
(set-window-buffer (selected-window) (current-buffer))
|
|
|
|
(use-local-map erc-mode-map)
|
|
|
|
(execute-kbd-macro "\C-c\C-c")
|
|
|
|
(execute-kbd-macro "\C-c\C-k"))
|
|
|
|
(should (equal calls '(bar foo))))
|
|
|
|
(setq calls nil)
|
|
|
|
|
|
|
|
(ert-info ("Remove existing")
|
|
|
|
(ert-with-message-capture messages
|
|
|
|
(erc--modify-local-map nil "C-c C-c" cmd-foo "C-c C-k" cmd-bar)
|
|
|
|
(with-temp-buffer
|
|
|
|
(set-window-buffer (selected-window) (current-buffer))
|
|
|
|
(use-local-map erc-mode-map)
|
|
|
|
(execute-kbd-macro "\C-c\C-c")
|
|
|
|
(execute-kbd-macro "\C-c\C-k"))
|
|
|
|
(should (string-search "C-c C-c is undefined" messages))
|
|
|
|
(should (string-search "C-c C-k is undefined" messages))
|
|
|
|
(should-not calls)))))
|
|
|
|
|
2021-02-27 05:35:40 +01:00
|
|
|
(ert-deftest erc-ring-previous-command-base-case ()
|
|
|
|
(ert-info ("Create ring when nonexistent and do nothing")
|
|
|
|
(let (erc-input-ring
|
|
|
|
erc-input-ring-index)
|
|
|
|
(erc-previous-command)
|
|
|
|
(should (ring-p erc-input-ring))
|
|
|
|
(should (zerop (ring-length erc-input-ring)))
|
|
|
|
(should-not erc-input-ring-index)))
|
|
|
|
(should-not erc-input-ring))
|
|
|
|
|
|
|
|
(ert-deftest erc-ring-previous-command ()
|
|
|
|
(with-current-buffer (get-buffer-create "*#fake*")
|
|
|
|
(erc-mode)
|
2022-04-05 17:45:00 -07:00
|
|
|
(erc-tests--send-prep)
|
Improve erc-warn-about-blank-lines behavior
* etc/ERC-NEWS: Mention more detailed feedback when option
`erc-warn-about-blank-lines' is non-nil.
* lisp/erc/erc-common.el (erc--input-split): Add `abortp' slot to
allow a premature exit while validating prompt input.
* lisp/erc/erc.el (erc-warn-about-blank-lines): Clarify meaning of
"blank lines" in doc string, and mention interaction with
companion option `erc-send-whitespace-lines'.
(erc-inhibit-multiline-input): Fix inaccurate description in doc
string.
(erc--input-review-functions): Move
`erc--discard-trailing-multiline-nulls' to end of list, after
`erc--run-input-validation-checks' so that the latter doesn't have to
resplit the original input string in order to issue feedback.
(erc--blank-in-multiline-input-p): Remove unused internal function
originally slated to be part of ERC 5.6.
(erc--check-prompt-input-for-something): New trivial validation
function to check if the input is empty.
(erc--count-blank-lines): New function that tallies up the number of
blank and whitespace-only lines in the current input. One downside of
this design is that this function's conclusions aren't shared with
`erc--discard-trailing-multiline-nulls', which must decide on its own
how many lines to strip.
(erc--check-prompt-explanation): New variable.
(erc--check-prompt-input-for-multiline-blanks): Rework significantly
to provide more informative messages and more sensible behavior for
common cases with respect to relevant option values.
(erc--check-prompt-input-functions): Add new validation function
`erc--check-prompt-for-something'.
(erc--run-input-validation-checks): Set `abortp' slot of
`erc--input-split' when hooks return a non-string, rather than
generate an unhelpful fallback message. Also print a message when
the variable `erc--check-prompt-explanation' is non-nil.
(erc-send-current-line): When the `abortp' slot of the current
`erc--input-split' object is non-nil, forgo normal input processing.
This fixes a regression in 5.6-git, which previously emitted an error
message when it should have just exited the command.
(erc--discard-trailing-multiline-nulls): Always run, regardless of
`erc-send-whitespace-lines', and leave a blank line behind when
stripping a message consisting of only blank lines.
(erc--run-send-hooks): Always run hooks and surrounding logic rather
than only when hooks are populated.
* test/lisp/erc/erc-tests.el (erc--refresh-prompt): Add assertion and
use default value for `erc--input-review-functions'.
(erc-ring-previous-command): Use default value for
`erc--input-review-functions' and ensure `erc-current-nick' does not
error.
(erc--blank-in-multiline-input-p): Remove obsolete test.
(erc--check-prompt-input-functions): Update expected message.
(erc--discard-trailing-multiline-nulls, erc--count-blank-lines): New
tests.
(erc-tests--check-prompt-input--expect,
erc-tests--check-prompt-input-messages): New helper variables.
(erc--check-prompt-input-for-multiline-blanks,
erc--check-prompt-input-for-multiline-blanks/explanations): New tests.
(erc-send-whitespace-lines): Expect hook-processing logic to pad empty
lines instead of deferring to `erc-send-input-line-function'.
(Bug#66073)
2023-09-15 06:08:55 -07:00
|
|
|
(setq erc-server-current-nick "tester")
|
2022-04-05 17:45:00 -07:00
|
|
|
(setq-local erc-last-input-time 0)
|
2021-09-16 15:20:59 +02:00
|
|
|
(should-not (local-variable-if-set-p 'erc-send-completed-hook))
|
|
|
|
(set (make-local-variable 'erc-send-completed-hook) nil) ; skip t (globals)
|
|
|
|
;; Just in case erc-ring-mode is already on
|
Improve erc-warn-about-blank-lines behavior
* etc/ERC-NEWS: Mention more detailed feedback when option
`erc-warn-about-blank-lines' is non-nil.
* lisp/erc/erc-common.el (erc--input-split): Add `abortp' slot to
allow a premature exit while validating prompt input.
* lisp/erc/erc.el (erc-warn-about-blank-lines): Clarify meaning of
"blank lines" in doc string, and mention interaction with
companion option `erc-send-whitespace-lines'.
(erc-inhibit-multiline-input): Fix inaccurate description in doc
string.
(erc--input-review-functions): Move
`erc--discard-trailing-multiline-nulls' to end of list, after
`erc--run-input-validation-checks' so that the latter doesn't have to
resplit the original input string in order to issue feedback.
(erc--blank-in-multiline-input-p): Remove unused internal function
originally slated to be part of ERC 5.6.
(erc--check-prompt-input-for-something): New trivial validation
function to check if the input is empty.
(erc--count-blank-lines): New function that tallies up the number of
blank and whitespace-only lines in the current input. One downside of
this design is that this function's conclusions aren't shared with
`erc--discard-trailing-multiline-nulls', which must decide on its own
how many lines to strip.
(erc--check-prompt-explanation): New variable.
(erc--check-prompt-input-for-multiline-blanks): Rework significantly
to provide more informative messages and more sensible behavior for
common cases with respect to relevant option values.
(erc--check-prompt-input-functions): Add new validation function
`erc--check-prompt-for-something'.
(erc--run-input-validation-checks): Set `abortp' slot of
`erc--input-split' when hooks return a non-string, rather than
generate an unhelpful fallback message. Also print a message when
the variable `erc--check-prompt-explanation' is non-nil.
(erc-send-current-line): When the `abortp' slot of the current
`erc--input-split' object is non-nil, forgo normal input processing.
This fixes a regression in 5.6-git, which previously emitted an error
message when it should have just exited the command.
(erc--discard-trailing-multiline-nulls): Always run, regardless of
`erc-send-whitespace-lines', and leave a blank line behind when
stripping a message consisting of only blank lines.
(erc--run-send-hooks): Always run hooks and surrounding logic rather
than only when hooks are populated.
* test/lisp/erc/erc-tests.el (erc--refresh-prompt): Add assertion and
use default value for `erc--input-review-functions'.
(erc-ring-previous-command): Use default value for
`erc--input-review-functions' and ensure `erc-current-nick' does not
error.
(erc--blank-in-multiline-input-p): Remove obsolete test.
(erc--check-prompt-input-functions): Update expected message.
(erc--discard-trailing-multiline-nulls, erc--count-blank-lines): New
tests.
(erc-tests--check-prompt-input--expect,
erc-tests--check-prompt-input-messages): New helper variables.
(erc--check-prompt-input-for-multiline-blanks,
erc--check-prompt-input-for-multiline-blanks/explanations): New tests.
(erc-send-whitespace-lines): Expect hook-processing logic to pad empty
lines instead of deferring to `erc-send-input-line-function'.
(Bug#66073)
2023-09-15 06:08:55 -07:00
|
|
|
(setq-local erc--input-review-functions erc--input-review-functions)
|
2023-04-30 07:12:56 -07:00
|
|
|
(add-hook 'erc--input-review-functions #'erc-add-to-input-ring)
|
2021-02-27 05:35:40 +01:00
|
|
|
;;
|
|
|
|
(cl-letf (((symbol-function 'erc-process-input-line)
|
|
|
|
(lambda (&rest _)
|
2023-02-19 21:33:36 -08:00
|
|
|
(erc-display-message
|
|
|
|
nil 'notice (current-buffer) "echo: one\n")))
|
2021-02-27 05:35:40 +01:00
|
|
|
((symbol-function 'erc-command-no-process-p)
|
|
|
|
(lambda (&rest _) t)))
|
|
|
|
(ert-info ("Create ring, populate, recall")
|
|
|
|
(insert "/one")
|
|
|
|
(erc-send-current-line)
|
|
|
|
(should (ring-p erc-input-ring))
|
|
|
|
(should (zerop (ring-member erc-input-ring "/one"))) ; equal
|
2022-08-17 00:00:53 -07:00
|
|
|
(should (save-excursion (forward-line -1)
|
2021-02-27 05:35:40 +01:00
|
|
|
(looking-at-p "[*]+ echo: one")))
|
|
|
|
(should-not erc-input-ring-index)
|
|
|
|
(erc-bol)
|
|
|
|
(should (looking-at "$"))
|
|
|
|
(erc-previous-command)
|
|
|
|
(erc-bol)
|
|
|
|
(should (looking-at "/one"))
|
|
|
|
(should (zerop erc-input-ring-index)))
|
|
|
|
(ert-info ("Back to one")
|
|
|
|
(should (= (ring-length erc-input-ring) (1+ erc-input-ring-index)))
|
|
|
|
(erc-previous-command)
|
|
|
|
(should-not erc-input-ring-index)
|
|
|
|
(erc-bol)
|
|
|
|
(should (looking-at "$"))
|
|
|
|
(should (equal (ring-ref erc-input-ring 0) "/one")))
|
|
|
|
(ert-info ("Swap input after prompt with previous (#bug46339)")
|
|
|
|
(insert "abc")
|
|
|
|
(erc-previous-command)
|
|
|
|
(should (= 1 erc-input-ring-index))
|
|
|
|
(erc-bol)
|
|
|
|
(should (looking-at "/one"))
|
|
|
|
(should (equal (ring-ref erc-input-ring 0) "abc"))
|
|
|
|
(should (equal (ring-ref erc-input-ring 1) "/one"))
|
|
|
|
(erc-next-command)
|
|
|
|
(erc-bol)
|
|
|
|
(should (looking-at "abc")))))
|
|
|
|
(when noninteractive
|
|
|
|
(kill-buffer "*#fake*")))
|
2021-09-16 15:35:55 +02:00
|
|
|
|
2022-11-13 01:52:48 -08:00
|
|
|
(ert-deftest erc--debug-irc-protocol-mask-secrets ()
|
|
|
|
(should-not erc-debug-irc-protocol)
|
|
|
|
(should erc--debug-irc-protocol-mask-secrets)
|
|
|
|
(with-temp-buffer
|
|
|
|
(setq erc-server-process (start-process "fake" (current-buffer) "true")
|
|
|
|
erc-server-current-nick "tester"
|
|
|
|
erc-session-server "myproxy.localhost"
|
|
|
|
erc-session-port 6667)
|
|
|
|
(let ((inhibit-message noninteractive))
|
|
|
|
(erc-toggle-debug-irc-protocol)
|
|
|
|
(erc-log-irc-protocol
|
|
|
|
(concat "PASS :" (erc--unfun (lambda () "changeme")) "\r\n")
|
|
|
|
'outgoing)
|
|
|
|
(set-process-query-on-exit-flag erc-server-process nil))
|
|
|
|
(with-current-buffer "*erc-protocol*"
|
|
|
|
(goto-char (point-min))
|
|
|
|
(search-forward "\r\n\r\n")
|
|
|
|
(search-forward "myproxy.localhost:6667 >> PASS :????????" (pos-eol)))
|
|
|
|
(when noninteractive
|
|
|
|
(kill-buffer "*erc-protocol*")
|
|
|
|
(should-not erc-debug-irc-protocol))))
|
|
|
|
|
2021-09-16 15:35:55 +02:00
|
|
|
(ert-deftest erc-log-irc-protocol ()
|
|
|
|
(should-not erc-debug-irc-protocol)
|
|
|
|
(with-temp-buffer
|
|
|
|
(setq erc-server-process (start-process "fake" (current-buffer) "true")
|
|
|
|
erc-server-current-nick "tester"
|
|
|
|
erc-session-server "myproxy.localhost"
|
|
|
|
erc-session-port 6667)
|
|
|
|
(let ((inhibit-message noninteractive))
|
|
|
|
(erc-toggle-debug-irc-protocol)
|
|
|
|
(erc-log-irc-protocol "PASS changeme\r\n" 'outgoing)
|
|
|
|
(setq erc-server-announced-name "irc.gnu.org")
|
|
|
|
(erc-log-irc-protocol ":irc.gnu.org 001 tester :Welcome")
|
|
|
|
(erc-log-irc-protocol ":irc.gnu.org 002 tester :Your host is irc.gnu.org")
|
|
|
|
(setq erc-network 'FooNet)
|
Address long-standing ERC buffer-naming issues
* lisp/erc/erc-backend.el (erc-server-connected): Revise doc string.
(erc-server-reconnect, erc-server-JOIN): Reuse original ID param from
the first connection when calling `erc-open'.
(erc-server-NICK): Apply same name generation process used by
`erc-open'; except here, do so for the purpose of "re-nicking".
Update network identifier and maybe buffer names after a user's own
nick changes.
* lisp/erc/erc-networks.el (erc-networks--id, erc-networks--id-fixed,
erc-networks--id-qualifying): Define new set of structs to contain all
info relevant to specifying a unique identifier for a network context.
Add a new variable `erc-networks--id' to store a local reference to a
`erc-networks--id' object, shared among all buffers in a logical
session.
(erc-networks--id-given, erc-networks--id-create,
erc-networks--id-on-connect, erc-networks--id--equal-p,
erc-networks--id-qualifying-init-parts,
erc-networks--id-qualifying-init-symbol,
erc-networks--id-qualifying-grow-id,
erc-networks--id-qualifying-reset-id,
erc-networks--id-qualifying-prefix-length,
erc-networks--id-qualifying-update, erc-networks--id-reload,
erc-networks--id-ensure-comparable, erc-networks--id-sort-buffers):
Add new functions to support management of `erc-networks--id' struct
instances.
(erc-networks--id-sep): New variable for to help when formatting
buffer names.
(erc-obsolete-var): Define new generic context rewriter.
(erc-networks-shrink-ids-and-buffer-names,
erc-networks--refresh-buffer-names,
erc-networks--shrink-ids-and-buffer-names-any): Add functions to
reassess all network IDs and shrink them if necessary along with
affected buffer names. Also add function to rename buffers so that
their names are unique. Register these on all three of ERC's
kill-buffer hooks because an orphaned target buffer is enough to keep
its session alive.
(erc-networks-rename-surviving-target-buffer): Add new function that
renames a target buffer when it becomes the sole bearer of a name
based on a target that has become unique across all sessions and, in
most cases, all networks. IOW, remove the @NETWORK-ID suffix from the
last remaining channel or query buffer after its namesakes have all
been killed off. Register this function with ERC's target-related
kill-buffer hooks.
(erc-networks--examine-targets): Add new utility function that visits
all ERC buffers and runs callbacks when a buffer-name collision is
encountered.
(erc-networks--qualified-sep): Add constant to hold separator between
target and suffix.
(erc-networks--construct-target-buffer-name,
erc-networks--ensure-unique-target-buffer-name,
erc-networks--ensure-unique-server-buffer-name,
erc-networks--maybe-update-buffer-name): Add helpers to support
`erc-networks--reconcile-buffer-names' and friends.
(erc-networks--reconcile-buffer-names): Add new buffer-naming strategy
function and helper for `erc-generate-new-buffer-name' that only run
in target buffers.
(erc-determine-network, erc-networks--determine): Deprecate former and
partially replace with latter, which demotes RPL_ISUPPORT-derived
NETWORK name to fallback in favor of known `erc-networks-alist'
members as part of shift to network-based connection-identity policy.
Return sentinel on failure. Expect `erc-server-announced-name' to be
set, and signal when it's not.
(erc-networks--name-missing-sentinel): Value returned when new
function `erc-networks--determine' fails to find network name. The
rationale for not making this customizable is that the value signifies
the pathological case where a user of an uncommon IRC setup has not
yet set a mapping from announced- to network name. And the chances of
there being multiple unknown networks is low.
(erc-set-network-name, erc-networks--set-name): Deprecate former and
partially replace with latter. Ding with helpful message, and don't
set `erc-network' when network name is not found.
(erc-networks--ensure-announced): Add new fallback function to ensure
`erc-server-announced-name' is set. Register with post-MOTD hooks.
(erc-unset-network-name): Deprecate function unused internally.
(erc-networks--insert-transplanted-content,
erc-networks--reclaim-orphaned-target-buffers,
erc-networks--copy-over-server-buffer-contents,
erc--update-server-identity): Add helpers for
`erc-networks--rename-server-buffer'. The first re-associates all
existing target buffers that ought to be owned by the new server
process. The second grabs buffer text from an old, dead server buffer
before killing it. It then inserts that text above everything in the
current, replacement server buffer. The other two massage the IDs of
related sessions, possibly renaming them as well. They may also
uniquify the current session's network ID.
(erc-networks--init-identity): Add new function to perform one-time
session-related setup. This could be combined with
`erc-set-network-name'.
(erc-networks--rename-server-buffer): Add new function to replace
`erc-unset-network-name' as default `erc-disconnected-hook' member;
renames server buffers once network is discovered; added to/removed
from `erc-after-connect' hook on `erc-networks' minor mode.
(erc-networks--bouncer-targets): Add constant to hold target symbols
of well known bouncer-configuration bots.
(erc-networks-on-MOTD-end): Add primary network-context handler to run
on 376/422 functions, just before logical connection is officially
established.
(erc-networks-enable, erc-networks-mode): Register main network-setup
handler with 376/422 hooks.
* lisp/erc/erc.el (erc-rename-buffers): Change this option's default
to t, remove the only instance where it's actually used, and make it
an obsolete variable.
(erc-reuse-buffers): Make this an obsolete variable, but take pains to
ensure its pre-28.1 behavior is preserved. That is, undo the
regression involving unwanted automatic reassociation of channel
buffers during joins, which arrived in ERC 5.4 and effectively
inverted the meaning of this variable, when nil, for channel buffers,
all without accompanying documentation or announcement.
(erc-generate-new-buffer-name): Replace current policy of appending a
slash and the invocation host name. Favor instead temporary names for
server buffers and network-based uniquifying suffixes for channels and
query buffers. Fall back to the TCP host:port<n> convention when
necessary. Accept additional optional params after the others.
(erc-get-buffer-create): Don't generate a new name when reconnecting,
just return the same buffer. `erc-open' starts from a clean slate
anyway, so this just keeps things simple. Also add optional params.
(erc-open): Add new ID param to for a network identifier explicitly
passed to an entry-point command. This is stored in the `given' slot
of the `erc-network--id' object. Also initialize the latter in new
connections and otherwise copy it over. As part of the push to recast
erc-networks.el as an essential library, set `erc-network' explicitly,
when known, rather than via hooks.
(erc, erc-tls): Add new ID keyword parameter and pass it to
`erc-open'.
(erc-log-irc-protocol): Use `erc--network-id' instead of the function
`erc-network' to determine preferred peer name.
(erc-format-target-and/or-network): This is called frequently from
mode-line updates, so renaming buffers here is not ideal. Instead, do
so in `erc-networks--rename-server-buffer'.
(erc-kill-server-hook): Add `erc-networks-shrink-ids-and-buffer-names'
as default member.
(erc-kill-channel-hook, erc-kill-buffer-hook): Add
`erc-networks-shrink-ids-and-buffer-names' and
`erc-networks-rename-surviving-target-buffer' as default member.
* test/lisp/erc/erc-tests.el (erc-log-irc-protocol): Use network-ID
focused internal API.
* test/lisp/erc/erc-networks-tests.el: Add new file that includes
tests for the above network-ID focused functions.
See bug#48598 for background on all of the above.
2021-05-03 05:54:56 -07:00
|
|
|
(setq erc-networks--id (erc-networks--id-create nil))
|
2021-09-16 15:35:55 +02:00
|
|
|
(erc-log-irc-protocol ":irc.gnu.org 422 tester :MOTD missing")
|
Address long-standing ERC buffer-naming issues
* lisp/erc/erc-backend.el (erc-server-connected): Revise doc string.
(erc-server-reconnect, erc-server-JOIN): Reuse original ID param from
the first connection when calling `erc-open'.
(erc-server-NICK): Apply same name generation process used by
`erc-open'; except here, do so for the purpose of "re-nicking".
Update network identifier and maybe buffer names after a user's own
nick changes.
* lisp/erc/erc-networks.el (erc-networks--id, erc-networks--id-fixed,
erc-networks--id-qualifying): Define new set of structs to contain all
info relevant to specifying a unique identifier for a network context.
Add a new variable `erc-networks--id' to store a local reference to a
`erc-networks--id' object, shared among all buffers in a logical
session.
(erc-networks--id-given, erc-networks--id-create,
erc-networks--id-on-connect, erc-networks--id--equal-p,
erc-networks--id-qualifying-init-parts,
erc-networks--id-qualifying-init-symbol,
erc-networks--id-qualifying-grow-id,
erc-networks--id-qualifying-reset-id,
erc-networks--id-qualifying-prefix-length,
erc-networks--id-qualifying-update, erc-networks--id-reload,
erc-networks--id-ensure-comparable, erc-networks--id-sort-buffers):
Add new functions to support management of `erc-networks--id' struct
instances.
(erc-networks--id-sep): New variable for to help when formatting
buffer names.
(erc-obsolete-var): Define new generic context rewriter.
(erc-networks-shrink-ids-and-buffer-names,
erc-networks--refresh-buffer-names,
erc-networks--shrink-ids-and-buffer-names-any): Add functions to
reassess all network IDs and shrink them if necessary along with
affected buffer names. Also add function to rename buffers so that
their names are unique. Register these on all three of ERC's
kill-buffer hooks because an orphaned target buffer is enough to keep
its session alive.
(erc-networks-rename-surviving-target-buffer): Add new function that
renames a target buffer when it becomes the sole bearer of a name
based on a target that has become unique across all sessions and, in
most cases, all networks. IOW, remove the @NETWORK-ID suffix from the
last remaining channel or query buffer after its namesakes have all
been killed off. Register this function with ERC's target-related
kill-buffer hooks.
(erc-networks--examine-targets): Add new utility function that visits
all ERC buffers and runs callbacks when a buffer-name collision is
encountered.
(erc-networks--qualified-sep): Add constant to hold separator between
target and suffix.
(erc-networks--construct-target-buffer-name,
erc-networks--ensure-unique-target-buffer-name,
erc-networks--ensure-unique-server-buffer-name,
erc-networks--maybe-update-buffer-name): Add helpers to support
`erc-networks--reconcile-buffer-names' and friends.
(erc-networks--reconcile-buffer-names): Add new buffer-naming strategy
function and helper for `erc-generate-new-buffer-name' that only run
in target buffers.
(erc-determine-network, erc-networks--determine): Deprecate former and
partially replace with latter, which demotes RPL_ISUPPORT-derived
NETWORK name to fallback in favor of known `erc-networks-alist'
members as part of shift to network-based connection-identity policy.
Return sentinel on failure. Expect `erc-server-announced-name' to be
set, and signal when it's not.
(erc-networks--name-missing-sentinel): Value returned when new
function `erc-networks--determine' fails to find network name. The
rationale for not making this customizable is that the value signifies
the pathological case where a user of an uncommon IRC setup has not
yet set a mapping from announced- to network name. And the chances of
there being multiple unknown networks is low.
(erc-set-network-name, erc-networks--set-name): Deprecate former and
partially replace with latter. Ding with helpful message, and don't
set `erc-network' when network name is not found.
(erc-networks--ensure-announced): Add new fallback function to ensure
`erc-server-announced-name' is set. Register with post-MOTD hooks.
(erc-unset-network-name): Deprecate function unused internally.
(erc-networks--insert-transplanted-content,
erc-networks--reclaim-orphaned-target-buffers,
erc-networks--copy-over-server-buffer-contents,
erc--update-server-identity): Add helpers for
`erc-networks--rename-server-buffer'. The first re-associates all
existing target buffers that ought to be owned by the new server
process. The second grabs buffer text from an old, dead server buffer
before killing it. It then inserts that text above everything in the
current, replacement server buffer. The other two massage the IDs of
related sessions, possibly renaming them as well. They may also
uniquify the current session's network ID.
(erc-networks--init-identity): Add new function to perform one-time
session-related setup. This could be combined with
`erc-set-network-name'.
(erc-networks--rename-server-buffer): Add new function to replace
`erc-unset-network-name' as default `erc-disconnected-hook' member;
renames server buffers once network is discovered; added to/removed
from `erc-after-connect' hook on `erc-networks' minor mode.
(erc-networks--bouncer-targets): Add constant to hold target symbols
of well known bouncer-configuration bots.
(erc-networks-on-MOTD-end): Add primary network-context handler to run
on 376/422 functions, just before logical connection is officially
established.
(erc-networks-enable, erc-networks-mode): Register main network-setup
handler with 376/422 hooks.
* lisp/erc/erc.el (erc-rename-buffers): Change this option's default
to t, remove the only instance where it's actually used, and make it
an obsolete variable.
(erc-reuse-buffers): Make this an obsolete variable, but take pains to
ensure its pre-28.1 behavior is preserved. That is, undo the
regression involving unwanted automatic reassociation of channel
buffers during joins, which arrived in ERC 5.4 and effectively
inverted the meaning of this variable, when nil, for channel buffers,
all without accompanying documentation or announcement.
(erc-generate-new-buffer-name): Replace current policy of appending a
slash and the invocation host name. Favor instead temporary names for
server buffers and network-based uniquifying suffixes for channels and
query buffers. Fall back to the TCP host:port<n> convention when
necessary. Accept additional optional params after the others.
(erc-get-buffer-create): Don't generate a new name when reconnecting,
just return the same buffer. `erc-open' starts from a clean slate
anyway, so this just keeps things simple. Also add optional params.
(erc-open): Add new ID param to for a network identifier explicitly
passed to an entry-point command. This is stored in the `given' slot
of the `erc-network--id' object. Also initialize the latter in new
connections and otherwise copy it over. As part of the push to recast
erc-networks.el as an essential library, set `erc-network' explicitly,
when known, rather than via hooks.
(erc, erc-tls): Add new ID keyword parameter and pass it to
`erc-open'.
(erc-log-irc-protocol): Use `erc--network-id' instead of the function
`erc-network' to determine preferred peer name.
(erc-format-target-and/or-network): This is called frequently from
mode-line updates, so renaming buffers here is not ideal. Instead, do
so in `erc-networks--rename-server-buffer'.
(erc-kill-server-hook): Add `erc-networks-shrink-ids-and-buffer-names'
as default member.
(erc-kill-channel-hook, erc-kill-buffer-hook): Add
`erc-networks-shrink-ids-and-buffer-names' and
`erc-networks-rename-surviving-target-buffer' as default member.
* test/lisp/erc/erc-tests.el (erc-log-irc-protocol): Use network-ID
focused internal API.
* test/lisp/erc/erc-networks-tests.el: Add new file that includes
tests for the above network-ID focused functions.
See bug#48598 for background on all of the above.
2021-05-03 05:54:56 -07:00
|
|
|
(setq erc-networks--id (erc-networks--id-create 'BarNet))
|
2021-09-16 15:35:55 +02:00
|
|
|
(erc-log-irc-protocol ":irc.gnu.org 221 tester +i")
|
|
|
|
(set-process-query-on-exit-flag erc-server-process nil)))
|
|
|
|
(with-current-buffer "*erc-protocol*"
|
|
|
|
(goto-char (point-min))
|
|
|
|
(search-forward "Version")
|
|
|
|
(search-forward "\r\n\r\n")
|
2022-08-21 17:33:55 +02:00
|
|
|
(search-forward "myproxy.localhost:6667 >> PASS" (pos-eol))
|
2021-09-16 15:35:55 +02:00
|
|
|
(forward-line)
|
2022-08-21 17:33:55 +02:00
|
|
|
(search-forward "irc.gnu.org << :irc.gnu.org 001" (pos-eol))
|
2021-09-16 15:35:55 +02:00
|
|
|
(forward-line)
|
2022-08-21 17:33:55 +02:00
|
|
|
(search-forward "irc.gnu.org << :irc.gnu.org 002" (pos-eol))
|
2021-09-16 15:35:55 +02:00
|
|
|
(forward-line)
|
2022-08-21 17:33:55 +02:00
|
|
|
(search-forward "FooNet << :irc.gnu.org 422" (pos-eol))
|
2021-09-16 15:35:55 +02:00
|
|
|
(forward-line)
|
2022-08-21 17:33:55 +02:00
|
|
|
(search-forward "BarNet << :irc.gnu.org 221" (pos-eol)))
|
2021-09-16 15:35:55 +02:00
|
|
|
(when noninteractive
|
|
|
|
(kill-buffer "*erc-protocol*")
|
|
|
|
(should-not erc-debug-irc-protocol)))
|
2021-09-26 01:53:56 +02:00
|
|
|
|
2023-04-17 00:01:15 -07:00
|
|
|
(ert-deftest erc--split-line ()
|
|
|
|
(let ((erc-default-recipients '("#chan"))
|
|
|
|
(erc-split-line-length 10))
|
|
|
|
(should (equal (erc--split-line "") '("")))
|
|
|
|
(should (equal (erc--split-line "0123456789") '("0123456789")))
|
|
|
|
(should (equal (erc--split-line "0123456789a") '("0123456789" "a")))
|
|
|
|
|
|
|
|
(should (equal (erc--split-line "0123456789 ") '("0123456789" " ")))
|
|
|
|
(should (equal (erc--split-line "01234567 89") '("01234567 " "89")))
|
|
|
|
(should (equal (erc--split-line "0123456 789") '("0123456 " "789")))
|
|
|
|
(should (equal (erc--split-line "0 123456789") '("0 " "123456789")))
|
|
|
|
(should (equal (erc--split-line " 0123456789") '(" " "0123456789")))
|
|
|
|
(should (equal (erc--split-line "012345678 9a") '("012345678 " "9a")))
|
|
|
|
(should (equal (erc--split-line "0123456789 a") '("0123456789" " a")))
|
|
|
|
|
|
|
|
;; UTF-8 vs. KOI-8
|
|
|
|
(should (= 10 (string-bytes "Русск"))) ; utf-8
|
|
|
|
(should (equal (erc--split-line "Русск") '("Русск")))
|
|
|
|
(should (equal (erc--split-line "РусскийТекст") '("Русск" "ийТек" "ст")))
|
|
|
|
(should (equal (erc--split-line "Русский Текст") '("Русск" "ий " "Текст")))
|
|
|
|
(let ((erc-encoding-coding-alist '(("#chan" . cyrillic-koi8))))
|
|
|
|
(should (equal (erc--split-line "Русск") '("Русск")))
|
|
|
|
(should (equal (erc--split-line "РусскийТекст") '("РусскийТек" "ст")))
|
|
|
|
(should (equal (erc--split-line "Русский Текст") '("Русский " "Текст"))))
|
|
|
|
|
|
|
|
;; UTF-8 vs. Latin 1
|
|
|
|
(should (= 17 (string-bytes "Hyvää päivää")))
|
|
|
|
(should (equal (erc--split-line "Hyvää päivää") '("Hyvää " "päivää")))
|
|
|
|
(should (equal (erc--split-line "HyvääPäivää") '("HyvääPä" "ivää")))
|
|
|
|
(let ((erc-encoding-coding-alist '(("#chan" . latin-1))))
|
|
|
|
(should (equal (erc--split-line "Hyvää päivää") '("Hyvää " "päivää")))
|
|
|
|
(should (equal (erc--split-line "HyvääPäivää") '("HyvääPäivä" "ä"))))
|
|
|
|
|
|
|
|
;; Combining characters
|
|
|
|
(should (= 10 (string-bytes "Åström")))
|
|
|
|
(should (equal (erc--split-line "_Åström") '("_Åströ" "m")))
|
|
|
|
(should (equal (erc--split-line "__Åström") '("__Åstr" "öm")))
|
|
|
|
(should (equal (erc--split-line "___Åström") '("___Åstr" "öm")))
|
|
|
|
(when (> emacs-major-version 27)
|
|
|
|
(should (equal (erc--split-line "🏁🚩🎌🏴🏳️🏳️🌈🏳️⚧️🏴☠️")
|
|
|
|
'("🏁🚩" "🎌🏴" "🏳️" "🏳️🌈" "🏳️⚧️" "🏴☠️"))))))
|
|
|
|
|
Improve ERC's handling of multiline prompt input
* lisp/erc/erc.el (erc--pre-send-split-functions): Add new internal
hook allowing members to revise individual lines before sending. This
was created with an eye toward possibly exporting it publicly as a
customizable option.
(erc-last-input-time): Tweak meaning of variable to match likely
original intent, which is that it's only updated on successful calls
to `erc-send-current-line'.
(erc--discard-trailing-multiline-nulls): Conditionally truncate list
of lines to be sent, skipping trailing blanks. This constitutes a
behavioral change. But, considering the nature of the bug being
fixed, it is thought to be justified.
(erc--input-split): Add new internal struct containing split input
lines and flag for command detection.
(erc--input-line-delim-regexp): Add regex var for splitting multiline
prompt input.
(erc--blank-in-multiline-p): Add helper for detecting blank lines.
(erc--check-prompt-input-for-multiline-blanks,
erc--check-prompt-input-for-point-in-bounds,
erc--check-prompt-input-for-running-process): New functions to
encapsulate logic for various pre-flight idiot checks.
(erc--check-prompt-input-functions): Add new hook for validating
prompt input prior to clearing it, internal for now.
(erc-send-current-line): Pre-screen for blank lines and bail out if
necessary.
(erc-send-input): Add optional param to skip checking for blank lines.
Call hook `erc--pre-send-split-functions'.
* test/lisp/erc/erc-tests.el (erc-ring-previous-command): Use new test
helper.
(erc--input-line-delim-regexp,
erc--blank-in-multiline-input-p): Add tests.
(erc-tests--send-prep, erc-tests--set-fake-server-process,
erc-tests--with-process-input-spy): Add test helpers.
(erc--check-prompt-input-functions, erc-send-current-line,
erc-send-whitespace-lines): Add tests.
(Bug#54536)
2022-03-21 05:40:16 -07:00
|
|
|
(ert-deftest erc--input-line-delim-regexp ()
|
|
|
|
(let ((p erc--input-line-delim-regexp))
|
|
|
|
;; none
|
|
|
|
(should (equal '("a" "b") (split-string "a\r\nb" p)))
|
|
|
|
(should (equal '("a" "b") (split-string "a\nb" p)))
|
|
|
|
(should (equal '("a" "b") (split-string "a\rb" p)))
|
|
|
|
|
|
|
|
;; one
|
|
|
|
(should (equal '("") (split-string "" p)))
|
|
|
|
(should (equal '("a" "" "b") (split-string "a\r\rb" p)))
|
|
|
|
(should (equal '("a" "" "b") (split-string "a\n\rb" p)))
|
|
|
|
(should (equal '("a" "" "b") (split-string "a\n\nb" p)))
|
|
|
|
(should (equal '("a" "" "b") (split-string "a\r\r\nb" p)))
|
|
|
|
(should (equal '("a" "" "b") (split-string "a\n\r\nb" p)))
|
|
|
|
(should (equal '("a" "") (split-string "a\n" p)))
|
|
|
|
(should (equal '("a" "") (split-string "a\r" p)))
|
|
|
|
(should (equal '("a" "") (split-string "a\r\n" p)))
|
|
|
|
(should (equal '("" "b") (split-string "\nb" p)))
|
|
|
|
(should (equal '("" "b") (split-string "\rb" p)))
|
|
|
|
(should (equal '("" "b") (split-string "\r\nb" p)))
|
|
|
|
|
|
|
|
;; two
|
|
|
|
(should (equal '("" "") (split-string "\r" p)))
|
|
|
|
(should (equal '("" "") (split-string "\n" p)))
|
|
|
|
(should (equal '("" "") (split-string "\r\n" p)))
|
|
|
|
|
|
|
|
;; three
|
|
|
|
(should (equal '("" "" "") (split-string "\r\r" p)))
|
|
|
|
(should (equal '("" "" "") (split-string "\n\n" p)))
|
|
|
|
(should (equal '("" "" "") (split-string "\n\r" p)))))
|
|
|
|
|
|
|
|
(defun erc-tests--with-process-input-spy (test)
|
|
|
|
(with-current-buffer (get-buffer-create "FakeNet")
|
2023-04-30 07:12:56 -07:00
|
|
|
(let* ((erc--input-review-functions
|
|
|
|
(remove #'erc-add-to-input-ring erc--input-review-functions))
|
|
|
|
(erc-pre-send-functions
|
Improve ERC's handling of multiline prompt input
* lisp/erc/erc.el (erc--pre-send-split-functions): Add new internal
hook allowing members to revise individual lines before sending. This
was created with an eye toward possibly exporting it publicly as a
customizable option.
(erc-last-input-time): Tweak meaning of variable to match likely
original intent, which is that it's only updated on successful calls
to `erc-send-current-line'.
(erc--discard-trailing-multiline-nulls): Conditionally truncate list
of lines to be sent, skipping trailing blanks. This constitutes a
behavioral change. But, considering the nature of the bug being
fixed, it is thought to be justified.
(erc--input-split): Add new internal struct containing split input
lines and flag for command detection.
(erc--input-line-delim-regexp): Add regex var for splitting multiline
prompt input.
(erc--blank-in-multiline-p): Add helper for detecting blank lines.
(erc--check-prompt-input-for-multiline-blanks,
erc--check-prompt-input-for-point-in-bounds,
erc--check-prompt-input-for-running-process): New functions to
encapsulate logic for various pre-flight idiot checks.
(erc--check-prompt-input-functions): Add new hook for validating
prompt input prior to clearing it, internal for now.
(erc-send-current-line): Pre-screen for blank lines and bail out if
necessary.
(erc-send-input): Add optional param to skip checking for blank lines.
Call hook `erc--pre-send-split-functions'.
* test/lisp/erc/erc-tests.el (erc-ring-previous-command): Use new test
helper.
(erc--input-line-delim-regexp,
erc--blank-in-multiline-input-p): Add tests.
(erc-tests--send-prep, erc-tests--set-fake-server-process,
erc-tests--with-process-input-spy): Add test helpers.
(erc--check-prompt-input-functions, erc-send-current-line,
erc-send-whitespace-lines): Add tests.
(Bug#54536)
2022-03-21 05:40:16 -07:00
|
|
|
(remove #'erc-add-to-input-ring erc-pre-send-functions)) ; for now
|
|
|
|
(inhibit-message noninteractive)
|
|
|
|
(erc-server-current-nick "tester")
|
|
|
|
(erc-last-input-time 0)
|
|
|
|
erc-accidental-paste-threshold-seconds
|
2022-06-30 17:15:25 -07:00
|
|
|
erc-send-modify-hook
|
Improve ERC's handling of multiline prompt input
* lisp/erc/erc.el (erc--pre-send-split-functions): Add new internal
hook allowing members to revise individual lines before sending. This
was created with an eye toward possibly exporting it publicly as a
customizable option.
(erc-last-input-time): Tweak meaning of variable to match likely
original intent, which is that it's only updated on successful calls
to `erc-send-current-line'.
(erc--discard-trailing-multiline-nulls): Conditionally truncate list
of lines to be sent, skipping trailing blanks. This constitutes a
behavioral change. But, considering the nature of the bug being
fixed, it is thought to be justified.
(erc--input-split): Add new internal struct containing split input
lines and flag for command detection.
(erc--input-line-delim-regexp): Add regex var for splitting multiline
prompt input.
(erc--blank-in-multiline-p): Add helper for detecting blank lines.
(erc--check-prompt-input-for-multiline-blanks,
erc--check-prompt-input-for-point-in-bounds,
erc--check-prompt-input-for-running-process): New functions to
encapsulate logic for various pre-flight idiot checks.
(erc--check-prompt-input-functions): Add new hook for validating
prompt input prior to clearing it, internal for now.
(erc-send-current-line): Pre-screen for blank lines and bail out if
necessary.
(erc-send-input): Add optional param to skip checking for blank lines.
Call hook `erc--pre-send-split-functions'.
* test/lisp/erc/erc-tests.el (erc-ring-previous-command): Use new test
helper.
(erc--input-line-delim-regexp,
erc--blank-in-multiline-input-p): Add tests.
(erc-tests--send-prep, erc-tests--set-fake-server-process,
erc-tests--with-process-input-spy): Add test helpers.
(erc--check-prompt-input-functions, erc-send-current-line,
erc-send-whitespace-lines): Add tests.
(Bug#54536)
2022-03-21 05:40:16 -07:00
|
|
|
;;
|
|
|
|
calls)
|
|
|
|
(cl-letf (((symbol-function 'erc-process-input-line)
|
|
|
|
(lambda (&rest r) (push r calls)))
|
|
|
|
((symbol-function 'erc-server-buffer)
|
|
|
|
(lambda () (current-buffer))))
|
|
|
|
(erc-tests--send-prep)
|
|
|
|
(funcall test (lambda () (pop calls)))))
|
|
|
|
(when noninteractive (kill-buffer))))
|
|
|
|
|
|
|
|
(ert-deftest erc--check-prompt-input-functions ()
|
|
|
|
(erc-tests--with-process-input-spy
|
|
|
|
(lambda (next)
|
|
|
|
|
|
|
|
(ert-info ("Errors when point not in prompt area") ; actually just dings
|
|
|
|
(insert "/msg #chan hi")
|
|
|
|
(forward-line -1)
|
|
|
|
(let ((e (should-error (erc-send-current-line))))
|
|
|
|
(should (equal "Point is not in the input area" (cadr e))))
|
|
|
|
(goto-char (point-max))
|
|
|
|
(ert-info ("Input remains untouched")
|
|
|
|
(should (save-excursion (erc-bol) (looking-at "/msg #chan hi")))))
|
|
|
|
|
|
|
|
(ert-info ("Errors when no process running")
|
|
|
|
(let ((e (should-error (erc-send-current-line))))
|
|
|
|
(should (equal "ERC: No process running" (cadr e))))
|
|
|
|
(ert-info ("Input remains untouched")
|
|
|
|
(should (save-excursion (erc-bol) (looking-at "/msg #chan hi")))))
|
|
|
|
|
|
|
|
(ert-info ("Errors when line contains empty newline")
|
|
|
|
(erc-bol)
|
|
|
|
(delete-region (point) (point-max))
|
|
|
|
(insert "one\n")
|
|
|
|
(let ((e (should-error (erc-send-current-line))))
|
Improve erc-warn-about-blank-lines behavior
* etc/ERC-NEWS: Mention more detailed feedback when option
`erc-warn-about-blank-lines' is non-nil.
* lisp/erc/erc-common.el (erc--input-split): Add `abortp' slot to
allow a premature exit while validating prompt input.
* lisp/erc/erc.el (erc-warn-about-blank-lines): Clarify meaning of
"blank lines" in doc string, and mention interaction with
companion option `erc-send-whitespace-lines'.
(erc-inhibit-multiline-input): Fix inaccurate description in doc
string.
(erc--input-review-functions): Move
`erc--discard-trailing-multiline-nulls' to end of list, after
`erc--run-input-validation-checks' so that the latter doesn't have to
resplit the original input string in order to issue feedback.
(erc--blank-in-multiline-input-p): Remove unused internal function
originally slated to be part of ERC 5.6.
(erc--check-prompt-input-for-something): New trivial validation
function to check if the input is empty.
(erc--count-blank-lines): New function that tallies up the number of
blank and whitespace-only lines in the current input. One downside of
this design is that this function's conclusions aren't shared with
`erc--discard-trailing-multiline-nulls', which must decide on its own
how many lines to strip.
(erc--check-prompt-explanation): New variable.
(erc--check-prompt-input-for-multiline-blanks): Rework significantly
to provide more informative messages and more sensible behavior for
common cases with respect to relevant option values.
(erc--check-prompt-input-functions): Add new validation function
`erc--check-prompt-for-something'.
(erc--run-input-validation-checks): Set `abortp' slot of
`erc--input-split' when hooks return a non-string, rather than
generate an unhelpful fallback message. Also print a message when
the variable `erc--check-prompt-explanation' is non-nil.
(erc-send-current-line): When the `abortp' slot of the current
`erc--input-split' object is non-nil, forgo normal input processing.
This fixes a regression in 5.6-git, which previously emitted an error
message when it should have just exited the command.
(erc--discard-trailing-multiline-nulls): Always run, regardless of
`erc-send-whitespace-lines', and leave a blank line behind when
stripping a message consisting of only blank lines.
(erc--run-send-hooks): Always run hooks and surrounding logic rather
than only when hooks are populated.
* test/lisp/erc/erc-tests.el (erc--refresh-prompt): Add assertion and
use default value for `erc--input-review-functions'.
(erc-ring-previous-command): Use default value for
`erc--input-review-functions' and ensure `erc-current-nick' does not
error.
(erc--blank-in-multiline-input-p): Remove obsolete test.
(erc--check-prompt-input-functions): Update expected message.
(erc--discard-trailing-multiline-nulls, erc--count-blank-lines): New
tests.
(erc-tests--check-prompt-input--expect,
erc-tests--check-prompt-input-messages): New helper variables.
(erc--check-prompt-input-for-multiline-blanks,
erc--check-prompt-input-for-multiline-blanks/explanations): New tests.
(erc-send-whitespace-lines): Expect hook-processing logic to pad empty
lines instead of deferring to `erc-send-input-line-function'.
(Bug#66073)
2023-09-15 06:08:55 -07:00
|
|
|
(should (string-prefix-p "Trailing line detected" (cadr e))))
|
Improve ERC's handling of multiline prompt input
* lisp/erc/erc.el (erc--pre-send-split-functions): Add new internal
hook allowing members to revise individual lines before sending. This
was created with an eye toward possibly exporting it publicly as a
customizable option.
(erc-last-input-time): Tweak meaning of variable to match likely
original intent, which is that it's only updated on successful calls
to `erc-send-current-line'.
(erc--discard-trailing-multiline-nulls): Conditionally truncate list
of lines to be sent, skipping trailing blanks. This constitutes a
behavioral change. But, considering the nature of the bug being
fixed, it is thought to be justified.
(erc--input-split): Add new internal struct containing split input
lines and flag for command detection.
(erc--input-line-delim-regexp): Add regex var for splitting multiline
prompt input.
(erc--blank-in-multiline-p): Add helper for detecting blank lines.
(erc--check-prompt-input-for-multiline-blanks,
erc--check-prompt-input-for-point-in-bounds,
erc--check-prompt-input-for-running-process): New functions to
encapsulate logic for various pre-flight idiot checks.
(erc--check-prompt-input-functions): Add new hook for validating
prompt input prior to clearing it, internal for now.
(erc-send-current-line): Pre-screen for blank lines and bail out if
necessary.
(erc-send-input): Add optional param to skip checking for blank lines.
Call hook `erc--pre-send-split-functions'.
* test/lisp/erc/erc-tests.el (erc-ring-previous-command): Use new test
helper.
(erc--input-line-delim-regexp,
erc--blank-in-multiline-input-p): Add tests.
(erc-tests--send-prep, erc-tests--set-fake-server-process,
erc-tests--with-process-input-spy): Add test helpers.
(erc--check-prompt-input-functions, erc-send-current-line,
erc-send-whitespace-lines): Add tests.
(Bug#54536)
2022-03-21 05:40:16 -07:00
|
|
|
(goto-char (point-max))
|
|
|
|
(ert-info ("Input remains untouched")
|
|
|
|
(should (save-excursion (goto-char erc-input-marker)
|
|
|
|
(looking-at "one\n")))))
|
|
|
|
|
|
|
|
(should (= 0 erc-last-input-time))
|
|
|
|
(should-not (funcall next)))))
|
|
|
|
|
|
|
|
;; These also indirectly tests `erc-send-input'
|
|
|
|
|
|
|
|
(ert-deftest erc-send-current-line ()
|
|
|
|
(erc-tests--with-process-input-spy
|
|
|
|
(lambda (next)
|
|
|
|
(erc-tests--set-fake-server-process "sleep" "1")
|
|
|
|
(should (= 0 erc-last-input-time))
|
|
|
|
|
|
|
|
(ert-info ("Simple command")
|
|
|
|
(insert "/msg #chan hi")
|
|
|
|
(erc-send-current-line)
|
|
|
|
(ert-info ("Prompt restored")
|
|
|
|
(forward-line 0)
|
|
|
|
(should (looking-at-p erc-prompt)))
|
|
|
|
(ert-info ("Input cleared")
|
|
|
|
(erc-bol)
|
|
|
|
(should (eq (point) (point-max))))
|
2023-04-17 00:01:15 -07:00
|
|
|
;; The `force' argument is irrelevant here because it can't
|
|
|
|
;; influence dispatched handlers, such as `erc-cmd-MSG'.
|
|
|
|
(should (pcase (funcall next) (`("/msg #chan hi\n" ,_ nil) t))))
|
Improve ERC's handling of multiline prompt input
* lisp/erc/erc.el (erc--pre-send-split-functions): Add new internal
hook allowing members to revise individual lines before sending. This
was created with an eye toward possibly exporting it publicly as a
customizable option.
(erc-last-input-time): Tweak meaning of variable to match likely
original intent, which is that it's only updated on successful calls
to `erc-send-current-line'.
(erc--discard-trailing-multiline-nulls): Conditionally truncate list
of lines to be sent, skipping trailing blanks. This constitutes a
behavioral change. But, considering the nature of the bug being
fixed, it is thought to be justified.
(erc--input-split): Add new internal struct containing split input
lines and flag for command detection.
(erc--input-line-delim-regexp): Add regex var for splitting multiline
prompt input.
(erc--blank-in-multiline-p): Add helper for detecting blank lines.
(erc--check-prompt-input-for-multiline-blanks,
erc--check-prompt-input-for-point-in-bounds,
erc--check-prompt-input-for-running-process): New functions to
encapsulate logic for various pre-flight idiot checks.
(erc--check-prompt-input-functions): Add new hook for validating
prompt input prior to clearing it, internal for now.
(erc-send-current-line): Pre-screen for blank lines and bail out if
necessary.
(erc-send-input): Add optional param to skip checking for blank lines.
Call hook `erc--pre-send-split-functions'.
* test/lisp/erc/erc-tests.el (erc-ring-previous-command): Use new test
helper.
(erc--input-line-delim-regexp,
erc--blank-in-multiline-input-p): Add tests.
(erc-tests--send-prep, erc-tests--set-fake-server-process,
erc-tests--with-process-input-spy): Add test helpers.
(erc--check-prompt-input-functions, erc-send-current-line,
erc-send-whitespace-lines): Add tests.
(Bug#54536)
2022-03-21 05:40:16 -07:00
|
|
|
|
|
|
|
(ert-info ("Simple non-command")
|
|
|
|
(insert "hi")
|
|
|
|
(erc-send-current-line)
|
|
|
|
(should (eq (point) (point-max)))
|
|
|
|
(should (save-excursion (forward-line -1)
|
|
|
|
(search-forward "<tester> hi")))
|
2023-04-17 00:01:15 -07:00
|
|
|
;; Non-commands are forced only when `erc-flood-protect' is
|
|
|
|
;; nil, which conflates two orthogonal concerns.
|
Improve ERC's handling of multiline prompt input
* lisp/erc/erc.el (erc--pre-send-split-functions): Add new internal
hook allowing members to revise individual lines before sending. This
was created with an eye toward possibly exporting it publicly as a
customizable option.
(erc-last-input-time): Tweak meaning of variable to match likely
original intent, which is that it's only updated on successful calls
to `erc-send-current-line'.
(erc--discard-trailing-multiline-nulls): Conditionally truncate list
of lines to be sent, skipping trailing blanks. This constitutes a
behavioral change. But, considering the nature of the bug being
fixed, it is thought to be justified.
(erc--input-split): Add new internal struct containing split input
lines and flag for command detection.
(erc--input-line-delim-regexp): Add regex var for splitting multiline
prompt input.
(erc--blank-in-multiline-p): Add helper for detecting blank lines.
(erc--check-prompt-input-for-multiline-blanks,
erc--check-prompt-input-for-point-in-bounds,
erc--check-prompt-input-for-running-process): New functions to
encapsulate logic for various pre-flight idiot checks.
(erc--check-prompt-input-functions): Add new hook for validating
prompt input prior to clearing it, internal for now.
(erc-send-current-line): Pre-screen for blank lines and bail out if
necessary.
(erc-send-input): Add optional param to skip checking for blank lines.
Call hook `erc--pre-send-split-functions'.
* test/lisp/erc/erc-tests.el (erc-ring-previous-command): Use new test
helper.
(erc--input-line-delim-regexp,
erc--blank-in-multiline-input-p): Add tests.
(erc-tests--send-prep, erc-tests--set-fake-server-process,
erc-tests--with-process-input-spy): Add test helpers.
(erc--check-prompt-input-functions, erc-send-current-line,
erc-send-whitespace-lines): Add tests.
(Bug#54536)
2022-03-21 05:40:16 -07:00
|
|
|
(should (equal (funcall next) '("hi\n" nil t))))
|
|
|
|
|
|
|
|
(should (consp erc-last-input-time)))))
|
|
|
|
|
Improve erc-warn-about-blank-lines behavior
* etc/ERC-NEWS: Mention more detailed feedback when option
`erc-warn-about-blank-lines' is non-nil.
* lisp/erc/erc-common.el (erc--input-split): Add `abortp' slot to
allow a premature exit while validating prompt input.
* lisp/erc/erc.el (erc-warn-about-blank-lines): Clarify meaning of
"blank lines" in doc string, and mention interaction with
companion option `erc-send-whitespace-lines'.
(erc-inhibit-multiline-input): Fix inaccurate description in doc
string.
(erc--input-review-functions): Move
`erc--discard-trailing-multiline-nulls' to end of list, after
`erc--run-input-validation-checks' so that the latter doesn't have to
resplit the original input string in order to issue feedback.
(erc--blank-in-multiline-input-p): Remove unused internal function
originally slated to be part of ERC 5.6.
(erc--check-prompt-input-for-something): New trivial validation
function to check if the input is empty.
(erc--count-blank-lines): New function that tallies up the number of
blank and whitespace-only lines in the current input. One downside of
this design is that this function's conclusions aren't shared with
`erc--discard-trailing-multiline-nulls', which must decide on its own
how many lines to strip.
(erc--check-prompt-explanation): New variable.
(erc--check-prompt-input-for-multiline-blanks): Rework significantly
to provide more informative messages and more sensible behavior for
common cases with respect to relevant option values.
(erc--check-prompt-input-functions): Add new validation function
`erc--check-prompt-for-something'.
(erc--run-input-validation-checks): Set `abortp' slot of
`erc--input-split' when hooks return a non-string, rather than
generate an unhelpful fallback message. Also print a message when
the variable `erc--check-prompt-explanation' is non-nil.
(erc-send-current-line): When the `abortp' slot of the current
`erc--input-split' object is non-nil, forgo normal input processing.
This fixes a regression in 5.6-git, which previously emitted an error
message when it should have just exited the command.
(erc--discard-trailing-multiline-nulls): Always run, regardless of
`erc-send-whitespace-lines', and leave a blank line behind when
stripping a message consisting of only blank lines.
(erc--run-send-hooks): Always run hooks and surrounding logic rather
than only when hooks are populated.
* test/lisp/erc/erc-tests.el (erc--refresh-prompt): Add assertion and
use default value for `erc--input-review-functions'.
(erc-ring-previous-command): Use default value for
`erc--input-review-functions' and ensure `erc-current-nick' does not
error.
(erc--blank-in-multiline-input-p): Remove obsolete test.
(erc--check-prompt-input-functions): Update expected message.
(erc--discard-trailing-multiline-nulls, erc--count-blank-lines): New
tests.
(erc-tests--check-prompt-input--expect,
erc-tests--check-prompt-input-messages): New helper variables.
(erc--check-prompt-input-for-multiline-blanks,
erc--check-prompt-input-for-multiline-blanks/explanations): New tests.
(erc-send-whitespace-lines): Expect hook-processing logic to pad empty
lines instead of deferring to `erc-send-input-line-function'.
(Bug#66073)
2023-09-15 06:08:55 -07:00
|
|
|
(ert-deftest erc--discard-trailing-multiline-nulls ()
|
|
|
|
(pcase-dolist (`(,input ,want) '((("") (""))
|
|
|
|
(("" "") (""))
|
|
|
|
(("a") ("a"))
|
|
|
|
(("a" "") ("a"))
|
|
|
|
(("" "a") ("" "a"))
|
|
|
|
(("" "a" "") ("" "a"))))
|
|
|
|
(ert-info ((format "Input: %S, want: %S" input want))
|
|
|
|
(let ((s (make-erc--input-split :lines input)))
|
|
|
|
(erc--discard-trailing-multiline-nulls s)
|
|
|
|
(should (equal (erc--input-split-lines s) want))))))
|
|
|
|
|
|
|
|
(ert-deftest erc--count-blank-lines ()
|
|
|
|
(pcase-dolist (`(,input ,want) '((() (0 0 0))
|
|
|
|
(("") (1 1 0))
|
|
|
|
(("" "") (2 1 1))
|
|
|
|
(("" "" "") (3 1 2))
|
|
|
|
((" " "") (2 0 1))
|
|
|
|
((" " "" "") (3 0 2))
|
|
|
|
(("" " " "") (3 1 1))
|
|
|
|
(("" "" " ") (3 2 0))
|
|
|
|
(("a") (0 0 0))
|
|
|
|
(("a" "") (1 0 1))
|
|
|
|
(("a" " " "") (2 0 1))
|
|
|
|
(("a" "" "") (2 0 2))
|
|
|
|
(("a" "b") (0 0 0))
|
|
|
|
(("a" "" "b") (1 1 0))
|
|
|
|
(("a" " " "b") (1 0 0))
|
|
|
|
(("" "a") (1 1 0))
|
|
|
|
((" " "a") (1 0 0))
|
|
|
|
(("" "a" "") (2 1 1))
|
|
|
|
(("" " " "a" "" " ") (4 2 0))
|
|
|
|
(("" " " "a" "" " " "") (5 2 1))))
|
|
|
|
(ert-info ((format "Input: %S, want: %S" input want))
|
|
|
|
(should (equal (erc--count-blank-lines input) want)))))
|
|
|
|
|
|
|
|
;; Opt `wb': `erc-warn-about-blank-lines'
|
|
|
|
;; Opt `sw': `erc-send-whitespace-lines'
|
|
|
|
;; `s': " \n",`a': "a\n",`b': "b\n"
|
|
|
|
(defvar erc-tests--check-prompt-input--expect
|
|
|
|
;; opts "" " " "\n" "\n " " \n" "\n\n" "a\n" "a\n " "a\n \nb"
|
|
|
|
'(((+wb -sw) err err err err err err err err err)
|
|
|
|
((-wb -sw) nop nop nop nop nop nop nop nop nop)
|
|
|
|
((+wb +sw) err (s) (0 s) (1 s s) (s) (0 s) (0 a) (a s) (a s b))
|
|
|
|
((-wb +sw) nop (s) (s) (s s) (s) (s) (a) (a s) (a s b))))
|
|
|
|
|
|
|
|
;; Help messages echoed (not IRC message) was emitted
|
|
|
|
(defvar erc-tests--check-prompt-input-messages
|
|
|
|
'("Stripping" "Padding"))
|
|
|
|
|
|
|
|
(ert-deftest erc--check-prompt-input-for-multiline-blanks ()
|
|
|
|
(erc-tests--with-process-input-spy
|
|
|
|
(lambda (next)
|
|
|
|
(erc-tests--set-fake-server-process "sleep" "1")
|
|
|
|
(should-not erc-send-whitespace-lines)
|
|
|
|
(should erc-warn-about-blank-lines)
|
|
|
|
|
|
|
|
(pcase-dolist (`((,wb ,sw) . ,ex) erc-tests--check-prompt-input--expect)
|
|
|
|
(let ((print-escape-newlines t)
|
|
|
|
(erc-warn-about-blank-lines (eq wb '+wb))
|
|
|
|
(erc-send-whitespace-lines (eq sw '+sw))
|
|
|
|
(samples '("" " " "\n" "\n " " \n" "\n\n"
|
|
|
|
"a\n" "a\n " "a\n \nb")))
|
|
|
|
(setq ex `(,@ex (a) (a b)) ; baseline, same for all combos
|
|
|
|
samples `(,@samples "a" "a\nb"))
|
|
|
|
(dolist (input samples)
|
|
|
|
(insert input)
|
|
|
|
(ert-info ((format "Opts: %S, Input: %S, want: %S"
|
|
|
|
(list wb sw) input (car ex)))
|
|
|
|
(ert-with-message-capture messages
|
|
|
|
(pcase-exhaustive (pop ex)
|
|
|
|
('err (let ((e (should-error (erc-send-current-line))))
|
|
|
|
(should (string-match (rx (| "trailing" "blank"))
|
|
|
|
(cadr e))))
|
|
|
|
(should (equal (erc-user-input) input))
|
|
|
|
(should-not (funcall next)))
|
|
|
|
('nop (erc-send-current-line)
|
|
|
|
(should (equal (erc-user-input) input))
|
|
|
|
(should-not (funcall next)))
|
|
|
|
('clr (erc-send-current-line)
|
|
|
|
(should (string-empty-p (erc-user-input)))
|
|
|
|
(should-not (funcall next)))
|
|
|
|
((and (pred consp) v)
|
|
|
|
(erc-send-current-line)
|
|
|
|
(should (string-empty-p (erc-user-input)))
|
|
|
|
(setq v (reverse v)) ; don't use `nreverse' here
|
|
|
|
(while v
|
|
|
|
(pcase (pop v)
|
|
|
|
((and (pred integerp) n)
|
|
|
|
(should (string-search
|
|
|
|
(nth n erc-tests--check-prompt-input-messages)
|
|
|
|
messages)))
|
|
|
|
('s (should (equal " \n" (car (funcall next)))))
|
|
|
|
('a (should (equal "a\n" (car (funcall next)))))
|
|
|
|
('b (should (equal "b\n" (car (funcall next)))))))
|
|
|
|
(should-not (funcall next))))))
|
|
|
|
(delete-region erc-input-marker (point-max))))))))
|
|
|
|
|
|
|
|
(ert-deftest erc--check-prompt-input-for-multiline-blanks/explanations ()
|
|
|
|
(should erc-warn-about-blank-lines)
|
|
|
|
(should-not erc-send-whitespace-lines)
|
|
|
|
|
|
|
|
(let ((erc-send-whitespace-lines t))
|
|
|
|
(pcase-dolist (`(,input ,msg)
|
|
|
|
'((("") "Padding (1) blank line")
|
|
|
|
(("" " ") "Padding (1) blank line")
|
|
|
|
((" " "") "Stripping (1) blank line")
|
|
|
|
(("a" "") "Stripping (1) blank line")
|
|
|
|
(("" "") "Stripping (1) and padding (1) blank lines")
|
|
|
|
(("" "" "") "Stripping (2) and padding (1) blank lines")
|
|
|
|
(("" "a" "" "b" "" "c" "" "")
|
|
|
|
"Stripping (2) and padding (3) blank lines")))
|
|
|
|
(ert-info ((format "Input: %S, Msg: %S" input msg))
|
|
|
|
(let (erc--check-prompt-explanation)
|
|
|
|
(should-not (erc--check-prompt-input-for-multiline-blanks nil input))
|
|
|
|
(should (equal (list msg) erc--check-prompt-explanation))))))
|
|
|
|
|
|
|
|
(pcase-dolist (`(,input ,msg)
|
|
|
|
'((("") "Blank line detected")
|
|
|
|
(("" " ") "2 blank lines detected")
|
|
|
|
((" " "") "2 blank (1 trailing) lines detected")
|
|
|
|
(("a" "") "Trailing line detected")
|
|
|
|
(("" "") "2 blank (1 trailing) lines detected")
|
|
|
|
(("a" "" "") "2 trailing lines detected")
|
|
|
|
(("" "a" "" "b" "" "c" "" "")
|
|
|
|
"5 blank (2 trailing) lines detected")))
|
|
|
|
(ert-info ((format "Input: %S, Msg: %S" input msg))
|
|
|
|
(let ((rv (erc--check-prompt-input-for-multiline-blanks nil input)))
|
|
|
|
(should (equal (concat msg " (see `erc-send-whitespace-lines')")
|
|
|
|
rv ))))))
|
|
|
|
|
Improve ERC's handling of multiline prompt input
* lisp/erc/erc.el (erc--pre-send-split-functions): Add new internal
hook allowing members to revise individual lines before sending. This
was created with an eye toward possibly exporting it publicly as a
customizable option.
(erc-last-input-time): Tweak meaning of variable to match likely
original intent, which is that it's only updated on successful calls
to `erc-send-current-line'.
(erc--discard-trailing-multiline-nulls): Conditionally truncate list
of lines to be sent, skipping trailing blanks. This constitutes a
behavioral change. But, considering the nature of the bug being
fixed, it is thought to be justified.
(erc--input-split): Add new internal struct containing split input
lines and flag for command detection.
(erc--input-line-delim-regexp): Add regex var for splitting multiline
prompt input.
(erc--blank-in-multiline-p): Add helper for detecting blank lines.
(erc--check-prompt-input-for-multiline-blanks,
erc--check-prompt-input-for-point-in-bounds,
erc--check-prompt-input-for-running-process): New functions to
encapsulate logic for various pre-flight idiot checks.
(erc--check-prompt-input-functions): Add new hook for validating
prompt input prior to clearing it, internal for now.
(erc-send-current-line): Pre-screen for blank lines and bail out if
necessary.
(erc-send-input): Add optional param to skip checking for blank lines.
Call hook `erc--pre-send-split-functions'.
* test/lisp/erc/erc-tests.el (erc-ring-previous-command): Use new test
helper.
(erc--input-line-delim-regexp,
erc--blank-in-multiline-input-p): Add tests.
(erc-tests--send-prep, erc-tests--set-fake-server-process,
erc-tests--with-process-input-spy): Add test helpers.
(erc--check-prompt-input-functions, erc-send-current-line,
erc-send-whitespace-lines): Add tests.
(Bug#54536)
2022-03-21 05:40:16 -07:00
|
|
|
(ert-deftest erc-send-whitespace-lines ()
|
|
|
|
(erc-tests--with-process-input-spy
|
|
|
|
(lambda (next)
|
|
|
|
(erc-tests--set-fake-server-process "sleep" "1")
|
|
|
|
(setq-local erc-send-whitespace-lines t)
|
|
|
|
|
|
|
|
(ert-info ("Multiline hunk with blank line correctly split")
|
|
|
|
(insert "one\n\ntwo")
|
|
|
|
(erc-send-current-line)
|
|
|
|
(ert-info ("Prompt restored")
|
|
|
|
(forward-line 0)
|
|
|
|
(should (looking-at-p erc-prompt)))
|
|
|
|
(ert-info ("Input cleared")
|
|
|
|
(erc-bol)
|
|
|
|
(should (eq (point) (point-max))))
|
|
|
|
(should (equal (funcall next) '("two\n" nil t)))
|
Improve erc-warn-about-blank-lines behavior
* etc/ERC-NEWS: Mention more detailed feedback when option
`erc-warn-about-blank-lines' is non-nil.
* lisp/erc/erc-common.el (erc--input-split): Add `abortp' slot to
allow a premature exit while validating prompt input.
* lisp/erc/erc.el (erc-warn-about-blank-lines): Clarify meaning of
"blank lines" in doc string, and mention interaction with
companion option `erc-send-whitespace-lines'.
(erc-inhibit-multiline-input): Fix inaccurate description in doc
string.
(erc--input-review-functions): Move
`erc--discard-trailing-multiline-nulls' to end of list, after
`erc--run-input-validation-checks' so that the latter doesn't have to
resplit the original input string in order to issue feedback.
(erc--blank-in-multiline-input-p): Remove unused internal function
originally slated to be part of ERC 5.6.
(erc--check-prompt-input-for-something): New trivial validation
function to check if the input is empty.
(erc--count-blank-lines): New function that tallies up the number of
blank and whitespace-only lines in the current input. One downside of
this design is that this function's conclusions aren't shared with
`erc--discard-trailing-multiline-nulls', which must decide on its own
how many lines to strip.
(erc--check-prompt-explanation): New variable.
(erc--check-prompt-input-for-multiline-blanks): Rework significantly
to provide more informative messages and more sensible behavior for
common cases with respect to relevant option values.
(erc--check-prompt-input-functions): Add new validation function
`erc--check-prompt-for-something'.
(erc--run-input-validation-checks): Set `abortp' slot of
`erc--input-split' when hooks return a non-string, rather than
generate an unhelpful fallback message. Also print a message when
the variable `erc--check-prompt-explanation' is non-nil.
(erc-send-current-line): When the `abortp' slot of the current
`erc--input-split' object is non-nil, forgo normal input processing.
This fixes a regression in 5.6-git, which previously emitted an error
message when it should have just exited the command.
(erc--discard-trailing-multiline-nulls): Always run, regardless of
`erc-send-whitespace-lines', and leave a blank line behind when
stripping a message consisting of only blank lines.
(erc--run-send-hooks): Always run hooks and surrounding logic rather
than only when hooks are populated.
* test/lisp/erc/erc-tests.el (erc--refresh-prompt): Add assertion and
use default value for `erc--input-review-functions'.
(erc-ring-previous-command): Use default value for
`erc--input-review-functions' and ensure `erc-current-nick' does not
error.
(erc--blank-in-multiline-input-p): Remove obsolete test.
(erc--check-prompt-input-functions): Update expected message.
(erc--discard-trailing-multiline-nulls, erc--count-blank-lines): New
tests.
(erc-tests--check-prompt-input--expect,
erc-tests--check-prompt-input-messages): New helper variables.
(erc--check-prompt-input-for-multiline-blanks,
erc--check-prompt-input-for-multiline-blanks/explanations): New tests.
(erc-send-whitespace-lines): Expect hook-processing logic to pad empty
lines instead of deferring to `erc-send-input-line-function'.
(Bug#66073)
2023-09-15 06:08:55 -07:00
|
|
|
(should (equal (funcall next) '(" \n" nil t)))
|
Improve ERC's handling of multiline prompt input
* lisp/erc/erc.el (erc--pre-send-split-functions): Add new internal
hook allowing members to revise individual lines before sending. This
was created with an eye toward possibly exporting it publicly as a
customizable option.
(erc-last-input-time): Tweak meaning of variable to match likely
original intent, which is that it's only updated on successful calls
to `erc-send-current-line'.
(erc--discard-trailing-multiline-nulls): Conditionally truncate list
of lines to be sent, skipping trailing blanks. This constitutes a
behavioral change. But, considering the nature of the bug being
fixed, it is thought to be justified.
(erc--input-split): Add new internal struct containing split input
lines and flag for command detection.
(erc--input-line-delim-regexp): Add regex var for splitting multiline
prompt input.
(erc--blank-in-multiline-p): Add helper for detecting blank lines.
(erc--check-prompt-input-for-multiline-blanks,
erc--check-prompt-input-for-point-in-bounds,
erc--check-prompt-input-for-running-process): New functions to
encapsulate logic for various pre-flight idiot checks.
(erc--check-prompt-input-functions): Add new hook for validating
prompt input prior to clearing it, internal for now.
(erc-send-current-line): Pre-screen for blank lines and bail out if
necessary.
(erc-send-input): Add optional param to skip checking for blank lines.
Call hook `erc--pre-send-split-functions'.
* test/lisp/erc/erc-tests.el (erc-ring-previous-command): Use new test
helper.
(erc--input-line-delim-regexp,
erc--blank-in-multiline-input-p): Add tests.
(erc-tests--send-prep, erc-tests--set-fake-server-process,
erc-tests--with-process-input-spy): Add test helpers.
(erc--check-prompt-input-functions, erc-send-current-line,
erc-send-whitespace-lines): Add tests.
(Bug#54536)
2022-03-21 05:40:16 -07:00
|
|
|
(should (equal (funcall next) '("one\n" nil t))))
|
|
|
|
|
|
|
|
(ert-info ("Multiline hunk with trailing newline filtered")
|
|
|
|
(insert "hi\n")
|
|
|
|
(erc-send-current-line)
|
|
|
|
(ert-info ("Input cleared")
|
|
|
|
(erc-bol)
|
|
|
|
(should (eq (point) (point-max))))
|
|
|
|
(should (equal (funcall next) '("hi\n" nil t)))
|
|
|
|
(should-not (funcall next)))
|
|
|
|
|
|
|
|
(ert-info ("Multiline hunk with trailing carriage filtered")
|
|
|
|
(insert "hi\r")
|
|
|
|
(erc-send-current-line)
|
|
|
|
(ert-info ("Input cleared")
|
|
|
|
(erc-bol)
|
|
|
|
(should (eq (point) (point-max))))
|
|
|
|
(should (equal (funcall next) '("hi\n" nil t)))
|
|
|
|
(should-not (funcall next)))
|
|
|
|
|
|
|
|
(ert-info ("Multiline command with trailing blank filtered")
|
2023-06-09 21:00:03 -07:00
|
|
|
(dolist (p '("/a b" "/a b\n" "/a b\n\n" "/a b\n\n\n"))
|
Improve ERC's handling of multiline prompt input
* lisp/erc/erc.el (erc--pre-send-split-functions): Add new internal
hook allowing members to revise individual lines before sending. This
was created with an eye toward possibly exporting it publicly as a
customizable option.
(erc-last-input-time): Tweak meaning of variable to match likely
original intent, which is that it's only updated on successful calls
to `erc-send-current-line'.
(erc--discard-trailing-multiline-nulls): Conditionally truncate list
of lines to be sent, skipping trailing blanks. This constitutes a
behavioral change. But, considering the nature of the bug being
fixed, it is thought to be justified.
(erc--input-split): Add new internal struct containing split input
lines and flag for command detection.
(erc--input-line-delim-regexp): Add regex var for splitting multiline
prompt input.
(erc--blank-in-multiline-p): Add helper for detecting blank lines.
(erc--check-prompt-input-for-multiline-blanks,
erc--check-prompt-input-for-point-in-bounds,
erc--check-prompt-input-for-running-process): New functions to
encapsulate logic for various pre-flight idiot checks.
(erc--check-prompt-input-functions): Add new hook for validating
prompt input prior to clearing it, internal for now.
(erc-send-current-line): Pre-screen for blank lines and bail out if
necessary.
(erc-send-input): Add optional param to skip checking for blank lines.
Call hook `erc--pre-send-split-functions'.
* test/lisp/erc/erc-tests.el (erc-ring-previous-command): Use new test
helper.
(erc--input-line-delim-regexp,
erc--blank-in-multiline-input-p): Add tests.
(erc-tests--send-prep, erc-tests--set-fake-server-process,
erc-tests--with-process-input-spy): Add test helpers.
(erc--check-prompt-input-functions, erc-send-current-line,
erc-send-whitespace-lines): Add tests.
(Bug#54536)
2022-03-21 05:40:16 -07:00
|
|
|
(insert p)
|
|
|
|
(erc-send-current-line)
|
|
|
|
(erc-bol)
|
|
|
|
(should (eq (point) (point-max)))
|
2023-06-09 21:00:03 -07:00
|
|
|
(should (pcase (funcall next) (`(,cmd ,_ nil) (equal cmd "/a b\n"))))
|
2023-04-17 23:09:49 -07:00
|
|
|
(should-not (funcall next))))
|
|
|
|
|
|
|
|
(ert-info ("Multiline command with non-blanks errors")
|
|
|
|
(dolist (p '("/a b\nc\n\n" "/a b\n/c\n\n" "/a b\n\nc\n\n"
|
|
|
|
"/a\n c\n" "/a\nb\n" "/a\n/b\n" "/a \n \n"))
|
|
|
|
(insert p)
|
|
|
|
(should-error (erc-send-current-line))
|
|
|
|
(goto-char erc-input-marker)
|
|
|
|
(delete-region (point) (point-max))
|
Improve ERC's handling of multiline prompt input
* lisp/erc/erc.el (erc--pre-send-split-functions): Add new internal
hook allowing members to revise individual lines before sending. This
was created with an eye toward possibly exporting it publicly as a
customizable option.
(erc-last-input-time): Tweak meaning of variable to match likely
original intent, which is that it's only updated on successful calls
to `erc-send-current-line'.
(erc--discard-trailing-multiline-nulls): Conditionally truncate list
of lines to be sent, skipping trailing blanks. This constitutes a
behavioral change. But, considering the nature of the bug being
fixed, it is thought to be justified.
(erc--input-split): Add new internal struct containing split input
lines and flag for command detection.
(erc--input-line-delim-regexp): Add regex var for splitting multiline
prompt input.
(erc--blank-in-multiline-p): Add helper for detecting blank lines.
(erc--check-prompt-input-for-multiline-blanks,
erc--check-prompt-input-for-point-in-bounds,
erc--check-prompt-input-for-running-process): New functions to
encapsulate logic for various pre-flight idiot checks.
(erc--check-prompt-input-functions): Add new hook for validating
prompt input prior to clearing it, internal for now.
(erc-send-current-line): Pre-screen for blank lines and bail out if
necessary.
(erc-send-input): Add optional param to skip checking for blank lines.
Call hook `erc--pre-send-split-functions'.
* test/lisp/erc/erc-tests.el (erc-ring-previous-command): Use new test
helper.
(erc--input-line-delim-regexp,
erc--blank-in-multiline-input-p): Add tests.
(erc-tests--send-prep, erc-tests--set-fake-server-process,
erc-tests--with-process-input-spy): Add test helpers.
(erc--check-prompt-input-functions, erc-send-current-line,
erc-send-whitespace-lines): Add tests.
(Bug#54536)
2022-03-21 05:40:16 -07:00
|
|
|
(should-not (funcall next))))
|
|
|
|
|
|
|
|
(ert-info ("Multiline hunk with trailing whitespace not filtered")
|
|
|
|
(insert "there\n ")
|
|
|
|
(erc-send-current-line)
|
|
|
|
(should (equal (funcall next) '(" \n" nil t)))
|
|
|
|
(should (equal (funcall next) '("there\n" nil t)))
|
|
|
|
(should-not (funcall next))))))
|
2021-11-06 03:09:43 +01:00
|
|
|
|
2022-04-27 02:27:32 -07:00
|
|
|
(ert-deftest erc--check-prompt-input-for-excess-lines ()
|
|
|
|
(ert-info ("Without `erc-inhibit-multiline-input'")
|
|
|
|
(should-not erc-inhibit-multiline-input)
|
|
|
|
(should-not (erc--check-prompt-input-for-excess-lines "" '("a" "b"))))
|
|
|
|
|
|
|
|
(ert-info ("With `erc-inhibit-multiline-input' as t (2)")
|
|
|
|
(let ((erc-inhibit-multiline-input t))
|
|
|
|
(should-not (erc--check-prompt-input-for-excess-lines "" '("a")))
|
2023-04-30 07:12:56 -07:00
|
|
|
;; Does not trim trailing blanks.
|
|
|
|
(should (erc--check-prompt-input-for-excess-lines "" '("a" "")))
|
2022-04-27 02:27:32 -07:00
|
|
|
(should (erc--check-prompt-input-for-excess-lines "" '("a" "b")))))
|
|
|
|
|
|
|
|
(ert-info ("With `erc-inhibit-multiline-input' as 3")
|
|
|
|
(let ((erc-inhibit-multiline-input 3))
|
|
|
|
(should-not (erc--check-prompt-input-for-excess-lines "" '("a" "b")))
|
2023-04-30 07:12:56 -07:00
|
|
|
(should (erc--check-prompt-input-for-excess-lines "" '("a" "b" "")))
|
2022-04-27 02:27:32 -07:00
|
|
|
(should (erc--check-prompt-input-for-excess-lines "" '("a" "b" "c")))))
|
|
|
|
|
|
|
|
(ert-info ("With `erc-ask-about-multiline-input'")
|
|
|
|
(let ((erc-inhibit-multiline-input t)
|
|
|
|
(erc-ask-about-multiline-input t))
|
|
|
|
(ert-simulate-keys '(?n ?\r ?y ?\r)
|
|
|
|
(should (erc--check-prompt-input-for-excess-lines "" '("a" "b")))
|
|
|
|
(should-not (erc--check-prompt-input-for-excess-lines "" '("a" "b")))))
|
|
|
|
(should-not erc-ask-about-multiline-input)))
|
|
|
|
|
2021-11-06 03:09:43 +01:00
|
|
|
;; The point of this test is to ensure output is handled identically
|
|
|
|
;; regardless of whether a command handler is summoned.
|
|
|
|
|
|
|
|
(ert-deftest erc-process-input-line ()
|
|
|
|
(let (erc-server-last-sent-time
|
|
|
|
erc-server-flood-queue
|
|
|
|
(orig-erc-cmd-MSG (symbol-function 'erc-cmd-MSG))
|
2021-06-13 02:15:55 -07:00
|
|
|
(erc-default-recipients '("#chan"))
|
2021-11-06 03:09:43 +01:00
|
|
|
calls)
|
|
|
|
(with-temp-buffer
|
2023-04-14 00:07:31 -07:00
|
|
|
(erc-tests--set-fake-server-process "sleep" "1")
|
2021-11-06 03:09:43 +01:00
|
|
|
(cl-letf (((symbol-function 'erc-cmd-MSG)
|
|
|
|
(lambda (line)
|
|
|
|
(push line calls)
|
Extend erc-interactive-display to cover /JOINs
* lisp/erc/erc.el (erc-display): Mention that buffer-related display
options live in the customization group `erc-buffers'.
(erc-buffer-display, erc-join-buffer): Swap alias and aliased so that
the favored name, `erc-buffer-display', appears in the definition and
in the Customize menu. Also note related buffer-display options in
the doc string.
(erc-query-display, erc-interactive-display): Make the former an alias
of the latter, new in ERC 5.6, because their roles were functionally
redundant and thus confusing. Inherit the default value from
`erc-query-display' because users are more familiar with the pop-up
window behavior than a single-window replacement.
(erc-reconnect-display): Use preferred name for cross-referencing
fallback option `erc-buffer-display' in doc string, and explain how
/reconnect handling differs.
(erc--setup-buffer-hook): Add new internal hook for modules that
operate on windows and frames, such as erc-speedbar and
erc-status-sidebar.
(erc-open): Run `erc--setup-buffer-hook' after `erc-setup-buffer' so
hook members know their code isn't tied to `erc-setup-buffer' itself,
which may be used in other contexts, but rather to a new ERC buffer on
which some display-related action has just been performed.
(erc--called-as-input-p): New variable for "slash" commands, like
`erc-cmd-FOO', to detect whether they're being called "interactively"
as a result of input given at ERC's prompt.
(erc-process-input-line): Bind `erc--called-as-input-p' when running
slash commands.
(erc-cmd-JOIN): When called interactively, schedule a callback to wrap
the response handler and control how new buffers are thus displayed.
(erc-cmd-QUERY): Use preferred alias for `erc-query-display'.
* test/lisp/erc/erc-scenarios-base-buffer-display.el:
(erc-scenarios-base-buffer-display--interactive-default): New test.
* test/lisp/erc/erc-tests.el (erc-process-input-line,
erc-select-read-args, erc-tls, erc--interactive): Change expected
default value of `erc-interactive-display' from `buffer' to
`window'. (Bug#62833)
2023-04-10 17:58:05 -07:00
|
|
|
(should erc--called-as-input-p)
|
2021-11-06 03:09:43 +01:00
|
|
|
(funcall orig-erc-cmd-MSG line)))
|
|
|
|
((symbol-function 'erc-server-send-queue)
|
2021-06-13 02:15:55 -07:00
|
|
|
#'ignore))
|
2021-11-06 03:09:43 +01:00
|
|
|
|
|
|
|
(ert-info ("Dispatch to user command handler")
|
|
|
|
|
|
|
|
(ert-info ("Baseline")
|
|
|
|
(erc-process-input-line "/msg #chan hi\n")
|
|
|
|
(should (equal (pop calls) " #chan hi"))
|
|
|
|
(should (equal (pop erc-server-flood-queue)
|
|
|
|
'("PRIVMSG #chan :hi\r\n" . utf-8))))
|
|
|
|
|
2021-06-13 02:15:55 -07:00
|
|
|
(ert-info ("Quote preserves line intact")
|
|
|
|
(erc-process-input-line "/QUOTE FAKE foo bar\n")
|
|
|
|
(should (equal (pop erc-server-flood-queue)
|
|
|
|
'("FAKE foo bar\r\n" . utf-8))))
|
|
|
|
|
|
|
|
(ert-info ("Unknown command respected")
|
|
|
|
(erc-process-input-line "/FAKE foo bar\n")
|
|
|
|
(should (equal (pop erc-server-flood-queue)
|
|
|
|
'("FAKE foo bar\r\n" . utf-8))))
|
|
|
|
|
2021-11-06 03:09:43 +01:00
|
|
|
(ert-info ("Spaces preserved")
|
|
|
|
(erc-process-input-line "/msg #chan hi you\n")
|
|
|
|
(should (equal (pop calls) " #chan hi you"))
|
|
|
|
(should (equal (pop erc-server-flood-queue)
|
|
|
|
'("PRIVMSG #chan :hi you\r\n" . utf-8))))
|
|
|
|
|
|
|
|
(ert-info ("Empty line honored")
|
|
|
|
(erc-process-input-line "/msg #chan\n")
|
|
|
|
(should (equal (pop calls) " #chan"))
|
|
|
|
(should (equal (pop erc-server-flood-queue)
|
|
|
|
'("PRIVMSG #chan :\r\n" . utf-8)))))
|
|
|
|
|
|
|
|
(ert-info ("Implicit cmd via `erc-send-input-line-function'")
|
|
|
|
|
|
|
|
(ert-info ("Baseline")
|
2022-03-21 19:21:57 -07:00
|
|
|
(erc-process-input-line "hi\n")
|
2021-11-06 03:09:43 +01:00
|
|
|
(should (equal (pop erc-server-flood-queue)
|
|
|
|
'("PRIVMSG #chan :hi\r\n" . utf-8))))
|
|
|
|
|
|
|
|
(ert-info ("Spaces preserved")
|
2022-03-21 19:21:57 -07:00
|
|
|
(erc-process-input-line "hi you\n")
|
2021-11-06 03:09:43 +01:00
|
|
|
(should (equal (pop erc-server-flood-queue)
|
|
|
|
'("PRIVMSG #chan :hi you\r\n" . utf-8))))
|
|
|
|
|
2022-03-21 19:21:57 -07:00
|
|
|
(ert-info ("Empty line transmitted with injected-space kludge")
|
|
|
|
(erc-process-input-line "\n")
|
2021-11-06 03:09:43 +01:00
|
|
|
(should (equal (pop erc-server-flood-queue)
|
2022-03-21 19:21:57 -07:00
|
|
|
'("PRIVMSG #chan : \r\n" . utf-8))))
|
2021-11-06 03:09:43 +01:00
|
|
|
|
|
|
|
(should-not calls))))))
|
|
|
|
|
Improve ERC's internal invisibility API
* etc/ERC-NEWS: Mention that line endings have moved from the end to
the beginning of hidden messages.
* lisp/erc/erc-fill.el (erc-fill--wrap-ensure-dependencies): Warn when
users have `erc-legacy-invisible-bounds-p' enabled, and force it to
its default value of nil in the current buffer.
(erc-fill-wrap-mode, erc-fill-wrap-enable): Move business involving
compat variable for enabling legacy hidden-message behavior to helper.
* lisp/erc/erc-match.el (erc-match--hide-fools-offset-bounds): Move
internal variable from to main library file and rename to
`erc-legacy-invisible-bounds-p'. Also make obsolete and flip
semantics so a non-nil value enables the traditional behavior.
(erc-match--hide-message): Move to main library file and rename to
`erc--hide-message'. Add a property-value parameter instead of
hard-coding to `erc-match'. Also, condition behavior on renamed
compatibility flag `erc-legacy-invisible-bounds-p'.
(erc-hide-fools): Call `erc--hide-message' with own value for
`invisible' property specifically for fools. That is, use
`match-fools' rather than `erc-match' or `erc-match-fools' to save
room when visually inspecting. This retains the module name as a
prefix to hopefully minimize collisions with invisibility spec members
owned by non-ERC minor modes. The `timestamp' spec member owned by
erc-stamp likewise lacks a namespace prefix, but its feature/group
affiliation is self-evident.
(erc-match--modify-invisibility-spec): Use toggle command
non-interactively for adding and removing invisibility spec member.
(erc-match-toggle-hidden-fools): Add explicit override argument and
defer to general helper for actually modifying spec.
(erc-match--toggle-hidden): New helper for toggling invisibility
spec.
* lisp/erc/erc.el (erc--merge-prop): If new value is a list, prepend
onto existing. Add note about possible space optimization.
(erc-legacy-invisible-bounds-p): New obsolete compat variable to
enable traditional pre-5.6 invisibility interval on hidden messages.
Replaces `erc-match--hide-fools-offset-bounds-p' but has an inverted
meaning. The new default value of nil means invisibility covers a
shifted interval consisting of the message body plus the line ending
immediately preceding it.
(erc--hide-message): New function, formerly `erc-match--hide-message'
from erc-match.el introduced in ERC 5.6.
* test/lisp/erc/erc-scenarios-match.el:
(erc-scenarios-match--invisible-stamp): Fix comment and use API
function in interactive convenience setup.
(erc-scenarios-match--find-bol): New test helper.
(erc-scenarios-match--find-eol): Fix bug affecting interactive use.
(erc-scenarios-match--stamp-left-fools-invisible,
erc-scenarios-match--stamp-right-fools-invisible,
erc-scenarios-match--stamp-right-invisible-fill-wrap,
erc-scenarios-match--stamp-both-invisible-fill-static): Update
`invisible' property from `erc-match' to `match-fools'.
(erc-scenarios-match--stamp-right-fools-invisible,
erc-scenarios-match--stamp-both-invisible-fill-static): Move test
body to function of same name for use in multiple cases.
(erc-scenarios-match--stamp-right-fools-invisible--nooffset,
erc-scenarios-match--stamp-both-invisible-fill-static--nooffset): New
test variants asserting proper hiding with old pre-5.6 invisibility
interval.
* test/lisp/erc/erc-tests.el (erc-tests--equal-including-properties):
Relocate macro higher in same file.
(erc--merge-prop): New test. (Bug#64301)
2023-07-14 21:08:31 -07:00
|
|
|
(defmacro erc-tests--equal-including-properties (a b)
|
|
|
|
(list (if (< emacs-major-version 29)
|
|
|
|
'ert-equal-including-properties
|
|
|
|
'equal-including-properties)
|
|
|
|
a b))
|
|
|
|
|
|
|
|
(ert-deftest erc--merge-prop ()
|
|
|
|
(with-current-buffer (get-buffer-create "*erc-test*")
|
|
|
|
;; Baseline.
|
|
|
|
(insert "abc\n")
|
|
|
|
(erc--merge-prop 1 3 'erc-test 'x)
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(buffer-substring 1 4) #("abc" 0 2 (erc-test x))))
|
|
|
|
(erc--merge-prop 1 3 'erc-test 'y)
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(buffer-substring 1 4) #("abc" 0 2 (erc-test (y x)))))
|
|
|
|
|
|
|
|
;; Multiple intervals.
|
|
|
|
(goto-char (point-min))
|
|
|
|
(insert "def\n")
|
|
|
|
(erc--merge-prop 1 2 'erc-test 'x)
|
|
|
|
(erc--merge-prop 2 3 'erc-test 'y)
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(buffer-substring 1 4)
|
|
|
|
#("def" 0 1 (erc-test x) 1 2 (erc-test y))))
|
|
|
|
(erc--merge-prop 1 3 'erc-test 'z)
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(buffer-substring 1 4)
|
|
|
|
#("def" 0 1 (erc-test (z x)) 1 2 (erc-test (z y)))))
|
|
|
|
|
|
|
|
;; New val as list.
|
|
|
|
(goto-char (point-min))
|
|
|
|
(insert "ghi\n")
|
|
|
|
(erc--merge-prop 2 3 'erc-test '(y z))
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(buffer-substring 1 4) #("ghi" 1 2 (erc-test (y z)))))
|
|
|
|
(erc--merge-prop 1 3 'erc-test '(w x))
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(buffer-substring 1 4)
|
|
|
|
#("ghi" 0 1 (erc-test (w x)) 1 2 (erc-test (w x y z)))))
|
|
|
|
|
|
|
|
(when noninteractive
|
|
|
|
(kill-buffer))))
|
|
|
|
|
2023-10-03 23:15:40 -07:00
|
|
|
(ert-deftest erc--remove-from-prop-value-list ()
|
|
|
|
(with-current-buffer (get-buffer-create "*erc-test*")
|
|
|
|
;; Non-list match.
|
|
|
|
(insert "abc\n")
|
|
|
|
(put-text-property 1 2 'erc-test 'a)
|
|
|
|
(put-text-property 2 3 'erc-test 'b)
|
|
|
|
(put-text-property 3 4 'erc-test 'c)
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(buffer-substring 1 4) #("abc"
|
|
|
|
0 1 (erc-test a)
|
|
|
|
1 2 (erc-test b)
|
|
|
|
2 3 (erc-test c))))
|
|
|
|
|
|
|
|
(erc--remove-from-prop-value-list 1 4 'erc-test 'b)
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(buffer-substring 1 4) #("abc"
|
|
|
|
0 1 (erc-test a)
|
|
|
|
2 3 (erc-test c))))
|
|
|
|
(erc--remove-from-prop-value-list 1 4 'erc-test 'a)
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(buffer-substring 1 4) #("abc" 2 3 (erc-test c))))
|
|
|
|
(erc--remove-from-prop-value-list 1 4 'erc-test 'c)
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(buffer-substring 1 4) "abc"))
|
|
|
|
|
|
|
|
;; List match.
|
|
|
|
(goto-char (point-min))
|
|
|
|
(insert "def\n")
|
|
|
|
(put-text-property 1 2 'erc-test '(d x))
|
|
|
|
(put-text-property 2 3 'erc-test '(e y))
|
|
|
|
(put-text-property 3 4 'erc-test '(f z))
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(buffer-substring 1 4) #("def"
|
|
|
|
0 1 (erc-test (d x))
|
|
|
|
1 2 (erc-test (e y))
|
|
|
|
2 3 (erc-test (f z)))))
|
|
|
|
(erc--remove-from-prop-value-list 1 4 'erc-test 'y)
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(buffer-substring 1 4) #("def"
|
|
|
|
0 1 (erc-test (d x))
|
|
|
|
1 2 (erc-test e)
|
|
|
|
2 3 (erc-test (f z)))))
|
|
|
|
(erc--remove-from-prop-value-list 1 4 'erc-test 'd)
|
|
|
|
(erc--remove-from-prop-value-list 1 4 'erc-test 'f)
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(buffer-substring 1 4) #("def"
|
|
|
|
0 1 (erc-test x)
|
|
|
|
1 2 (erc-test e)
|
|
|
|
2 3 (erc-test z))))
|
|
|
|
(erc--remove-from-prop-value-list 1 4 'erc-test 'e)
|
|
|
|
(erc--remove-from-prop-value-list 1 4 'erc-test 'z)
|
|
|
|
(erc--remove-from-prop-value-list 1 4 'erc-test 'x)
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(buffer-substring 1 4) "def"))
|
|
|
|
|
|
|
|
;; List match.
|
|
|
|
(goto-char (point-min))
|
|
|
|
(insert "ghi\n")
|
|
|
|
(put-text-property 1 2 'erc-test '(g x))
|
|
|
|
(put-text-property 2 3 'erc-test '(h x))
|
|
|
|
(put-text-property 3 4 'erc-test '(i y))
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(buffer-substring 1 4) #("ghi"
|
|
|
|
0 1 (erc-test (g x))
|
|
|
|
1 2 (erc-test (h x))
|
|
|
|
2 3 (erc-test (i y)))))
|
|
|
|
(erc--remove-from-prop-value-list 1 4 'erc-test 'x)
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(buffer-substring 1 4) #("ghi"
|
|
|
|
0 1 (erc-test g)
|
|
|
|
1 2 (erc-test h)
|
|
|
|
2 3 (erc-test (i y)))))
|
|
|
|
(erc--remove-from-prop-value-list 1 2 'erc-test 'g) ; narrowed
|
|
|
|
(erc--remove-from-prop-value-list 3 4 'erc-test 'i) ; narrowed
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(buffer-substring 1 4) #("ghi"
|
|
|
|
1 2 (erc-test h)
|
|
|
|
2 3 (erc-test y))))
|
|
|
|
|
|
|
|
;; Pathological (,c) case (hopefully not created by ERC)
|
|
|
|
(goto-char (point-min))
|
|
|
|
(insert "jkl\n")
|
|
|
|
(put-text-property 1 2 'erc-test '(j x))
|
|
|
|
(put-text-property 2 3 'erc-test '(k))
|
|
|
|
(put-text-property 3 4 'erc-test '(k))
|
|
|
|
(erc--remove-from-prop-value-list 1 4 'erc-test 'k)
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(buffer-substring 1 4) #("jkl" 0 1 (erc-test (j x)))))
|
|
|
|
|
|
|
|
(when noninteractive
|
|
|
|
(kill-buffer))))
|
|
|
|
|
|
|
|
(ert-deftest erc--remove-from-prop-value-list/many ()
|
|
|
|
(with-current-buffer (get-buffer-create "*erc-test*")
|
|
|
|
;; Non-list match.
|
|
|
|
(insert "abc\n")
|
|
|
|
(put-text-property 1 2 'erc-test 'a)
|
|
|
|
(put-text-property 2 3 'erc-test 'b)
|
|
|
|
(put-text-property 3 4 'erc-test 'c)
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(buffer-substring 1 4) #("abc"
|
|
|
|
0 1 (erc-test a)
|
|
|
|
1 2 (erc-test b)
|
|
|
|
2 3 (erc-test c))))
|
|
|
|
|
|
|
|
(erc--remove-from-prop-value-list 1 4 'erc-test '(a b))
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(buffer-substring 1 4) #("abc" 2 3 (erc-test c))))
|
|
|
|
(erc--remove-from-prop-value-list 1 4 'erc-test 'a)
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(buffer-substring 1 4) #("abc" 2 3 (erc-test c))))
|
|
|
|
(erc--remove-from-prop-value-list 1 4 'erc-test '(c))
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(buffer-substring 1 4) "abc"))
|
|
|
|
|
|
|
|
;; List match.
|
|
|
|
(goto-char (point-min))
|
|
|
|
(insert "def\n")
|
|
|
|
(put-text-property 1 2 'erc-test '(d x y))
|
|
|
|
(put-text-property 2 3 'erc-test '(e y))
|
|
|
|
(put-text-property 3 4 'erc-test '(f z))
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(buffer-substring 1 4) #("def"
|
|
|
|
0 1 (erc-test (d x y))
|
|
|
|
1 2 (erc-test (e y))
|
|
|
|
2 3 (erc-test (f z)))))
|
|
|
|
(erc--remove-from-prop-value-list 1 4 'erc-test '(d y f))
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(buffer-substring 1 4) #("def"
|
|
|
|
0 1 (erc-test x)
|
|
|
|
1 2 (erc-test e)
|
|
|
|
2 3 (erc-test z))))
|
|
|
|
(erc--remove-from-prop-value-list 1 4 'erc-test '(e z x))
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(buffer-substring 1 4) "def"))
|
|
|
|
|
|
|
|
;; Narrowed beg.
|
|
|
|
(goto-char (point-min))
|
|
|
|
(insert "ghi\n")
|
|
|
|
(put-text-property 1 2 'erc-test '(g x))
|
|
|
|
(put-text-property 2 3 'erc-test '(h x))
|
|
|
|
(put-text-property 3 4 'erc-test '(i x))
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(buffer-substring 1 4) #("ghi"
|
|
|
|
0 1 (erc-test (g x))
|
|
|
|
1 2 (erc-test (h x))
|
|
|
|
2 3 (erc-test (i x)))))
|
|
|
|
(erc--remove-from-prop-value-list 1 3 'erc-test '(x g i))
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(buffer-substring 1 4) #("ghi"
|
|
|
|
1 2 (erc-test h)
|
|
|
|
2 3 (erc-test (i x)))))
|
|
|
|
|
|
|
|
;; Narrowed middle.
|
|
|
|
(goto-char (point-min))
|
|
|
|
(insert "jkl\n")
|
|
|
|
(put-text-property 1 2 'erc-test '(j x))
|
|
|
|
(put-text-property 2 3 'erc-test '(k))
|
|
|
|
(put-text-property 3 4 'erc-test '(l y z))
|
|
|
|
(erc--remove-from-prop-value-list 3 4 'erc-test '(k x y z))
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(buffer-substring 1 4) #("jkl"
|
|
|
|
0 1 (erc-test (j x))
|
|
|
|
1 2 (erc-test (k))
|
|
|
|
2 3 (erc-test l))))
|
|
|
|
|
|
|
|
(when noninteractive
|
|
|
|
(kill-buffer))))
|
|
|
|
|
2023-07-07 21:27:03 -07:00
|
|
|
(ert-deftest erc--split-string-shell-cmd ()
|
|
|
|
|
|
|
|
;; Leading and trailing space
|
|
|
|
(should (equal (erc--split-string-shell-cmd "1 2 3") '("1" "2" "3")))
|
|
|
|
(should (equal (erc--split-string-shell-cmd " 1 2 3 ") '("1" "2" "3")))
|
|
|
|
|
|
|
|
;; Empty string
|
|
|
|
(should (equal (erc--split-string-shell-cmd "\"\"") '("")))
|
|
|
|
(should (equal (erc--split-string-shell-cmd " \"\" ") '("")))
|
|
|
|
(should (equal (erc--split-string-shell-cmd "1 \"\"") '("1" "")))
|
|
|
|
(should (equal (erc--split-string-shell-cmd "1 \"\" ") '("1" "")))
|
|
|
|
(should (equal (erc--split-string-shell-cmd "\"\" 1") '("" "1")))
|
|
|
|
(should (equal (erc--split-string-shell-cmd " \"\" 1") '("" "1")))
|
|
|
|
|
|
|
|
(should (equal (erc--split-string-shell-cmd "''") '("")))
|
|
|
|
(should (equal (erc--split-string-shell-cmd " '' ") '("")))
|
|
|
|
(should (equal (erc--split-string-shell-cmd "1 ''") '("1" "")))
|
|
|
|
(should (equal (erc--split-string-shell-cmd "1 '' ") '("1" "")))
|
|
|
|
(should (equal (erc--split-string-shell-cmd "'' 1") '("" "1")))
|
|
|
|
(should (equal (erc--split-string-shell-cmd " '' 1") '("" "1")))
|
|
|
|
|
|
|
|
;; Backslash
|
|
|
|
(should (equal (erc--split-string-shell-cmd "\\ ") '(" ")))
|
|
|
|
(should (equal (erc--split-string-shell-cmd " \\ ") '(" ")))
|
|
|
|
(should (equal (erc--split-string-shell-cmd "1\\ ") '("1 ")))
|
|
|
|
(should (equal (erc--split-string-shell-cmd "1\\ 2") '("1 2")))
|
|
|
|
|
|
|
|
;; Embedded
|
|
|
|
(should (equal (erc--split-string-shell-cmd "\"\\\"\"") '("\"")))
|
|
|
|
(should (equal (erc--split-string-shell-cmd "1 \"2 \\\" \\\" 3\"")
|
|
|
|
'("1" "2 \" \" 3")))
|
|
|
|
(should (equal (erc--split-string-shell-cmd "1 \"2 ' ' 3\"")
|
|
|
|
'("1" "2 ' ' 3")))
|
|
|
|
(should (equal (erc--split-string-shell-cmd "1 '2 \" \" 3'")
|
|
|
|
'("1" "2 \" \" 3")))
|
|
|
|
(should (equal (erc--split-string-shell-cmd "1 '2 \\ 3'")
|
|
|
|
'("1" "2 \\ 3")))
|
|
|
|
(should (equal (erc--split-string-shell-cmd "1 \"2 \\\\ 3\"")
|
|
|
|
'("1" "2 \\ 3"))) ; see comment re ^
|
|
|
|
|
|
|
|
;; Realistic
|
|
|
|
(should (equal (erc--split-string-shell-cmd "GET bob \"my file.txt\"")
|
|
|
|
'("GET" "bob" "my file.txt")))
|
|
|
|
(should (equal (erc--split-string-shell-cmd "GET EXAMPLE|bob \"my file.txt\"")
|
|
|
|
'("GET" "EXAMPLE|bob" "my file.txt")))) ; regression
|
|
|
|
|
2023-04-30 07:12:56 -07:00
|
|
|
|
|
|
|
;; The behavior of `erc-pre-send-functions' differs between versions
|
|
|
|
;; in how hook members see and influence a trailing newline that's
|
|
|
|
;; part of the original prompt submission:
|
|
|
|
;;
|
|
|
|
;; 5.4: both seen and sent
|
|
|
|
;; 5.5: seen but not sent*
|
|
|
|
;; 5.6: neither seen nor sent*
|
|
|
|
;;
|
|
|
|
;; * requires `erc-send-whitespace-lines' for hook to run
|
|
|
|
;;
|
|
|
|
;; Two aspects that have remained consistent are
|
|
|
|
;;
|
|
|
|
;; - a final nonempty line in any submission is always sent
|
|
|
|
;; - a trailing newline appended by a hook member is always sent
|
|
|
|
;;
|
|
|
|
;; The last bullet would seem to contradict the "not sent" behavior of
|
|
|
|
;; 5.5 and 5.6, but what's actually happening is that exactly one
|
|
|
|
;; trailing newline is culled, so anything added always goes through.
|
|
|
|
;; Also, in ERC 5.6, all empty lines are actually padded, but this is
|
|
|
|
;; merely incidental WRT the above.
|
|
|
|
;;
|
|
|
|
;; Note that this test doesn't run any input-prep hooks and thus can't
|
|
|
|
;; account for the "seen" dimension noted above.
|
|
|
|
|
|
|
|
(ert-deftest erc--run-send-hooks ()
|
|
|
|
(with-suppressed-warnings ((obsolete erc-send-this)
|
|
|
|
(obsolete erc-send-pre-hook))
|
|
|
|
(should erc-insert-this)
|
|
|
|
(should erc-send-this) ; populates `erc--input-split-sendp'
|
|
|
|
|
|
|
|
(let (erc-pre-send-functions erc-send-pre-hook)
|
|
|
|
|
|
|
|
(ert-info ("String preserved, lines rewritten, empties padded")
|
|
|
|
(setq erc-pre-send-functions
|
|
|
|
(lambda (o) (setf (erc-input-string o) "bar\n\nbaz\n")))
|
|
|
|
(should (pcase (erc--run-send-hooks (make-erc--input-split
|
|
|
|
:string "foo" :lines '("foo")))
|
|
|
|
((cl-struct erc--input-split
|
|
|
|
(string "foo") (sendp 't) (insertp 't)
|
|
|
|
(lines '("bar" " " "baz" " ")) (cmdp 'nil))
|
|
|
|
t))))
|
|
|
|
|
|
|
|
(ert-info ("Multiline commands rejected")
|
|
|
|
(should-error (erc--run-send-hooks (make-erc--input-split
|
|
|
|
:string "/mycmd foo"
|
|
|
|
:lines '("/mycmd foo")
|
|
|
|
:cmdp t))))
|
|
|
|
|
|
|
|
(ert-info ("Single-line commands pass")
|
|
|
|
(setq erc-pre-send-functions
|
|
|
|
(lambda (o) (setf (erc-input-sendp o) nil
|
|
|
|
(erc-input-string o) "/mycmd bar")))
|
|
|
|
(should (pcase (erc--run-send-hooks (make-erc--input-split
|
|
|
|
:string "/mycmd foo"
|
|
|
|
:lines '("/mycmd foo")
|
|
|
|
:cmdp t))
|
|
|
|
((cl-struct erc--input-split
|
|
|
|
(string "/mycmd foo") (sendp 'nil) (insertp 't)
|
|
|
|
(lines '("/mycmd bar")) (cmdp 't))
|
|
|
|
t))))
|
|
|
|
|
|
|
|
(ert-info ("Legacy hook respected, special vars confined")
|
|
|
|
(setq erc-send-pre-hook (lambda (_) (setq erc-send-this nil))
|
|
|
|
erc-pre-send-functions (lambda (o) ; propagates
|
|
|
|
(should-not (erc-input-sendp o))))
|
|
|
|
(should (pcase (erc--run-send-hooks (make-erc--input-split
|
|
|
|
:string "foo" :lines '("foo")))
|
|
|
|
((cl-struct erc--input-split
|
|
|
|
(string "foo") (sendp 'nil) (insertp 't)
|
|
|
|
(lines '("foo")) (cmdp 'nil))
|
|
|
|
t)))
|
|
|
|
(should erc-send-this))
|
|
|
|
|
|
|
|
(ert-info ("Request to resplit honored")
|
|
|
|
(setq erc-send-pre-hook nil
|
|
|
|
erc-pre-send-functions
|
|
|
|
(lambda (o) (setf (erc-input-string o) "foo bar baz"
|
|
|
|
(erc-input-refoldp o) t)))
|
|
|
|
(let ((erc-split-line-length 8))
|
|
|
|
(should
|
|
|
|
(pcase (erc--run-send-hooks (make-erc--input-split
|
|
|
|
:string "foo" :lines '("foo")))
|
|
|
|
((cl-struct erc--input-split
|
|
|
|
(string "foo") (sendp 't) (insertp 't)
|
|
|
|
(lines '("foo bar " "baz")) (cmdp 'nil))
|
|
|
|
t))))))))
|
|
|
|
|
2022-07-06 00:40:42 -07:00
|
|
|
;; Note: if adding an erc-backend-tests.el, please relocate this there.
|
|
|
|
|
|
|
|
(ert-deftest erc-message ()
|
|
|
|
(should-not erc-server-last-peers)
|
|
|
|
(let (server-proc
|
|
|
|
calls
|
|
|
|
erc-kill-channel-hook erc-kill-server-hook erc-kill-buffer-hook)
|
|
|
|
(cl-letf (((symbol-function 'erc-display-message)
|
|
|
|
(lambda (_ _ _ line) (push line calls)))
|
|
|
|
((symbol-function 'erc-server-send)
|
|
|
|
(lambda (line _) (push line calls)))
|
|
|
|
((symbol-function 'erc-server-buffer)
|
|
|
|
(lambda () (process-buffer server-proc))))
|
|
|
|
(with-current-buffer (get-buffer-create "ExampleNet")
|
|
|
|
(erc-mode)
|
|
|
|
(setq erc-server-current-nick "tester"
|
|
|
|
server-proc (start-process "sleep" (current-buffer) "sleep" "1")
|
|
|
|
erc-server-process server-proc
|
|
|
|
erc-server-last-peers (cons nil nil)
|
|
|
|
erc-server-users (make-hash-table :test 'equal)
|
|
|
|
erc-network 'ExampleNet)
|
|
|
|
(set-process-query-on-exit-flag erc-server-process nil))
|
|
|
|
|
|
|
|
(with-current-buffer (get-buffer-create "#chan")
|
|
|
|
(erc-mode)
|
|
|
|
(setq erc-server-process (buffer-local-value 'erc-server-process
|
|
|
|
(get-buffer "ExampleNet"))
|
|
|
|
erc-default-recipients '("#chan")
|
|
|
|
erc-channel-users (make-hash-table :test 'equal)
|
|
|
|
erc-network 'ExampleNet)
|
|
|
|
(erc-update-current-channel-member "alice" "alice")
|
|
|
|
(erc-update-current-channel-member "tester" "tester"))
|
|
|
|
|
|
|
|
(with-current-buffer "ExampleNet"
|
|
|
|
(erc-server-PRIVMSG erc-server-process
|
|
|
|
(make-erc-response
|
|
|
|
:sender "alice!~u@fsf.org"
|
|
|
|
:command "PRIVMSG"
|
|
|
|
:command-args '("#chan" "hi")
|
|
|
|
:unparsed ":alice!~u@fsf.org PRIVMSG #chan :hi"))
|
|
|
|
(should (equal erc-server-last-peers '("alice")))
|
|
|
|
(should (string-match "<alice>" (pop calls))))
|
|
|
|
|
|
|
|
(with-current-buffer "#chan"
|
|
|
|
(ert-info ("Shortcuts usable in target buffers")
|
|
|
|
(should-not (local-variable-p 'erc-server-last-peers))
|
|
|
|
(should-not erc-server-last-peers)
|
|
|
|
(erc-message "PRIVMSG" ". hi")
|
|
|
|
(should-not erc-server-last-peers)
|
|
|
|
(should (eq 'no-target (pop calls)))
|
|
|
|
(erc-message "PRIVMSG" ", hi")
|
|
|
|
(should-not erc-server-last-peers)
|
|
|
|
(should (string-match "alice :hi" (pop calls)))))
|
|
|
|
|
|
|
|
(with-current-buffer "ExampleNet"
|
|
|
|
(ert-info ("Shortcuts local in server bufs")
|
|
|
|
(should (equal erc-server-last-peers '("alice" . "alice")))
|
|
|
|
(erc-message "PRIVMSG" ", hi")
|
|
|
|
(should (equal erc-server-last-peers '("alice" . "alice")))
|
|
|
|
(should (string-match "PRIVMSG alice :hi" (pop calls)))
|
|
|
|
(setcdr erc-server-last-peers "bob")
|
|
|
|
(erc-message "PRIVMSG" ". hi")
|
|
|
|
(should (equal erc-server-last-peers '("alice" . "bob")))
|
|
|
|
(should (string-match "PRIVMSG bob :hi" (pop calls)))))
|
|
|
|
|
|
|
|
(with-current-buffer "#chan"
|
|
|
|
(ert-info ("Non-shortcuts are local to server buffer")
|
|
|
|
(should-not (local-variable-p 'erc-server-last-peers))
|
|
|
|
(should-not erc-server-last-peers)
|
|
|
|
(erc-message "PRIVMSG" "#chan hola")
|
|
|
|
(should-not erc-server-last-peers)
|
|
|
|
(should-not (default-value 'erc-server-last-peers))
|
|
|
|
(should (equal (buffer-local-value 'erc-server-last-peers
|
|
|
|
(get-buffer "ExampleNet"))
|
|
|
|
'("alice" . "#chan")))
|
|
|
|
(should (string-match "hola" (pop calls))))))
|
|
|
|
|
|
|
|
(should-not erc-server-last-peers)
|
|
|
|
(should-not calls)
|
|
|
|
(kill-buffer "ExampleNet")
|
|
|
|
(kill-buffer "#chan")))
|
|
|
|
|
2023-06-24 18:33:20 -07:00
|
|
|
(ert-deftest erc-format-privmessage ()
|
|
|
|
;; Basic PRIVMSG
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(erc-format-privmessage (copy-sequence "bob")
|
|
|
|
(copy-sequence "oh my")
|
|
|
|
nil 'msgp)
|
|
|
|
#("<bob> oh my"
|
|
|
|
0 1 (font-lock-face erc-default-face)
|
|
|
|
1 4 (erc-speaker "bob" font-lock-face erc-nick-default-face)
|
|
|
|
4 11 (font-lock-face erc-default-face))))
|
|
|
|
|
|
|
|
;; Basic NOTICE
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(erc-format-privmessage (copy-sequence "bob")
|
|
|
|
(copy-sequence "oh my")
|
|
|
|
nil nil)
|
|
|
|
#("-bob- oh my"
|
|
|
|
0 1 (font-lock-face erc-default-face)
|
|
|
|
1 4 (erc-speaker "bob" font-lock-face erc-nick-default-face)
|
|
|
|
4 11 (font-lock-face erc-default-face))))
|
|
|
|
|
|
|
|
;; Prefixed PRIVMSG
|
|
|
|
(let* ((user (make-erc-server-user :nickname (copy-sequence "Bob")))
|
|
|
|
(cuser (make-erc-channel-user :op t))
|
|
|
|
(erc-channel-users (make-hash-table :test #'equal)))
|
|
|
|
(puthash "bob" (cons user cuser) erc-channel-users)
|
|
|
|
|
|
|
|
(should (erc-tests--equal-including-properties
|
|
|
|
(erc-format-privmessage (erc-format-@nick user cuser)
|
|
|
|
(copy-sequence "oh my")
|
|
|
|
nil 'msgp)
|
|
|
|
#("<@Bob> oh my"
|
|
|
|
0 1 (font-lock-face erc-default-face)
|
|
|
|
1 2 (font-lock-face erc-nick-prefix-face help-echo "operator")
|
|
|
|
2 5 (erc-speaker "Bob" font-lock-face erc-nick-default-face)
|
|
|
|
5 12 (font-lock-face erc-default-face))))))
|
|
|
|
|
2022-07-11 05:14:57 -07:00
|
|
|
(defvar erc-tests--ipv6-examples
|
|
|
|
'("1:2:3:4:5:6:7:8"
|
|
|
|
"::ffff:10.0.0.1" "::ffff:1.2.3.4" "::ffff:0.0.0.0"
|
|
|
|
"1:2:3:4:5:6:77:88" "::ffff:255.255.255.255"
|
|
|
|
"fe08::7:8" "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"
|
|
|
|
"1:2:3:4:5:6:7:8" "1::" "1:2:3:4:5:6:7::" "1::8"
|
|
|
|
"1:2:3:4:5:6::8" "1:2:3:4:5:6::8" "1::7:8" "1:2:3:4:5::7:8"
|
|
|
|
"1:2:3:4:5::8" "1::6:7:8" "1:2:3:4::6:7:8" "1:2:3:4::8"
|
|
|
|
"1::5:6:7:8" "1:2:3::5:6:7:8" "1:2:3::8" "1::4:5:6:7:8"
|
|
|
|
"1:2::4:5:6:7:8" "1:2::8" "1::3:4:5:6:7:8" "1::3:4:5:6:7:8"
|
|
|
|
"1::8" "::2:3:4:5:6:7:8" "::2:3:4:5:6:7:8" "::8"
|
|
|
|
"::" "fe08::7:8%eth0" "fe08::7:8%1" "::255.255.255.255"
|
|
|
|
"::ffff:255.255.255.255" "::ffff:0:255.255.255.255"
|
|
|
|
"2001:db8:3:4::192.0.2.33" "64:ff9b::192.0.2.33"))
|
|
|
|
|
|
|
|
(ert-deftest erc--server-connect-dumb-ipv6-regexp ()
|
|
|
|
(dolist (a erc-tests--ipv6-examples)
|
|
|
|
(should-not (string-match erc--server-connect-dumb-ipv6-regexp a))
|
|
|
|
(should (string-match erc--server-connect-dumb-ipv6-regexp
|
|
|
|
(concat "[" a "]")))))
|
|
|
|
|
2022-12-29 06:43:19 -08:00
|
|
|
(ert-deftest erc--with-entrypoint-environment ()
|
|
|
|
(let ((env '((erc-join-buffer . foo)
|
|
|
|
(erc-server-connect-function . bar))))
|
|
|
|
(erc--with-entrypoint-environment env
|
|
|
|
(should (eq erc-join-buffer 'foo))
|
|
|
|
(should (eq erc-server-connect-function 'bar)))))
|
|
|
|
|
2022-07-11 05:14:57 -07:00
|
|
|
(ert-deftest erc-select-read-args ()
|
|
|
|
|
2022-12-29 06:43:19 -08:00
|
|
|
(ert-info ("Prompts for switch to TLS by default")
|
|
|
|
(should (equal (ert-simulate-keys "\r\r\r\ry\r"
|
2022-07-11 05:14:57 -07:00
|
|
|
(erc-select-read-args))
|
|
|
|
(list :server "irc.libera.chat"
|
2022-12-29 06:43:19 -08:00
|
|
|
:port 6697
|
|
|
|
:nick (user-login-name)
|
2022-12-29 06:43:19 -08:00
|
|
|
'&interactive-env
|
|
|
|
'((erc-server-connect-function . erc-open-tls-stream)
|
Extend erc-interactive-display to cover /JOINs
* lisp/erc/erc.el (erc-display): Mention that buffer-related display
options live in the customization group `erc-buffers'.
(erc-buffer-display, erc-join-buffer): Swap alias and aliased so that
the favored name, `erc-buffer-display', appears in the definition and
in the Customize menu. Also note related buffer-display options in
the doc string.
(erc-query-display, erc-interactive-display): Make the former an alias
of the latter, new in ERC 5.6, because their roles were functionally
redundant and thus confusing. Inherit the default value from
`erc-query-display' because users are more familiar with the pop-up
window behavior than a single-window replacement.
(erc-reconnect-display): Use preferred name for cross-referencing
fallback option `erc-buffer-display' in doc string, and explain how
/reconnect handling differs.
(erc--setup-buffer-hook): Add new internal hook for modules that
operate on windows and frames, such as erc-speedbar and
erc-status-sidebar.
(erc-open): Run `erc--setup-buffer-hook' after `erc-setup-buffer' so
hook members know their code isn't tied to `erc-setup-buffer' itself,
which may be used in other contexts, but rather to a new ERC buffer on
which some display-related action has just been performed.
(erc--called-as-input-p): New variable for "slash" commands, like
`erc-cmd-FOO', to detect whether they're being called "interactively"
as a result of input given at ERC's prompt.
(erc-process-input-line): Bind `erc--called-as-input-p' when running
slash commands.
(erc-cmd-JOIN): When called interactively, schedule a callback to wrap
the response handler and control how new buffers are thus displayed.
(erc-cmd-QUERY): Use preferred alias for `erc-query-display'.
* test/lisp/erc/erc-scenarios-base-buffer-display.el:
(erc-scenarios-base-buffer-display--interactive-default): New test.
* test/lisp/erc/erc-tests.el (erc-process-input-line,
erc-select-read-args, erc-tls, erc--interactive): Change expected
default value of `erc-interactive-display' from `buffer' to
`window'. (Bug#62833)
2023-04-10 17:58:05 -07:00
|
|
|
(erc-join-buffer . window))))))
|
2022-12-29 06:43:19 -08:00
|
|
|
|
|
|
|
(ert-info ("Switches to TLS when port matches default TLS port")
|
|
|
|
(should (equal (ert-simulate-keys "irc.gnu.org\r6697\r\r\r"
|
|
|
|
(erc-select-read-args))
|
|
|
|
(list :server "irc.gnu.org"
|
|
|
|
:port 6697
|
|
|
|
:nick (user-login-name)
|
2022-12-29 06:43:19 -08:00
|
|
|
'&interactive-env
|
|
|
|
'((erc-server-connect-function . erc-open-tls-stream)
|
Extend erc-interactive-display to cover /JOINs
* lisp/erc/erc.el (erc-display): Mention that buffer-related display
options live in the customization group `erc-buffers'.
(erc-buffer-display, erc-join-buffer): Swap alias and aliased so that
the favored name, `erc-buffer-display', appears in the definition and
in the Customize menu. Also note related buffer-display options in
the doc string.
(erc-query-display, erc-interactive-display): Make the former an alias
of the latter, new in ERC 5.6, because their roles were functionally
redundant and thus confusing. Inherit the default value from
`erc-query-display' because users are more familiar with the pop-up
window behavior than a single-window replacement.
(erc-reconnect-display): Use preferred name for cross-referencing
fallback option `erc-buffer-display' in doc string, and explain how
/reconnect handling differs.
(erc--setup-buffer-hook): Add new internal hook for modules that
operate on windows and frames, such as erc-speedbar and
erc-status-sidebar.
(erc-open): Run `erc--setup-buffer-hook' after `erc-setup-buffer' so
hook members know their code isn't tied to `erc-setup-buffer' itself,
which may be used in other contexts, but rather to a new ERC buffer on
which some display-related action has just been performed.
(erc--called-as-input-p): New variable for "slash" commands, like
`erc-cmd-FOO', to detect whether they're being called "interactively"
as a result of input given at ERC's prompt.
(erc-process-input-line): Bind `erc--called-as-input-p' when running
slash commands.
(erc-cmd-JOIN): When called interactively, schedule a callback to wrap
the response handler and control how new buffers are thus displayed.
(erc-cmd-QUERY): Use preferred alias for `erc-query-display'.
* test/lisp/erc/erc-scenarios-base-buffer-display.el:
(erc-scenarios-base-buffer-display--interactive-default): New test.
* test/lisp/erc/erc-tests.el (erc-process-input-line,
erc-select-read-args, erc-tls, erc--interactive): Change expected
default value of `erc-interactive-display' from `buffer' to
`window'. (Bug#62833)
2023-04-10 17:58:05 -07:00
|
|
|
(erc-join-buffer . window))))))
|
2022-12-29 06:43:19 -08:00
|
|
|
|
|
|
|
(ert-info ("Switches to TLS when URL is ircs://")
|
Allow custom display-buffer actions in ERC
* doc/misc/erc.texi: Add new section under "Integrations" chapter
describing `display-buffer' Custom function choice for ERC's many
buffer-display options.
* etc/ERC-NEWS: Mention new function variant for all buffer-display
options.
* lisp/erc/erc-backend.el: Add forward declaration for
`erc--called-as-input-p' and `erc--display-context'.
(erc--server-reconnect-display-timer,
erc--server-last-reconnect-display-reset): Use new name for option
`erc-reconnect-display', now `erc-auto-reconnect-display'.
(erc--server-determine-join-display-context): New generic function to
determine value of `erc--display-context' during JOINs.
(erc-server-JOIN, erc-server-PRIVMSG): Set `erc--display-context' to a
symbol for the handler's IRC command, like `JOIN', for the benefit of
custom `display-buffer'-like functions running in `erc-setup-buffer'.
(erc-server-471, erc-server-471-functions, erc-server-473,
erc-server-473-functions): New handlers for JOIN rejections. Also
remove 471 and 473 from comment at bottom of file.
(erc-server-475): Bind `erc--called-as-input-p' so that `erc-cmd-JOIN'
sets `erc-interactive-display' context.
* lisp/erc/erc-join.el (erc-autojoin-mode, erc-autojoin-enable,
erc-autojoin-disable): Kill local variable
`erc-join--requested-channels'. Add and remove
`erc-join--remove-requested-channels' to/from various server-handler
hooks for JOIN rejection numerics.
(erc-join--requested-channels): New local variable to remember
channels we've attempted to JOIN this session that haven't yet been
confirmed by the server.
(erc-join--remove-requested-channel): New JOIN rejection handler to
stop tracking channel in `erc-join--requested-channels'.
(erc--server-determine-join-display-context): module-specific
implementation of generic function for `erc-autojoin-mode'.
(erc-autojoin--join): Remember channels slated for JOIN'ing.
* lisp/erc/erc.el (erc--buffer-display-choices): New helper constant
for defining common `:type' for all buffer-display options.
(erc-buffer-display, erc-interactive-display,
erc-auto-reconnect-display, erc-receive-query-display): Use helper
`erc--buffer-display-choices' for defining `:type', which
includes a new choice for a `display-buffer'-like function.
(erc-reconnect-display, erc-auto-reconnect-display): Alias former to
latter, now the preferred name.
(erc-reconnect-timeout, erc-auto-reconnect-timeout): Change name from
former to latter. This option is new in ERC 5.6.
(erc-reconnect-display-server-buffers): New option.
(erc-buffer-do): Revise doc string.
(erc--display-context): New variable, an alist of "context tokens" to
be forwarded as the "action alist" to `erc-buffer-display' functions.
(erc-skip-displaying-selected-window-buffer): New variable, deprecated
at birth, to act as an escape hatch for folks who don't want to skip
the displaying of buffers already showing in the selected window.
(erc--display-buffer-overriding-action): Local variable allowing
modules to influence the displaying of new ERC buffers independently
of user options.
(erc-setup-buffer): Do nothing when the selected window already shows
current buffer unless user has provided a custom display function.
Accommodate new Custom choice function values, like `display-buffer'
and `pop-to-buffer'.
(erc-open): Run `erc-setup-buffer' when option
`erc-reconnect-display-server-buffers' is non-nil, even for existing
server buffers. Bind `display-buffer-overriding-action' to the value
of `erc--display-buffer-overriding-action' around calls to
`erc-setup-buffer'.
(erc-select-read-args): Add `erc--display-context' to environment.
(erc, erc-tls): Bind `erc--display-context' around calls to
`erc-select-read-args' and main body.
(erc-cmd-JOIN, erc-cmd-QUERY, erc--cmd-reconnect, erc-handle-irc-url):
Add item for `erc-interactive-display' to `erc--display-context'.
(erc-connection-established): Update name of
`erc-reconnect-display-timeout' to
`erc-auto-reconnect-display-timeout'.
(erc-message-english-s471, erc-message-english-s473): New variables,
format templates for JOIN rejection messages.
* test/lisp/erc/erc-scenarios-base-buffer-display.el
(erc-scenarios-base-buffer-display--defwin-recbury-intbuf,
erc-scenarios-base-buffer-display--defwino-recbury-intbuf,
erc-scenarios-base-buffer-display--count-reset-timeout): Use preferred
name `erc-auto-reconnect-display' for `erc-reconnect-display'.
* test/lisp/erc/erc-scenarios-join-display-context.el: New file.
* test/lisp/erc/erc-tests.el (erc--initialize-markers): Fix
unrealistic call to `erc-open'.
(erc-setup-buffer--custom-action): New test.
(erc-select-read-args, erc-tls, erc--interactive, erc-server-select):
Expect new environment binding for `erc--display-context'.
* test/lisp/erc/resources/join/buffer-display/mode-context.eld: New
file. (Bug#62833)
2023-05-30 23:27:12 -07:00
|
|
|
(let ((erc--display-context '((erc-interactive-display . erc))))
|
|
|
|
(should (equal (ert-simulate-keys "ircs://irc.gnu.org\r\r\r\r"
|
|
|
|
(erc-select-read-args))
|
|
|
|
(list :server "irc.gnu.org"
|
|
|
|
:port 6697
|
|
|
|
:nick (user-login-name)
|
|
|
|
'&interactive-env
|
|
|
|
'((erc-server-connect-function
|
|
|
|
. erc-open-tls-stream)
|
|
|
|
(erc--display-context
|
|
|
|
. ((erc-interactive-display . erc)))
|
|
|
|
(erc-join-buffer . window)))))))
|
2022-12-29 06:43:19 -08:00
|
|
|
|
|
|
|
(setq-local erc-interactive-display nil) ; cheat to save space
|
2022-12-29 06:43:19 -08:00
|
|
|
|
|
|
|
(ert-info ("Opt out of non-TLS warning manually")
|
|
|
|
(should (equal (ert-simulate-keys "\r\r\r\rn\r"
|
|
|
|
(erc-select-read-args))
|
|
|
|
(list :server "irc.libera.chat"
|
|
|
|
:port 6667
|
|
|
|
:nick (user-login-name)))))
|
2022-07-11 05:14:57 -07:00
|
|
|
|
|
|
|
(ert-info ("Override default TLS")
|
|
|
|
(should (equal (ert-simulate-keys "irc://irc.libera.chat\r\r\r\r"
|
|
|
|
(erc-select-read-args))
|
|
|
|
(list :server "irc.libera.chat"
|
|
|
|
:port 6667
|
2022-12-29 06:43:19 -08:00
|
|
|
:nick (user-login-name)))))
|
2022-07-11 05:14:57 -07:00
|
|
|
|
|
|
|
(ert-info ("Address includes port")
|
2022-12-29 06:43:19 -08:00
|
|
|
(should (equal (ert-simulate-keys "localhost:6667\rnick\r\r"
|
2022-07-11 05:14:57 -07:00
|
|
|
(erc-select-read-args))
|
|
|
|
(list :server "localhost"
|
|
|
|
:port 6667
|
2022-12-29 06:43:19 -08:00
|
|
|
:nick "nick"))))
|
2022-07-11 05:14:57 -07:00
|
|
|
|
|
|
|
(ert-info ("Address includes nick, password skipped via option")
|
|
|
|
(should (equal (ert-simulate-keys "nick@localhost:6667\r"
|
|
|
|
(let (erc-prompt-for-password)
|
|
|
|
(erc-select-read-args)))
|
|
|
|
(list :server "localhost"
|
|
|
|
:port 6667
|
2022-12-29 06:43:19 -08:00
|
|
|
:nick "nick"))))
|
2022-07-11 05:14:57 -07:00
|
|
|
|
2022-11-18 15:48:22 +01:00
|
|
|
(ert-info ("Address includes nick and password")
|
2022-12-29 06:43:19 -08:00
|
|
|
(should (equal (ert-simulate-keys "nick:sesame@localhost:6667\r\r"
|
2022-07-11 05:14:57 -07:00
|
|
|
(erc-select-read-args))
|
|
|
|
(list :server "localhost"
|
|
|
|
:port 6667
|
|
|
|
:nick "nick"
|
|
|
|
:password "sesame"))))
|
|
|
|
|
|
|
|
(ert-info ("IPv6 address plain")
|
|
|
|
(should (equal (ert-simulate-keys "::1\r\r\r\r"
|
|
|
|
(erc-select-read-args))
|
|
|
|
(list :server "[::1]"
|
|
|
|
:port 6667
|
2022-12-29 06:43:19 -08:00
|
|
|
:nick (user-login-name)))))
|
2022-07-11 05:14:57 -07:00
|
|
|
|
|
|
|
(ert-info ("IPv6 address with port")
|
|
|
|
(should (equal (ert-simulate-keys "[::1]:6667\r\r\r"
|
|
|
|
(erc-select-read-args))
|
|
|
|
(list :server "[::1]"
|
|
|
|
:port 6667
|
2022-12-29 06:43:19 -08:00
|
|
|
:nick (user-login-name)))))
|
2022-07-11 05:14:57 -07:00
|
|
|
|
|
|
|
(ert-info ("IPv6 address includes nick")
|
|
|
|
(should (equal (ert-simulate-keys "nick@[::1]:6667\r\r"
|
|
|
|
(erc-select-read-args))
|
|
|
|
(list :server "[::1]"
|
|
|
|
:port 6667
|
2022-12-29 06:43:19 -08:00
|
|
|
:nick "nick"))))
|
|
|
|
|
|
|
|
(ert-info ("Extra args use URL nick by default")
|
|
|
|
(should (equal (ert-simulate-keys "nick:sesame@localhost:6667\r\r\r\r"
|
|
|
|
(let ((current-prefix-arg '(4)))
|
|
|
|
(erc-select-read-args)))
|
|
|
|
(list :server "localhost"
|
|
|
|
:port 6667
|
|
|
|
:nick "nick"
|
|
|
|
:user "nick"
|
|
|
|
:password "sesame"
|
|
|
|
:full-name "nick")))))
|
2022-07-11 05:14:57 -07:00
|
|
|
|
2022-07-11 05:14:57 -07:00
|
|
|
(ert-deftest erc-tls ()
|
2022-12-29 06:43:19 -08:00
|
|
|
(let (calls env)
|
2022-07-11 05:14:57 -07:00
|
|
|
(cl-letf (((symbol-function 'user-login-name)
|
|
|
|
(lambda (&optional _) "tester"))
|
|
|
|
((symbol-function 'erc-open)
|
2022-12-29 06:43:19 -08:00
|
|
|
(lambda (&rest r)
|
2022-12-29 06:43:19 -08:00
|
|
|
(push `((erc-join-buffer ,erc-join-buffer)
|
Allow custom display-buffer actions in ERC
* doc/misc/erc.texi: Add new section under "Integrations" chapter
describing `display-buffer' Custom function choice for ERC's many
buffer-display options.
* etc/ERC-NEWS: Mention new function variant for all buffer-display
options.
* lisp/erc/erc-backend.el: Add forward declaration for
`erc--called-as-input-p' and `erc--display-context'.
(erc--server-reconnect-display-timer,
erc--server-last-reconnect-display-reset): Use new name for option
`erc-reconnect-display', now `erc-auto-reconnect-display'.
(erc--server-determine-join-display-context): New generic function to
determine value of `erc--display-context' during JOINs.
(erc-server-JOIN, erc-server-PRIVMSG): Set `erc--display-context' to a
symbol for the handler's IRC command, like `JOIN', for the benefit of
custom `display-buffer'-like functions running in `erc-setup-buffer'.
(erc-server-471, erc-server-471-functions, erc-server-473,
erc-server-473-functions): New handlers for JOIN rejections. Also
remove 471 and 473 from comment at bottom of file.
(erc-server-475): Bind `erc--called-as-input-p' so that `erc-cmd-JOIN'
sets `erc-interactive-display' context.
* lisp/erc/erc-join.el (erc-autojoin-mode, erc-autojoin-enable,
erc-autojoin-disable): Kill local variable
`erc-join--requested-channels'. Add and remove
`erc-join--remove-requested-channels' to/from various server-handler
hooks for JOIN rejection numerics.
(erc-join--requested-channels): New local variable to remember
channels we've attempted to JOIN this session that haven't yet been
confirmed by the server.
(erc-join--remove-requested-channel): New JOIN rejection handler to
stop tracking channel in `erc-join--requested-channels'.
(erc--server-determine-join-display-context): module-specific
implementation of generic function for `erc-autojoin-mode'.
(erc-autojoin--join): Remember channels slated for JOIN'ing.
* lisp/erc/erc.el (erc--buffer-display-choices): New helper constant
for defining common `:type' for all buffer-display options.
(erc-buffer-display, erc-interactive-display,
erc-auto-reconnect-display, erc-receive-query-display): Use helper
`erc--buffer-display-choices' for defining `:type', which
includes a new choice for a `display-buffer'-like function.
(erc-reconnect-display, erc-auto-reconnect-display): Alias former to
latter, now the preferred name.
(erc-reconnect-timeout, erc-auto-reconnect-timeout): Change name from
former to latter. This option is new in ERC 5.6.
(erc-reconnect-display-server-buffers): New option.
(erc-buffer-do): Revise doc string.
(erc--display-context): New variable, an alist of "context tokens" to
be forwarded as the "action alist" to `erc-buffer-display' functions.
(erc-skip-displaying-selected-window-buffer): New variable, deprecated
at birth, to act as an escape hatch for folks who don't want to skip
the displaying of buffers already showing in the selected window.
(erc--display-buffer-overriding-action): Local variable allowing
modules to influence the displaying of new ERC buffers independently
of user options.
(erc-setup-buffer): Do nothing when the selected window already shows
current buffer unless user has provided a custom display function.
Accommodate new Custom choice function values, like `display-buffer'
and `pop-to-buffer'.
(erc-open): Run `erc-setup-buffer' when option
`erc-reconnect-display-server-buffers' is non-nil, even for existing
server buffers. Bind `display-buffer-overriding-action' to the value
of `erc--display-buffer-overriding-action' around calls to
`erc-setup-buffer'.
(erc-select-read-args): Add `erc--display-context' to environment.
(erc, erc-tls): Bind `erc--display-context' around calls to
`erc-select-read-args' and main body.
(erc-cmd-JOIN, erc-cmd-QUERY, erc--cmd-reconnect, erc-handle-irc-url):
Add item for `erc-interactive-display' to `erc--display-context'.
(erc-connection-established): Update name of
`erc-reconnect-display-timeout' to
`erc-auto-reconnect-display-timeout'.
(erc-message-english-s471, erc-message-english-s473): New variables,
format templates for JOIN rejection messages.
* test/lisp/erc/erc-scenarios-base-buffer-display.el
(erc-scenarios-base-buffer-display--defwin-recbury-intbuf,
erc-scenarios-base-buffer-display--defwino-recbury-intbuf,
erc-scenarios-base-buffer-display--count-reset-timeout): Use preferred
name `erc-auto-reconnect-display' for `erc-reconnect-display'.
* test/lisp/erc/erc-scenarios-join-display-context.el: New file.
* test/lisp/erc/erc-tests.el (erc--initialize-markers): Fix
unrealistic call to `erc-open'.
(erc-setup-buffer--custom-action): New test.
(erc-select-read-args, erc-tls, erc--interactive, erc-server-select):
Expect new environment binding for `erc--display-context'.
* test/lisp/erc/resources/join/buffer-display/mode-context.eld: New
file. (Bug#62833)
2023-05-30 23:27:12 -07:00
|
|
|
(erc--display-context ,@erc--display-context)
|
2022-12-29 06:43:19 -08:00
|
|
|
(erc-server-connect-function
|
2022-12-29 06:43:19 -08:00
|
|
|
,erc-server-connect-function))
|
|
|
|
env)
|
|
|
|
(push r calls))))
|
2022-07-11 05:14:57 -07:00
|
|
|
|
|
|
|
(ert-info ("Defaults")
|
|
|
|
(erc-tls)
|
|
|
|
(should (equal (pop calls)
|
|
|
|
'("irc.libera.chat" 6697 "tester" "unknown" t
|
2022-12-29 06:43:19 -08:00
|
|
|
nil nil nil nil nil "user" nil)))
|
|
|
|
(should (equal (pop env)
|
2022-12-29 06:43:19 -08:00
|
|
|
'((erc-join-buffer bury)
|
Allow custom display-buffer actions in ERC
* doc/misc/erc.texi: Add new section under "Integrations" chapter
describing `display-buffer' Custom function choice for ERC's many
buffer-display options.
* etc/ERC-NEWS: Mention new function variant for all buffer-display
options.
* lisp/erc/erc-backend.el: Add forward declaration for
`erc--called-as-input-p' and `erc--display-context'.
(erc--server-reconnect-display-timer,
erc--server-last-reconnect-display-reset): Use new name for option
`erc-reconnect-display', now `erc-auto-reconnect-display'.
(erc--server-determine-join-display-context): New generic function to
determine value of `erc--display-context' during JOINs.
(erc-server-JOIN, erc-server-PRIVMSG): Set `erc--display-context' to a
symbol for the handler's IRC command, like `JOIN', for the benefit of
custom `display-buffer'-like functions running in `erc-setup-buffer'.
(erc-server-471, erc-server-471-functions, erc-server-473,
erc-server-473-functions): New handlers for JOIN rejections. Also
remove 471 and 473 from comment at bottom of file.
(erc-server-475): Bind `erc--called-as-input-p' so that `erc-cmd-JOIN'
sets `erc-interactive-display' context.
* lisp/erc/erc-join.el (erc-autojoin-mode, erc-autojoin-enable,
erc-autojoin-disable): Kill local variable
`erc-join--requested-channels'. Add and remove
`erc-join--remove-requested-channels' to/from various server-handler
hooks for JOIN rejection numerics.
(erc-join--requested-channels): New local variable to remember
channels we've attempted to JOIN this session that haven't yet been
confirmed by the server.
(erc-join--remove-requested-channel): New JOIN rejection handler to
stop tracking channel in `erc-join--requested-channels'.
(erc--server-determine-join-display-context): module-specific
implementation of generic function for `erc-autojoin-mode'.
(erc-autojoin--join): Remember channels slated for JOIN'ing.
* lisp/erc/erc.el (erc--buffer-display-choices): New helper constant
for defining common `:type' for all buffer-display options.
(erc-buffer-display, erc-interactive-display,
erc-auto-reconnect-display, erc-receive-query-display): Use helper
`erc--buffer-display-choices' for defining `:type', which
includes a new choice for a `display-buffer'-like function.
(erc-reconnect-display, erc-auto-reconnect-display): Alias former to
latter, now the preferred name.
(erc-reconnect-timeout, erc-auto-reconnect-timeout): Change name from
former to latter. This option is new in ERC 5.6.
(erc-reconnect-display-server-buffers): New option.
(erc-buffer-do): Revise doc string.
(erc--display-context): New variable, an alist of "context tokens" to
be forwarded as the "action alist" to `erc-buffer-display' functions.
(erc-skip-displaying-selected-window-buffer): New variable, deprecated
at birth, to act as an escape hatch for folks who don't want to skip
the displaying of buffers already showing in the selected window.
(erc--display-buffer-overriding-action): Local variable allowing
modules to influence the displaying of new ERC buffers independently
of user options.
(erc-setup-buffer): Do nothing when the selected window already shows
current buffer unless user has provided a custom display function.
Accommodate new Custom choice function values, like `display-buffer'
and `pop-to-buffer'.
(erc-open): Run `erc-setup-buffer' when option
`erc-reconnect-display-server-buffers' is non-nil, even for existing
server buffers. Bind `display-buffer-overriding-action' to the value
of `erc--display-buffer-overriding-action' around calls to
`erc-setup-buffer'.
(erc-select-read-args): Add `erc--display-context' to environment.
(erc, erc-tls): Bind `erc--display-context' around calls to
`erc-select-read-args' and main body.
(erc-cmd-JOIN, erc-cmd-QUERY, erc--cmd-reconnect, erc-handle-irc-url):
Add item for `erc-interactive-display' to `erc--display-context'.
(erc-connection-established): Update name of
`erc-reconnect-display-timeout' to
`erc-auto-reconnect-display-timeout'.
(erc-message-english-s471, erc-message-english-s473): New variables,
format templates for JOIN rejection messages.
* test/lisp/erc/erc-scenarios-base-buffer-display.el
(erc-scenarios-base-buffer-display--defwin-recbury-intbuf,
erc-scenarios-base-buffer-display--defwino-recbury-intbuf,
erc-scenarios-base-buffer-display--count-reset-timeout): Use preferred
name `erc-auto-reconnect-display' for `erc-reconnect-display'.
* test/lisp/erc/erc-scenarios-join-display-context.el: New file.
* test/lisp/erc/erc-tests.el (erc--initialize-markers): Fix
unrealistic call to `erc-open'.
(erc-setup-buffer--custom-action): New test.
(erc-select-read-args, erc-tls, erc--interactive, erc-server-select):
Expect new environment binding for `erc--display-context'.
* test/lisp/erc/resources/join/buffer-display/mode-context.eld: New
file. (Bug#62833)
2023-05-30 23:27:12 -07:00
|
|
|
(erc--display-context (erc-buffer-display . erc-tls))
|
2022-12-29 06:43:19 -08:00
|
|
|
(erc-server-connect-function erc-open-tls-stream)))))
|
2022-07-11 05:14:57 -07:00
|
|
|
|
|
|
|
(ert-info ("Full")
|
|
|
|
(erc-tls :server "irc.gnu.org"
|
|
|
|
:port 7000
|
|
|
|
:user "bobo"
|
|
|
|
:nick "bob"
|
|
|
|
:full-name "Bob's Name"
|
|
|
|
:password "bob:changeme"
|
|
|
|
:client-certificate t
|
|
|
|
:id 'GNU.org)
|
|
|
|
(should (equal (pop calls)
|
|
|
|
'("irc.gnu.org" 7000 "bob" "Bob's Name" t
|
2022-12-29 06:43:19 -08:00
|
|
|
"bob:changeme" nil nil nil t "bobo" GNU.org)))
|
|
|
|
(should (equal (pop env)
|
2022-12-29 06:43:19 -08:00
|
|
|
'((erc-join-buffer bury)
|
Allow custom display-buffer actions in ERC
* doc/misc/erc.texi: Add new section under "Integrations" chapter
describing `display-buffer' Custom function choice for ERC's many
buffer-display options.
* etc/ERC-NEWS: Mention new function variant for all buffer-display
options.
* lisp/erc/erc-backend.el: Add forward declaration for
`erc--called-as-input-p' and `erc--display-context'.
(erc--server-reconnect-display-timer,
erc--server-last-reconnect-display-reset): Use new name for option
`erc-reconnect-display', now `erc-auto-reconnect-display'.
(erc--server-determine-join-display-context): New generic function to
determine value of `erc--display-context' during JOINs.
(erc-server-JOIN, erc-server-PRIVMSG): Set `erc--display-context' to a
symbol for the handler's IRC command, like `JOIN', for the benefit of
custom `display-buffer'-like functions running in `erc-setup-buffer'.
(erc-server-471, erc-server-471-functions, erc-server-473,
erc-server-473-functions): New handlers for JOIN rejections. Also
remove 471 and 473 from comment at bottom of file.
(erc-server-475): Bind `erc--called-as-input-p' so that `erc-cmd-JOIN'
sets `erc-interactive-display' context.
* lisp/erc/erc-join.el (erc-autojoin-mode, erc-autojoin-enable,
erc-autojoin-disable): Kill local variable
`erc-join--requested-channels'. Add and remove
`erc-join--remove-requested-channels' to/from various server-handler
hooks for JOIN rejection numerics.
(erc-join--requested-channels): New local variable to remember
channels we've attempted to JOIN this session that haven't yet been
confirmed by the server.
(erc-join--remove-requested-channel): New JOIN rejection handler to
stop tracking channel in `erc-join--requested-channels'.
(erc--server-determine-join-display-context): module-specific
implementation of generic function for `erc-autojoin-mode'.
(erc-autojoin--join): Remember channels slated for JOIN'ing.
* lisp/erc/erc.el (erc--buffer-display-choices): New helper constant
for defining common `:type' for all buffer-display options.
(erc-buffer-display, erc-interactive-display,
erc-auto-reconnect-display, erc-receive-query-display): Use helper
`erc--buffer-display-choices' for defining `:type', which
includes a new choice for a `display-buffer'-like function.
(erc-reconnect-display, erc-auto-reconnect-display): Alias former to
latter, now the preferred name.
(erc-reconnect-timeout, erc-auto-reconnect-timeout): Change name from
former to latter. This option is new in ERC 5.6.
(erc-reconnect-display-server-buffers): New option.
(erc-buffer-do): Revise doc string.
(erc--display-context): New variable, an alist of "context tokens" to
be forwarded as the "action alist" to `erc-buffer-display' functions.
(erc-skip-displaying-selected-window-buffer): New variable, deprecated
at birth, to act as an escape hatch for folks who don't want to skip
the displaying of buffers already showing in the selected window.
(erc--display-buffer-overriding-action): Local variable allowing
modules to influence the displaying of new ERC buffers independently
of user options.
(erc-setup-buffer): Do nothing when the selected window already shows
current buffer unless user has provided a custom display function.
Accommodate new Custom choice function values, like `display-buffer'
and `pop-to-buffer'.
(erc-open): Run `erc-setup-buffer' when option
`erc-reconnect-display-server-buffers' is non-nil, even for existing
server buffers. Bind `display-buffer-overriding-action' to the value
of `erc--display-buffer-overriding-action' around calls to
`erc-setup-buffer'.
(erc-select-read-args): Add `erc--display-context' to environment.
(erc, erc-tls): Bind `erc--display-context' around calls to
`erc-select-read-args' and main body.
(erc-cmd-JOIN, erc-cmd-QUERY, erc--cmd-reconnect, erc-handle-irc-url):
Add item for `erc-interactive-display' to `erc--display-context'.
(erc-connection-established): Update name of
`erc-reconnect-display-timeout' to
`erc-auto-reconnect-display-timeout'.
(erc-message-english-s471, erc-message-english-s473): New variables,
format templates for JOIN rejection messages.
* test/lisp/erc/erc-scenarios-base-buffer-display.el
(erc-scenarios-base-buffer-display--defwin-recbury-intbuf,
erc-scenarios-base-buffer-display--defwino-recbury-intbuf,
erc-scenarios-base-buffer-display--count-reset-timeout): Use preferred
name `erc-auto-reconnect-display' for `erc-reconnect-display'.
* test/lisp/erc/erc-scenarios-join-display-context.el: New file.
* test/lisp/erc/erc-tests.el (erc--initialize-markers): Fix
unrealistic call to `erc-open'.
(erc-setup-buffer--custom-action): New test.
(erc-select-read-args, erc-tls, erc--interactive, erc-server-select):
Expect new environment binding for `erc--display-context'.
* test/lisp/erc/resources/join/buffer-display/mode-context.eld: New
file. (Bug#62833)
2023-05-30 23:27:12 -07:00
|
|
|
(erc--display-context (erc-buffer-display . erc-tls))
|
2022-12-29 06:43:19 -08:00
|
|
|
(erc-server-connect-function erc-open-tls-stream)))))
|
2022-07-11 05:14:57 -07:00
|
|
|
|
|
|
|
;; Values are often nil when called by lisp code, which leads to
|
|
|
|
;; null params. This is why `erc-open' recomputes almost
|
|
|
|
;; everything.
|
|
|
|
(ert-info ("Fallback")
|
|
|
|
(let ((erc-nick "bob")
|
|
|
|
(erc-server "irc.gnu.org")
|
|
|
|
(erc-email-userid "bobo")
|
|
|
|
(erc-user-full-name "Bob's Name"))
|
|
|
|
(erc-tls :server nil
|
|
|
|
:port 7000
|
|
|
|
:nick nil
|
|
|
|
:password "bob:changeme"))
|
|
|
|
(should (equal (pop calls)
|
|
|
|
'(nil 7000 nil "Bob's Name" t
|
2022-12-29 06:43:19 -08:00
|
|
|
"bob:changeme" nil nil nil nil "bobo" nil)))
|
|
|
|
(should (equal (pop env)
|
2022-12-29 06:43:19 -08:00
|
|
|
'((erc-join-buffer bury)
|
Allow custom display-buffer actions in ERC
* doc/misc/erc.texi: Add new section under "Integrations" chapter
describing `display-buffer' Custom function choice for ERC's many
buffer-display options.
* etc/ERC-NEWS: Mention new function variant for all buffer-display
options.
* lisp/erc/erc-backend.el: Add forward declaration for
`erc--called-as-input-p' and `erc--display-context'.
(erc--server-reconnect-display-timer,
erc--server-last-reconnect-display-reset): Use new name for option
`erc-reconnect-display', now `erc-auto-reconnect-display'.
(erc--server-determine-join-display-context): New generic function to
determine value of `erc--display-context' during JOINs.
(erc-server-JOIN, erc-server-PRIVMSG): Set `erc--display-context' to a
symbol for the handler's IRC command, like `JOIN', for the benefit of
custom `display-buffer'-like functions running in `erc-setup-buffer'.
(erc-server-471, erc-server-471-functions, erc-server-473,
erc-server-473-functions): New handlers for JOIN rejections. Also
remove 471 and 473 from comment at bottom of file.
(erc-server-475): Bind `erc--called-as-input-p' so that `erc-cmd-JOIN'
sets `erc-interactive-display' context.
* lisp/erc/erc-join.el (erc-autojoin-mode, erc-autojoin-enable,
erc-autojoin-disable): Kill local variable
`erc-join--requested-channels'. Add and remove
`erc-join--remove-requested-channels' to/from various server-handler
hooks for JOIN rejection numerics.
(erc-join--requested-channels): New local variable to remember
channels we've attempted to JOIN this session that haven't yet been
confirmed by the server.
(erc-join--remove-requested-channel): New JOIN rejection handler to
stop tracking channel in `erc-join--requested-channels'.
(erc--server-determine-join-display-context): module-specific
implementation of generic function for `erc-autojoin-mode'.
(erc-autojoin--join): Remember channels slated for JOIN'ing.
* lisp/erc/erc.el (erc--buffer-display-choices): New helper constant
for defining common `:type' for all buffer-display options.
(erc-buffer-display, erc-interactive-display,
erc-auto-reconnect-display, erc-receive-query-display): Use helper
`erc--buffer-display-choices' for defining `:type', which
includes a new choice for a `display-buffer'-like function.
(erc-reconnect-display, erc-auto-reconnect-display): Alias former to
latter, now the preferred name.
(erc-reconnect-timeout, erc-auto-reconnect-timeout): Change name from
former to latter. This option is new in ERC 5.6.
(erc-reconnect-display-server-buffers): New option.
(erc-buffer-do): Revise doc string.
(erc--display-context): New variable, an alist of "context tokens" to
be forwarded as the "action alist" to `erc-buffer-display' functions.
(erc-skip-displaying-selected-window-buffer): New variable, deprecated
at birth, to act as an escape hatch for folks who don't want to skip
the displaying of buffers already showing in the selected window.
(erc--display-buffer-overriding-action): Local variable allowing
modules to influence the displaying of new ERC buffers independently
of user options.
(erc-setup-buffer): Do nothing when the selected window already shows
current buffer unless user has provided a custom display function.
Accommodate new Custom choice function values, like `display-buffer'
and `pop-to-buffer'.
(erc-open): Run `erc-setup-buffer' when option
`erc-reconnect-display-server-buffers' is non-nil, even for existing
server buffers. Bind `display-buffer-overriding-action' to the value
of `erc--display-buffer-overriding-action' around calls to
`erc-setup-buffer'.
(erc-select-read-args): Add `erc--display-context' to environment.
(erc, erc-tls): Bind `erc--display-context' around calls to
`erc-select-read-args' and main body.
(erc-cmd-JOIN, erc-cmd-QUERY, erc--cmd-reconnect, erc-handle-irc-url):
Add item for `erc-interactive-display' to `erc--display-context'.
(erc-connection-established): Update name of
`erc-reconnect-display-timeout' to
`erc-auto-reconnect-display-timeout'.
(erc-message-english-s471, erc-message-english-s473): New variables,
format templates for JOIN rejection messages.
* test/lisp/erc/erc-scenarios-base-buffer-display.el
(erc-scenarios-base-buffer-display--defwin-recbury-intbuf,
erc-scenarios-base-buffer-display--defwino-recbury-intbuf,
erc-scenarios-base-buffer-display--count-reset-timeout): Use preferred
name `erc-auto-reconnect-display' for `erc-reconnect-display'.
* test/lisp/erc/erc-scenarios-join-display-context.el: New file.
* test/lisp/erc/erc-tests.el (erc--initialize-markers): Fix
unrealistic call to `erc-open'.
(erc-setup-buffer--custom-action): New test.
(erc-select-read-args, erc-tls, erc--interactive, erc-server-select):
Expect new environment binding for `erc--display-context'.
* test/lisp/erc/resources/join/buffer-display/mode-context.eld: New
file. (Bug#62833)
2023-05-30 23:27:12 -07:00
|
|
|
(erc--display-context (erc-buffer-display . erc-tls))
|
2022-12-29 06:43:19 -08:00
|
|
|
(erc-server-connect-function erc-open-tls-stream)))))
|
2022-12-29 06:43:19 -08:00
|
|
|
|
|
|
|
(ert-info ("Interactive")
|
|
|
|
(ert-simulate-keys "nick:sesame@localhost:6667\r\r"
|
|
|
|
(call-interactively #'erc-tls))
|
|
|
|
(should (equal (pop calls)
|
|
|
|
'("localhost" 6667 "nick" "unknown" t "sesame"
|
|
|
|
nil nil nil nil "user" nil)))
|
|
|
|
(should (equal (pop env)
|
Extend erc-interactive-display to cover /JOINs
* lisp/erc/erc.el (erc-display): Mention that buffer-related display
options live in the customization group `erc-buffers'.
(erc-buffer-display, erc-join-buffer): Swap alias and aliased so that
the favored name, `erc-buffer-display', appears in the definition and
in the Customize menu. Also note related buffer-display options in
the doc string.
(erc-query-display, erc-interactive-display): Make the former an alias
of the latter, new in ERC 5.6, because their roles were functionally
redundant and thus confusing. Inherit the default value from
`erc-query-display' because users are more familiar with the pop-up
window behavior than a single-window replacement.
(erc-reconnect-display): Use preferred name for cross-referencing
fallback option `erc-buffer-display' in doc string, and explain how
/reconnect handling differs.
(erc--setup-buffer-hook): Add new internal hook for modules that
operate on windows and frames, such as erc-speedbar and
erc-status-sidebar.
(erc-open): Run `erc--setup-buffer-hook' after `erc-setup-buffer' so
hook members know their code isn't tied to `erc-setup-buffer' itself,
which may be used in other contexts, but rather to a new ERC buffer on
which some display-related action has just been performed.
(erc--called-as-input-p): New variable for "slash" commands, like
`erc-cmd-FOO', to detect whether they're being called "interactively"
as a result of input given at ERC's prompt.
(erc-process-input-line): Bind `erc--called-as-input-p' when running
slash commands.
(erc-cmd-JOIN): When called interactively, schedule a callback to wrap
the response handler and control how new buffers are thus displayed.
(erc-cmd-QUERY): Use preferred alias for `erc-query-display'.
* test/lisp/erc/erc-scenarios-base-buffer-display.el:
(erc-scenarios-base-buffer-display--interactive-default): New test.
* test/lisp/erc/erc-tests.el (erc-process-input-line,
erc-select-read-args, erc-tls, erc--interactive): Change expected
default value of `erc-interactive-display' from `buffer' to
`window'. (Bug#62833)
2023-04-10 17:58:05 -07:00
|
|
|
'((erc-join-buffer window)
|
Allow custom display-buffer actions in ERC
* doc/misc/erc.texi: Add new section under "Integrations" chapter
describing `display-buffer' Custom function choice for ERC's many
buffer-display options.
* etc/ERC-NEWS: Mention new function variant for all buffer-display
options.
* lisp/erc/erc-backend.el: Add forward declaration for
`erc--called-as-input-p' and `erc--display-context'.
(erc--server-reconnect-display-timer,
erc--server-last-reconnect-display-reset): Use new name for option
`erc-reconnect-display', now `erc-auto-reconnect-display'.
(erc--server-determine-join-display-context): New generic function to
determine value of `erc--display-context' during JOINs.
(erc-server-JOIN, erc-server-PRIVMSG): Set `erc--display-context' to a
symbol for the handler's IRC command, like `JOIN', for the benefit of
custom `display-buffer'-like functions running in `erc-setup-buffer'.
(erc-server-471, erc-server-471-functions, erc-server-473,
erc-server-473-functions): New handlers for JOIN rejections. Also
remove 471 and 473 from comment at bottom of file.
(erc-server-475): Bind `erc--called-as-input-p' so that `erc-cmd-JOIN'
sets `erc-interactive-display' context.
* lisp/erc/erc-join.el (erc-autojoin-mode, erc-autojoin-enable,
erc-autojoin-disable): Kill local variable
`erc-join--requested-channels'. Add and remove
`erc-join--remove-requested-channels' to/from various server-handler
hooks for JOIN rejection numerics.
(erc-join--requested-channels): New local variable to remember
channels we've attempted to JOIN this session that haven't yet been
confirmed by the server.
(erc-join--remove-requested-channel): New JOIN rejection handler to
stop tracking channel in `erc-join--requested-channels'.
(erc--server-determine-join-display-context): module-specific
implementation of generic function for `erc-autojoin-mode'.
(erc-autojoin--join): Remember channels slated for JOIN'ing.
* lisp/erc/erc.el (erc--buffer-display-choices): New helper constant
for defining common `:type' for all buffer-display options.
(erc-buffer-display, erc-interactive-display,
erc-auto-reconnect-display, erc-receive-query-display): Use helper
`erc--buffer-display-choices' for defining `:type', which
includes a new choice for a `display-buffer'-like function.
(erc-reconnect-display, erc-auto-reconnect-display): Alias former to
latter, now the preferred name.
(erc-reconnect-timeout, erc-auto-reconnect-timeout): Change name from
former to latter. This option is new in ERC 5.6.
(erc-reconnect-display-server-buffers): New option.
(erc-buffer-do): Revise doc string.
(erc--display-context): New variable, an alist of "context tokens" to
be forwarded as the "action alist" to `erc-buffer-display' functions.
(erc-skip-displaying-selected-window-buffer): New variable, deprecated
at birth, to act as an escape hatch for folks who don't want to skip
the displaying of buffers already showing in the selected window.
(erc--display-buffer-overriding-action): Local variable allowing
modules to influence the displaying of new ERC buffers independently
of user options.
(erc-setup-buffer): Do nothing when the selected window already shows
current buffer unless user has provided a custom display function.
Accommodate new Custom choice function values, like `display-buffer'
and `pop-to-buffer'.
(erc-open): Run `erc-setup-buffer' when option
`erc-reconnect-display-server-buffers' is non-nil, even for existing
server buffers. Bind `display-buffer-overriding-action' to the value
of `erc--display-buffer-overriding-action' around calls to
`erc-setup-buffer'.
(erc-select-read-args): Add `erc--display-context' to environment.
(erc, erc-tls): Bind `erc--display-context' around calls to
`erc-select-read-args' and main body.
(erc-cmd-JOIN, erc-cmd-QUERY, erc--cmd-reconnect, erc-handle-irc-url):
Add item for `erc-interactive-display' to `erc--display-context'.
(erc-connection-established): Update name of
`erc-reconnect-display-timeout' to
`erc-auto-reconnect-display-timeout'.
(erc-message-english-s471, erc-message-english-s473): New variables,
format templates for JOIN rejection messages.
* test/lisp/erc/erc-scenarios-base-buffer-display.el
(erc-scenarios-base-buffer-display--defwin-recbury-intbuf,
erc-scenarios-base-buffer-display--defwino-recbury-intbuf,
erc-scenarios-base-buffer-display--count-reset-timeout): Use preferred
name `erc-auto-reconnect-display' for `erc-reconnect-display'.
* test/lisp/erc/erc-scenarios-join-display-context.el: New file.
* test/lisp/erc/erc-tests.el (erc--initialize-markers): Fix
unrealistic call to `erc-open'.
(erc-setup-buffer--custom-action): New test.
(erc-select-read-args, erc-tls, erc--interactive, erc-server-select):
Expect new environment binding for `erc--display-context'.
* test/lisp/erc/resources/join/buffer-display/mode-context.eld: New
file. (Bug#62833)
2023-05-30 23:27:12 -07:00
|
|
|
(erc--display-context
|
|
|
|
(erc-interactive-display . erc-tls))
|
2022-12-29 06:43:19 -08:00
|
|
|
(erc-server-connect-function erc-open-tls-stream)))))
|
2022-12-29 06:43:19 -08:00
|
|
|
|
|
|
|
(ert-info ("Custom connect function")
|
|
|
|
(let ((erc-server-connect-function 'my-connect-func))
|
|
|
|
(erc-tls)
|
|
|
|
(should (equal (pop calls)
|
|
|
|
'("irc.libera.chat" 6697 "tester" "unknown" t
|
|
|
|
nil nil nil nil nil "user" nil)))
|
|
|
|
(should (equal (pop env)
|
2022-12-29 06:43:19 -08:00
|
|
|
'((erc-join-buffer bury)
|
Allow custom display-buffer actions in ERC
* doc/misc/erc.texi: Add new section under "Integrations" chapter
describing `display-buffer' Custom function choice for ERC's many
buffer-display options.
* etc/ERC-NEWS: Mention new function variant for all buffer-display
options.
* lisp/erc/erc-backend.el: Add forward declaration for
`erc--called-as-input-p' and `erc--display-context'.
(erc--server-reconnect-display-timer,
erc--server-last-reconnect-display-reset): Use new name for option
`erc-reconnect-display', now `erc-auto-reconnect-display'.
(erc--server-determine-join-display-context): New generic function to
determine value of `erc--display-context' during JOINs.
(erc-server-JOIN, erc-server-PRIVMSG): Set `erc--display-context' to a
symbol for the handler's IRC command, like `JOIN', for the benefit of
custom `display-buffer'-like functions running in `erc-setup-buffer'.
(erc-server-471, erc-server-471-functions, erc-server-473,
erc-server-473-functions): New handlers for JOIN rejections. Also
remove 471 and 473 from comment at bottom of file.
(erc-server-475): Bind `erc--called-as-input-p' so that `erc-cmd-JOIN'
sets `erc-interactive-display' context.
* lisp/erc/erc-join.el (erc-autojoin-mode, erc-autojoin-enable,
erc-autojoin-disable): Kill local variable
`erc-join--requested-channels'. Add and remove
`erc-join--remove-requested-channels' to/from various server-handler
hooks for JOIN rejection numerics.
(erc-join--requested-channels): New local variable to remember
channels we've attempted to JOIN this session that haven't yet been
confirmed by the server.
(erc-join--remove-requested-channel): New JOIN rejection handler to
stop tracking channel in `erc-join--requested-channels'.
(erc--server-determine-join-display-context): module-specific
implementation of generic function for `erc-autojoin-mode'.
(erc-autojoin--join): Remember channels slated for JOIN'ing.
* lisp/erc/erc.el (erc--buffer-display-choices): New helper constant
for defining common `:type' for all buffer-display options.
(erc-buffer-display, erc-interactive-display,
erc-auto-reconnect-display, erc-receive-query-display): Use helper
`erc--buffer-display-choices' for defining `:type', which
includes a new choice for a `display-buffer'-like function.
(erc-reconnect-display, erc-auto-reconnect-display): Alias former to
latter, now the preferred name.
(erc-reconnect-timeout, erc-auto-reconnect-timeout): Change name from
former to latter. This option is new in ERC 5.6.
(erc-reconnect-display-server-buffers): New option.
(erc-buffer-do): Revise doc string.
(erc--display-context): New variable, an alist of "context tokens" to
be forwarded as the "action alist" to `erc-buffer-display' functions.
(erc-skip-displaying-selected-window-buffer): New variable, deprecated
at birth, to act as an escape hatch for folks who don't want to skip
the displaying of buffers already showing in the selected window.
(erc--display-buffer-overriding-action): Local variable allowing
modules to influence the displaying of new ERC buffers independently
of user options.
(erc-setup-buffer): Do nothing when the selected window already shows
current buffer unless user has provided a custom display function.
Accommodate new Custom choice function values, like `display-buffer'
and `pop-to-buffer'.
(erc-open): Run `erc-setup-buffer' when option
`erc-reconnect-display-server-buffers' is non-nil, even for existing
server buffers. Bind `display-buffer-overriding-action' to the value
of `erc--display-buffer-overriding-action' around calls to
`erc-setup-buffer'.
(erc-select-read-args): Add `erc--display-context' to environment.
(erc, erc-tls): Bind `erc--display-context' around calls to
`erc-select-read-args' and main body.
(erc-cmd-JOIN, erc-cmd-QUERY, erc--cmd-reconnect, erc-handle-irc-url):
Add item for `erc-interactive-display' to `erc--display-context'.
(erc-connection-established): Update name of
`erc-reconnect-display-timeout' to
`erc-auto-reconnect-display-timeout'.
(erc-message-english-s471, erc-message-english-s473): New variables,
format templates for JOIN rejection messages.
* test/lisp/erc/erc-scenarios-base-buffer-display.el
(erc-scenarios-base-buffer-display--defwin-recbury-intbuf,
erc-scenarios-base-buffer-display--defwino-recbury-intbuf,
erc-scenarios-base-buffer-display--count-reset-timeout): Use preferred
name `erc-auto-reconnect-display' for `erc-reconnect-display'.
* test/lisp/erc/erc-scenarios-join-display-context.el: New file.
* test/lisp/erc/erc-tests.el (erc--initialize-markers): Fix
unrealistic call to `erc-open'.
(erc-setup-buffer--custom-action): New test.
(erc-select-read-args, erc-tls, erc--interactive, erc-server-select):
Expect new environment binding for `erc--display-context'.
* test/lisp/erc/resources/join/buffer-display/mode-context.eld: New
file. (Bug#62833)
2023-05-30 23:27:12 -07:00
|
|
|
(erc--display-context
|
|
|
|
(erc-buffer-display . erc-tls))
|
2022-12-29 06:43:19 -08:00
|
|
|
(erc-server-connect-function my-connect-func))))))
|
2022-12-29 06:43:19 -08:00
|
|
|
|
|
|
|
(ert-info ("Advised default function overlooked") ; intentional
|
|
|
|
(advice-add 'erc-server-connect-function :around #'ignore
|
|
|
|
'((name . erc-tests--erc-tls)))
|
|
|
|
(erc-tls)
|
|
|
|
(should (equal (pop calls)
|
|
|
|
'("irc.libera.chat" 6697 "tester" "unknown" t
|
|
|
|
nil nil nil nil nil "user" nil)))
|
|
|
|
(should (equal (pop env)
|
2022-12-29 06:43:19 -08:00
|
|
|
'((erc-join-buffer bury)
|
Allow custom display-buffer actions in ERC
* doc/misc/erc.texi: Add new section under "Integrations" chapter
describing `display-buffer' Custom function choice for ERC's many
buffer-display options.
* etc/ERC-NEWS: Mention new function variant for all buffer-display
options.
* lisp/erc/erc-backend.el: Add forward declaration for
`erc--called-as-input-p' and `erc--display-context'.
(erc--server-reconnect-display-timer,
erc--server-last-reconnect-display-reset): Use new name for option
`erc-reconnect-display', now `erc-auto-reconnect-display'.
(erc--server-determine-join-display-context): New generic function to
determine value of `erc--display-context' during JOINs.
(erc-server-JOIN, erc-server-PRIVMSG): Set `erc--display-context' to a
symbol for the handler's IRC command, like `JOIN', for the benefit of
custom `display-buffer'-like functions running in `erc-setup-buffer'.
(erc-server-471, erc-server-471-functions, erc-server-473,
erc-server-473-functions): New handlers for JOIN rejections. Also
remove 471 and 473 from comment at bottom of file.
(erc-server-475): Bind `erc--called-as-input-p' so that `erc-cmd-JOIN'
sets `erc-interactive-display' context.
* lisp/erc/erc-join.el (erc-autojoin-mode, erc-autojoin-enable,
erc-autojoin-disable): Kill local variable
`erc-join--requested-channels'. Add and remove
`erc-join--remove-requested-channels' to/from various server-handler
hooks for JOIN rejection numerics.
(erc-join--requested-channels): New local variable to remember
channels we've attempted to JOIN this session that haven't yet been
confirmed by the server.
(erc-join--remove-requested-channel): New JOIN rejection handler to
stop tracking channel in `erc-join--requested-channels'.
(erc--server-determine-join-display-context): module-specific
implementation of generic function for `erc-autojoin-mode'.
(erc-autojoin--join): Remember channels slated for JOIN'ing.
* lisp/erc/erc.el (erc--buffer-display-choices): New helper constant
for defining common `:type' for all buffer-display options.
(erc-buffer-display, erc-interactive-display,
erc-auto-reconnect-display, erc-receive-query-display): Use helper
`erc--buffer-display-choices' for defining `:type', which
includes a new choice for a `display-buffer'-like function.
(erc-reconnect-display, erc-auto-reconnect-display): Alias former to
latter, now the preferred name.
(erc-reconnect-timeout, erc-auto-reconnect-timeout): Change name from
former to latter. This option is new in ERC 5.6.
(erc-reconnect-display-server-buffers): New option.
(erc-buffer-do): Revise doc string.
(erc--display-context): New variable, an alist of "context tokens" to
be forwarded as the "action alist" to `erc-buffer-display' functions.
(erc-skip-displaying-selected-window-buffer): New variable, deprecated
at birth, to act as an escape hatch for folks who don't want to skip
the displaying of buffers already showing in the selected window.
(erc--display-buffer-overriding-action): Local variable allowing
modules to influence the displaying of new ERC buffers independently
of user options.
(erc-setup-buffer): Do nothing when the selected window already shows
current buffer unless user has provided a custom display function.
Accommodate new Custom choice function values, like `display-buffer'
and `pop-to-buffer'.
(erc-open): Run `erc-setup-buffer' when option
`erc-reconnect-display-server-buffers' is non-nil, even for existing
server buffers. Bind `display-buffer-overriding-action' to the value
of `erc--display-buffer-overriding-action' around calls to
`erc-setup-buffer'.
(erc-select-read-args): Add `erc--display-context' to environment.
(erc, erc-tls): Bind `erc--display-context' around calls to
`erc-select-read-args' and main body.
(erc-cmd-JOIN, erc-cmd-QUERY, erc--cmd-reconnect, erc-handle-irc-url):
Add item for `erc-interactive-display' to `erc--display-context'.
(erc-connection-established): Update name of
`erc-reconnect-display-timeout' to
`erc-auto-reconnect-display-timeout'.
(erc-message-english-s471, erc-message-english-s473): New variables,
format templates for JOIN rejection messages.
* test/lisp/erc/erc-scenarios-base-buffer-display.el
(erc-scenarios-base-buffer-display--defwin-recbury-intbuf,
erc-scenarios-base-buffer-display--defwino-recbury-intbuf,
erc-scenarios-base-buffer-display--count-reset-timeout): Use preferred
name `erc-auto-reconnect-display' for `erc-reconnect-display'.
* test/lisp/erc/erc-scenarios-join-display-context.el: New file.
* test/lisp/erc/erc-tests.el (erc--initialize-markers): Fix
unrealistic call to `erc-open'.
(erc-setup-buffer--custom-action): New test.
(erc-select-read-args, erc-tls, erc--interactive, erc-server-select):
Expect new environment binding for `erc--display-context'.
* test/lisp/erc/resources/join/buffer-display/mode-context.eld: New
file. (Bug#62833)
2023-05-30 23:27:12 -07:00
|
|
|
(erc--display-context (erc-buffer-display . erc-tls))
|
2022-12-29 06:43:19 -08:00
|
|
|
(erc-server-connect-function erc-open-tls-stream))))
|
2022-12-29 06:43:19 -08:00
|
|
|
(advice-remove 'erc-server-connect-function 'erc-tests--erc-tls))
|
|
|
|
|
|
|
|
(ert-info ("Advised non-default function honored")
|
|
|
|
(let ((f (lambda (&rest r) (ignore r))))
|
|
|
|
(cl-letf (((symbol-value 'erc-server-connect-function) f))
|
|
|
|
(advice-add 'erc-server-connect-function :around #'ignore
|
|
|
|
'((name . erc-tests--erc-tls)))
|
|
|
|
(erc-tls)
|
|
|
|
(should (equal (pop calls)
|
|
|
|
'("irc.libera.chat" 6697 "tester" "unknown" t
|
|
|
|
nil nil nil nil nil "user" nil)))
|
2022-12-29 06:43:19 -08:00
|
|
|
(should (equal (pop env) `((erc-join-buffer bury)
|
Allow custom display-buffer actions in ERC
* doc/misc/erc.texi: Add new section under "Integrations" chapter
describing `display-buffer' Custom function choice for ERC's many
buffer-display options.
* etc/ERC-NEWS: Mention new function variant for all buffer-display
options.
* lisp/erc/erc-backend.el: Add forward declaration for
`erc--called-as-input-p' and `erc--display-context'.
(erc--server-reconnect-display-timer,
erc--server-last-reconnect-display-reset): Use new name for option
`erc-reconnect-display', now `erc-auto-reconnect-display'.
(erc--server-determine-join-display-context): New generic function to
determine value of `erc--display-context' during JOINs.
(erc-server-JOIN, erc-server-PRIVMSG): Set `erc--display-context' to a
symbol for the handler's IRC command, like `JOIN', for the benefit of
custom `display-buffer'-like functions running in `erc-setup-buffer'.
(erc-server-471, erc-server-471-functions, erc-server-473,
erc-server-473-functions): New handlers for JOIN rejections. Also
remove 471 and 473 from comment at bottom of file.
(erc-server-475): Bind `erc--called-as-input-p' so that `erc-cmd-JOIN'
sets `erc-interactive-display' context.
* lisp/erc/erc-join.el (erc-autojoin-mode, erc-autojoin-enable,
erc-autojoin-disable): Kill local variable
`erc-join--requested-channels'. Add and remove
`erc-join--remove-requested-channels' to/from various server-handler
hooks for JOIN rejection numerics.
(erc-join--requested-channels): New local variable to remember
channels we've attempted to JOIN this session that haven't yet been
confirmed by the server.
(erc-join--remove-requested-channel): New JOIN rejection handler to
stop tracking channel in `erc-join--requested-channels'.
(erc--server-determine-join-display-context): module-specific
implementation of generic function for `erc-autojoin-mode'.
(erc-autojoin--join): Remember channels slated for JOIN'ing.
* lisp/erc/erc.el (erc--buffer-display-choices): New helper constant
for defining common `:type' for all buffer-display options.
(erc-buffer-display, erc-interactive-display,
erc-auto-reconnect-display, erc-receive-query-display): Use helper
`erc--buffer-display-choices' for defining `:type', which
includes a new choice for a `display-buffer'-like function.
(erc-reconnect-display, erc-auto-reconnect-display): Alias former to
latter, now the preferred name.
(erc-reconnect-timeout, erc-auto-reconnect-timeout): Change name from
former to latter. This option is new in ERC 5.6.
(erc-reconnect-display-server-buffers): New option.
(erc-buffer-do): Revise doc string.
(erc--display-context): New variable, an alist of "context tokens" to
be forwarded as the "action alist" to `erc-buffer-display' functions.
(erc-skip-displaying-selected-window-buffer): New variable, deprecated
at birth, to act as an escape hatch for folks who don't want to skip
the displaying of buffers already showing in the selected window.
(erc--display-buffer-overriding-action): Local variable allowing
modules to influence the displaying of new ERC buffers independently
of user options.
(erc-setup-buffer): Do nothing when the selected window already shows
current buffer unless user has provided a custom display function.
Accommodate new Custom choice function values, like `display-buffer'
and `pop-to-buffer'.
(erc-open): Run `erc-setup-buffer' when option
`erc-reconnect-display-server-buffers' is non-nil, even for existing
server buffers. Bind `display-buffer-overriding-action' to the value
of `erc--display-buffer-overriding-action' around calls to
`erc-setup-buffer'.
(erc-select-read-args): Add `erc--display-context' to environment.
(erc, erc-tls): Bind `erc--display-context' around calls to
`erc-select-read-args' and main body.
(erc-cmd-JOIN, erc-cmd-QUERY, erc--cmd-reconnect, erc-handle-irc-url):
Add item for `erc-interactive-display' to `erc--display-context'.
(erc-connection-established): Update name of
`erc-reconnect-display-timeout' to
`erc-auto-reconnect-display-timeout'.
(erc-message-english-s471, erc-message-english-s473): New variables,
format templates for JOIN rejection messages.
* test/lisp/erc/erc-scenarios-base-buffer-display.el
(erc-scenarios-base-buffer-display--defwin-recbury-intbuf,
erc-scenarios-base-buffer-display--defwino-recbury-intbuf,
erc-scenarios-base-buffer-display--count-reset-timeout): Use preferred
name `erc-auto-reconnect-display' for `erc-reconnect-display'.
* test/lisp/erc/erc-scenarios-join-display-context.el: New file.
* test/lisp/erc/erc-tests.el (erc--initialize-markers): Fix
unrealistic call to `erc-open'.
(erc-setup-buffer--custom-action): New test.
(erc-select-read-args, erc-tls, erc--interactive, erc-server-select):
Expect new environment binding for `erc--display-context'.
* test/lisp/erc/resources/join/buffer-display/mode-context.eld: New
file. (Bug#62833)
2023-05-30 23:27:12 -07:00
|
|
|
(erc--display-context
|
|
|
|
(erc-buffer-display . erc-tls))
|
2022-12-29 06:43:19 -08:00
|
|
|
(erc-server-connect-function ,f))))
|
2022-12-29 06:43:19 -08:00
|
|
|
(advice-remove 'erc-server-connect-function
|
|
|
|
'erc-tests--erc-tls)))))))
|
|
|
|
|
|
|
|
;; See `erc-select-read-args' above for argument parsing.
|
|
|
|
;; This only tests the "hidden" arguments.
|
|
|
|
|
|
|
|
(ert-deftest erc--interactive ()
|
|
|
|
(let (calls env)
|
|
|
|
(cl-letf (((symbol-function 'user-login-name)
|
|
|
|
(lambda (&optional _) "tester"))
|
|
|
|
((symbol-function 'erc-open)
|
|
|
|
(lambda (&rest r)
|
2022-12-29 06:43:19 -08:00
|
|
|
(push `((erc-join-buffer ,erc-join-buffer)
|
Allow custom display-buffer actions in ERC
* doc/misc/erc.texi: Add new section under "Integrations" chapter
describing `display-buffer' Custom function choice for ERC's many
buffer-display options.
* etc/ERC-NEWS: Mention new function variant for all buffer-display
options.
* lisp/erc/erc-backend.el: Add forward declaration for
`erc--called-as-input-p' and `erc--display-context'.
(erc--server-reconnect-display-timer,
erc--server-last-reconnect-display-reset): Use new name for option
`erc-reconnect-display', now `erc-auto-reconnect-display'.
(erc--server-determine-join-display-context): New generic function to
determine value of `erc--display-context' during JOINs.
(erc-server-JOIN, erc-server-PRIVMSG): Set `erc--display-context' to a
symbol for the handler's IRC command, like `JOIN', for the benefit of
custom `display-buffer'-like functions running in `erc-setup-buffer'.
(erc-server-471, erc-server-471-functions, erc-server-473,
erc-server-473-functions): New handlers for JOIN rejections. Also
remove 471 and 473 from comment at bottom of file.
(erc-server-475): Bind `erc--called-as-input-p' so that `erc-cmd-JOIN'
sets `erc-interactive-display' context.
* lisp/erc/erc-join.el (erc-autojoin-mode, erc-autojoin-enable,
erc-autojoin-disable): Kill local variable
`erc-join--requested-channels'. Add and remove
`erc-join--remove-requested-channels' to/from various server-handler
hooks for JOIN rejection numerics.
(erc-join--requested-channels): New local variable to remember
channels we've attempted to JOIN this session that haven't yet been
confirmed by the server.
(erc-join--remove-requested-channel): New JOIN rejection handler to
stop tracking channel in `erc-join--requested-channels'.
(erc--server-determine-join-display-context): module-specific
implementation of generic function for `erc-autojoin-mode'.
(erc-autojoin--join): Remember channels slated for JOIN'ing.
* lisp/erc/erc.el (erc--buffer-display-choices): New helper constant
for defining common `:type' for all buffer-display options.
(erc-buffer-display, erc-interactive-display,
erc-auto-reconnect-display, erc-receive-query-display): Use helper
`erc--buffer-display-choices' for defining `:type', which
includes a new choice for a `display-buffer'-like function.
(erc-reconnect-display, erc-auto-reconnect-display): Alias former to
latter, now the preferred name.
(erc-reconnect-timeout, erc-auto-reconnect-timeout): Change name from
former to latter. This option is new in ERC 5.6.
(erc-reconnect-display-server-buffers): New option.
(erc-buffer-do): Revise doc string.
(erc--display-context): New variable, an alist of "context tokens" to
be forwarded as the "action alist" to `erc-buffer-display' functions.
(erc-skip-displaying-selected-window-buffer): New variable, deprecated
at birth, to act as an escape hatch for folks who don't want to skip
the displaying of buffers already showing in the selected window.
(erc--display-buffer-overriding-action): Local variable allowing
modules to influence the displaying of new ERC buffers independently
of user options.
(erc-setup-buffer): Do nothing when the selected window already shows
current buffer unless user has provided a custom display function.
Accommodate new Custom choice function values, like `display-buffer'
and `pop-to-buffer'.
(erc-open): Run `erc-setup-buffer' when option
`erc-reconnect-display-server-buffers' is non-nil, even for existing
server buffers. Bind `display-buffer-overriding-action' to the value
of `erc--display-buffer-overriding-action' around calls to
`erc-setup-buffer'.
(erc-select-read-args): Add `erc--display-context' to environment.
(erc, erc-tls): Bind `erc--display-context' around calls to
`erc-select-read-args' and main body.
(erc-cmd-JOIN, erc-cmd-QUERY, erc--cmd-reconnect, erc-handle-irc-url):
Add item for `erc-interactive-display' to `erc--display-context'.
(erc-connection-established): Update name of
`erc-reconnect-display-timeout' to
`erc-auto-reconnect-display-timeout'.
(erc-message-english-s471, erc-message-english-s473): New variables,
format templates for JOIN rejection messages.
* test/lisp/erc/erc-scenarios-base-buffer-display.el
(erc-scenarios-base-buffer-display--defwin-recbury-intbuf,
erc-scenarios-base-buffer-display--defwino-recbury-intbuf,
erc-scenarios-base-buffer-display--count-reset-timeout): Use preferred
name `erc-auto-reconnect-display' for `erc-reconnect-display'.
* test/lisp/erc/erc-scenarios-join-display-context.el: New file.
* test/lisp/erc/erc-tests.el (erc--initialize-markers): Fix
unrealistic call to `erc-open'.
(erc-setup-buffer--custom-action): New test.
(erc-select-read-args, erc-tls, erc--interactive, erc-server-select):
Expect new environment binding for `erc--display-context'.
* test/lisp/erc/resources/join/buffer-display/mode-context.eld: New
file. (Bug#62833)
2023-05-30 23:27:12 -07:00
|
|
|
(erc--display-context ,@erc--display-context)
|
2022-12-29 06:43:19 -08:00
|
|
|
(erc-server-connect-function
|
2022-12-29 06:43:19 -08:00
|
|
|
,erc-server-connect-function))
|
|
|
|
env)
|
|
|
|
(push r calls))))
|
|
|
|
|
|
|
|
(ert-info ("Default click-through accept TLS upgrade")
|
|
|
|
(ert-simulate-keys "\r\r\r\ry\r"
|
|
|
|
(call-interactively #'erc))
|
|
|
|
(should (equal (pop calls)
|
|
|
|
'("irc.libera.chat" 6697 "tester" "unknown" t nil
|
|
|
|
nil nil nil nil "user" nil)))
|
|
|
|
(should (equal (pop env)
|
Allow custom display-buffer actions in ERC
* doc/misc/erc.texi: Add new section under "Integrations" chapter
describing `display-buffer' Custom function choice for ERC's many
buffer-display options.
* etc/ERC-NEWS: Mention new function variant for all buffer-display
options.
* lisp/erc/erc-backend.el: Add forward declaration for
`erc--called-as-input-p' and `erc--display-context'.
(erc--server-reconnect-display-timer,
erc--server-last-reconnect-display-reset): Use new name for option
`erc-reconnect-display', now `erc-auto-reconnect-display'.
(erc--server-determine-join-display-context): New generic function to
determine value of `erc--display-context' during JOINs.
(erc-server-JOIN, erc-server-PRIVMSG): Set `erc--display-context' to a
symbol for the handler's IRC command, like `JOIN', for the benefit of
custom `display-buffer'-like functions running in `erc-setup-buffer'.
(erc-server-471, erc-server-471-functions, erc-server-473,
erc-server-473-functions): New handlers for JOIN rejections. Also
remove 471 and 473 from comment at bottom of file.
(erc-server-475): Bind `erc--called-as-input-p' so that `erc-cmd-JOIN'
sets `erc-interactive-display' context.
* lisp/erc/erc-join.el (erc-autojoin-mode, erc-autojoin-enable,
erc-autojoin-disable): Kill local variable
`erc-join--requested-channels'. Add and remove
`erc-join--remove-requested-channels' to/from various server-handler
hooks for JOIN rejection numerics.
(erc-join--requested-channels): New local variable to remember
channels we've attempted to JOIN this session that haven't yet been
confirmed by the server.
(erc-join--remove-requested-channel): New JOIN rejection handler to
stop tracking channel in `erc-join--requested-channels'.
(erc--server-determine-join-display-context): module-specific
implementation of generic function for `erc-autojoin-mode'.
(erc-autojoin--join): Remember channels slated for JOIN'ing.
* lisp/erc/erc.el (erc--buffer-display-choices): New helper constant
for defining common `:type' for all buffer-display options.
(erc-buffer-display, erc-interactive-display,
erc-auto-reconnect-display, erc-receive-query-display): Use helper
`erc--buffer-display-choices' for defining `:type', which
includes a new choice for a `display-buffer'-like function.
(erc-reconnect-display, erc-auto-reconnect-display): Alias former to
latter, now the preferred name.
(erc-reconnect-timeout, erc-auto-reconnect-timeout): Change name from
former to latter. This option is new in ERC 5.6.
(erc-reconnect-display-server-buffers): New option.
(erc-buffer-do): Revise doc string.
(erc--display-context): New variable, an alist of "context tokens" to
be forwarded as the "action alist" to `erc-buffer-display' functions.
(erc-skip-displaying-selected-window-buffer): New variable, deprecated
at birth, to act as an escape hatch for folks who don't want to skip
the displaying of buffers already showing in the selected window.
(erc--display-buffer-overriding-action): Local variable allowing
modules to influence the displaying of new ERC buffers independently
of user options.
(erc-setup-buffer): Do nothing when the selected window already shows
current buffer unless user has provided a custom display function.
Accommodate new Custom choice function values, like `display-buffer'
and `pop-to-buffer'.
(erc-open): Run `erc-setup-buffer' when option
`erc-reconnect-display-server-buffers' is non-nil, even for existing
server buffers. Bind `display-buffer-overriding-action' to the value
of `erc--display-buffer-overriding-action' around calls to
`erc-setup-buffer'.
(erc-select-read-args): Add `erc--display-context' to environment.
(erc, erc-tls): Bind `erc--display-context' around calls to
`erc-select-read-args' and main body.
(erc-cmd-JOIN, erc-cmd-QUERY, erc--cmd-reconnect, erc-handle-irc-url):
Add item for `erc-interactive-display' to `erc--display-context'.
(erc-connection-established): Update name of
`erc-reconnect-display-timeout' to
`erc-auto-reconnect-display-timeout'.
(erc-message-english-s471, erc-message-english-s473): New variables,
format templates for JOIN rejection messages.
* test/lisp/erc/erc-scenarios-base-buffer-display.el
(erc-scenarios-base-buffer-display--defwin-recbury-intbuf,
erc-scenarios-base-buffer-display--defwino-recbury-intbuf,
erc-scenarios-base-buffer-display--count-reset-timeout): Use preferred
name `erc-auto-reconnect-display' for `erc-reconnect-display'.
* test/lisp/erc/erc-scenarios-join-display-context.el: New file.
* test/lisp/erc/erc-tests.el (erc--initialize-markers): Fix
unrealistic call to `erc-open'.
(erc-setup-buffer--custom-action): New test.
(erc-select-read-args, erc-tls, erc--interactive, erc-server-select):
Expect new environment binding for `erc--display-context'.
* test/lisp/erc/resources/join/buffer-display/mode-context.eld: New
file. (Bug#62833)
2023-05-30 23:27:12 -07:00
|
|
|
'((erc-join-buffer window)
|
|
|
|
(erc--display-context (erc-interactive-display . erc))
|
|
|
|
(erc-server-connect-function erc-open-tls-stream)))))
|
2022-12-29 06:43:19 -08:00
|
|
|
|
|
|
|
(ert-info ("Nick supplied, decline TLS upgrade")
|
|
|
|
(ert-simulate-keys "\r\rdummy\r\rn\r"
|
|
|
|
(call-interactively #'erc))
|
|
|
|
(should (equal (pop calls)
|
|
|
|
'("irc.libera.chat" 6667 "dummy" "unknown" t nil
|
|
|
|
nil nil nil nil "user" nil)))
|
|
|
|
(should (equal (pop env)
|
Extend erc-interactive-display to cover /JOINs
* lisp/erc/erc.el (erc-display): Mention that buffer-related display
options live in the customization group `erc-buffers'.
(erc-buffer-display, erc-join-buffer): Swap alias and aliased so that
the favored name, `erc-buffer-display', appears in the definition and
in the Customize menu. Also note related buffer-display options in
the doc string.
(erc-query-display, erc-interactive-display): Make the former an alias
of the latter, new in ERC 5.6, because their roles were functionally
redundant and thus confusing. Inherit the default value from
`erc-query-display' because users are more familiar with the pop-up
window behavior than a single-window replacement.
(erc-reconnect-display): Use preferred name for cross-referencing
fallback option `erc-buffer-display' in doc string, and explain how
/reconnect handling differs.
(erc--setup-buffer-hook): Add new internal hook for modules that
operate on windows and frames, such as erc-speedbar and
erc-status-sidebar.
(erc-open): Run `erc--setup-buffer-hook' after `erc-setup-buffer' so
hook members know their code isn't tied to `erc-setup-buffer' itself,
which may be used in other contexts, but rather to a new ERC buffer on
which some display-related action has just been performed.
(erc--called-as-input-p): New variable for "slash" commands, like
`erc-cmd-FOO', to detect whether they're being called "interactively"
as a result of input given at ERC's prompt.
(erc-process-input-line): Bind `erc--called-as-input-p' when running
slash commands.
(erc-cmd-JOIN): When called interactively, schedule a callback to wrap
the response handler and control how new buffers are thus displayed.
(erc-cmd-QUERY): Use preferred alias for `erc-query-display'.
* test/lisp/erc/erc-scenarios-base-buffer-display.el:
(erc-scenarios-base-buffer-display--interactive-default): New test.
* test/lisp/erc/erc-tests.el (erc-process-input-line,
erc-select-read-args, erc-tls, erc--interactive): Change expected
default value of `erc-interactive-display' from `buffer' to
`window'. (Bug#62833)
2023-04-10 17:58:05 -07:00
|
|
|
'((erc-join-buffer window)
|
Allow custom display-buffer actions in ERC
* doc/misc/erc.texi: Add new section under "Integrations" chapter
describing `display-buffer' Custom function choice for ERC's many
buffer-display options.
* etc/ERC-NEWS: Mention new function variant for all buffer-display
options.
* lisp/erc/erc-backend.el: Add forward declaration for
`erc--called-as-input-p' and `erc--display-context'.
(erc--server-reconnect-display-timer,
erc--server-last-reconnect-display-reset): Use new name for option
`erc-reconnect-display', now `erc-auto-reconnect-display'.
(erc--server-determine-join-display-context): New generic function to
determine value of `erc--display-context' during JOINs.
(erc-server-JOIN, erc-server-PRIVMSG): Set `erc--display-context' to a
symbol for the handler's IRC command, like `JOIN', for the benefit of
custom `display-buffer'-like functions running in `erc-setup-buffer'.
(erc-server-471, erc-server-471-functions, erc-server-473,
erc-server-473-functions): New handlers for JOIN rejections. Also
remove 471 and 473 from comment at bottom of file.
(erc-server-475): Bind `erc--called-as-input-p' so that `erc-cmd-JOIN'
sets `erc-interactive-display' context.
* lisp/erc/erc-join.el (erc-autojoin-mode, erc-autojoin-enable,
erc-autojoin-disable): Kill local variable
`erc-join--requested-channels'. Add and remove
`erc-join--remove-requested-channels' to/from various server-handler
hooks for JOIN rejection numerics.
(erc-join--requested-channels): New local variable to remember
channels we've attempted to JOIN this session that haven't yet been
confirmed by the server.
(erc-join--remove-requested-channel): New JOIN rejection handler to
stop tracking channel in `erc-join--requested-channels'.
(erc--server-determine-join-display-context): module-specific
implementation of generic function for `erc-autojoin-mode'.
(erc-autojoin--join): Remember channels slated for JOIN'ing.
* lisp/erc/erc.el (erc--buffer-display-choices): New helper constant
for defining common `:type' for all buffer-display options.
(erc-buffer-display, erc-interactive-display,
erc-auto-reconnect-display, erc-receive-query-display): Use helper
`erc--buffer-display-choices' for defining `:type', which
includes a new choice for a `display-buffer'-like function.
(erc-reconnect-display, erc-auto-reconnect-display): Alias former to
latter, now the preferred name.
(erc-reconnect-timeout, erc-auto-reconnect-timeout): Change name from
former to latter. This option is new in ERC 5.6.
(erc-reconnect-display-server-buffers): New option.
(erc-buffer-do): Revise doc string.
(erc--display-context): New variable, an alist of "context tokens" to
be forwarded as the "action alist" to `erc-buffer-display' functions.
(erc-skip-displaying-selected-window-buffer): New variable, deprecated
at birth, to act as an escape hatch for folks who don't want to skip
the displaying of buffers already showing in the selected window.
(erc--display-buffer-overriding-action): Local variable allowing
modules to influence the displaying of new ERC buffers independently
of user options.
(erc-setup-buffer): Do nothing when the selected window already shows
current buffer unless user has provided a custom display function.
Accommodate new Custom choice function values, like `display-buffer'
and `pop-to-buffer'.
(erc-open): Run `erc-setup-buffer' when option
`erc-reconnect-display-server-buffers' is non-nil, even for existing
server buffers. Bind `display-buffer-overriding-action' to the value
of `erc--display-buffer-overriding-action' around calls to
`erc-setup-buffer'.
(erc-select-read-args): Add `erc--display-context' to environment.
(erc, erc-tls): Bind `erc--display-context' around calls to
`erc-select-read-args' and main body.
(erc-cmd-JOIN, erc-cmd-QUERY, erc--cmd-reconnect, erc-handle-irc-url):
Add item for `erc-interactive-display' to `erc--display-context'.
(erc-connection-established): Update name of
`erc-reconnect-display-timeout' to
`erc-auto-reconnect-display-timeout'.
(erc-message-english-s471, erc-message-english-s473): New variables,
format templates for JOIN rejection messages.
* test/lisp/erc/erc-scenarios-base-buffer-display.el
(erc-scenarios-base-buffer-display--defwin-recbury-intbuf,
erc-scenarios-base-buffer-display--defwino-recbury-intbuf,
erc-scenarios-base-buffer-display--count-reset-timeout): Use preferred
name `erc-auto-reconnect-display' for `erc-reconnect-display'.
* test/lisp/erc/erc-scenarios-join-display-context.el: New file.
* test/lisp/erc/erc-tests.el (erc--initialize-markers): Fix
unrealistic call to `erc-open'.
(erc-setup-buffer--custom-action): New test.
(erc-select-read-args, erc-tls, erc--interactive, erc-server-select):
Expect new environment binding for `erc--display-context'.
* test/lisp/erc/resources/join/buffer-display/mode-context.eld: New
file. (Bug#62833)
2023-05-30 23:27:12 -07:00
|
|
|
(erc--display-context (erc-interactive-display . erc))
|
2022-12-29 06:43:19 -08:00
|
|
|
(erc-server-connect-function
|
|
|
|
erc-open-network-stream))))))))
|
2022-07-11 05:14:57 -07:00
|
|
|
|
2023-06-29 07:12:46 -07:00
|
|
|
(ert-deftest erc-server-select ()
|
|
|
|
(let (calls env)
|
|
|
|
(cl-letf (((symbol-function 'user-login-name)
|
|
|
|
(lambda (&optional _) "tester"))
|
|
|
|
((symbol-function 'erc-open)
|
|
|
|
(lambda (&rest r)
|
|
|
|
(push `((erc-join-buffer ,erc-join-buffer)
|
Allow custom display-buffer actions in ERC
* doc/misc/erc.texi: Add new section under "Integrations" chapter
describing `display-buffer' Custom function choice for ERC's many
buffer-display options.
* etc/ERC-NEWS: Mention new function variant for all buffer-display
options.
* lisp/erc/erc-backend.el: Add forward declaration for
`erc--called-as-input-p' and `erc--display-context'.
(erc--server-reconnect-display-timer,
erc--server-last-reconnect-display-reset): Use new name for option
`erc-reconnect-display', now `erc-auto-reconnect-display'.
(erc--server-determine-join-display-context): New generic function to
determine value of `erc--display-context' during JOINs.
(erc-server-JOIN, erc-server-PRIVMSG): Set `erc--display-context' to a
symbol for the handler's IRC command, like `JOIN', for the benefit of
custom `display-buffer'-like functions running in `erc-setup-buffer'.
(erc-server-471, erc-server-471-functions, erc-server-473,
erc-server-473-functions): New handlers for JOIN rejections. Also
remove 471 and 473 from comment at bottom of file.
(erc-server-475): Bind `erc--called-as-input-p' so that `erc-cmd-JOIN'
sets `erc-interactive-display' context.
* lisp/erc/erc-join.el (erc-autojoin-mode, erc-autojoin-enable,
erc-autojoin-disable): Kill local variable
`erc-join--requested-channels'. Add and remove
`erc-join--remove-requested-channels' to/from various server-handler
hooks for JOIN rejection numerics.
(erc-join--requested-channels): New local variable to remember
channels we've attempted to JOIN this session that haven't yet been
confirmed by the server.
(erc-join--remove-requested-channel): New JOIN rejection handler to
stop tracking channel in `erc-join--requested-channels'.
(erc--server-determine-join-display-context): module-specific
implementation of generic function for `erc-autojoin-mode'.
(erc-autojoin--join): Remember channels slated for JOIN'ing.
* lisp/erc/erc.el (erc--buffer-display-choices): New helper constant
for defining common `:type' for all buffer-display options.
(erc-buffer-display, erc-interactive-display,
erc-auto-reconnect-display, erc-receive-query-display): Use helper
`erc--buffer-display-choices' for defining `:type', which
includes a new choice for a `display-buffer'-like function.
(erc-reconnect-display, erc-auto-reconnect-display): Alias former to
latter, now the preferred name.
(erc-reconnect-timeout, erc-auto-reconnect-timeout): Change name from
former to latter. This option is new in ERC 5.6.
(erc-reconnect-display-server-buffers): New option.
(erc-buffer-do): Revise doc string.
(erc--display-context): New variable, an alist of "context tokens" to
be forwarded as the "action alist" to `erc-buffer-display' functions.
(erc-skip-displaying-selected-window-buffer): New variable, deprecated
at birth, to act as an escape hatch for folks who don't want to skip
the displaying of buffers already showing in the selected window.
(erc--display-buffer-overriding-action): Local variable allowing
modules to influence the displaying of new ERC buffers independently
of user options.
(erc-setup-buffer): Do nothing when the selected window already shows
current buffer unless user has provided a custom display function.
Accommodate new Custom choice function values, like `display-buffer'
and `pop-to-buffer'.
(erc-open): Run `erc-setup-buffer' when option
`erc-reconnect-display-server-buffers' is non-nil, even for existing
server buffers. Bind `display-buffer-overriding-action' to the value
of `erc--display-buffer-overriding-action' around calls to
`erc-setup-buffer'.
(erc-select-read-args): Add `erc--display-context' to environment.
(erc, erc-tls): Bind `erc--display-context' around calls to
`erc-select-read-args' and main body.
(erc-cmd-JOIN, erc-cmd-QUERY, erc--cmd-reconnect, erc-handle-irc-url):
Add item for `erc-interactive-display' to `erc--display-context'.
(erc-connection-established): Update name of
`erc-reconnect-display-timeout' to
`erc-auto-reconnect-display-timeout'.
(erc-message-english-s471, erc-message-english-s473): New variables,
format templates for JOIN rejection messages.
* test/lisp/erc/erc-scenarios-base-buffer-display.el
(erc-scenarios-base-buffer-display--defwin-recbury-intbuf,
erc-scenarios-base-buffer-display--defwino-recbury-intbuf,
erc-scenarios-base-buffer-display--count-reset-timeout): Use preferred
name `erc-auto-reconnect-display' for `erc-reconnect-display'.
* test/lisp/erc/erc-scenarios-join-display-context.el: New file.
* test/lisp/erc/erc-tests.el (erc--initialize-markers): Fix
unrealistic call to `erc-open'.
(erc-setup-buffer--custom-action): New test.
(erc-select-read-args, erc-tls, erc--interactive, erc-server-select):
Expect new environment binding for `erc--display-context'.
* test/lisp/erc/resources/join/buffer-display/mode-context.eld: New
file. (Bug#62833)
2023-05-30 23:27:12 -07:00
|
|
|
(erc--display-context ,@erc--display-context)
|
2023-06-29 07:12:46 -07:00
|
|
|
(erc-server-connect-function
|
|
|
|
,erc-server-connect-function))
|
|
|
|
env)
|
|
|
|
(push r calls))))
|
|
|
|
|
|
|
|
(ert-info ("Selects Libera.Chat Europe, automatic TSL")
|
|
|
|
(ert-simulate-keys "Libera.Chat\rirc.eu.\t\r\r\r"
|
|
|
|
(with-suppressed-warnings ((obsolete erc-server-select))
|
|
|
|
(call-interactively #'erc-server-select)))
|
|
|
|
(should (equal (pop calls)
|
|
|
|
'("irc.eu.libera.chat" 6697 "tester" "unknown" t nil
|
|
|
|
nil nil nil nil "user" nil)))
|
|
|
|
(should (equal (pop env)
|
|
|
|
'((erc-join-buffer window)
|
Allow custom display-buffer actions in ERC
* doc/misc/erc.texi: Add new section under "Integrations" chapter
describing `display-buffer' Custom function choice for ERC's many
buffer-display options.
* etc/ERC-NEWS: Mention new function variant for all buffer-display
options.
* lisp/erc/erc-backend.el: Add forward declaration for
`erc--called-as-input-p' and `erc--display-context'.
(erc--server-reconnect-display-timer,
erc--server-last-reconnect-display-reset): Use new name for option
`erc-reconnect-display', now `erc-auto-reconnect-display'.
(erc--server-determine-join-display-context): New generic function to
determine value of `erc--display-context' during JOINs.
(erc-server-JOIN, erc-server-PRIVMSG): Set `erc--display-context' to a
symbol for the handler's IRC command, like `JOIN', for the benefit of
custom `display-buffer'-like functions running in `erc-setup-buffer'.
(erc-server-471, erc-server-471-functions, erc-server-473,
erc-server-473-functions): New handlers for JOIN rejections. Also
remove 471 and 473 from comment at bottom of file.
(erc-server-475): Bind `erc--called-as-input-p' so that `erc-cmd-JOIN'
sets `erc-interactive-display' context.
* lisp/erc/erc-join.el (erc-autojoin-mode, erc-autojoin-enable,
erc-autojoin-disable): Kill local variable
`erc-join--requested-channels'. Add and remove
`erc-join--remove-requested-channels' to/from various server-handler
hooks for JOIN rejection numerics.
(erc-join--requested-channels): New local variable to remember
channels we've attempted to JOIN this session that haven't yet been
confirmed by the server.
(erc-join--remove-requested-channel): New JOIN rejection handler to
stop tracking channel in `erc-join--requested-channels'.
(erc--server-determine-join-display-context): module-specific
implementation of generic function for `erc-autojoin-mode'.
(erc-autojoin--join): Remember channels slated for JOIN'ing.
* lisp/erc/erc.el (erc--buffer-display-choices): New helper constant
for defining common `:type' for all buffer-display options.
(erc-buffer-display, erc-interactive-display,
erc-auto-reconnect-display, erc-receive-query-display): Use helper
`erc--buffer-display-choices' for defining `:type', which
includes a new choice for a `display-buffer'-like function.
(erc-reconnect-display, erc-auto-reconnect-display): Alias former to
latter, now the preferred name.
(erc-reconnect-timeout, erc-auto-reconnect-timeout): Change name from
former to latter. This option is new in ERC 5.6.
(erc-reconnect-display-server-buffers): New option.
(erc-buffer-do): Revise doc string.
(erc--display-context): New variable, an alist of "context tokens" to
be forwarded as the "action alist" to `erc-buffer-display' functions.
(erc-skip-displaying-selected-window-buffer): New variable, deprecated
at birth, to act as an escape hatch for folks who don't want to skip
the displaying of buffers already showing in the selected window.
(erc--display-buffer-overriding-action): Local variable allowing
modules to influence the displaying of new ERC buffers independently
of user options.
(erc-setup-buffer): Do nothing when the selected window already shows
current buffer unless user has provided a custom display function.
Accommodate new Custom choice function values, like `display-buffer'
and `pop-to-buffer'.
(erc-open): Run `erc-setup-buffer' when option
`erc-reconnect-display-server-buffers' is non-nil, even for existing
server buffers. Bind `display-buffer-overriding-action' to the value
of `erc--display-buffer-overriding-action' around calls to
`erc-setup-buffer'.
(erc-select-read-args): Add `erc--display-context' to environment.
(erc, erc-tls): Bind `erc--display-context' around calls to
`erc-select-read-args' and main body.
(erc-cmd-JOIN, erc-cmd-QUERY, erc--cmd-reconnect, erc-handle-irc-url):
Add item for `erc-interactive-display' to `erc--display-context'.
(erc-connection-established): Update name of
`erc-reconnect-display-timeout' to
`erc-auto-reconnect-display-timeout'.
(erc-message-english-s471, erc-message-english-s473): New variables,
format templates for JOIN rejection messages.
* test/lisp/erc/erc-scenarios-base-buffer-display.el
(erc-scenarios-base-buffer-display--defwin-recbury-intbuf,
erc-scenarios-base-buffer-display--defwino-recbury-intbuf,
erc-scenarios-base-buffer-display--count-reset-timeout): Use preferred
name `erc-auto-reconnect-display' for `erc-reconnect-display'.
* test/lisp/erc/erc-scenarios-join-display-context.el: New file.
* test/lisp/erc/erc-tests.el (erc--initialize-markers): Fix
unrealistic call to `erc-open'.
(erc-setup-buffer--custom-action): New test.
(erc-select-read-args, erc-tls, erc--interactive, erc-server-select):
Expect new environment binding for `erc--display-context'.
* test/lisp/erc/resources/join/buffer-display/mode-context.eld: New
file. (Bug#62833)
2023-05-30 23:27:12 -07:00
|
|
|
(erc--display-context (erc-interactive-display . erc))
|
2023-06-29 07:12:46 -07:00
|
|
|
(erc-server-connect-function erc-open-tls-stream)))))
|
|
|
|
|
|
|
|
(ert-info ("Selects entry that doesn't support TLS")
|
|
|
|
(ert-simulate-keys "IRCnet\rirc.fr.\t\rdummy\r\r"
|
|
|
|
(with-suppressed-warnings ((obsolete erc-server-select))
|
|
|
|
(call-interactively #'erc-server-select)))
|
|
|
|
(should (equal (pop calls)
|
|
|
|
'("irc.fr.ircnet.net" 6667 "dummy" "unknown" t nil
|
|
|
|
nil nil nil nil "user" nil)))
|
|
|
|
(should (equal (pop env)
|
|
|
|
'((erc-join-buffer window)
|
Allow custom display-buffer actions in ERC
* doc/misc/erc.texi: Add new section under "Integrations" chapter
describing `display-buffer' Custom function choice for ERC's many
buffer-display options.
* etc/ERC-NEWS: Mention new function variant for all buffer-display
options.
* lisp/erc/erc-backend.el: Add forward declaration for
`erc--called-as-input-p' and `erc--display-context'.
(erc--server-reconnect-display-timer,
erc--server-last-reconnect-display-reset): Use new name for option
`erc-reconnect-display', now `erc-auto-reconnect-display'.
(erc--server-determine-join-display-context): New generic function to
determine value of `erc--display-context' during JOINs.
(erc-server-JOIN, erc-server-PRIVMSG): Set `erc--display-context' to a
symbol for the handler's IRC command, like `JOIN', for the benefit of
custom `display-buffer'-like functions running in `erc-setup-buffer'.
(erc-server-471, erc-server-471-functions, erc-server-473,
erc-server-473-functions): New handlers for JOIN rejections. Also
remove 471 and 473 from comment at bottom of file.
(erc-server-475): Bind `erc--called-as-input-p' so that `erc-cmd-JOIN'
sets `erc-interactive-display' context.
* lisp/erc/erc-join.el (erc-autojoin-mode, erc-autojoin-enable,
erc-autojoin-disable): Kill local variable
`erc-join--requested-channels'. Add and remove
`erc-join--remove-requested-channels' to/from various server-handler
hooks for JOIN rejection numerics.
(erc-join--requested-channels): New local variable to remember
channels we've attempted to JOIN this session that haven't yet been
confirmed by the server.
(erc-join--remove-requested-channel): New JOIN rejection handler to
stop tracking channel in `erc-join--requested-channels'.
(erc--server-determine-join-display-context): module-specific
implementation of generic function for `erc-autojoin-mode'.
(erc-autojoin--join): Remember channels slated for JOIN'ing.
* lisp/erc/erc.el (erc--buffer-display-choices): New helper constant
for defining common `:type' for all buffer-display options.
(erc-buffer-display, erc-interactive-display,
erc-auto-reconnect-display, erc-receive-query-display): Use helper
`erc--buffer-display-choices' for defining `:type', which
includes a new choice for a `display-buffer'-like function.
(erc-reconnect-display, erc-auto-reconnect-display): Alias former to
latter, now the preferred name.
(erc-reconnect-timeout, erc-auto-reconnect-timeout): Change name from
former to latter. This option is new in ERC 5.6.
(erc-reconnect-display-server-buffers): New option.
(erc-buffer-do): Revise doc string.
(erc--display-context): New variable, an alist of "context tokens" to
be forwarded as the "action alist" to `erc-buffer-display' functions.
(erc-skip-displaying-selected-window-buffer): New variable, deprecated
at birth, to act as an escape hatch for folks who don't want to skip
the displaying of buffers already showing in the selected window.
(erc--display-buffer-overriding-action): Local variable allowing
modules to influence the displaying of new ERC buffers independently
of user options.
(erc-setup-buffer): Do nothing when the selected window already shows
current buffer unless user has provided a custom display function.
Accommodate new Custom choice function values, like `display-buffer'
and `pop-to-buffer'.
(erc-open): Run `erc-setup-buffer' when option
`erc-reconnect-display-server-buffers' is non-nil, even for existing
server buffers. Bind `display-buffer-overriding-action' to the value
of `erc--display-buffer-overriding-action' around calls to
`erc-setup-buffer'.
(erc-select-read-args): Add `erc--display-context' to environment.
(erc, erc-tls): Bind `erc--display-context' around calls to
`erc-select-read-args' and main body.
(erc-cmd-JOIN, erc-cmd-QUERY, erc--cmd-reconnect, erc-handle-irc-url):
Add item for `erc-interactive-display' to `erc--display-context'.
(erc-connection-established): Update name of
`erc-reconnect-display-timeout' to
`erc-auto-reconnect-display-timeout'.
(erc-message-english-s471, erc-message-english-s473): New variables,
format templates for JOIN rejection messages.
* test/lisp/erc/erc-scenarios-base-buffer-display.el
(erc-scenarios-base-buffer-display--defwin-recbury-intbuf,
erc-scenarios-base-buffer-display--defwino-recbury-intbuf,
erc-scenarios-base-buffer-display--count-reset-timeout): Use preferred
name `erc-auto-reconnect-display' for `erc-reconnect-display'.
* test/lisp/erc/erc-scenarios-join-display-context.el: New file.
* test/lisp/erc/erc-tests.el (erc--initialize-markers): Fix
unrealistic call to `erc-open'.
(erc-setup-buffer--custom-action): New test.
(erc-select-read-args, erc-tls, erc--interactive, erc-server-select):
Expect new environment binding for `erc--display-context'.
* test/lisp/erc/resources/join/buffer-display/mode-context.eld: New
file. (Bug#62833)
2023-05-30 23:27:12 -07:00
|
|
|
(erc--display-context (erc-interactive-display . erc))
|
2023-06-29 07:12:46 -07:00
|
|
|
(erc-server-connect-function
|
|
|
|
erc-open-network-stream))))))))
|
|
|
|
|
2022-07-11 05:14:57 -07:00
|
|
|
(defun erc-tests--make-server-buf (name)
|
|
|
|
(with-current-buffer (get-buffer-create name)
|
|
|
|
(erc-mode)
|
|
|
|
(setq erc-server-process (start-process "sleep" (current-buffer)
|
|
|
|
"sleep" "1")
|
|
|
|
erc-session-server (concat "irc." name ".org")
|
|
|
|
erc-session-port 6667
|
|
|
|
erc-network (intern name))
|
|
|
|
(set-process-query-on-exit-flag erc-server-process nil)
|
|
|
|
(current-buffer)))
|
|
|
|
|
|
|
|
(defun erc-tests--make-client-buf (server name)
|
|
|
|
(unless (bufferp server)
|
|
|
|
(setq server (get-buffer server)))
|
|
|
|
(with-current-buffer (get-buffer-create name)
|
|
|
|
(erc-mode)
|
|
|
|
(setq erc--target (erc--target-from-string name))
|
|
|
|
(dolist (v '(erc-server-process
|
|
|
|
erc-session-server
|
|
|
|
erc-session-port
|
|
|
|
erc-network))
|
|
|
|
(set v (buffer-local-value v server)))
|
|
|
|
(current-buffer)))
|
|
|
|
|
|
|
|
(ert-deftest erc-handle-irc-url ()
|
|
|
|
(let* (calls
|
|
|
|
rvbuf
|
|
|
|
erc-networks-alist
|
|
|
|
erc-kill-channel-hook erc-kill-server-hook erc-kill-buffer-hook
|
|
|
|
(erc-url-connect-function
|
|
|
|
(lambda (&rest r)
|
|
|
|
(push r calls)
|
|
|
|
(if (functionp rvbuf) (funcall rvbuf) rvbuf))))
|
|
|
|
|
|
|
|
(cl-letf (((symbol-function 'erc-cmd-JOIN)
|
|
|
|
(lambda (&rest r) (push r calls))))
|
|
|
|
|
|
|
|
(with-current-buffer (erc-tests--make-server-buf "foonet")
|
|
|
|
(setq rvbuf (current-buffer)))
|
|
|
|
(erc-tests--make-server-buf "barnet")
|
|
|
|
(erc-tests--make-server-buf "baznet")
|
|
|
|
|
|
|
|
(ert-info ("Unknown network")
|
|
|
|
(erc-handle-irc-url "irc.foonet.org" 6667 "#chan" nil nil "irc")
|
|
|
|
(should (equal '("#chan" nil) (pop calls)))
|
|
|
|
(should-not calls))
|
|
|
|
|
|
|
|
(ert-info ("Unknown network, no port")
|
|
|
|
(erc-handle-irc-url "irc.foonet.org" nil "#chan" nil nil "irc")
|
|
|
|
(should (equal '("#chan" nil) (pop calls)))
|
|
|
|
(should-not calls))
|
|
|
|
|
|
|
|
(ert-info ("Known network, no port")
|
|
|
|
(setq erc-networks-alist '((foonet "irc.foonet.org")))
|
|
|
|
(erc-handle-irc-url "irc.foonet.org" nil "#chan" nil nil "irc")
|
|
|
|
(should (equal '("#chan" nil) (pop calls)))
|
|
|
|
(should-not calls))
|
|
|
|
|
|
|
|
(ert-info ("Known network, different port")
|
|
|
|
(erc-handle-irc-url "irc.foonet.org" 6697 "#chan" nil nil "irc")
|
|
|
|
(should (equal '("#chan" nil) (pop calls)))
|
|
|
|
(should-not calls))
|
|
|
|
|
|
|
|
(ert-info ("Known network, existing chan with key")
|
|
|
|
(erc-tests--make-client-buf "foonet" "#chan")
|
|
|
|
(erc-handle-irc-url "irc.foonet.org" nil "#chan?sec" nil nil "irc")
|
|
|
|
(should (equal '("#chan" "sec") (pop calls)))
|
|
|
|
(should-not calls))
|
|
|
|
|
|
|
|
(ert-info ("Unknown network, connect, no chan")
|
|
|
|
(erc-handle-irc-url "irc.gnu.org" nil nil nil nil "irc")
|
|
|
|
(should (equal '("irc" :server "irc.gnu.org") (pop calls)))
|
|
|
|
(should-not calls))
|
|
|
|
|
|
|
|
(ert-info ("Unknown network, connect, chan")
|
|
|
|
(with-current-buffer "foonet"
|
|
|
|
(should-not (local-variable-p 'erc-after-connect)))
|
|
|
|
(setq rvbuf (lambda () (erc-tests--make-server-buf "gnu")))
|
|
|
|
(erc-handle-irc-url "irc.gnu.org" nil "#spam" nil nil "irc")
|
|
|
|
(should (equal '("irc" :server "irc.gnu.org") (pop calls)))
|
|
|
|
(should-not calls)
|
|
|
|
(with-current-buffer "gnu"
|
|
|
|
(should (local-variable-p 'erc-after-connect))
|
|
|
|
(funcall (car erc-after-connect))
|
|
|
|
(should (equal '("#spam" nil) (pop calls)))
|
|
|
|
(should-not (local-variable-p 'erc-after-connect)))
|
|
|
|
(should-not calls))))
|
|
|
|
|
|
|
|
(when noninteractive
|
|
|
|
(kill-buffer "foonet")
|
|
|
|
(kill-buffer "barnet")
|
|
|
|
(kill-buffer "baznet")
|
|
|
|
(kill-buffer "#chan")))
|
|
|
|
|
2023-02-04 06:24:59 -08:00
|
|
|
(defconst erc-tests--modules
|
2023-05-04 00:01:11 -07:00
|
|
|
'( autoaway autojoin bufbar button capab-identify completion dcc fill identd
|
2023-01-19 21:07:27 -08:00
|
|
|
imenu irccontrols keep-place list log match menu move-to-prompt netsplit
|
2023-05-04 00:01:11 -07:00
|
|
|
networks nickbar nicks noncommands notifications notify page readonly
|
2023-02-04 06:24:59 -08:00
|
|
|
replace ring sasl scrolltobottom services smiley sound
|
|
|
|
spelling stamp track truncate unmorse xdcc))
|
|
|
|
|
|
|
|
;; Ensure that `:initialize' doesn't change the ordering of the
|
|
|
|
;; members because otherwise the widget's state is "edited".
|
|
|
|
|
|
|
|
(ert-deftest erc-modules--initialize ()
|
|
|
|
;; This is `custom--standard-value' from Emacs 28.
|
|
|
|
(should (equal (eval (car (get 'erc-modules 'standard-value)) t)
|
|
|
|
erc-modules)))
|
|
|
|
|
|
|
|
;; Ensure the `:initialize' function for `erc-modules' successfully
|
|
|
|
;; tags all built-in modules with the internal property `erc--module'.
|
|
|
|
|
|
|
|
(ert-deftest erc-modules--internal-property ()
|
|
|
|
(let (ours)
|
|
|
|
(mapatoms (lambda (s)
|
|
|
|
(when-let ((v (get s 'erc--module))
|
|
|
|
((eq v s)))
|
|
|
|
(push s ours))))
|
|
|
|
(should (equal (sort ours #'string-lessp) erc-tests--modules))))
|
|
|
|
|
|
|
|
(ert-deftest erc--normalize-module-symbol ()
|
|
|
|
(dolist (mod erc-tests--modules)
|
|
|
|
(should (eq (erc--normalize-module-symbol mod) mod)))
|
|
|
|
(should (eq (erc--normalize-module-symbol 'pcomplete) 'completion))
|
|
|
|
(should (eq (erc--normalize-module-symbol 'Completion) 'completion))
|
|
|
|
(should (eq (erc--normalize-module-symbol 'ctcp-page) 'page))
|
|
|
|
(should (eq (erc--normalize-module-symbol 'ctcp-sound) 'sound))
|
|
|
|
(should (eq (erc--normalize-module-symbol 'timestamp) 'stamp))
|
|
|
|
(should (eq (erc--normalize-module-symbol 'nickserv) 'services)))
|
|
|
|
|
2023-06-05 03:49:44 -07:00
|
|
|
(defun erc-tests--assert-printed-in-subprocess (code expected)
|
2023-02-04 06:24:59 -08:00
|
|
|
(let* ((package (if-let* ((found (getenv "ERC_PACKAGE_NAME"))
|
|
|
|
((string-prefix-p "erc-" found)))
|
|
|
|
(intern found)
|
|
|
|
'erc))
|
2023-06-05 03:49:44 -07:00
|
|
|
;; This is for integrations testing with managed configs
|
|
|
|
;; ("starter kits") that use a different package manager.
|
|
|
|
(init (and-let* ((found (getenv "ERC_TESTS_INIT"))
|
2023-08-25 19:03:26 -07:00
|
|
|
(files (split-string found ",")))
|
2023-06-05 03:49:44 -07:00
|
|
|
(mapcan (lambda (f) (list "-l" f)) files)))
|
2023-02-04 06:24:59 -08:00
|
|
|
(prog
|
2023-06-05 03:49:44 -07:00
|
|
|
`(progn
|
|
|
|
,@(and (not init) (featurep 'compat)
|
|
|
|
`((require 'package)
|
|
|
|
(let ((package-load-list '((compat t) (,package t))))
|
|
|
|
(package-initialize))))
|
|
|
|
(require 'erc)
|
|
|
|
(cl-assert (equal erc-version ,erc-version) t)
|
|
|
|
,code))
|
|
|
|
(proc (apply #'start-process
|
|
|
|
(symbol-name (ert-test-name (ert-running-test)))
|
|
|
|
(current-buffer)
|
|
|
|
(concat invocation-directory invocation-name)
|
|
|
|
`("-batch" ,@(or init '("-Q"))
|
|
|
|
"-eval" ,(format "%S" prog)))))
|
2023-02-04 06:24:59 -08:00
|
|
|
(set-process-query-on-exit-flag proc t)
|
|
|
|
(while (accept-process-output proc 10))
|
|
|
|
(goto-char (point-min))
|
2023-06-05 03:49:44 -07:00
|
|
|
(unless (equal (read (current-buffer)) expected)
|
|
|
|
(message "Exepcted: %S\nGot: %s" expected (buffer-string))
|
|
|
|
(ert-fail "Mismatch"))))
|
|
|
|
|
|
|
|
;; Worrying about which library a module comes from is mostly not
|
|
|
|
;; worth the hassle so long as ERC can find its minor mode. However,
|
|
|
|
;; bugs involving multiple modules living in the same library may slip
|
|
|
|
;; by because a module's loading problems may remain hidden on account
|
|
|
|
;; of its place in the default ordering.
|
|
|
|
|
|
|
|
(ert-deftest erc--find-mode ()
|
|
|
|
(erc-tests--assert-printed-in-subprocess
|
|
|
|
`(let ((mods (mapcar #'cadddr (cdddr (get 'erc-modules 'custom-type))))
|
|
|
|
moded)
|
|
|
|
(setq mods (sort mods (lambda (a b) (if (zerop (random 2)) a b))))
|
|
|
|
(dolist (mod mods)
|
|
|
|
(unless (keywordp mod)
|
|
|
|
(push (if-let ((mode (erc--find-mode mod))) mod (list :missing mod))
|
|
|
|
moded)))
|
|
|
|
(message "%S"
|
|
|
|
(sort moded (lambda (a b)
|
|
|
|
(string< (symbol-name a) (symbol-name b))))))
|
|
|
|
erc-tests--modules))
|
|
|
|
|
|
|
|
(ert-deftest erc--essential-hook-ordering ()
|
|
|
|
(erc-tests--assert-printed-in-subprocess
|
|
|
|
'(progn
|
|
|
|
(erc-update-modules)
|
|
|
|
(message "%S"
|
|
|
|
(list :erc-insert-modify-hook erc-insert-modify-hook
|
|
|
|
:erc-send-modify-hook erc-send-modify-hook)))
|
|
|
|
|
|
|
|
'( :erc-insert-modify-hook (erc-controls-highlight ; 0
|
|
|
|
erc-button-add-buttons ; 30
|
|
|
|
erc-fill ; 40
|
2023-07-02 20:57:46 -07:00
|
|
|
erc-match-message ; 50
|
|
|
|
erc-add-timestamp) ; 60
|
2023-06-05 03:49:44 -07:00
|
|
|
|
|
|
|
:erc-send-modify-hook ( erc-controls-highlight ; 0
|
|
|
|
erc-button-add-buttons ; 30
|
|
|
|
erc-fill ; 40
|
|
|
|
erc-add-timestamp)))) ; 50
|
2023-02-04 06:24:59 -08:00
|
|
|
|
2021-07-12 03:44:28 -07:00
|
|
|
(ert-deftest erc-migrate-modules ()
|
|
|
|
(should (equal (erc-migrate-modules '(autojoin timestamp button))
|
|
|
|
'(autojoin stamp button)))
|
|
|
|
;; Default unchanged
|
|
|
|
(should (equal (erc-migrate-modules erc-modules) erc-modules)))
|
|
|
|
|
2023-01-14 19:05:59 -08:00
|
|
|
(ert-deftest erc--find-group ()
|
|
|
|
;; These two are loaded by default
|
|
|
|
(should (eq (erc--find-group 'keep-place nil) 'erc))
|
|
|
|
(should (eq (erc--find-group 'networks nil) 'erc-networks))
|
|
|
|
;; These are fake
|
|
|
|
(cl-letf (((get 'erc-bar 'group-documentation) "")
|
|
|
|
((get 'baz 'erc-group) 'erc-foo))
|
|
|
|
(should (eq (erc--find-group 'foo 'bar) 'erc-bar))
|
|
|
|
(should (eq (erc--find-group 'bar 'foo) 'erc-bar))
|
|
|
|
(should (eq (erc--find-group 'bar nil) 'erc-bar))
|
|
|
|
(should (eq (erc--find-group 'foo nil) 'erc))
|
|
|
|
(should (eq (erc--find-group 'fake 'baz) 'erc-foo))))
|
|
|
|
|
|
|
|
(ert-deftest erc--find-group--real ()
|
|
|
|
:tags '(:unstable)
|
|
|
|
(require 'erc-services)
|
|
|
|
(require 'erc-stamp)
|
|
|
|
(require 'erc-sound)
|
|
|
|
(require 'erc-page)
|
|
|
|
(require 'erc-join)
|
|
|
|
(require 'erc-capab)
|
|
|
|
(require 'erc-pcomplete)
|
|
|
|
(should (eq (erc--find-group 'services 'nickserv) 'erc-services))
|
|
|
|
(should (eq (erc--find-group 'stamp 'timestamp) 'erc-stamp))
|
|
|
|
(should (eq (erc--find-group 'sound 'ctcp-sound) 'erc-sound))
|
|
|
|
(should (eq (erc--find-group 'page 'ctcp-page) 'erc-page))
|
|
|
|
(should (eq (erc--find-group 'autojoin) 'erc-autojoin))
|
|
|
|
(should (eq (erc--find-group 'pcomplete 'Completion) 'erc-pcomplete))
|
|
|
|
(should (eq (erc--find-group 'capab-identify) 'erc-capab))
|
|
|
|
;; No group specified.
|
|
|
|
(should (eq (erc--find-group 'smiley nil) 'erc))
|
|
|
|
(should (eq (erc--find-group 'unmorse nil) 'erc)))
|
|
|
|
|
Sort and dedupe when loading modules in erc-open
* doc/misc/erc.texi: Add new subheading "Module Loading" under the
"Modules" chapter.
* lisp/erc/erc.el (erc--sort-modules): New utility function to sort
and dedupe modules.
(erc-modules): In `custom-set' function, factor out collation into
separate utility `erc--sort-modules'.
(erc-update-modules): Call `erc--update-modules' with an argument, the
current value of `erc-modules'.
(erc--aberrant-modules): New variable, a list of symbols whose modules
ERC suspects of being incorrectly defined.
(erc--warn-about-aberrant-modules): New function to print an error
message and emit a warning prior to connecting when
`erc--aberrant-modules' is non-nil.
(erc--find-mode): Make heuristic more robust by always checking for a
mode activation command rather than just a state variable. This fixes
a compatibility bug, new in 5.6, affecting third-party modules that
autoload module definitions instead of their corresponding
mode-activation commands.
(erc--update-modules): Add new positional argument `modules'.
(erc--setup-buffer-hook): Add new default member,
`erc--warn-about-aberrant-modules'.
(erc-open): Pass sorted `erc-modules' to `erc--update-modules'.
* test/lisp/erc/erc-tests.el (erc--sort-modules): New test.
(erc-tests--update-modules): New fixture.
(erc--update-modules): Remove and rework as three separate tests
dedicated to specific contexts. The existing one had poor coverage
and was difficult, if not impossible, to follow.
(erc--update-modules/unknown, erc--update-modules/local,
erc--update-modules/realistic): New tests. (Bug#57955)
2023-10-06 17:34:04 -07:00
|
|
|
(ert-deftest erc--sort-modules ()
|
|
|
|
(should (equal (erc--sort-modules '(networks foo fill bar fill stamp bar))
|
|
|
|
;; Third-party mods appear in original order.
|
|
|
|
'(fill networks stamp foo bar))))
|
|
|
|
|
|
|
|
(defun erc-tests--update-modules (fn)
|
|
|
|
(let* ((calls nil)
|
|
|
|
(custom-modes nil)
|
|
|
|
(on-load nil)
|
|
|
|
|
|
|
|
(get-calls (lambda () (prog1 (nreverse calls) (setq calls nil))))
|
|
|
|
|
|
|
|
(add-onload (lambda (m k v)
|
|
|
|
(put (intern m) 'erc--feature k)
|
|
|
|
(push (cons k (lambda () (funcall v m))) on-load)))
|
2023-02-04 06:24:59 -08:00
|
|
|
|
Sort and dedupe when loading modules in erc-open
* doc/misc/erc.texi: Add new subheading "Module Loading" under the
"Modules" chapter.
* lisp/erc/erc.el (erc--sort-modules): New utility function to sort
and dedupe modules.
(erc-modules): In `custom-set' function, factor out collation into
separate utility `erc--sort-modules'.
(erc-update-modules): Call `erc--update-modules' with an argument, the
current value of `erc-modules'.
(erc--aberrant-modules): New variable, a list of symbols whose modules
ERC suspects of being incorrectly defined.
(erc--warn-about-aberrant-modules): New function to print an error
message and emit a warning prior to connecting when
`erc--aberrant-modules' is non-nil.
(erc--find-mode): Make heuristic more robust by always checking for a
mode activation command rather than just a state variable. This fixes
a compatibility bug, new in 5.6, affecting third-party modules that
autoload module definitions instead of their corresponding
mode-activation commands.
(erc--update-modules): Add new positional argument `modules'.
(erc--setup-buffer-hook): Add new default member,
`erc--warn-about-aberrant-modules'.
(erc-open): Pass sorted `erc-modules' to `erc--update-modules'.
* test/lisp/erc/erc-tests.el (erc--sort-modules): New test.
(erc-tests--update-modules): New fixture.
(erc--update-modules): Remove and rework as three separate tests
dedicated to specific contexts. The existing one had poor coverage
and was difficult, if not impossible, to follow.
(erc--update-modules/unknown, erc--update-modules/local,
erc--update-modules/realistic): New tests. (Bug#57955)
2023-10-06 17:34:04 -07:00
|
|
|
(mk-cmd (lambda (module)
|
|
|
|
(let ((mode (intern (format "erc-%s-mode" module))))
|
|
|
|
(fset mode (lambda (n) (push (cons mode n) calls))))))
|
|
|
|
|
|
|
|
(mk-builtin (lambda (module-string)
|
|
|
|
(let ((s (intern module-string)))
|
|
|
|
(put s 'erc--module s))))
|
|
|
|
|
|
|
|
(mk-global (lambda (module)
|
|
|
|
(push (intern (format "erc-%s-mode" module))
|
|
|
|
custom-modes))))
|
2023-02-04 06:24:59 -08:00
|
|
|
|
2021-07-12 03:44:28 -07:00
|
|
|
(cl-letf (((symbol-function 'require)
|
2023-02-04 06:24:59 -08:00
|
|
|
(lambda (s &rest _)
|
Sort and dedupe when loading modules in erc-open
* doc/misc/erc.texi: Add new subheading "Module Loading" under the
"Modules" chapter.
* lisp/erc/erc.el (erc--sort-modules): New utility function to sort
and dedupe modules.
(erc-modules): In `custom-set' function, factor out collation into
separate utility `erc--sort-modules'.
(erc-update-modules): Call `erc--update-modules' with an argument, the
current value of `erc-modules'.
(erc--aberrant-modules): New variable, a list of symbols whose modules
ERC suspects of being incorrectly defined.
(erc--warn-about-aberrant-modules): New function to print an error
message and emit a warning prior to connecting when
`erc--aberrant-modules' is non-nil.
(erc--find-mode): Make heuristic more robust by always checking for a
mode activation command rather than just a state variable. This fixes
a compatibility bug, new in 5.6, affecting third-party modules that
autoload module definitions instead of their corresponding
mode-activation commands.
(erc--update-modules): Add new positional argument `modules'.
(erc--setup-buffer-hook): Add new default member,
`erc--warn-about-aberrant-modules'.
(erc-open): Pass sorted `erc-modules' to `erc--update-modules'.
* test/lisp/erc/erc-tests.el (erc--sort-modules): New test.
(erc-tests--update-modules): New fixture.
(erc--update-modules): Remove and rework as three separate tests
dedicated to specific contexts. The existing one had poor coverage
and was difficult, if not impossible, to follow.
(erc--update-modules/unknown, erc--update-modules/local,
erc--update-modules/realistic): New tests. (Bug#57955)
2023-10-06 17:34:04 -07:00
|
|
|
;; Simulate library being loaded, things defined.
|
|
|
|
(when-let ((h (alist-get s on-load))) (funcall h))
|
|
|
|
(push (cons 'req s) calls)))
|
|
|
|
|
|
|
|
;; Spoof global module detection.
|
|
|
|
((symbol-function 'custom-variable-p)
|
|
|
|
(lambda (v) (memq v custom-modes))))
|
|
|
|
|
|
|
|
(funcall fn get-calls add-onload mk-cmd mk-builtin mk-global))
|
|
|
|
(should-not erc--aberrant-modules)))
|
|
|
|
|
|
|
|
(ert-deftest erc--update-modules/unknown ()
|
|
|
|
(erc-tests--update-modules
|
|
|
|
|
|
|
|
(lambda (get-calls _ mk-cmd _ mk-global)
|
|
|
|
|
|
|
|
(ert-info ("Baseline")
|
|
|
|
(let* ((erc-modules '(foo))
|
|
|
|
(obarray (obarray-make))
|
|
|
|
(err (should-error (erc--update-modules erc-modules))))
|
|
|
|
(should (equal (cadr err) "`foo' is not a known ERC module"))
|
|
|
|
(should (equal (funcall get-calls)
|
|
|
|
`((req . ,(intern-soft "erc-foo")))))))
|
|
|
|
|
|
|
|
;; Module's mode command exists but lacks an associated file.
|
|
|
|
(ert-info ("Bad autoload flagged as suspect")
|
|
|
|
(should-not erc--aberrant-modules)
|
|
|
|
(let* ((erc--aberrant-modules nil)
|
|
|
|
(obarray (obarray-make))
|
|
|
|
(erc-modules (list (intern "foo"))))
|
|
|
|
|
|
|
|
;; Create a mode activation command.
|
|
|
|
(funcall mk-cmd "foo")
|
|
|
|
|
|
|
|
;; Make the mode var global.
|
|
|
|
(funcall mk-global "foo")
|
|
|
|
|
|
|
|
;; No local modules to return.
|
|
|
|
(should-not (erc--update-modules erc-modules))
|
|
|
|
(should (equal (mapcar #'prin1-to-string erc--aberrant-modules)
|
|
|
|
'("foo")))
|
|
|
|
;; ERC requires the library via prefixed module name.
|
|
|
|
(should (equal (mapcar #'prin1-to-string (funcall get-calls))
|
|
|
|
`("(req . erc-foo)" "(erc-foo-mode . 1)"))))))))
|
|
|
|
|
|
|
|
;; A local module (here, `lo2') lacks a mode toggle, so ERC tries to
|
|
|
|
;; load its defining library, first via the symbol property
|
|
|
|
;; `erc--feature', and then via an "erc-" prefixed symbol.
|
|
|
|
(ert-deftest erc--update-modules/local ()
|
|
|
|
(erc-tests--update-modules
|
|
|
|
|
|
|
|
(lambda (get-calls add-onload mk-cmd mk-builtin mk-global)
|
|
|
|
|
|
|
|
(let* ((obarray (obarray-make 20))
|
|
|
|
(erc-modules (mapcar #'intern '("glo" "lo1" "lo2"))))
|
|
|
|
|
|
|
|
;; Create a global and a local module.
|
|
|
|
(mapc mk-cmd '("glo" "lo1"))
|
|
|
|
(mapc mk-builtin '("glo" "lo1"))
|
|
|
|
(funcall mk-global "glo")
|
|
|
|
(funcall add-onload "lo2" 'explicit-feature-lib mk-cmd)
|
|
|
|
|
|
|
|
;; Returns local modules.
|
|
|
|
(should (equal (mapcar #'symbol-name (erc--update-modules erc-modules))
|
|
|
|
'("erc-lo2-mode" "erc-lo1-mode")))
|
|
|
|
|
|
|
|
;; Requiring `erc-lo2' defines `erc-lo2-mode'.
|
|
|
|
(should (equal (mapcar #'prin1-to-string (funcall get-calls))
|
|
|
|
`("(erc-glo-mode . 1)"
|
|
|
|
"(req . explicit-feature-lib)")))))))
|
|
|
|
|
|
|
|
(ert-deftest erc--update-modules/realistic ()
|
|
|
|
(let ((calls nil)
|
|
|
|
;; Module `pcomplete' "resolves" to `completion'.
|
|
|
|
(erc-modules '(pcomplete autojoin networks)))
|
|
|
|
(cl-letf (((symbol-function 'require)
|
|
|
|
(lambda (s &rest _) (push (cons 'req s) calls)))
|
|
|
|
|
|
|
|
;; Spoof global module detection.
|
|
|
|
((symbol-function 'custom-variable-p)
|
|
|
|
(lambda (v)
|
|
|
|
(memq v '(erc-autojoin-mode erc-networks-mode
|
|
|
|
erc-completion-mode))))
|
|
|
|
;; Mock and spy real builtins.
|
2021-07-12 03:44:28 -07:00
|
|
|
((symbol-function 'erc-autojoin-mode)
|
|
|
|
(lambda (n) (push (cons 'autojoin n) calls)))
|
|
|
|
((symbol-function 'erc-networks-mode)
|
|
|
|
(lambda (n) (push (cons 'networks n) calls)))
|
|
|
|
((symbol-function 'erc-completion-mode)
|
Sort and dedupe when loading modules in erc-open
* doc/misc/erc.texi: Add new subheading "Module Loading" under the
"Modules" chapter.
* lisp/erc/erc.el (erc--sort-modules): New utility function to sort
and dedupe modules.
(erc-modules): In `custom-set' function, factor out collation into
separate utility `erc--sort-modules'.
(erc-update-modules): Call `erc--update-modules' with an argument, the
current value of `erc-modules'.
(erc--aberrant-modules): New variable, a list of symbols whose modules
ERC suspects of being incorrectly defined.
(erc--warn-about-aberrant-modules): New function to print an error
message and emit a warning prior to connecting when
`erc--aberrant-modules' is non-nil.
(erc--find-mode): Make heuristic more robust by always checking for a
mode activation command rather than just a state variable. This fixes
a compatibility bug, new in 5.6, affecting third-party modules that
autoload module definitions instead of their corresponding
mode-activation commands.
(erc--update-modules): Add new positional argument `modules'.
(erc--setup-buffer-hook): Add new default member,
`erc--warn-about-aberrant-modules'.
(erc-open): Pass sorted `erc-modules' to `erc--update-modules'.
* test/lisp/erc/erc-tests.el (erc--sort-modules): New test.
(erc-tests--update-modules): New fixture.
(erc--update-modules): Remove and rework as three separate tests
dedicated to specific contexts. The existing one had poor coverage
and was difficult, if not impossible, to follow.
(erc--update-modules/unknown, erc--update-modules/local,
erc--update-modules/realistic): New tests. (Bug#57955)
2023-10-06 17:34:04 -07:00
|
|
|
(lambda (n) (push (cons 'completion n) calls))))
|
2023-02-04 06:24:59 -08:00
|
|
|
|
Sort and dedupe when loading modules in erc-open
* doc/misc/erc.texi: Add new subheading "Module Loading" under the
"Modules" chapter.
* lisp/erc/erc.el (erc--sort-modules): New utility function to sort
and dedupe modules.
(erc-modules): In `custom-set' function, factor out collation into
separate utility `erc--sort-modules'.
(erc-update-modules): Call `erc--update-modules' with an argument, the
current value of `erc-modules'.
(erc--aberrant-modules): New variable, a list of symbols whose modules
ERC suspects of being incorrectly defined.
(erc--warn-about-aberrant-modules): New function to print an error
message and emit a warning prior to connecting when
`erc--aberrant-modules' is non-nil.
(erc--find-mode): Make heuristic more robust by always checking for a
mode activation command rather than just a state variable. This fixes
a compatibility bug, new in 5.6, affecting third-party modules that
autoload module definitions instead of their corresponding
mode-activation commands.
(erc--update-modules): Add new positional argument `modules'.
(erc--setup-buffer-hook): Add new default member,
`erc--warn-about-aberrant-modules'.
(erc-open): Pass sorted `erc-modules' to `erc--update-modules'.
* test/lisp/erc/erc-tests.el (erc--sort-modules): New test.
(erc-tests--update-modules): New fixture.
(erc--update-modules): Remove and rework as three separate tests
dedicated to specific contexts. The existing one had poor coverage
and was difficult, if not impossible, to follow.
(erc--update-modules/unknown, erc--update-modules/local,
erc--update-modules/realistic): New tests. (Bug#57955)
2023-10-06 17:34:04 -07:00
|
|
|
(should-not (erc--update-modules erc-modules)) ; no locals
|
|
|
|
(should (equal (nreverse calls)
|
|
|
|
'((completion . 1) (autojoin . 1) (networks . 1)))))))
|
2021-07-12 03:44:28 -07:00
|
|
|
|
|
|
|
(ert-deftest erc--merge-local-modes ()
|
2023-01-13 06:03:15 -08:00
|
|
|
(cl-letf (((get 'erc-b-mode 'erc-module) 'b)
|
|
|
|
((get 'erc-c-mode 'erc-module) 'c)
|
|
|
|
((get 'erc-d-mode 'erc-module) 'd)
|
|
|
|
((get 'erc-e-mode 'erc-module) 'e))
|
|
|
|
|
|
|
|
(ert-info ("No existing modes")
|
|
|
|
(let ((old '((a) (b . t)))
|
|
|
|
(new '(erc-c-mode erc-d-mode)))
|
|
|
|
(should (equal (erc--merge-local-modes new old)
|
|
|
|
'((erc-c-mode erc-d-mode))))))
|
|
|
|
|
|
|
|
(ert-info ("Active existing added, inactive existing removed, deduped")
|
|
|
|
(let ((old '((a) (erc-b-mode) (c . t) (erc-d-mode . t) (erc-e-mode . t)))
|
|
|
|
(new '(erc-b-mode erc-d-mode)))
|
|
|
|
(should (equal (erc--merge-local-modes new old)
|
|
|
|
'((erc-d-mode erc-e-mode) . (erc-b-mode))))))
|
|
|
|
|
|
|
|
(ert-info ("Non-module erc-prefixed mode ignored")
|
|
|
|
(let ((old '((erc-b-mode) (erc-f-mode . t) (erc-d-mode . t)))
|
|
|
|
(new '(erc-b-mode)))
|
|
|
|
(should (equal (erc--merge-local-modes new old)
|
|
|
|
'((erc-d-mode) . (erc-b-mode))))))))
|
2021-07-12 03:44:28 -07:00
|
|
|
|
|
|
|
(ert-deftest define-erc-module--global ()
|
|
|
|
(let ((global-module '(define-erc-module mname malias
|
2023-01-16 20:18:32 -08:00
|
|
|
"Some docstring."
|
2021-07-12 03:44:28 -07:00
|
|
|
((ignore a) (ignore b))
|
|
|
|
((ignore c) (ignore d)))))
|
|
|
|
|
2023-01-14 19:08:11 -08:00
|
|
|
(should (equal (cl-letf (((symbol-function
|
|
|
|
'erc--prepare-custom-module-type)
|
|
|
|
#'symbol-name))
|
|
|
|
(macroexpand global-module))
|
2021-07-12 03:44:28 -07:00
|
|
|
`(progn
|
|
|
|
|
|
|
|
(define-minor-mode erc-mname-mode
|
|
|
|
"Toggle ERC mname mode.
|
2023-01-16 20:18:32 -08:00
|
|
|
With a prefix argument ARG, enable mname if ARG is positive, and
|
|
|
|
disable it otherwise. If called from Lisp, enable the mode if
|
|
|
|
ARG is omitted or nil.
|
|
|
|
|
|
|
|
Some docstring."
|
2021-07-12 03:44:28 -07:00
|
|
|
:global t
|
2023-01-14 19:05:59 -08:00
|
|
|
:group (erc--find-group 'mname 'malias)
|
2023-04-14 00:07:31 -07:00
|
|
|
:require 'nil
|
2023-01-14 19:08:11 -08:00
|
|
|
:type "mname"
|
2023-05-15 00:16:00 -07:00
|
|
|
(let ((erc--module-toggle-prefix-arg arg))
|
|
|
|
(if erc-mname-mode
|
|
|
|
(erc-mname-enable)
|
|
|
|
(erc-mname-disable))))
|
2021-07-12 03:44:28 -07:00
|
|
|
|
|
|
|
(defun erc-mname-enable ()
|
|
|
|
"Enable ERC mname mode."
|
|
|
|
(interactive)
|
2023-01-14 19:08:11 -08:00
|
|
|
(unless (or erc--inside-mode-toggle-p
|
|
|
|
(memq 'mname erc-modules))
|
|
|
|
(let ((erc--inside-mode-toggle-p t))
|
|
|
|
(erc--favor-changed-reverted-modules-state
|
|
|
|
'mname #'cons)))
|
2021-07-12 03:44:28 -07:00
|
|
|
(setq erc-mname-mode t)
|
|
|
|
(ignore a) (ignore b))
|
|
|
|
|
|
|
|
(defun erc-mname-disable ()
|
|
|
|
"Disable ERC mname mode."
|
|
|
|
(interactive)
|
2023-01-14 19:08:11 -08:00
|
|
|
(unless (or erc--inside-mode-toggle-p
|
|
|
|
(not (memq 'mname erc-modules)))
|
|
|
|
(let ((erc--inside-mode-toggle-p t))
|
|
|
|
(erc--favor-changed-reverted-modules-state
|
|
|
|
'mname #'delq)))
|
2021-07-12 03:44:28 -07:00
|
|
|
(setq erc-mname-mode nil)
|
|
|
|
(ignore c) (ignore d))
|
|
|
|
|
|
|
|
(defalias 'erc-malias-mode #'erc-mname-mode)
|
2023-01-13 06:03:15 -08:00
|
|
|
(put 'erc-malias-mode 'erc-module 'mname)
|
2021-07-12 03:44:28 -07:00
|
|
|
|
2023-01-13 06:03:15 -08:00
|
|
|
(put 'erc-mname-mode 'erc-module 'mname)
|
2021-07-12 03:44:28 -07:00
|
|
|
(put 'erc-mname-mode 'definition-name 'mname)
|
|
|
|
(put 'erc-mname-enable 'definition-name 'mname)
|
|
|
|
(put 'erc-mname-disable 'definition-name 'mname))))))
|
|
|
|
|
|
|
|
(ert-deftest define-erc-module--local ()
|
2023-01-13 06:03:15 -08:00
|
|
|
(let* ((global-module '(define-erc-module mname nil ; no alias
|
2023-01-16 20:18:32 -08:00
|
|
|
"Some docstring."
|
2021-07-12 03:44:28 -07:00
|
|
|
((ignore a) (ignore b))
|
|
|
|
((ignore c) (ignore d))
|
|
|
|
'local))
|
|
|
|
(got (macroexpand global-module))
|
|
|
|
(arg-en (cadr (nth 2 (nth 2 got))))
|
|
|
|
(arg-dis (cadr (nth 2 (nth 3 got)))))
|
|
|
|
|
|
|
|
(should (equal got
|
|
|
|
`(progn
|
|
|
|
(define-minor-mode erc-mname-mode
|
|
|
|
"Toggle ERC mname mode.
|
2023-01-16 20:18:32 -08:00
|
|
|
With a prefix argument ARG, enable mname if ARG is positive, and
|
|
|
|
disable it otherwise. If called from Lisp, enable the mode if
|
|
|
|
ARG is omitted or nil.
|
|
|
|
|
|
|
|
Some docstring."
|
2021-07-12 03:44:28 -07:00
|
|
|
:global nil
|
2023-01-14 19:05:59 -08:00
|
|
|
:group (erc--find-group 'mname nil)
|
2023-05-15 00:16:00 -07:00
|
|
|
(let ((erc--module-toggle-prefix-arg arg))
|
|
|
|
(if erc-mname-mode
|
|
|
|
(erc-mname-enable)
|
|
|
|
(erc-mname-disable))))
|
2021-07-12 03:44:28 -07:00
|
|
|
|
|
|
|
(defun erc-mname-enable (&optional ,arg-en)
|
|
|
|
"Enable ERC mname mode.
|
2023-01-16 20:18:32 -08:00
|
|
|
When called interactively, do so in all buffers for the current
|
|
|
|
connection."
|
2021-07-12 03:44:28 -07:00
|
|
|
(interactive "p")
|
|
|
|
(when (derived-mode-p 'erc-mode)
|
|
|
|
(if ,arg-en
|
|
|
|
(erc-with-all-buffers-of-server
|
|
|
|
erc-server-process nil
|
|
|
|
(erc-mname-enable))
|
|
|
|
(setq erc-mname-mode t)
|
|
|
|
(ignore a) (ignore b))))
|
|
|
|
|
|
|
|
(defun erc-mname-disable (&optional ,arg-dis)
|
|
|
|
"Disable ERC mname mode.
|
2023-01-16 20:18:32 -08:00
|
|
|
When called interactively, do so in all buffers for the current
|
|
|
|
connection."
|
2021-07-12 03:44:28 -07:00
|
|
|
(interactive "p")
|
|
|
|
(when (derived-mode-p 'erc-mode)
|
|
|
|
(if ,arg-dis
|
|
|
|
(erc-with-all-buffers-of-server
|
|
|
|
erc-server-process nil
|
|
|
|
(erc-mname-disable))
|
|
|
|
(setq erc-mname-mode nil)
|
|
|
|
(ignore c) (ignore d))))
|
|
|
|
|
2023-01-13 06:03:15 -08:00
|
|
|
(put 'erc-mname-mode 'erc-module 'mname)
|
2021-07-12 03:44:28 -07:00
|
|
|
(put 'erc-mname-mode 'definition-name 'mname)
|
|
|
|
(put 'erc-mname-enable 'definition-name 'mname)
|
|
|
|
(put 'erc-mname-disable 'definition-name 'mname))))))
|
|
|
|
|
2021-09-26 01:53:56 +02:00
|
|
|
;;; erc-tests.el ends here
|