emacs-diffs
[Top][All Lists]
Advanced

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

master 23d692ed014 2/5: Populate erc--msg-prop-overrides for CTCP replie


From: F. Jason Park
Subject: master 23d692ed014 2/5: Populate erc--msg-prop-overrides for CTCP replies
Date: Sat, 23 Dec 2023 09:51:10 -0500 (EST)

branch: master
commit 23d692ed0149e9cda327141082cafdba1e1266fe
Author: F. Jason Park <jp@neverwas.me>
Commit: F. Jason Park <jp@neverwas.me>

    Populate erc--msg-prop-overrides for CTCP replies
    
    * lisp/erc/erc-backend.el (erc-server-PRIVMSG): Don't set string
    intended for insertion to the undefined return value of
    `erc-process-ctcp-reply' and `erc-process-ctcp-query'.  Rework control
    flow slightly for clarity.
    * lisp/erc/erc.el (erc-process-ctcp-reply): Bind
    `erc--msg-prop-overrides' and populate with `erc--ctcp' and `erc--cmd'
    "msg props" for the benefit of `erc-display-message' calls made by
    the various CTCP reply handlers.  (Bug#67677)
---
 lisp/erc/erc-backend.el | 53 ++++++++++++++++++++++---------------------------
 lisp/erc/erc.el         | 10 ++++++++--
 2 files changed, 32 insertions(+), 31 deletions(-)

diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el
index 0c336540483..6d30409e156 100644
--- a/lisp/erc/erc-backend.el
+++ b/lisp/erc/erc-backend.el
@@ -1996,8 +1996,8 @@ like `erc-insert-modify-hook'.")
              (erc--msg-prop-overrides `((erc--tmp) ,@erc--msg-prop-overrides))
              (erc--speaker-status-prefix-wanted-p nil)
              (erc-current-message-catalog erc--message-speaker-catalog)
-             s buffer statusmsg cmem-prefix
-             fnick)
+             ;;
+             buffer statusmsg cmem-prefix fnick)
         (setq buffer (erc-get-buffer (if privp nick tgt) proc))
         ;; Even worth checking for empty target here? (invalid anyway)
         (unless (or buffer noticep (string-empty-p tgt) (eq ?$ (aref tgt 0))
@@ -2042,36 +2042,31 @@ like `erc-insert-modify-hook'.")
                                          erc-show-speaker-membership-status
                                          inputp)
                                      (cdr cdata))))))
-        (cond
-         ((erc-is-message-ctcp-p msg)
-          ;; FIXME explain undefined return values being assigned to `s'.
-          (setq s (if-let ((parsed
-                            (erc--ctcp-response-from-parsed
-                             :parsed parsed :buffer buffer :statusmsg statusmsg
-                             :prefix cmem-prefix :dispname fnick))
-                           (msgp))
-                      (erc-process-ctcp-query proc parsed nick login host)
-                    (erc-process-ctcp-reply proc parsed nick login host
-                                            (match-string 1 msg)))))
-         (t
+        (if (erc-is-message-ctcp-p msg)
+            (if noticep
+                (erc-process-ctcp-reply proc parsed nick login host
+                                        (match-string 1 msg))
+              (setq parsed (erc--ctcp-response-from-parsed
+                            :parsed parsed :buffer buffer :statusmsg statusmsg
+                            :prefix cmem-prefix :dispname fnick))
+              (erc-process-ctcp-query proc parsed nick login host))
           (setq erc-server-last-peers (cons nick (cdr erc-server-last-peers)))
           (with-current-buffer (or buffer (current-buffer))
             ;; Re-bind in case either buffer has a local value.
-            (let ((erc-current-message-catalog erc--message-speaker-catalog))
-              (setq s (erc--determine-speaker-message-format-args
-                       nick msg privp msgp inputp statusmsg
-                       cmem-prefix fnick))))))
-        (when s
-          (if (and noticep privp)
-              (progn
-                (push (cons 'erc--msg (car s)) erc--msg-prop-overrides)
-                (setq s (apply #'erc-format-message s))
-                (run-hook-with-args 'erc-echo-notice-always-hook
-                                    s parsed buffer nick)
-                (run-hook-with-args-until-success
-                 'erc-echo-notice-hook s parsed buffer nick))
-            (apply #'erc-display-message parsed nil buffer
-                   (ensure-list s))))))))
+            (let ((erc-current-message-catalog erc--message-speaker-catalog)
+                  (msg-args (erc--determine-speaker-message-format-args
+                             nick msg privp msgp inputp statusmsg
+                             cmem-prefix fnick)))
+              (if (or msgp (not privp))
+                  ;; This is a PRIVMSG or a NOTICE to a channel.
+                  (apply #'erc-display-message parsed nil buffer msg-args)
+                ;; This is a NOTICE directed at the client's current nick.
+                (push (cons 'erc--msg (car msg-args)) erc--msg-prop-overrides)
+                (let ((fmtmsg (apply #'erc-format-message msg-args)))
+                  (run-hook-with-args 'erc-echo-notice-always-hook
+                                      fmtmsg parsed buffer nick)
+                  (run-hook-with-args-until-success
+                   'erc-echo-notice-hook fmtmsg parsed buffer nick))))))))))
 
 (define-erc-response-handler (QUIT)
   "Another user has quit IRC." nil
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 7071d8ca2d7..241e260e518 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -6528,8 +6528,14 @@ See also `erc-display-message'."
 (defun erc-process-ctcp-reply (proc parsed nick login host msg)
   "Process MSG as a CTCP reply."
   (let* ((type (car (split-string msg)))
-         (hook (intern (concat "erc-ctcp-reply-" type "-hook"))))
-    (if (boundp hook)
+         (hook (intern-soft (concat "erc-ctcp-reply-" type "-hook")))
+         ;; Help `erc-display-message' by ensuring subsequent
+         ;; insertions retain the necessary props.
+         (cmd (erc--get-eq-comparable-cmd (erc-response.command parsed)))
+         (erc--msg-prop-overrides `((erc--ctcp . ,(and hook (intern type)))
+                                    (erc--cmd . ,cmd)
+                                    ,@erc--msg-prop-overrides)))
+    (if (and hook (boundp hook))
         (run-hook-with-args-until-success
          hook proc nick login host
          (car (erc-response.command-args parsed)) msg)



reply via email to

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