Re: Add compat to ERC
"J.P." <[email protected]>
| Newsgroups | gmane.emacs.erc.general |
|---|---|
| Message-ID | <[email protected]> |
Hi folks, Nothing to see here other than a minor heads up that I split off the erc-compat portion of that POC into a separate patch to serve as a stopgap in the interim for any Emacs 27 people wanting the ERC on trunk via elpa-devel (or in case ERC 5.5 is released before we can require the actual compat). Thanks, J.P.
0000-v1-v2.diff
(text/x-patch, 3.1 KB)
From 1a5ce365e0b2cd39a1bd3491b44c3fd9d10d5136 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" <[email protected]> Date: Thu, 14 Jul 2022 23:16:59 -0700 Subject: [PATCH 0/2] *** NOT A PATCH *** *** BLURB HERE *** F. Jason Park (2): Add temporary compatibility stopgaps to ERC Add compat from GNU ELPA as a soft dependency in ERC lisp/erc/erc-backend.el | 36 +++++++----------------------------- lisp/erc/erc-compat.el | 13 +++++++++++++ lisp/erc/erc-dcc.el | 12 ++---------- lisp/erc/erc-speedbar.el | 24 ++++++------------------ lisp/erc/erc.el | 33 +++++++++++---------------------- 5 files changed, 39 insertions(+), 79 deletions(-) Interdiff: diff --git a/lisp/erc/erc-compat.el b/lisp/erc/erc-compat.el index 899522f186..dec38df80a 100644 --- a/lisp/erc/erc-compat.el +++ b/lisp/erc/erc-compat.el @@ -151,39 +151,17 @@ erc-subseq (setq i (1+ i) start (1+ start))) res)))))) -;;;; lisp/calendar/time-date.el - -(defun erc-compat--28-decoded-time-period (time) - "Interpret DECODED as a period and return its length in seconds. -For computational purposes, years are 365 days long and months -are 30 days long." - (+ (if (consp (decoded-time-second time)) - ;; Fractional second. - (/ (float (car (decoded-time-second time))) - (cdr (decoded-time-second time))) - (or (decoded-time-second time) 0)) - (* (or (decoded-time-minute time) 0) 60) - (* (or (decoded-time-hour time) 0) 60 60) - (* (or (decoded-time-day time) 0) 60 60 24) - (* (or (decoded-time-month time) 0) 60 60 24 30) - (* (or (decoded-time-year time) 0) 60 60 24 365))) - -(defmacro erc-compat--decoded-time-period (time) - (declare (indent defun)) - (list (if (< emacs-major-version 28) - 'erc-compat--28-decoded-time-period - 'decoded-time-period) - time)) - ;;;; lisp/emacs-lisp/subr-x.el -(defmacro erc-compat--with-memoization (table &rest forms) +(defmacro erc-compat--with-memoization (place &rest forms) (declare (indent defun)) - ;; For now, assume the version in 29 will remain as is. - (if (< emacs-major-version 29) - `(cl--generic-with-memoization ,table ,@forms) - `(with-memoization ,table ,@forms))) - + ;; Degrade as an emergency stopgap in the unlikely event this gets + ;; renamed on trunk (does nothing for a change in arity). + (cond ((fboundp 'with-memoization) ; t when compiling + `(with-memoization ,place ,@forms)) + ((< 26 emacs-major-version 29) + `(cl--generic-with-memoization ,place ,@forms)) + (t (cons 'progn forms)))) (provide 'erc-compat) diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 613c805b31..3a58a0975e 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -3211,7 +3211,7 @@ erc--read-time-period (wrong-type-argument nil)))) (unless time (user-error "%s is not a valid time period" period)) - (erc-compat--decoded-time-period time)))))) + (decoded-time-period time)))))) (defun erc-cmd-IGNORE (&optional user) "Ignore USER. This should be a regexp matching nick!user@host. -- 2.36.1
0001-Add-temporary-compatibility-stopgaps-to-ERC.patch
(text/x-patch, 6.7 KB)
From 30d6755c4e943a6d9170aa3281122bff493a2621 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" <[email protected]> Date: Thu, 14 Jul 2022 22:23:48 -0700 Subject: [PATCH 1/2] Add temporary compatibility stopgaps to ERC * lisp/erc/erc.el: Load erc-compat.el after main requirements. Eventually, this will in turn load the compat package from GNU ELPA. (erc--read-time-period): Use adapter for `decoded-time-period'. (erc-join-channel): Use adapter for `format-prompt'. * lisp/erc/erc-backend.el: (erc--with-memoization, erc-compat--with-memoization): Move to `erc-compat'. * lisp/erc/erc-compat.el: (erc-compat--28-decoded-time-period, erc-compat--decoded-time-period): Add adapter and backport definition for `decoded-time-period'. (erc-compat--with-memoization): Add adapter for `with-memoization'. (erc--read-time-period): Use `erc-compat--decoded-time-period' adapter. (erc-compat--28-format-prompt, erc-compat--format-prompt): Add adapters for `format-prompt'. * lisp/erc/erc-dcc.el: (erc-dcc-do-GET-command): Use adapter for `format-prompt'. --- lisp/erc/erc-backend.el | 12 +-------- lisp/erc/erc-compat.el | 59 +++++++++++++++++++++++++++++++++++++++++ lisp/erc/erc-dcc.el | 4 +-- lisp/erc/erc.el | 6 +++-- 4 files changed, 66 insertions(+), 15 deletions(-) diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index 8be4894ecb..2df2a57690 100644 --- a/lisp/erc/erc-backend.el +++ b/lisp/erc/erc-backend.el @@ -1673,16 +1673,6 @@ erc--parse-isupport-value (split-string value ",") (list value))))) -(defmacro erc--with-memoization (table &rest forms) - "Adapter to be migrated to erc-compat." - (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 ,@forms))) - (defun erc--get-isupport-entry (key &optional single) "Return an item for \"ISUPPORT\" token KEY, a symbol. When a lookup fails return nil. Otherwise return a list whose @@ -1692,7 +1682,7 @@ erc--get-isupport-entry primitive value." (if-let* ((table (or erc--isupport-params (erc-with-server-buffer erc--isupport-params))) - (value (erc--with-memoization (gethash key table) + (value (erc-compat--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 16cfb15a5a..e45b52f0c7 100644 --- a/lisp/erc/erc-compat.el +++ b/lisp/erc/erc-compat.el @@ -150,6 +150,65 @@ erc-subseq (setq i (1+ i) start (1+ start))) res)))))) +;;;; lisp/calendar/time-date.el + +(defun erc-compat--28-decoded-time-period (time) + "Interpret DECODED as a period and return its length in seconds. +For computational purposes, years are 365 days long and months +are 30 days long." + (+ (if (consp (decoded-time-second time)) + ;; Fractional second. + (/ (float (car (decoded-time-second time))) + (cdr (decoded-time-second time))) + (or (decoded-time-second time) 0)) + (* (or (decoded-time-minute time) 0) 60) + (* (or (decoded-time-hour time) 0) 60 60) + (* (or (decoded-time-day time) 0) 60 60 24) + (* (or (decoded-time-month time) 0) 60 60 24 30) + (* (or (decoded-time-year time) 0) 60 60 24 365))) + +(defmacro erc-compat--decoded-time-period (time) + (declare (indent defun)) + (list (if (< emacs-major-version 28) + 'erc-compat--28-decoded-time-period + 'decoded-time-period) + time)) + +;;;; lisp/minibuffer.el + +(defun erc-compat--28-format-prompt (prompt default &rest format-args) + (concat + (if (null format-args) + prompt + (apply #'format prompt format-args)) + (and default + (or (not (stringp default)) + (> (length default) 0)) + (format " (default %s)" + (if (consp default) + (car default) + default))) + ": ")) + +(defmacro erc-compat--format-prompt (&rest rest) + (declare (indent defun)) + (cons (if (< emacs-major-version 28) + 'erc-compat--28-format-prompt + 'format-prompt) + rest)) + +;;;; lisp/emacs-lisp/subr-x.el + +(defmacro erc-compat--with-memoization (place &rest forms) + (declare (indent defun)) + ;; Degrade as an emergency stopgap in the unlikely event this gets + ;; renamed on trunk (does nothing for a change in arity). + (cond ((fboundp 'with-memoization) ; t when compiling + `(with-memoization ,place ,@forms)) + ((< 26 emacs-major-version 29) + `(cl--generic-with-memoization ,place ,@forms)) + (t (cons 'progn forms)))) + (provide 'erc-compat) ;;; erc-compat.el ends here diff --git a/lisp/erc/erc-dcc.el b/lisp/erc/erc-dcc.el index d0e1848e0e..c8a66dd1d6 100644 --- a/lisp/erc/erc-dcc.el +++ b/lisp/erc/erc-dcc.el @@ -520,8 +520,8 @@ erc-dcc-do-GET-command (filename (or file (plist-get elt :file) "unknown"))) (if elt (let* ((file (read-file-name - (format-prompt "Local filename" - (file-name-nondirectory filename)) + (erc-compat--format-prompt + "Local filename" (file-name-nondirectory filename)) (or erc-dcc-get-default-directory default-directory) (expand-file-name (file-name-nondirectory filename) diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 0a16831fba..508f0e9620 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -69,6 +69,8 @@ (require 'iso8601) (eval-when-compile (require 'subr-x)) +(require 'erc-compat) + (defconst erc-version "5.4.1" "This version of ERC.") @@ -3209,7 +3211,7 @@ erc--read-time-period (wrong-type-argument nil)))) (unless time (user-error "%s is not a valid time period" period)) - (decoded-time-period time)))))) + (erc-compat--decoded-time-period time)))))) (defun erc-cmd-IGNORE (&optional user) "Ignore USER. This should be a regexp matching nick!user@host. @@ -4480,7 +4482,7 @@ erc-join-channel (table (when (erc-server-buffer-live-p) (set-buffer (process-buffer erc-server-process)) erc-channel-list))) - (completing-read (format-prompt "Join channel" chnl) + (completing-read (erc-compat--format-prompt "Join channel" chnl) table nil nil nil nil chnl)) (when (or current-prefix-arg erc-prompt-for-channel-key) (read-string "Channel key (RET for none): ")))) -- 2.36.1
0002-Add-compat-from-GNU-ELPA-as-a-soft-dependency-in-ERC.patch
(text/x-patch, 14.6 KB)
From 1a5ce365e0b2cd39a1bd3491b44c3fd9d10d5136 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" <[email protected]> Date: Fri, 8 Jul 2022 04:58:26 -0700 Subject: [PATCH 2/2] Add compat from GNU ELPA as a soft dependency in ERC FIXME update version in Package-Requires header to appropriate compat release. * lisp/erc/erc-backend.el (erc-parse-server-response, erc--parse-isupport-value): Remove sub-28 compat code involving `string-search'. * lisp/erc/erc-compat.el: Require compat package, but don't error when absent. * lisp/erc/erc-dcc.el (erc-dcc-member): Remove `string-search' compat code. (erc-dcc-unquote-filename): Remove `string-replace' compat code. * lisp/erc/erc-speedbar.el (erc-speedbar-expand-server, erc-speedbar-expand-channel, erc-speedbar-expand-user): Remove `string-search' compat code. * lisp/erc/erc.el: Add compat version 28.1.1.0 to Package-Requires header. (erc--valid-local-channel-p): Remove `string-search' compat code. (erc-update-mode-line-buffer): Remove `string-replace' compat code. (erc-message-english-PART): Remove `string-replace' compat code. --- lisp/erc/erc-backend.el | 24 +++++--------------- lisp/erc/erc-compat.el | 48 +--------------------------------------- lisp/erc/erc-dcc.el | 16 ++++---------- lisp/erc/erc-speedbar.el | 24 +++++--------------- lisp/erc/erc.el | 35 +++++++++-------------------- 5 files changed, 28 insertions(+), 119 deletions(-) diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index 2df2a57690..5858502eb2 100644 --- a/lisp/erc/erc-backend.el +++ b/lisp/erc/erc-backend.el @@ -1012,21 +1012,15 @@ erc-parse-server-response (save-match-data (let* ((tag-list (when (eq (aref string 0) ?@) (substring string 1 - (if (>= emacs-major-version 28) - (string-search " " string) - (string-match " " string))))) + (string-search " " string)))) (msg (make-erc-response :unparsed string :tags (when tag-list (erc-parse-tags tag-list)))) (string (if tag-list - (substring string (+ 1 (if (>= emacs-major-version 28) - (string-search " " string) - (string-match " " string)))) + (substring string (+ 1 (string-search " " string))) string)) (posn (if (eq (aref string 0) ?:) - (if (>= emacs-major-version 28) - (string-search " " string) - (string-match " " string)) + (string-search " " string) 0))) (setf (erc-response.sender msg) @@ -1036,9 +1030,7 @@ erc-parse-server-response (setf (erc-response.command msg) (let* ((bposn (string-match "[^ \n]" string posn)) - (eposn (if (>= emacs-major-version 28) - (string-search " " string bposn) - (string-match " " string bposn)))) + (eposn (string-search " " string bposn))) (setq posn (and eposn (string-match "[^ \n]" string eposn))) (substring string bposn eposn))) @@ -1046,9 +1038,7 @@ erc-parse-server-response (while (and posn (not (eq (aref string posn) ?:))) (push (let* ((bposn posn) - (eposn (if (>= emacs-major-version 28) - (string-search " " string bposn) - (string-match " " string bposn)))) + (eposn (string-search " " string bposn))) (setq posn (and eposn (string-match "[^ \n]" string eposn))) (substring string bposn eposn)) @@ -1667,9 +1657,7 @@ erc--parse-isupport-value start (- (match-end 0) 3)) (setq start (match-end 0)))) v)) - (if (if (>= emacs-major-version 28) - (string-search "," value) - (string-match-p "," value)) + (if (string-search "," value) (split-string value ",") (list value))))) diff --git a/lisp/erc/erc-compat.el b/lisp/erc/erc-compat.el index e45b52f0c7..dec38df80a 100644 --- a/lisp/erc/erc-compat.el +++ b/lisp/erc/erc-compat.el @@ -26,6 +26,7 @@ ;; This mostly defines stuff that cannot be worked around easily. ;;; Code: +(require 'compat nil 'noerror) ;;;###autoload(autoload 'erc-define-minor-mode "erc-compat") (define-obsolete-function-alias 'erc-define-minor-mode @@ -150,53 +151,6 @@ erc-subseq (setq i (1+ i) start (1+ start))) res)))))) -;;;; lisp/calendar/time-date.el - -(defun erc-compat--28-decoded-time-period (time) - "Interpret DECODED as a period and return its length in seconds. -For computational purposes, years are 365 days long and months -are 30 days long." - (+ (if (consp (decoded-time-second time)) - ;; Fractional second. - (/ (float (car (decoded-time-second time))) - (cdr (decoded-time-second time))) - (or (decoded-time-second time) 0)) - (* (or (decoded-time-minute time) 0) 60) - (* (or (decoded-time-hour time) 0) 60 60) - (* (or (decoded-time-day time) 0) 60 60 24) - (* (or (decoded-time-month time) 0) 60 60 24 30) - (* (or (decoded-time-year time) 0) 60 60 24 365))) - -(defmacro erc-compat--decoded-time-period (time) - (declare (indent defun)) - (list (if (< emacs-major-version 28) - 'erc-compat--28-decoded-time-period - 'decoded-time-period) - time)) - -;;;; lisp/minibuffer.el - -(defun erc-compat--28-format-prompt (prompt default &rest format-args) - (concat - (if (null format-args) - prompt - (apply #'format prompt format-args)) - (and default - (or (not (stringp default)) - (> (length default) 0)) - (format " (default %s)" - (if (consp default) - (car default) - default))) - ": ")) - -(defmacro erc-compat--format-prompt (&rest rest) - (declare (indent defun)) - (cons (if (< emacs-major-version 28) - 'erc-compat--28-format-prompt - 'format-prompt) - rest)) - ;;;; lisp/emacs-lisp/subr-x.el (defmacro erc-compat--with-memoization (place &rest forms) diff --git a/lisp/erc/erc-dcc.el b/lisp/erc/erc-dcc.el index c8a66dd1d6..7a24acc433 100644 --- a/lisp/erc/erc-dcc.el +++ b/lisp/erc/erc-dcc.el @@ -191,9 +191,7 @@ erc-dcc-member test (cadr (plist-member elt prop))) ;; if the property exists and is equal, we continue, else, try the ;; next element of the list - (or (and (eq prop :nick) (if (>= emacs-major-version 28) - (string-search "!" val) - (string-match "!" val)) + (or (and (eq prop :nick) (string-search "!" val) test (string-equal test val)) (and (eq prop :nick) test val @@ -520,8 +518,8 @@ erc-dcc-do-GET-command (filename (or file (plist-get elt :file) "unknown"))) (if elt (let* ((file (read-file-name - (erc-compat--format-prompt - "Local filename" (file-name-nondirectory filename)) + (format-prompt "Local filename" + (file-name-nondirectory filename)) (or erc-dcc-get-default-directory default-directory) (expand-file-name (file-name-nondirectory filename) @@ -659,13 +657,7 @@ erc-dcc-ctcp-query-send-regexp (define-inline erc-dcc-unquote-filename (filename) (inline-quote - (if (>= emacs-major-version 28) - (string-replace - "\\\\" "\\" - (string-replace "\\\"" "\"" ,filename)) - (replace-regexp-in-string - "\\\\\\\\" "\\" - (replace-regexp-in-string "\\\\\"" "\"" ,filename t t) t t)))) + (string-replace "\\\\" "\\" (string-replace "\\\"" "\"" ,filename)))) (defun erc-dcc-handle-ctcp-send (proc query nick login host to) "This is called if a CTCP DCC SEND subcommand is sent to the client. diff --git a/lisp/erc/erc-speedbar.el b/lisp/erc/erc-speedbar.el index 5b06c21612..19113c5aad 100644 --- a/lisp/erc/erc-speedbar.el +++ b/lisp/erc/erc-speedbar.el @@ -139,9 +139,7 @@ erc-speedbar-server-buttons t)))) (defun erc-speedbar-expand-server (text server indent) - (cond ((if (>= emacs-major-version 28) - (string-search "+" text) - (string-match "\\+" text)) + (cond ((string-search "+" text) (speedbar-change-expand-button-char ?-) (if (speedbar-with-writable (save-excursion @@ -150,9 +148,7 @@ erc-speedbar-expand-server (speedbar-change-expand-button-char ?-) (speedbar-change-expand-button-char ??))) (;; we have to contract this node - (if (>= emacs-major-version 28) - (string-search "-" text) - (string-match "-" text)) + (string-search "-" text) (speedbar-change-expand-button-char ?+) (speedbar-delete-subblock indent)) (t (error "Ooops... not sure what to do"))) @@ -189,9 +185,7 @@ erc-speedbar-expand-channel "For the line matching TEXT, in CHANNEL, expand or contract a line. INDENT is the current indentation level." (cond - ((if (>= emacs-major-version 28) - (string-search "+" text) - (string-match "\\+" text)) + ((string-search "+" text) (speedbar-change-expand-button-char ?-) (speedbar-with-writable (save-excursion @@ -240,9 +234,7 @@ erc-speedbar-expand-channel (speedbar-with-writable (dolist (entry names) (erc-speedbar-insert-user entry ?+ (1+ indent)))))))))) - ((if (>= emacs-major-version 28) - (string-search "-" text) - (string-match "-" text)) + ((string-search "-" text) (speedbar-change-expand-button-char ?+) (speedbar-delete-subblock indent)) (t (error "Ooops... not sure what to do"))) @@ -293,9 +285,7 @@ erc-speedbar-update-channel (erc-speedbar-expand-channel "+" buffer 1))))) (defun erc-speedbar-expand-user (text token indent) - (cond ((if (>= emacs-major-version 28) - (string-search "+" text) - (string-match "\\+" text)) + (cond ((string-search "+" text) (speedbar-change-expand-button-char ?-) (speedbar-with-writable (save-excursion @@ -318,9 +308,7 @@ erc-speedbar-expand-user nil nil nil nil info nil nil nil (1+ indent))))))) - ((if (>= emacs-major-version 28) - (string-search "-" text) - (string-match "-" text)) + ((string-search "-" text) (speedbar-change-expand-button-char ?+) (speedbar-delete-subblock indent)) (t (error "Ooops... not sure what to do"))) diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 508f0e9620..3a58a0975e 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -13,7 +13,7 @@ ;; Michael Olson ([email protected]) ;; Kelvin White ([email protected]) ;; Version: 5.4.1 -;; Package-Requires: ((emacs "27.1")) +;; Package-Requires: ((emacs "27.1") (compat "28.1.1.0")) ;; Keywords: IRC, chat, client, Internet ;; URL: https://www.gnu.org/software/emacs/erc.html @@ -3211,7 +3211,7 @@ erc--read-time-period (wrong-type-argument nil)))) (unless time (user-error "%s is not a valid time period" period)) - (erc-compat--decoded-time-period time)))))) + (decoded-time-period time)))))) (defun erc-cmd-IGNORE (&optional user) "Ignore USER. This should be a regexp matching nick!user@host. @@ -3521,9 +3521,7 @@ erc--valid-local-channel-p "Non-nil when channel is server-local on a network that allows them." (and-let* (((eq ?& (aref channel 0))) (chan-types (erc--get-isupport-entry 'CHANTYPES 'single)) - ((if (>= emacs-major-version 28) - (string-search "&" chan-types) - (string-match-p "&" chan-types)))))) + ((string-search "&" chan-types))))) (defun erc-cmd-JOIN (channel &optional key) "Join the channel given in CHANNEL, optionally with KEY. @@ -4482,7 +4480,7 @@ erc-join-channel (table (when (erc-server-buffer-live-p) (set-buffer (process-buffer erc-server-process)) erc-channel-list))) - (completing-read (erc-compat--format-prompt "Join channel" chnl) + (completing-read (format-prompt "Join channel" chnl) table nil nil nil nil chnl)) (when (or current-prefix-arg erc-prompt-for-channel-key) (read-string "Channel key (RET for none): ")))) @@ -7006,21 +7004,12 @@ erc-update-mode-line-buffer (fill-region (point-min) (point-max)) (buffer-string)))) (setq header-line-format - (if (>= emacs-major-version 28) - (string-replace - "%" - "%%" - (if face - (propertize header 'help-echo help-echo - 'face face) - (propertize header 'help-echo help-echo))) - (replace-regexp-in-string - "%" - "%%" - (if face - (propertize header 'help-echo help-echo - 'face face) - (propertize header 'help-echo help-echo))))))) + (string-replace + "%" + "%%" + (if face + (propertize header 'help-echo help-echo 'face face) + (propertize header 'help-echo help-echo)))))) (t (setq header-line-format (if face (propertize header 'face face) @@ -7305,9 +7294,7 @@ erc-message-english-PART nick user host channel (if (not (string= reason "")) (format ": %s" - (if (>= emacs-major-version 28) - (string-replace "%" "%%" reason) - (replace-regexp-in-string "%" "%%" reason))) + (string-replace "%" "%%" reason)) ""))))) -- 2.36.1