* riece-mini.el (riece-mini-backlog-size): Change default value.
[riece] / lisp / riece-mini.el
index 1291e6c..1b23e6a 100644 (file)
 ;; To use, add the following line to your ~/.riece/init.el:
 ;; (add-to-list 'riece-addons 'riece-mini)
 ;;
 ;; To use, add the following line to your ~/.riece/init.el:
 ;; (add-to-list 'riece-addons 'riece-mini)
 ;;
-;; And for using conveniently, bind any global key to
-;; `riece-mini-send-message'.
+;; For using conveniently, bind any global key to
+;; `riece-mini-send-message' and `riece-mini-show-backlog'.
 ;; For example:
 ;; (global-set-key "\C-cm" 'riece-mini-send-message)
 ;; For example:
 ;; (global-set-key "\C-cm" 'riece-mini-send-message)
+;; (global-set-key "\C-cb" 'riece-mini-show-backlog)
 
 ;;; Code:
 
 (require 'riece-message)
 
 
 ;;; Code:
 
 (require 'riece-message)
 
+(defgroup riece-mini nil
+  "riece on minibuffer"
+  :group 'riece)
+
+(defcustom riece-mini-backlog-size 5
+  "*Line numbers for logging back log."
+  :type 'integer
+  :group 'riece-mini)
+
 (defvar riece-mini-last-channel nil)
 (defvar riece-mini-last-channel nil)
+(defvar riece-mini-backlog-history nil)
+(defvar riece-mini-backlog-shown nil)
 
 (defvar riece-mini-enabled nil)
 
 
 (defvar riece-mini-enabled nil)
 
 
 (defun riece-mini-display-message-function (message)
   "Show arrival messages to minibuffer."
 
 (defun riece-mini-display-message-function (message)
   "Show arrival messages to minibuffer."
-  (when (and riece-mini-enabled
-            (not (or (eq (window-buffer (selected-window))
-                         (get-buffer riece-command-buffer))
-                     (riece-message-own-p message)
-                     (active-minibuffer-window))))
-    (unless (riece-message-type message)
-      (setq riece-mini-last-channel (riece-message-target message)))
-    (riece-mini-message-no-log
-     "%s" (concat (format-time-string "%H:%M") " "
-                 (riece-format-message message t)))))
+  (let ((string (concat (format-time-string "%H:%M") " "
+                       (riece-format-message message t))))
+    (when (string-match "\\(.*\\)$" string)
+      (setq string (riece-match-string-no-properties 1 string)))
+    (while (>= (length riece-mini-backlog-history)
+              riece-mini-backlog-size)
+      (setq riece-mini-backlog-history
+           (cdr riece-mini-backlog-history)))
+    (setq riece-mini-backlog-history
+         (reverse (cons string (reverse riece-mini-backlog-history))))
+    (when (and riece-mini-enabled
+              (not (or (eq (window-buffer (selected-window))
+                           (get-buffer riece-command-buffer))
+                       (riece-message-own-p message)
+                       (active-minibuffer-window))))
+      (unless (riece-message-type message)
+       (setq riece-mini-last-channel (riece-message-target message)))
+      (riece-mini-message-no-log "%s" string))))
 
 (defun riece-mini-send-message (arg)
   "Send message using minibuffer.
 
 (defun riece-mini-send-message (arg)
   "Send message using minibuffer.
@@ -94,9 +114,31 @@ If twice (C-u C-u), then ask the channel."
        (riece-make-message (riece-current-nickname) target
                           message nil t)))))
 
        (riece-make-message (riece-current-nickname) target
                           message nil t)))))
 
+(defun riece-mini-show-backlog ()
+  "Send back logs to minibuffer."
+  (interactive)
+  (when riece-mini-backlog-history
+    (let ((height (1+ riece-mini-backlog-size)))
+      (mapc #'(lambda (string)
+               (setq height (+ height
+                               (/ (length string) (window-width)))))
+           riece-mini-backlog-history)
+      (let ((max-mini-window-height height)
+           (resize-mini-windows t))
+       (setq riece-mini-backlog-shown t)
+       (riece-mini-message-no-log
+        "%s" (mapconcat #'identity riece-mini-backlog-history "\n"))))))
+
+(defun riece-mini-pre-command ()
+  (when riece-mini-backlog-shown
+    (let ((resize-mini-windows t))
+      (setq riece-mini-backlog-shown nil)
+      (riece-mini-message-no-log ""))))
+
 (defun riece-mini-insinuate ()
   (add-hook 'riece-after-display-message-functions
 (defun riece-mini-insinuate ()
   (add-hook 'riece-after-display-message-functions
-           'riece-mini-display-message-function))
+           'riece-mini-display-message-function)
+  (add-hook 'pre-command-hook 'riece-mini-pre-command))
 
 (defun riece-mini-enable ()
   (setq riece-mini-enabled t))
 
 (defun riece-mini-enable ()
   (setq riece-mini-enabled t))