From 2d4dce2e09890ad28edf056df0bc23d818ace185 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Thu, 19 Jan 2023 20:52:47 -0800 Subject: [PATCH 2/4] [5.6] Copy over upstream Compat macros to erc-compat * lisp/erc/erc-backend: (erc--get-isupport-entry): Replace call to `erc-compat--with-memoization' with the built-in `with-memoization'. * lisp/erc/erc-compat.el: (erc-compat-function, erc-compat-call): Add new macros from Compat 29.1.2.0. (erc-compat--with-memoization): Remove because it's now provided by Compat. --- lisp/erc/erc-backend.el | 2 +- lisp/erc/erc-compat.el | 49 +++++++++++++++++++++++++++++++++-------- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index 1da701aebc4..f00c8b2841a 100644 --- a/lisp/erc/erc-backend.el +++ b/lisp/erc/erc-backend.el @@ -1878,7 +1878,7 @@ erc--get-isupport-entry primitive value." (if-let* ((table (or erc--isupport-params (erc-with-server-buffer erc--isupport-params))) - (value (erc-compat--with-memoization (gethash key table) + (value (with-memoization (gethash key table) (when-let ((v (assoc (symbol-name key) erc-server-parameters))) (if (cdr v) diff --git a/lisp/erc/erc-compat.el b/lisp/erc/erc-compat.el index 5601ede27a5..fb354a1d3f7 100644 --- a/lisp/erc/erc-compat.el +++ b/lisp/erc/erc-compat.el @@ -34,6 +34,46 @@ (require 'compat nil 'noerror) (eval-when-compile (require 'cl-lib) (require 'url-parse)) +;; Except for the "erc-" namespacing, these two definitions should be +;; continuously updated to match the latest upstream ones verbatim. +;; Although they're pretty simple, it's likely not worth checking for +;; and possibly deferring to the non-prefixed versions. +;; +;; BEGIN Compat macros + +;;;; Macros for explicit compatibility function calls + +(defmacro erc-compat-function (fun) + "Return compatibility function symbol for FUN. + +If the Emacs version provides a sufficiently recent version of +FUN, the symbol FUN is returned itself. Otherwise the macro +returns the symbol of a compatibility function which supports the +behavior and calling convention of the current stable Emacs +version. For example Compat 29.1 will provide compatibility +functions which implement the behavior and calling convention of +Emacs 29.1. + +An example is the function `plist-get' which got an additional +predicate argument in Emacs 29. The compatibility function, +which supports this additional argument can be obtained +via (compat-function plist-get) and called with the additional +predicate argument via (compat-call plist-get plist prop +predicate). It is not possible to directly call (plist-get plist +prop predicate), since the function does not yet support the +predicate argument on older Emacs versions and the Compat library +does not override existing functions." + (let ((compat (intern (format "compat--%s" fun)))) + `#',(if (fboundp compat) compat fun))) + +(defmacro erc-compat-call (fun &rest args) + "Call compatibility function or macro FUN with ARGS. +See `compat-function' for details." + (let ((compat (intern (format "compat--%s" fun)))) + `(,(if (fboundp compat) compat fun) ,@args))) + +;; END Compat macros + ;;;###autoload(autoload 'erc-define-minor-mode "erc-compat") (define-obsolete-function-alias 'erc-define-minor-mode #'define-minor-mode "28.1") @@ -368,15 +408,6 @@ erc-compat--29-sasl-scram--client-final-message ;;;; Misc 29.1 -(defmacro erc-compat--with-memoization (table &rest forms) - (declare (indent defun)) - (cond - ((fboundp 'with-memoization) - `(with-memoization ,table ,@forms)) ; 29.1 - ((fboundp 'cl--generic-with-memoization) - `(cl--generic-with-memoization ,table ,@forms)) - (t `(progn ,@forms)))) - (defvar url-irc-function) (defun erc-compat--29-browse-url-irc (string &rest _) -- 2.38.1