before showing hook members the result. For compatibility,
third-party code can request that the final input be adjusted again
prior to being sent. To facilitate this, the 'erc-input' object
-shared among hook members has gained a new 'refoldp' slot, making this
-a breaking change, if only in theory. See doc string for details.
+shared among hook members has gained a "phony" 'refoldp' slot that's
+only accessible from 'erc-pre-send-functions'. See doc string for
+details.
*** ERC's prompt survives the insertion of user input and messages.
Previously, ERC's prompt and its input marker disappeared while
`string': The current input string.
`insertp': Whether the string should be inserted into the erc buffer.
`sendp': Whether the string should be sent to the irc server.
+
+And one \"phony\" slot only accessible by hook members at runtime:
+
`refoldp': Whether the string should be re-split per protocol limits.
This hook runs after protocol line splitting has taken place, so
the value of `string' is originally \"pre-filled\". If you need
-ERC to refill the entire payload before sending it, set the
-`refoldp' slot to a non-nil value. Preformatted text and encoded
-subprotocols should probably be handled manually."
+ERC to refill the entire payload before sending it, set the phony
+`refoldp' slot to a non-nil value. Note that this refilling is
+only a convenience, and modules with special needs, such as
+preserving \"preformatted\" text or encoding for subprotocol
+\"tunneling\", should handle splitting manually."
:group 'erc
:type 'hook
:version "27.1")
(setf (erc--input-split-lines state)
(mapcan #'erc--split-line (erc--input-split-lines state)))))
+(defun erc--input-ensure-hook-context ()
+ (unless (erc--input-split-p erc--current-line-input-split)
+ (error "Invoked outside of `erc-pre-send-functions'")))
+
+(defun erc-input-refoldp (_)
+ "Impersonate accessor for phony `erc-input' `refoldp' slot.
+This function only works inside `erc-pre-send-functions' members."
+ (declare (gv-setter (lambda (v)
+ `(progn
+ (erc--input-ensure-hook-context)
+ (setf (erc--input-split-refoldp
+ erc--current-line-input-split)
+ ,v)))))
+ (erc--input-ensure-hook-context)
+ (erc--input-split-refoldp erc--current-line-input-split))
+
(defun erc--run-send-hooks (lines-obj)
"Run send-related hooks that operate on the entire prompt input.
Sequester some of the back and forth involved in honoring old
(run-hook-with-args 'erc-send-pre-hook str)
(make-erc-input :string str
:insertp erc-insert-this
- :refoldp (erc--input-split-refoldp
- lines-obj)
:sendp erc-send-this))))
(run-hook-with-args 'erc-pre-send-functions state)
(setf (erc--input-split-sendp lines-obj) (erc-input-sendp state)
(if erc--allow-empty-outgoing-lines-p
lines
(cl-nsubst " " "" lines :test #'equal))))
- (when (erc-input-refoldp state)
+ (when (erc--input-split-refoldp lines-obj)
(erc--split-lines lines-obj)))))
(when (and (erc--input-split-cmdp lines-obj)
(cdr (erc--input-split-lines lines-obj)))
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))
+ (let* ((split (make-erc--input-split :string "foo" :lines '("foo")))
+ (erc--current-line-input-split split)
+ (erc-split-line-length 8))
(should
- (pcase (erc--run-send-hooks (make-erc--input-split
- :string "foo" :lines '("foo")))
+ (pcase (erc--run-send-hooks split)
((cl-struct erc--input-split
(string "foo") (sendp 't) (insertp 't)
(lines '("foo bar " "baz")) (cmdp 'nil))