1 ;;; riece-button.el --- adding buttons in channel buffers
2 ;; Copyright (C) 1998-2003 Daiki Ueno
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
6 ;; Keywords: IRC, riece
8 ;; This file is part of Riece.
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; To use, add the following line to your ~/.riece/init.el:
28 ;; (add-to-list 'riece-addons 'riece-button)
32 (require 'riece-commands)
33 (require 'riece-identity)
37 (defvar help-echo-owns-message)
38 (define-widget 'riece-channel-button 'push-button
40 :action 'riece-channel-button-action
42 (lambda (widget/window &optional overlay pos)
43 ;; Needed to properly clear the message due to a bug in
44 ;; wid-edit (XEmacs only).
45 (if (boundp 'help-echo-owns-message)
46 (setq help-echo-owns-message t))
47 (format "Switch to %s"
48 ;; XEmacs will get a single widget arg; Emacs 21 will get
49 ;; window, overlay, position.
50 (riece-format-identity
52 (with-current-buffer (overlay-buffer overlay)
53 (widget-value (widget-at (overlay-start overlay))))
54 (widget-value widget/window))))))
56 (defun riece-channel-button-action (widget &optional event)
57 (let ((channel (widget-value widget)))
58 (if (riece-identity-member channel riece-current-channels)
59 (riece-command-switch-to-channel channel)
60 (message "%s" (substitute-command-keys
61 "Type \\[riece-command-join] to join the channel")))))
63 (defun riece-button-add-channel-buttons (start end)
67 ;; Search for the beginning of the button region.
68 (unless (get-text-property start 'riece-identity)
69 (setq start (next-single-property-change start 'riece-identity
71 ;; Search for the end of the button region.
72 (let* ((identity (get-text-property start 'riece-identity))
73 (button-end (next-single-property-change start 'riece-identity
75 (if (= button-end end)
77 (if (riece-channel-p (riece-identity-prefix identity))
78 (widget-convert-button
79 'riece-channel-button start button-end identity))
80 (setq start button-end)))))))
82 (defun riece-button-update-channel-list-buffer ()
83 (if riece-channel-list-buffer-mode
85 (set-buffer riece-channel-list-buffer)
86 (let ((inhibit-read-only t)
88 (riece-button-add-channel-buttons (point-min) (point-max))))))
90 (defun riece-button-requires ()
93 (defun riece-button-insinuate ()
94 (add-hook 'riece-channel-list-mode-hook
96 (set-keymap-parent riece-channel-list-mode-map widget-keymap)
97 (add-hook 'riece-update-buffer-functions
98 'riece-button-update-channel-list-buffer t)))
99 (add-hook 'riece-dialogue-mode-hook
101 (set-keymap-parent riece-dialogue-mode-map widget-keymap)))
102 (add-hook 'riece-after-insert-functions 'riece-button-add-channel-buttons))
104 (provide 'riece-button)
106 ;;; riece-button.el ends here