Include the message sender in desktop notification
[riece] / lisp / riece-message.el
index ea6285f..05c6fff 100644 (file)
@@ -1,4 +1,4 @@
-;;; riece-message.el --- generate and display message line
+;;; riece-message.el --- generate and display message line -*- lexical-binding: t -*-
 ;; Copyright (C) 1999-2003 Daiki Ueno
 
 ;; Author: Daiki Ueno <ueno@unixuser.org>
 ;; Copyright (C) 1999-2003 Daiki Ueno
 
 ;; Author: Daiki Ueno <ueno@unixuser.org>
@@ -18,8 +18,8 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Code:
 
 
 ;;; Code:
 
@@ -30,7 +30,7 @@
 (require 'riece-misc)
 
 (defgroup riece-message nil
 (require 'riece-misc)
 
 (defgroup riece-message nil
-  "Messages"
+  "Display messages."
   :tag "Message"
   :prefix "riece-"
   :group 'riece)
   :tag "Message"
   :prefix "riece-"
   :group 'riece)
   :type 'function
   :group 'riece-message)
 
   :type 'function
   :group 'riece-message)
 
+(defcustom riece-message-format-function-alist nil
+  "Alist mapping message types to format functions."
+  :type 'list
+  :group 'riece-message)
+
 (defun riece-message-make-open-bracket (message)
   "Make `open-bracket' string for MESSAGE."
 (defun riece-message-make-open-bracket (message)
   "Make `open-bracket' string for MESSAGE."
-  (if (riece-message-own-p message)
-      ">"
-    (if (eq (riece-message-type message) 'notice)
-       "{"
+  (if (eq (riece-message-type message) 'notice)
+      "{"
+    (if (riece-message-own-p message)
+       ">"
       (if (riece-message-private-p message)
          "="
        (if (riece-message-external-p message)
       (if (riece-message-private-p message)
          "="
        (if (riece-message-external-p message)
 
 (defun riece-message-make-close-bracket (message)
   "Make `close-bracket' string for MESSAGE."
 
 (defun riece-message-make-close-bracket (message)
   "Make `close-bracket' string for MESSAGE."
-  (if (riece-message-own-p message)
-      "<"
-    (if (eq (riece-message-type message) 'notice)
-       "}"
+  (if (eq (riece-message-type message) 'notice)
+      "}"
+    (if (riece-message-own-p message)
+       "<"
       (if (riece-message-private-p message)
          "="
        (if (riece-message-external-p message)
       (if (riece-message-private-p message)
          "="
        (if (riece-message-external-p message)
                  (riece-message-target message))))
     (unless (riece-identity-member target riece-current-channels)
       (riece-join-channel target)
                  (riece-message-target message))))
     (unless (riece-identity-member target riece-current-channels)
       (riece-join-channel target)
-      ;; If you are not joined any channel,
+      ;; If you are not joined to any channel,
       ;; switch to the target immediately.
       (unless riece-current-channel
        (riece-switch-to-channel target)))
       ;; switch to the target immediately.
       (unless riece-current-channel
        (riece-switch-to-channel target)))
@@ -142,7 +147,7 @@ Normally they are *Dialogue* and/or *Others*."
        (list riece-dialogue-buffer riece-others-buffer)
       riece-dialogue-buffer)))
 
        (list riece-dialogue-buffer riece-others-buffer)
       riece-dialogue-buffer)))
 
-(defun riece-format-message (message &optional global)
+(defun riece-format-message-1 (message &optional global)
   (let ((open-bracket
         (funcall riece-message-make-open-bracket-function message))
        (close-bracket
   (let ((open-bracket
         (funcall riece-message-make-open-bracket-function message))
        (close-bracket
@@ -162,6 +167,12 @@ Normally they are *Dialogue* and/or *Others*."
                 " " (riece-message-text message)))
        "\n"))))
 
                 " " (riece-message-text message)))
        "\n"))))
 
+(defun riece-format-message (message &optional global)
+  (funcall (or (cdr (assq (riece-message-type message)
+                         riece-message-format-function-alist))
+              #'riece-format-message-1)
+          message global))
+
 (defun riece-display-message-1 (message)
   (let ((buffer (riece-message-buffer message))
        parent-buffers)
 (defun riece-display-message-1 (message)
   (let ((buffer (riece-message-buffer message))
        parent-buffers)
@@ -174,13 +185,14 @@ Normally they are *Dialogue* and/or *Others*."
     (setq parent-buffers (riece-message-parent-buffers message buffer))
     (riece-insert buffer (riece-format-message message))
     (riece-insert parent-buffers (riece-format-message message t))
     (setq parent-buffers (riece-message-parent-buffers message buffer))
     (riece-insert buffer (riece-format-message message))
     (riece-insert parent-buffers (riece-format-message message t))
-    (run-hook-with-args 'riece-after-display-message-functions message)))
+    (with-current-buffer buffer
+      (run-hook-with-args 'riece-after-display-message-functions message))))
 
 (defun riece-display-message (message)
   "Display MESSAGE object."
   (let ((functions riece-message-filter-functions))
     (setq message (copy-sequence message))
 
 (defun riece-display-message (message)
   "Display MESSAGE object."
   (let ((functions riece-message-filter-functions))
     (setq message (copy-sequence message))
-    (while functions
+    (while (and functions message)
       (setq message (funcall (car functions) message)
            functions (cdr functions)))
     (if message
       (setq message (funcall (car functions) message)
            functions (cdr functions)))
     (if message
@@ -191,7 +203,7 @@ Normally they are *Dialogue* and/or *Others*."
 Arguments are appropriate to the sender, the receiver, and text
 content, respectively.
 Optional 4th argument TYPE specifies the type of the message.
 Arguments are appropriate to the sender, the receiver, and text
 content, respectively.
 Optional 4th argument TYPE specifies the type of the message.
-Currently possible values are `action' and `notice'.
+Currently possible values are `nil' or `notice'.
 Optional 5th argument is the flag to indicate that this message is not
 from the network."
   (vector speaker target text type own-p))
 Optional 5th argument is the flag to indicate that this message is not
 from the network."
   (vector speaker target text type own-p))