* Riece: Version 0.1.7 released.
[riece] / lisp / riece-mini.el
1 ;;; riece-mini.el --- "riece on minibuffer" add-on
2 ;; Copyright (C) 2003 OHASHI Akira
3
4 ;; Author: OHASHI Akira <bg66@koka-in.org>
5 ;; Keywords: IRC, riece
6
7 ;; This file is part of Riece.
8
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)
12 ;; any later version.
13
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.
18
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.
23
24 ;;; Commentary:
25
26 ;; This add-on shows arrival messages to minibuffer. And you can send
27 ;; message using minibuffer.
28 ;;
29 ;; By using this add-on, you can use always "mini riece", even if you
30 ;; are visiting other buffers.
31
32 ;; To use, add the following line to your ~/.riece/init.el:
33 ;; (add-to-list 'riece-addons 'riece-mini)
34 ;;
35 ;; And for using conveniently, bind any global key to
36 ;; `riece-mini-send-message'.
37 ;; For example:
38 ;; (global-set-key "\C-cm" 'riece-mini-send-message)
39
40 ;;; Code:
41
42 (eval-when-compile (require 'riece-message))
43
44 (defvar riece-mini-last-channel nil)
45
46 (defmacro riece-mini-message-no-log (string &rest args)
47   "Like `message', except that message logging is disabled."
48   (if (featurep 'xemacs)
49       (if args
50           `(display-message 'no-log (format ,string ,@args))
51         `(display-message 'no-log ,string))
52     `(let (message-log-max)
53        (message ,string ,@args))))
54
55 (defun riece-mini-display-message-function (message)
56   "Show arrival messages to minibuffer."
57   (unless (or (eq (window-buffer (selected-window))
58                   (get-buffer riece-command-buffer))
59               (riece-message-own-p message)
60               (active-minibuffer-window))
61     (let ((open-bracket
62            (funcall riece-message-make-open-bracket-function message))
63           (close-bracket
64            (funcall riece-message-make-close-bracket-function message))
65           (global-name
66            (funcall riece-message-make-global-name-function message)))
67       (unless (riece-message-type message)
68         (setq riece-mini-last-channel (riece-message-target message)))
69       (riece-mini-message-no-log
70        "%s" (concat (format-time-string "%H:%M") " "
71                     open-bracket global-name close-bracket
72                     " " (riece-message-text message))))))
73
74 (defun riece-mini-send-message (arg)
75   "Send message using minibuffer.
76 Prefix argument onece (C-u), send message to last received channel.
77 If twice (C-u C-u), then ask the channel."
78   (interactive "P")
79   (let* ((completion-ignore-case t)
80          (target
81           (cond
82            ((equal arg '(16))
83             (riece-completing-read-identity
84              "Channel/User: " riece-current-channels nil t))
85            (arg (or riece-mini-last-channel riece-current-channel))
86            (t riece-current-channel)))
87          (message (read-string (format "Message to %s: " target))))
88     (unless (equal message "")
89       (riece-switch-to-channel target)
90       (riece-send-string
91        (format "PRIVMSG %s :%s\r\n"
92                (riece-identity-prefix target)
93                message))
94       (riece-display-message
95        (riece-make-message (riece-current-nickname) target
96                            message nil t)))))
97
98 (defun riece-mini-insinuate ()
99   (add-hook 'riece-after-display-message-functions
100             'riece-mini-display-message-function))
101
102 (provide 'riece-mini)
103
104 ;;; riece-mini.el ends here