From b05b60a0d79aad70cb71681b4b9f1f519bba40e4 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Mon, 13 Nov 2023 18:24:59 -0800 Subject: [PATCH 1/3] [5.6] Make wrangling ISUPPORT data more convenient in ERC * lisp/erc/erc-backend.el (erc--get-isupport-entry): Check server for `erc-server-parameters' if it's empty in the current buffer. This is a bug fix. (erc--with-isupport-data): New macro for accessing and caching data derived from some ISUPPORT value. * lisp/erc/erc-common.el (erc--isupport-data): New type for storing cached ISUPPORT data. * test/lisp/erc/erc-scenarios-display-message.el: Remove stray `require'. (Bug#67220) --- lisp/erc/erc-backend.el | 16 +++++++++++++++- lisp/erc/erc-common.el | 4 ++++ test/lisp/erc/erc-scenarios-display-message.el | 2 -- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index 9281c107d06..573079272e6 100644 --- a/lisp/erc/erc-backend.el +++ b/lisp/erc/erc-backend.el @@ -2096,7 +2096,9 @@ erc--get-isupport-entry (erc-with-server-buffer erc--isupport-params))) (value (with-memoization (gethash key table) (when-let ((v (assoc (symbol-name key) - erc-server-parameters))) + (or erc-server-parameters + (erc-with-server-buffer + erc-server-parameters))))) (if (cdr v) (erc--parse-isupport-value (cdr v)) '--empty--))))) @@ -2106,6 +2108,18 @@ erc--get-isupport-entry (when table (remhash key table)))) +(defmacro erc--with-isupport-data (param var &rest body) + "Return processed data for \"ISUPPORT\" PARAM value stored VAR. +Expect VAR's value to be an instance of an object whose \"class\" +inherits from `erc--isupport-data'. If VAR is uninitialized or +stale, evaluate BODY and assign the result to VAR." + (declare (indent defun)) + `(erc-with-server-buffer + (pcase-let (((,@(list '\` (list param '\, 'key))) + (erc--get-isupport-entry ',param))) + (or (and ,var (eq key (erc--isupport-data-key ,var)) ,var) + (setq ,var (progn ,@body)))))) + (define-erc-response-handler (005) "Set the variable `erc-server-parameters' and display the received message. diff --git a/lisp/erc/erc-common.el b/lisp/erc/erc-common.el index 930e8032f6d..683b05c3543 100644 --- a/lisp/erc/erc-common.el +++ b/lisp/erc/erc-common.el @@ -101,6 +101,10 @@ erc--target (contents "" :type string) (tags '() :type list)) +(cl-defstruct erc--isupport-data + "Abstract class for parsed ISUPPORT data." + (key nil :type (or null cons))) + ;; After dropping 28, we can use prefixed "erc-autoload" cookies. (defun erc--normalize-module-symbol (symbol) "Return preferred SYMBOL for `erc--modules'." diff --git a/test/lisp/erc/erc-scenarios-display-message.el b/test/lisp/erc/erc-scenarios-display-message.el index 51bdf305ad5..5751a32212d 100644 --- a/test/lisp/erc/erc-scenarios-display-message.el +++ b/test/lisp/erc/erc-scenarios-display-message.el @@ -59,6 +59,4 @@ erc-scenarios-display-message--multibuf (erc-cmd-QUIT ""))) -(eval-when-compile (require 'erc-join)) - ;;; erc-scenarios-display-message.el ends here -- 2.41.0