From 8c712dc9f0adbfb02da35a2379a739e114939e89 Mon Sep 17 00:00:00 2001
From: Case Duckworth
Date: Mon, 3 Jan 2022 17:05:03 -0600
Subject: Format circe messages better

---
 init.el        | 98 +++++++++++++++++++++++++++++++++++++++++++++-------------
 lisp/+circe.el | 18 +++++++++--
 2 files changed, 91 insertions(+), 25 deletions(-)

diff --git a/init.el b/init.el
index 7cc4e43..066741a 100644
--- a/init.el
+++ b/init.el
@@ -549,28 +549,82 @@
   (:also-load circe-chanop)
 
   ;; Formatting options
-  (:option circe-format-action (format (format "%%%ds* {nick} {body}"
-                                               (- +circe-left-margin 2))
-                                       " ")
-           circe-format-say (format "{nick:%1$d.%1$ds} | {body}"
-                                    (- +circe-left-margin 3))
-           circe-format-self-action circe-format-action
-           circe-format-self-say (replace-regexp-in-string "|" ">"
-                                                           circe-format-say)
-           circe-format-server-part (+circe-format-meta
-                                     "PART {channel}: {reason}")
-           circe-format-server-quit (+circe-format-meta "QUIT: {reason}")
-           circe-format-server-quit-channel (+circe-format-meta
-                                             "QUIT {channel}: {reason}")
-           circe-format-server-join (+circe-format-meta "JOIN: {userinfo}")
-           circe-format-server-rejoin (+circe-format-meta
-                                       (concat "REJOIN: {userinfo} "
-                                               "after {departuredelta}"))
-           circe-format-server-topic (+circe-format-meta
-                                      "TOPIC: {new-topic}")
-           circe-prompt-string (format (format "%%%ds> "
-                                               (- +circe-left-margin 2))
-                                       " "))
+  (:option
+   ;; Messages between users
+   circe-format-action (format (format "%%%ds* {nick} {body}"
+                                       (- +circe-left-margin 2))
+                               " ")
+   circe-format-say (format "{nick:%1$d.%1$ds} | {body}"
+                            (- +circe-left-margin 3))
+   circe-format-self-action circe-format-action
+   circe-format-self-say (replace-regexp-in-string "|" ">" circe-format-say)
+   circe-format-notice (format "-{nick:%1$d.%1$ds}---{body}"
+                               (- +circe-left-margin 4))
+   circe-format-message (format (format "%%%ds@ *{nick}* {body}"
+                                        (- +circe-left-margin 2))
+                                " ")
+   circe-format-message-action (replace-regexp-in-string "@" "*"
+                                                         circe-format-message)
+   circe-format-self-message (format (format "%%%ds> *{chattarget}* {body}"
+                                             (- +circe-left-margin 2))
+                                     " ")
+   ;; Meta messages
+   circe-format-server-channel-creation-time (+circe-format-meta
+                                              (concat "Channel {channel}"
+                                                      " created on {date}") t)
+   circe-format-server-ctcp (+circe-format-meta
+                             (concat "CTCP PING request to {target} from"
+                                     " {userhost}: {body}"))
+   circe-format-server-ctcp-ping-reply (+circe-format-meta
+                                        (concat
+                                         "CTCP PING reply to {target} from"
+                                         " {userhost}: {body}"))
+   circe-format-server-part (+circe-format-meta "PART {channel}: {reason}")
+   circe-format-server-quit (+circe-format-meta "QUIT: {reason}")
+   circe-format-server-quit-channel (+circe-format-meta
+                                     "QUIT {channel}: {reason}")
+   circe-format-server-join (+circe-format-meta "JOIN: {userinfo}")
+   circe-format-server-join-in-channel (+circe-format-meta
+                                        "JOIN {channel}: {userinfo}")
+   circe-format-server-lurker-activity (+circe-format-meta
+                                        "(JOINED {joindelta} ago)")
+   circe-format-server-message (+circe-format-meta "{body}" t)
+   circe-fromat-server-mode-change (+circe-format-meta
+                                    (concat "MODE: {target} {change}"
+                                            " by {setter} ({userhost})") t)
+   circe-format-server-netmerge (+circe-format-meta
+                                 (concat "NETMERGE: {split} at {date}"
+                                         " (/WL to see who's still missing)") t)
+   circe-format-server-netsplit (+circe-format-meta
+                                 (concat "NETSPLIT: {split}"
+                                         " (/WL to see who left)") t)
+   circe-format-server-nick-change (+circe-format-meta
+                                    "NICK WAS {old-nick} ({userhost})"
+                                    "new-nick")
+   circe-format-server-nick-regain (+circe-format-meta
+                                    "NICK REGAINED: {old-nick} ({userhost})"
+                                    "new-nick")
+   circe-format-server-notice (+circe-format-meta "-SERVER NOTICE- {body}" t)
+   circe-format-server-topic-time (+circe-format-meta
+                                   "TOPIC SET BY {setter} on {topic-date}")
+   circe-format-server-topic-time-for-channel (+circe-format-meta
+                                               (concat
+                                                "TOPIC ({channel}) SET BY"
+                                                " {setter} on {topic-date}"))
+   circe-format-server-whois-idle (+circe-format-meta "IDLE FOR {idle-duration}"
+                                                      "whois-nick")
+   circe-format-server-whois-idle-with-signon (+circe-format-meta
+                                               (concat
+                                                "IDLE FOR {idle-duration}"
+                                                " (signon: {signon-date})")
+                                               "whois-nick")
+   circe-format-server-rejoin (+circe-format-meta
+                               (concat "REJOIN: {userinfo} "
+                                       "after {departuredelta}"))
+   circe-format-server-topic (+circe-format-meta "TOPIC: {new-topic}")
+   circe-prompt-string (format (format "%%%ds> "
+                                       (- +circe-left-margin 2))
+                               " "))
 
   (:option +circe-server-buffer-action (lambda (buf)
                                          (message "Connected to %s" buf))
diff --git a/lisp/+circe.el b/lisp/+circe.el
index 9078907..501bd21 100644
--- a/lisp/+circe.el
+++ b/lisp/+circe.el
@@ -66,9 +66,21 @@ message the current topic."
 
 ;;; Formatting messages
 
-(defun +circe-format-meta (string)
-  "Return a format string for `lui-format' for metadata messages."
-  (format "{nick:%1$d.%1$ds} *** %s" (- +circe-left-margin 3) string))
+(defun +circe-format-meta (string &optional no-nick)
+  "Return a format string for `lui-format' for metadata messages.
+Include nick unless NO-NICK is non-nil.  If NO-NICK is a string,
+replace {nick} in the string with {NO-NICK}."
+  (cond
+   ((stringp no-nick)
+    (format "{%1$s:%2$d.%2$ds} *** %3$s"
+            no-nick (- +circe-left-margin 3) string))
+   (no-nick
+    (format (format "%%%ds *** %s" (- +circe-left-margin 3) string) " "))
+   (t
+    (format "{nick:%1$d.%1$ds} *** %s" (- +circe-left-margin 3) string))))
+
+(defun +circe-format-meta* (string)
+  "Return a format string for `lui-format' for metadata messages, /without/ ")
 
 (defmacro +lui-make-formatting-list-rx (char)
   "Make a formatting regex for CHAR delimiters.
-- 
cgit 1.4.1-21-gabe81