((setq erc-pre-send-functions (delq 'erc-send-distinguish-noncommands
erc-pre-send-functions))))
-(defun erc-send-distinguish-noncommands (str)
- "If STR is an ERC non-command, set `erc-insert-this' to nil."
- (let* ((command (erc-extract-command-from-line str))
+(defun erc-send-distinguish-noncommands (state)
+ "If STR is an ERC non-command, set `insertp' in STATE to nil."
+ (let* ((string (erc-input-string state))
+ (command (erc-extract-command-from-line string))
(cmd-fun (and command
(car command))))
- (if (and cmd-fun
- (not (string-match "\n.+$" str))
- (memq cmd-fun erc-noncommands-list))
- ;; Inhibit sending this string.
- nil
- str)))
+ (when (and cmd-fun
+ (not (string-match "\n.+$" string))
+ (memq cmd-fun erc-noncommands-list))
+ ;; Inhibit sending this string.
+ (setf (erc-input-insertp state) nil))))
;;; IRC control character processing.
(defgroup erc-control-characters nil
(setq erc-input-ring (make-ring comint-input-ring-size)))
(setq erc-input-ring-index nil))
-(defun erc-add-to-input-ring (s)
+(defun erc-add-to-input-ring (state)
"Add string S to the input ring and reset history position."
(unless erc-input-ring (erc-input-ring-setup))
- (ring-insert erc-input-ring s)
- (setq erc-input-ring-index nil)
- s)
+ (ring-insert erc-input-ring (erc-input-string state))
+ (setq erc-input-ring-index nil))
(defun erc-clear-input-ring ()
"Remove all entries from the input ring, then call garbage-collect.
(defcustom erc-pre-send-functions nil
"List of functions called to possibly alter the string that is sent.
-The functions are called with one argument, the string, and
-should return a string.
+The functions are called with one argument, a `erc-input' struct,
+and should alter that struct.
-To suppress the string completely, one of the functions should
-return nil."
+The struct has three slots:
+
+ `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."
:group 'erc
:type '(repeat function)
:version "27.1")
"Send the text to the target or not.
Functions on `erc-send-pre-hook' can set this variable to nil
if they wish to avoid sending of a particular string.")
-(make-obsolete-variable 'erc-insert-this 'erc-pre-send-functions "27.1")
+(make-obsolete-variable 'erc-send-this 'erc-pre-send-functions "27.1")
(defcustom erc-insert-modify-hook ()
"Insertion hook for functions that will change the text's appearance.
(defvar erc-command-regexp "^/\\([A-Za-z']+\\)\\(\\s-+.*\\|\\s-*\\)$"
"Regular expression used for matching commands in ERC.")
+(cl-defstruct erc-input
+ string insertp sendp)
+
(defun erc-send-input (input)
"Treat INPUT as typed in by the user. It is assumed that the input
and the prompt is already deleted.
(with-suppressed-warnings ((lexical str))
(defvar str))
(let ((str input)
- (erc-insert-this t))
- (setq erc-send-this t)
+ (erc-insert-this t)
+ (erc-send-this t)
+ state)
;; The calling convention of `erc-send-pre-hook' is that it
;; should change the dynamic variable `str' or set
;; `erc-send-this' to nil. This has now been deprecated:
;; Instead `erc-pre-send-functions' is used as a filter to do
;; allow both changing and suppressing the string.
(run-hook-with-args 'erc-send-pre-hook input)
+ (setq state (make-erc-input :string str
+ :insertp erc-insert-this
+ :sendp erc-send-this))
(dolist (func erc-pre-send-functions)
;; The functions can return nil to inhibit sending.
- (when str
- (setq str (funcall func str))))
- (when (and erc-send-this
- str)
- (if (or (string-match "\n" str)
- (not (string-match erc-command-regexp str)))
+ (funcall func state))
+ (when (and (erc-input-sendp state)
+ erc-send-this))
+ (let ((string (erc-input-string state)))
+ (if (or (string-match "\n" string)
+ (not (string-match erc-command-regexp string)))
(mapc
(lambda (line)
- (mapc
+ (mapc
(lambda (line)
;; Insert what has to be inserted for this.
- (erc-display-msg line)
+ (when (erc-input-insertp state)
+ (erc-display-msg line))
(erc-process-input-line (concat line "\n")
(null erc-flood-protect) t))
(or (and erc-flood-protect (erc-split-line line))
(list line))))
- (split-string str "\n"))
- (erc-process-input-line (concat str "\n") t nil))
+ (split-string string "\n"))
+ (erc-process-input-line (concat string "\n") t nil))
t)))))
(defun erc-display-command (line)