emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 3fb6993 2/2: Fix previous change to erc (where comm


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] master 3fb6993 2/2: Fix previous change to erc (where commands like /me wouldn't be sent)
Date: Wed, 19 Jun 2019 11:07:50 -0400 (EDT)

branch: master
commit 3fb6993c8ddf433fab4b98ae2948b961482ef947
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>

    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.
---
 lisp/erc/erc-goodies.el | 18 +++++++++---------
 lisp/erc/erc-ring.el    |  7 +++----
 lisp/erc/erc.el         | 45 ++++++++++++++++++++++++++++-----------------
 3 files changed, 40 insertions(+), 30 deletions(-)

diff --git a/lisp/erc/erc-goodies.el b/lisp/erc/erc-goodies.el
index ff5539e..7a39105 100644
--- a/lisp/erc/erc-goodies.el
+++ b/lisp/erc/erc-goodies.el
@@ -181,17 +181,17 @@ themselves."
   ((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
diff --git a/lisp/erc/erc-ring.el b/lisp/erc/erc-ring.el
index aaf4bd8..ea57fae 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."
     (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.
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 0165f2c..8d5c972 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -1055,11 +1055,14 @@ anyway."
 
 (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")
@@ -1073,7 +1076,7 @@ if they wish to avoid insertion of a particular string.")
   "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.
@@ -5437,6 +5440,9 @@ submitted line to be intentional."
 (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.
@@ -5458,34 +5464,39 @@ This returns non-nil only if we actually send anything."
     (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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]