* riece-filter.el (riece-sentinel): Don't clear
[riece] / lisp / riece-display.el
index 810bc1a..6dcec6a 100644 (file)
     riece-update-short-channel-indicator
     riece-update-channel-list-indicator))
 
-(defvar riece-redisplay-buffer nil
-  "Non-nil means the buffer needs to be updated.
-Local to the buffers.")
+(defvar riece-channel-list-changed nil)
 
 (defun riece-update-user-list-buffer ()
   (save-excursion
     (set-buffer riece-user-list-buffer)
-    (when (and riece-redisplay-buffer
-              riece-current-channel
+    (when (and riece-current-channel
               (riece-channel-p (riece-identity-prefix riece-current-channel)))
       (let (users operators speakers)
        (with-current-buffer (process-buffer (riece-server-process
@@ -69,28 +66,26 @@ Local to the buffers.")
              (if (member (car users) speakers)
                  (insert "+" (car users) "\n")
                (insert " " (car users) "\n")))
-           (setq users (cdr users)))))
-      (setq riece-redisplay-buffer nil))))
+           (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))))
+  (if riece-channel-list-changed
+      (save-excursion
+       (set-buffer riece-channel-list-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)))))))
 
 (defun riece-update-channel-indicator ()
   (setq riece-channel-indicator
@@ -111,23 +106,25 @@ Local to the buffers.")
          "None")))
 
 (defun riece-update-channel-list-indicator ()
-  (if (and riece-current-channels
-          ;; There is at least one channel.
-          (delq nil (copy-sequence riece-current-channels)))
-      (let ((index 1))
-       (setq riece-channel-list-indicator
-             (mapconcat
-              #'identity
-              (delq nil
-                    (mapcar
-                     (lambda (channel)
-                       (prog1 (if channel
-                                  (format "%d:%s" index
-                                          (riece-format-identity channel)))
-                         (setq index (1+ index))))
-                     riece-current-channels))
-              ",")))
-    (setq riece-channel-list-indicator "No channel")))
+  (if riece-channel-list-changed
+      (if (and riece-current-channels
+              ;; There is at least one channel.
+              (delq nil (copy-sequence riece-current-channels)))
+         (let ((index 1))
+           (setq riece-channel-list-indicator
+                 (mapconcat
+                  #'identity
+                  (delq nil
+                        (mapcar
+                         (lambda (channel)
+                           (prog1
+                               (if channel
+                                   (format "%d:%s" index
+                                           (riece-format-identity channel)))
+                             (setq index (1+ index))))
+                         riece-current-channels))
+                  ",")))
+       (setq riece-channel-list-indicator "No channel"))))
 
 (defun riece-update-status-indicators ()
   (if riece-current-channel
@@ -160,6 +157,7 @@ Local to the buffers.")
       (setq riece-channel-buffer (get-buffer (riece-channel-buffer-name
                                              riece-current-channel))))
   (run-hooks 'riece-update-buffer-functions)
+  (setq riece-channel-list-changed nil)
   (force-mode-line-update t))
 
 (defun riece-channel-buffer-name (identity)
@@ -182,11 +180,9 @@ Local to the buffers.")
     (current-buffer)))
 
 (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)
+    (run-hook-with-args 'riece-after-switch-to-channel-functions last)))
 
 (defun riece-join-channel (identity)
   (unless (riece-identity-member identity riece-current-channels)
@@ -199,8 +195,7 @@ Local to the buffers.")
                  (riece-parse-identity channel)))
            riece-default-channel-binding)))
     (riece-channel-buffer-create identity)
-    (with-current-buffer riece-channel-list-buffer
-      (setq riece-redisplay-buffer t))))
+    (setq riece-channel-list-changed t)))
 
 (defun riece-switch-to-nearest-channel (pointer)
   (let ((start riece-current-channels)
@@ -216,8 +211,9 @@ 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)))
@@ -225,8 +221,7 @@ Local to the buffers.")
        (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))))
+    (setq riece-channel-list-changed t)))
 
 (defun riece-redisplay-buffers (&optional force)
   (riece-update-buffers)