diff options
| author | F. Jason Park | 2022-10-24 22:58:13 -0700 |
|---|---|---|
| committer | F. Jason Park | 2022-11-16 21:34:36 -0800 |
| commit | d4028ead897464c9799847900b4acb2276acaac6 (patch) | |
| tree | aa77e33da2a211cf91c52c55dfee146ea3655e99 | |
| parent | e7f2f6cd92b924ecdfcf1356560d4a168546677d (diff) | |
| download | emacs-d4028ead897464c9799847900b4acb2276acaac6.tar.gz emacs-d4028ead897464c9799847900b4acb2276acaac6.zip | |
Warn of future breaking change to erc-response.tags
* lisp/erc/erc-backend.el (erc-parse-tags-format): New option to
determine type of the `erc-response' "tags" field.
(erc-parse-tags): Defer to internal generic function.
(erc--parse-tags): New function to hold original `erc-parse-tags'
implementation.
(erc--parse-message-tags): New generic function that conditionally
calls `erc--parse-tags', perhaps emitting a warning beforehand.
(erc-parse-server-response): Call `erc--parse-message-tags'.
(Bug#58797.)
| -rw-r--r-- | lisp/erc/erc-backend.el | 57 | ||||
| -rw-r--r-- | lisp/erc/erc-common.el | 3 |
2 files changed, 57 insertions, 3 deletions
diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index 51c92e0f12a..d49e6a5f1a8 100644 --- a/lisp/erc/erc-backend.el +++ b/lisp/erc/erc-backend.el | |||
| @@ -1122,8 +1122,37 @@ See also `erc-server-send'." | |||
| 1122 | 1122 | ||
| 1123 | ;;;; Handling responses | 1123 | ;;;; Handling responses |
| 1124 | 1124 | ||
| 1125 | (defcustom erc-tags-format 'overridable | ||
| 1126 | "Shape of the `tags' alist in `erc-response' objects. | ||
| 1127 | When set to `legacy', pre-5.5 parsing behavior takes effect for | ||
| 1128 | the tags portion of every message. The resulting alist contains | ||
| 1129 | conses of the form (STRING . LIST), in which LIST is comprised of | ||
| 1130 | at most one, possibly empty string. When set to nil, ERC only | ||
| 1131 | parses tags if an active module defines an implementation. It | ||
| 1132 | otherwise ignores them. In such cases, each alist element is a | ||
| 1133 | cons of a symbol and an optional, nonempty string. | ||
| 1134 | |||
| 1135 | With the default value of `overridable', ERC behaves as it does | ||
| 1136 | with `legacy' except that it emits a warning whenever first | ||
| 1137 | encountering a message containing tags in a given Emacs session. | ||
| 1138 | But it only does so when a module implementing overriding, | ||
| 1139 | non-legacy behavior isn't already active in the current network | ||
| 1140 | context. | ||
| 1141 | |||
| 1142 | Note that future bundled modules providing IRCv3 functionality | ||
| 1143 | will not be compatible with the legacy format. User code should | ||
| 1144 | eventually transition to expecting this \"5.5+ variant\" and set | ||
| 1145 | this option to nil." | ||
| 1146 | :package-version '(ERC . "5.4.1") ; FIXME increment on next release | ||
| 1147 | :type '(choice (const nil) | ||
| 1148 | (const legacy) | ||
| 1149 | (const overridable))) | ||
| 1150 | |||
| 1125 | (defun erc-parse-tags (string) | 1151 | (defun erc-parse-tags (string) |
| 1126 | "Parse IRCv3 tags list in STRING to a (tag . value) alist." | 1152 | "Parse IRCv3 tags list in STRING to a (tag . value) alist." |
| 1153 | (erc--parse-message-tags string)) | ||
| 1154 | |||
| 1155 | (defun erc--parse-tags (string) | ||
| 1127 | (let ((tags) | 1156 | (let ((tags) |
| 1128 | (tag-strings (split-string string ";"))) | 1157 | (tag-strings (split-string string ";"))) |
| 1129 | (dolist (tag-string tag-strings tags) | 1158 | (dolist (tag-string tag-strings tags) |
| @@ -1133,6 +1162,28 @@ See also `erc-server-send'." | |||
| 1133 | `(,pair)) | 1162 | `(,pair)) |
| 1134 | tags))))) | 1163 | tags))))) |
| 1135 | 1164 | ||
| 1165 | ;; A benefit of this function being internal is not having to define a | ||
| 1166 | ;; separate method just to ensure an `erc-tags-format' value of | ||
| 1167 | ;; `legacy' always wins. A downside is that module code must take | ||
| 1168 | ;; care to preserve that promise manually. | ||
| 1169 | |||
| 1170 | (cl-defgeneric erc--parse-message-tags (string) | ||
| 1171 | "Parse STRING into an alist of (TAG . VALUE) conses. | ||
| 1172 | Expect TAG to be a symbol and VALUE nil or a nonempty string. | ||
| 1173 | Don't split composite raw-input values containing commas; | ||
| 1174 | instead, leave them as a single string." | ||
| 1175 | (when erc-tags-format | ||
| 1176 | (unless (or (eq erc-tags-format 'legacy) | ||
| 1177 | (get 'erc-parse-tags 'erc-v3-warned-p)) | ||
| 1178 | (put 'erc-parse-tags 'erc-v3-warned-p t) | ||
| 1179 | (display-warning | ||
| 1180 | 'ERC | ||
| 1181 | (concat | ||
| 1182 | "Legacy ERC tags behavior is currently in effect, but other modules," | ||
| 1183 | " including those bundled with ERC, may override this in future" | ||
| 1184 | " releases. See `erc-tags-format' for more info."))) | ||
| 1185 | (erc--parse-tags string))) | ||
| 1186 | |||
| 1136 | (defun erc-parse-server-response (proc string) | 1187 | (defun erc-parse-server-response (proc string) |
| 1137 | "Parse and act upon a complete line from an IRC server. | 1188 | "Parse and act upon a complete line from an IRC server. |
| 1138 | PROC is the process (connection) from which STRING was received. | 1189 | PROC is the process (connection) from which STRING was received. |
| @@ -1142,9 +1193,9 @@ PROCs `process-buffer' is `current-buffer' when this function is called." | |||
| 1142 | (let* ((tag-list (when (eq (aref string 0) ?@) | 1193 | (let* ((tag-list (when (eq (aref string 0) ?@) |
| 1143 | (substring string 1 | 1194 | (substring string 1 |
| 1144 | (string-search " " string)))) | 1195 | (string-search " " string)))) |
| 1145 | (msg (make-erc-response :unparsed string :tags (when tag-list | 1196 | (msg (make-erc-response :unparsed string :tags |
| 1146 | (erc-parse-tags | 1197 | (when tag-list |
| 1147 | tag-list)))) | 1198 | (erc--parse-message-tags tag-list)))) |
| 1148 | (string (if tag-list | 1199 | (string (if tag-list |
| 1149 | (substring string (+ 1 (string-search " " string))) | 1200 | (substring string (+ 1 (string-search " " string))) |
| 1150 | string)) | 1201 | string)) |
diff --git a/lisp/erc/erc-common.el b/lisp/erc/erc-common.el index d8aac36eab6..23a19337986 100644 --- a/lisp/erc/erc-common.el +++ b/lisp/erc/erc-common.el | |||
| @@ -77,6 +77,9 @@ | |||
| 77 | (cl-defstruct (erc--target-channel (:include erc--target))) | 77 | (cl-defstruct (erc--target-channel (:include erc--target))) |
| 78 | (cl-defstruct (erc--target-channel-local (:include erc--target-channel))) | 78 | (cl-defstruct (erc--target-channel-local (:include erc--target-channel))) |
| 79 | 79 | ||
| 80 | ;; Beginning in 5.5/29.1, the `tags' field may take on one of two | ||
| 81 | ;; differing types. See `erc-tags-format' for details. | ||
| 82 | |||
| 80 | (cl-defstruct (erc-response (:conc-name erc-response.)) | 83 | (cl-defstruct (erc-response (:conc-name erc-response.)) |
| 81 | (unparsed "" :type string) | 84 | (unparsed "" :type string) |
| 82 | (sender "" :type string) | 85 | (sender "" :type string) |