* riece-naming.el (riece-naming-assert-rename): Follow the
[riece] / lisp / riece-display.el
index 9a2400e..dcb834e 100644 (file)
 (require 'riece-misc)
 (require 'riece-layout)
 
-(defvar riece-update-buffer-functions
-  '(riece-update-user-list-buffer
-    riece-update-channel-list-buffer
-    riece-update-status-indicators
-    riece-update-channel-indicator
-    riece-update-short-channel-indicator
-    riece-update-channel-list-indicator))
+(defvar riece-channel-buffer-format "*Channel:%s*"
+  "Format of channel message buffer.")
+(defvar riece-channel-buffer-alist nil
+  "An alist mapping identities to channel buffers.")
 
-(defvar riece-redisplay-buffer nil
-  "Non-nil means the buffer needs to be updated.
-Local to the buffers.")
+(defvar riece-update-buffer-functions nil
+  "Functions to redisplay the buffer.
+Local to the buffer in `riece-buffer-list'.")
+  
+(defvar riece-update-indicator-functions
+  '(riece-update-status-indicators
+    riece-update-channel-indicator
+    riece-update-long-channel-indicator
+    riece-update-channel-list-indicator)
+  "Functions to update modeline indicators.")
 
 (defun riece-update-user-list-buffer ()
   (save-excursion
     (set-buffer riece-user-list-buffer)
-    (when (and riece-redisplay-buffer
-              riece-current-channel
-              (riece-channel-p (riece-identity-prefix riece-current-channel)))
-      (let (users operators speakers)
-       (with-current-buffer (process-buffer (riece-server-process
-                                             (riece-identity-server
-                                              riece-current-channel)))
-         (setq users
-               (riece-channel-get-users
-                (riece-identity-prefix riece-current-channel))
-               operators
-               (riece-channel-get-operators
-                (riece-identity-prefix riece-current-channel))
-               speakers
-               (riece-channel-get-speakers
-                (riece-identity-prefix riece-current-channel))))
-       (let ((inhibit-read-only t)
-             buffer-read-only)
+    (if (and riece-current-channel
+            (riece-channel-p (riece-identity-prefix riece-current-channel)))
+       (let* ((users
+               (with-current-buffer (process-buffer (riece-server-process
+                                                     (riece-identity-server
+                                                      riece-current-channel)))
+                 (riece-channel-get-users (riece-identity-prefix
+                                           riece-current-channel))))
+              (inhibit-read-only t)
+              buffer-read-only)
          (erase-buffer)
          (while users
-           (if (member (car users) operators)
-               (insert "@" (car users) "\n")
-             (if (member (car users) speakers)
-                 (insert "+" (car users) "\n")
-               (insert " " (car users) "\n")))
-           (setq users (cdr users)))))
-      (setq riece-redisplay-buffer nil))))
+           (insert (if (memq ?o (cdr (car users)))
+                       "@"
+                     (if (memq ?v (cdr (car users)))
+                         "+"
+                       " "))
+                   (riece-format-identity
+                    (riece-make-identity (car (car users))
+                                         (riece-identity-server
+                                          riece-current-channel))
+                    t)
+                   "\n")
+           (setq users (cdr users)))))))
 
 (defun riece-update-channel-list-buffer ()
   (save-excursion
     (set-buffer riece-channel-list-buffer)
-    (when riece-redisplay-buffer
-      (let ((inhibit-read-only t)
-           buffer-read-only
-           (index 1)
-           (channels riece-current-channels))
-       (erase-buffer)
-       (while channels
-         (if (car channels)
-             (let ((point (point)))
-               (insert (format "%2d: %s\n" index
-                               (riece-format-identity (car channels))))
-               (put-text-property point (point) 'riece-identity
-                                  (car channels))))
-         (setq index (1+ index)
-               channels (cdr channels))))
-      (setq riece-redisplay-buffer nil))))
+    (let ((inhibit-read-only t)
+         buffer-read-only
+         (index 1)
+         (channels riece-current-channels))
+      (erase-buffer)
+      (while channels
+       (if (car channels)
+           (insert (riece-format-channel-list-line
+                    index (car channels))))
+       (setq index (1+ index)
+             channels (cdr channels))))))
+
+(defun riece-format-channel-list-line (index channel)
+  (or (run-hook-with-args-until-success
+       'riece-format-channel-list-line-functions index channel)
+      (concat (format "%2d:%c" index
+                     (if (riece-identity-equal channel riece-current-channel)
+                         ?*
+                       ? ))
+             (riece-format-identity channel)
+             "\n")))
 
 (defun riece-update-channel-indicator ()
   (setq riece-channel-indicator
+       (if riece-current-channel
+           (riece-format-identity riece-current-channel)
+         "None")))
+
+(defun riece-update-long-channel-indicator ()
+  (setq riece-long-channel-indicator
        (if riece-current-channel
            (if (riece-channel-p (riece-identity-prefix riece-current-channel))
                (riece-concat-channel-modes
@@ -104,12 +116,6 @@ Local to the buffers.")
              (riece-format-identity riece-current-channel))
          "None")))
 
-(defun riece-update-short-channel-indicator ()
-  (setq riece-short-channel-indicator
-       (if riece-current-channel
-           (riece-format-identity riece-current-channel)
-         "None")))
-
 (defun riece-update-channel-list-indicator ()
   (if (and riece-current-channels
           ;; There is at least one channel.
@@ -121,9 +127,10 @@ Local to the buffers.")
               (delq nil
                     (mapcar
                      (lambda (channel)
-                       (prog1 (if channel
-                                  (format "%d:%s" index
-                                          (riece-format-identity channel)))
+                       (prog1
+                           (if channel
+                               (format "%d:%s" index
+                                       (riece-format-identity channel)))
                          (setq index (1+ index))))
                      riece-current-channels))
               ",")))
@@ -155,21 +162,35 @@ Local to the buffers.")
                "F"
              "-")))))
 
-(defun riece-update-buffers ()
-  (if riece-current-channel
-      (setq riece-channel-buffer (get-buffer (riece-channel-buffer-name
-                                             riece-current-channel))))
-  (run-hooks 'riece-update-buffer-functions)
-  (force-mode-line-update t))
+(defun riece-update-buffers (&optional buffers)
+  (unless buffers
+    (setq buffers riece-buffer-list))
+  (while buffers
+    (save-excursion
+      (set-buffer (car buffers))
+      (run-hooks 'riece-update-buffer-functions))
+    (setq buffers (cdr buffers)))
+  (run-hooks 'riece-update-indicator-functions)
+  (force-mode-line-update t)
+  (run-hooks 'riece-update-buffer-hook))
 
 (defun riece-channel-buffer-name (identity)
-  (format riece-channel-buffer-format (riece-format-identity identity)))
+  (let ((channels (riece-identity-member identity riece-current-channels)))
+    (if channels
+       (setq identity (car channels))
+      (if riece-debug
+         (message "%S is not a member of riece-current-channels" identity)))
+    (format riece-channel-buffer-format (riece-format-identity identity))))
 
 (eval-when-compile
   (autoload 'riece-channel-mode "riece"))
 (defun riece-channel-buffer-create (identity)
   (with-current-buffer
-      (riece-get-buffer-create (riece-channel-buffer-name identity))
+      (riece-get-buffer-create (riece-channel-buffer-name identity)
+                              'riece-channel-mode)
+    (setq riece-channel-buffer-alist
+         (cons (cons identity (current-buffer))
+               riece-channel-buffer-alist))
     (unless (eq major-mode 'riece-channel-mode)
       (riece-channel-mode)
       (let (buffer-read-only)
@@ -181,21 +202,26 @@ Local to the buffers.")
        (run-hook-with-args 'riece-channel-buffer-create-functions identity)))
     (current-buffer)))
 
+(defun riece-channel-buffer (identity)
+  (cdr (riece-identity-assoc identity riece-channel-buffer-alist)))
+
 (defun riece-switch-to-channel (identity)
-  (setq riece-last-channel riece-current-channel
-       riece-current-channel identity)
-  (with-current-buffer riece-user-list-buffer
-    (setq riece-redisplay-buffer t))
-  (run-hooks 'riece-channel-switch-hook))
+  (let ((last riece-current-channel))
+    (setq riece-current-channel identity
+         riece-channel-buffer (riece-channel-buffer riece-current-channel))
+    (run-hook-with-args 'riece-after-switch-to-channel-functions last)))
 
 (defun riece-join-channel (identity)
   (unless (riece-identity-member identity riece-current-channels)
     (setq riece-current-channels
-         (riece-identity-assign-binding identity riece-current-channels
-                                        riece-default-channel-binding))
-    (riece-channel-buffer-create identity)
-    (with-current-buffer riece-channel-list-buffer
-      (setq riece-redisplay-buffer t))))
+         (riece-identity-assign-binding
+          identity riece-current-channels
+          (mapcar
+           (lambda (channel)
+             (if channel
+                 (riece-parse-identity channel)))
+           riece-default-channel-binding)))
+    (riece-channel-buffer-create identity)))
 
 (defun riece-switch-to-nearest-channel (pointer)
   (let ((start riece-current-channels)
@@ -211,17 +237,16 @@ Local to the buffers.")
       (setq identity (car pointer)))
     (if identity
        (riece-switch-to-channel identity)
-      (setq riece-last-channel riece-current-channel
-           riece-current-channel nil))))
+      (let ((last riece-current-channel))
+       (run-hook-with-args 'riece-after-switch-to-channel-functions last)
+       (setq riece-current-channel nil)))))
 
 (defun riece-part-channel (identity)
   (let ((pointer (riece-identity-member identity riece-current-channels)))
     (if pointer
        (setcar pointer nil))
     (if (riece-identity-equal identity riece-current-channel)
-       (riece-switch-to-nearest-channel pointer))
-    (with-current-buffer riece-channel-list-buffer
-      (setq riece-redisplay-buffer t))))
+       (riece-switch-to-nearest-channel pointer))))
 
 (defun riece-redisplay-buffers (&optional force)
   (riece-update-buffers)