1 ;;; riece-mini.el --- "riece on minibuffer" add-on
2 ;; Copyright (C) 2003 OHASHI Akira
4 ;; Author: OHASHI Akira <bg66@koka-in.org>
5 ;; Keywords: IRC, riece
7 ;; This file is part of Riece.
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
26 ;; This add-on shows arrival messages to minibuffer. And you can send
27 ;; message using minibuffer.
29 ;; By using this add-on, you can use always "mini riece", even if you
30 ;; are visiting other buffers.
32 ;; To use, add the following line to your ~/.riece/init.el:
33 ;; (add-to-list 'riece-addons 'riece-mini)
35 ;; For using conveniently, bind any global key to
36 ;; `riece-mini-send-message' and `riece-mini-show-backlog'.
38 ;; (global-set-key "\C-cm" 'riece-mini-send-message)
39 ;; (global-set-key "\C-cb" 'riece-mini-show-backlog)
43 (require 'riece-message)
45 (defgroup riece-mini nil
49 (defcustom riece-mini-backlog-size 10
50 "*Line numbers for logging back log."
54 (defvar riece-mini-last-channel nil)
55 (defvar riece-mini-backlog-history nil)
56 (defvar riece-mini-backlog-shown nil)
58 (defvar riece-mini-enabled nil)
60 (defconst riece-mini-description
61 "Send arrival messages to minibuffer")
63 (defmacro riece-mini-message-no-log (string &rest args)
64 "Like `message', except that message logging is disabled."
65 (if (featurep 'xemacs)
67 `(display-message 'no-log (format ,string ,@args))
68 `(display-message 'no-log ,string))
69 `(let (message-log-max)
70 (message ,string ,@args))))
72 (defun riece-mini-display-message-function (message)
73 "Show arrival messages to minibuffer."
74 (when (and riece-mini-enabled
75 (not (or (eq (window-buffer (selected-window))
76 (get-buffer riece-command-buffer))
77 (riece-message-own-p message)
78 (active-minibuffer-window))))
79 (unless (riece-message-type message)
80 (setq riece-mini-last-channel (riece-message-target message)))
81 (let ((string (concat (format-time-string "%H:%M") " "
82 (riece-format-message message t))))
83 (when (string-match "\\(.*\\)$" string)
84 (setq string (riece-match-string-no-properties 1 string)))
85 (riece-mini-message-no-log "%s" string)
86 (while (>= (length riece-mini-backlog-history)
87 riece-mini-backlog-size)
88 (setq riece-mini-backlog-history
89 (cdr riece-mini-backlog-history)))
90 (setq riece-mini-backlog-history
91 (reverse (cons string (reverse riece-mini-backlog-history)))))))
93 (defun riece-mini-send-message (arg)
94 "Send message using minibuffer.
95 Prefix argument onece (C-u), send message to last received channel.
96 If twice (C-u C-u), then ask the channel."
98 (let* ((completion-ignore-case t)
102 (riece-completing-read-identity
103 "Channel/User: " riece-current-channels nil t))
104 (arg (or riece-mini-last-channel riece-current-channel))
105 (t riece-current-channel)))
106 (message (read-string (format "Message to %s: " target))))
107 (unless (equal message "")
108 (riece-switch-to-channel target)
110 (format "PRIVMSG %s :%s\r\n"
111 (riece-identity-prefix target)
113 (riece-display-message
114 (riece-make-message (riece-current-nickname) target
117 (defun riece-mini-show-backlog ()
118 "Send back logs to minibuffer."
120 (let ((max-mini-window-height (1+ riece-mini-backlog-size)
121 (resize-mini-windows t))
122 (when riece-mini-backlog-history
123 (setq riece-mini-backlog-shown t)
124 (riece-mini-message-no-log
125 (mapconcat 'identity riece-mini-backlog-history "\n")))))
127 (defun riece-mini-pre-command ()
128 (when riece-mini-backlog-shown
129 (let ((resize-mini-windows t))
130 (setq riece-mini-backlog-shown nil)
131 (riece-mini-message-no-log ""))))
133 (defun riece-mini-insinuate ()
134 (add-hook 'riece-after-display-message-functions
135 'riece-mini-display-message-function)
136 (add-hook 'pre-command-hook 'riece-mini-pre-command))
138 (defun riece-mini-enable ()
139 (setq riece-mini-enabled t))
141 (defun riece-mini-disable ()
142 (setq riece-mini-enabled nil))
144 (provide 'riece-mini)
146 ;;; riece-mini.el ends here