aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2019-06-19 17:07:36 +0200
committerLars Ingebrigtsen2019-06-19 17:07:41 +0200
commit3fb6993c8ddf433fab4b98ae2948b961482ef947 (patch)
tree44283e60c21dc9a89e444a1abf7c101c7c508af2
parent12efa07f95d96fe42d6c72794e3bf4fac62a4bf4 (diff)
downloademacs-3fb6993c8ddf433fab4b98ae2948b961482ef947.tar.gz
emacs-3fb6993c8ddf433fab4b98ae2948b961482ef947.zip
Fix previous change to erc (where commands like /me wouldn't be sent)
* lisp/erc/erc-ring.el (erc-add-to-input-ring): * lisp/erc/erc-goodies.el (erc-send-distinguish-noncommands): Pass in a erc-input structure instead of a simple string. * lisp/erc/erc.el (erc-pre-send-functions): Document the new argument to the filter functions. (erc-send-input): Use the new structure to allow the filter functions to alter all three things: The string, whether to insert the string, and whether to send the string.
-rw-r--r--lisp/erc/erc-goodies.el18
-rw-r--r--lisp/erc/erc-ring.el7
-rw-r--r--lisp/erc/erc.el45
3 files changed, 40 insertions, 30 deletions
diff --git a/lisp/erc/erc-goodies.el b/lisp/erc/erc-goodies.el
index ff5539e7928..7a3910567ab 100644
--- a/lisp/erc/erc-goodies.el
+++ b/lisp/erc/erc-goodies.el
@@ -181,17 +181,17 @@ themselves."
181 ((setq erc-pre-send-functions (delq 'erc-send-distinguish-noncommands 181 ((setq erc-pre-send-functions (delq 'erc-send-distinguish-noncommands
182 erc-pre-send-functions)))) 182 erc-pre-send-functions))))
183 183
184(defun erc-send-distinguish-noncommands (str) 184(defun erc-send-distinguish-noncommands (state)
185 "If STR is an ERC non-command, set `erc-insert-this' to nil." 185 "If STR is an ERC non-command, set `insertp' in STATE to nil."
186 (let* ((command (erc-extract-command-from-line str)) 186 (let* ((string (erc-input-string state))
187 (command (erc-extract-command-from-line string))
187 (cmd-fun (and command 188 (cmd-fun (and command
188 (car command)))) 189 (car command))))
189 (if (and cmd-fun 190 (when (and cmd-fun
190 (not (string-match "\n.+$" str)) 191 (not (string-match "\n.+$" string))
191 (memq cmd-fun erc-noncommands-list)) 192 (memq cmd-fun erc-noncommands-list))
192 ;; Inhibit sending this string. 193 ;; Inhibit sending this string.
193 nil 194 (setf (erc-input-insertp state) nil))))
194 str)))
195 195
196;;; IRC control character processing. 196;;; IRC control character processing.
197(defgroup erc-control-characters nil 197(defgroup erc-control-characters nil
diff --git a/lisp/erc/erc-ring.el b/lisp/erc/erc-ring.el
index aaf4bd8c499..ea57faebc45 100644
--- a/lisp/erc/erc-ring.el
+++ b/lisp/erc/erc-ring.el
@@ -72,12 +72,11 @@ Call this function when setting up the mode."
72 (setq erc-input-ring (make-ring comint-input-ring-size))) 72 (setq erc-input-ring (make-ring comint-input-ring-size)))
73 (setq erc-input-ring-index nil)) 73 (setq erc-input-ring-index nil))
74 74
75(defun erc-add-to-input-ring (s) 75(defun erc-add-to-input-ring (state)
76 "Add string S to the input ring and reset history position." 76 "Add string S to the input ring and reset history position."
77 (unless erc-input-ring (erc-input-ring-setup)) 77 (unless erc-input-ring (erc-input-ring-setup))
78 (ring-insert erc-input-ring s) 78 (ring-insert erc-input-ring (erc-input-string state))
79 (setq erc-input-ring-index nil) 79 (setq erc-input-ring-index nil))
80 s)
81 80
82(defun erc-clear-input-ring () 81(defun erc-clear-input-ring ()
83 "Remove all entries from the input ring, then call garbage-collect. 82 "Remove all entries from the input ring, then call garbage-collect.
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 0165f2c4703..8d5c9728285 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -1055,11 +1055,14 @@ anyway."
1055 1055
1056(defcustom erc-pre-send-functions nil 1056(defcustom erc-pre-send-functions nil
1057 "List of functions called to possibly alter the string that is sent. 1057 "List of functions called to possibly alter the string that is sent.
1058The functions are called with one argument, the string, and 1058The functions are called with one argument, a `erc-input' struct,
1059should return a string. 1059and should alter that struct.
1060 1060
1061To suppress the string completely, one of the functions should 1061The struct has three slots:
1062return nil." 1062
1063 `string': The current input string.
1064 `insertp': Whether the string should be inserted into the erc buffer.
1065 `sendp': Whether the string should be sent to the irc server."
1063 :group 'erc 1066 :group 'erc
1064 :type '(repeat function) 1067 :type '(repeat function)
1065 :version "27.1") 1068 :version "27.1")
@@ -1073,7 +1076,7 @@ if they wish to avoid insertion of a particular string.")
1073 "Send the text to the target or not. 1076 "Send the text to the target or not.
1074Functions on `erc-send-pre-hook' can set this variable to nil 1077Functions on `erc-send-pre-hook' can set this variable to nil
1075if they wish to avoid sending of a particular string.") 1078if they wish to avoid sending of a particular string.")
1076(make-obsolete-variable 'erc-insert-this 'erc-pre-send-functions "27.1") 1079(make-obsolete-variable 'erc-send-this 'erc-pre-send-functions "27.1")
1077 1080
1078(defcustom erc-insert-modify-hook () 1081(defcustom erc-insert-modify-hook ()
1079 "Insertion hook for functions that will change the text's appearance. 1082 "Insertion hook for functions that will change the text's appearance.
@@ -5437,6 +5440,9 @@ submitted line to be intentional."
5437(defvar erc-command-regexp "^/\\([A-Za-z']+\\)\\(\\s-+.*\\|\\s-*\\)$" 5440(defvar erc-command-regexp "^/\\([A-Za-z']+\\)\\(\\s-+.*\\|\\s-*\\)$"
5438 "Regular expression used for matching commands in ERC.") 5441 "Regular expression used for matching commands in ERC.")
5439 5442
5443(cl-defstruct erc-input
5444 string insertp sendp)
5445
5440(defun erc-send-input (input) 5446(defun erc-send-input (input)
5441 "Treat INPUT as typed in by the user. It is assumed that the input 5447 "Treat INPUT as typed in by the user. It is assumed that the input
5442and the prompt is already deleted. 5448and the prompt is already deleted.
@@ -5458,34 +5464,39 @@ This returns non-nil only if we actually send anything."
5458 (with-suppressed-warnings ((lexical str)) 5464 (with-suppressed-warnings ((lexical str))
5459 (defvar str)) 5465 (defvar str))
5460 (let ((str input) 5466 (let ((str input)
5461 (erc-insert-this t)) 5467 (erc-insert-this t)
5462 (setq erc-send-this t) 5468 (erc-send-this t)
5469 state)
5463 ;; The calling convention of `erc-send-pre-hook' is that it 5470 ;; The calling convention of `erc-send-pre-hook' is that it
5464 ;; should change the dynamic variable `str' or set 5471 ;; should change the dynamic variable `str' or set
5465 ;; `erc-send-this' to nil. This has now been deprecated: 5472 ;; `erc-send-this' to nil. This has now been deprecated:
5466 ;; Instead `erc-pre-send-functions' is used as a filter to do 5473 ;; Instead `erc-pre-send-functions' is used as a filter to do
5467 ;; allow both changing and suppressing the string. 5474 ;; allow both changing and suppressing the string.
5468 (run-hook-with-args 'erc-send-pre-hook input) 5475 (run-hook-with-args 'erc-send-pre-hook input)
5476 (setq state (make-erc-input :string str
5477 :insertp erc-insert-this
5478 :sendp erc-send-this))
5469 (dolist (func erc-pre-send-functions) 5479 (dolist (func erc-pre-send-functions)
5470 ;; The functions can return nil to inhibit sending. 5480 ;; The functions can return nil to inhibit sending.
5471 (when str 5481 (funcall func state))
5472 (setq str (funcall func str)))) 5482 (when (and (erc-input-sendp state)
5473 (when (and erc-send-this 5483 erc-send-this))
5474 str) 5484 (let ((string (erc-input-string state)))
5475 (if (or (string-match "\n" str) 5485 (if (or (string-match "\n" string)
5476 (not (string-match erc-command-regexp str))) 5486 (not (string-match erc-command-regexp string)))
5477 (mapc 5487 (mapc
5478 (lambda (line) 5488 (lambda (line)
5479 (mapc 5489 (mapc
5480 (lambda (line) 5490 (lambda (line)
5481 ;; Insert what has to be inserted for this. 5491 ;; Insert what has to be inserted for this.
5482 (erc-display-msg line) 5492 (when (erc-input-insertp state)
5493 (erc-display-msg line))
5483 (erc-process-input-line (concat line "\n") 5494 (erc-process-input-line (concat line "\n")
5484 (null erc-flood-protect) t)) 5495 (null erc-flood-protect) t))
5485 (or (and erc-flood-protect (erc-split-line line)) 5496 (or (and erc-flood-protect (erc-split-line line))
5486 (list line)))) 5497 (list line))))
5487 (split-string str "\n")) 5498 (split-string string "\n"))
5488 (erc-process-input-line (concat str "\n") t nil)) 5499 (erc-process-input-line (concat string "\n") t nil))
5489 t))))) 5500 t)))))
5490 5501
5491(defun erc-display-command (line) 5502(defun erc-display-command (line)