* riece-display.el (riece-configure-windows-top): New function.
[riece] / lisp / riece-layout.el
1 ;;; riece-layout.el --- layout manager add-on
2 ;; Copyright (C) 1998-2003 Daiki Ueno
3
4 ;; Author: Daiki Ueno <ueno@unixuser.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 ;; This add-on allows you to switch window configurations by their names.
25
26 ;; To use, add the following line to your ~/.riece/init.el:
27 ;; (add-to-list 'riece-addons 'riece-layout)
28
29 ;;; Code:
30
31 (require 'riece-display)
32
33 (defgroup riece-layout nil
34   "Manage window layouts"
35   :prefix "riece-"
36   :group 'riece)
37
38 (defcustom riece-default-layout "default"
39   "The default layout name."
40   :type 'string
41   :group 'riece-layout)
42
43 (defcustom riece-layout riece-default-layout
44   "Current layout setting."
45   :type 'string
46   :group 'riece-layout)
47
48 (defcustom riece-layout-alist
49   '(("default" riece-configure-windows riece-configure-windows-predicate)
50     ("top" riece-configure-windows-top riece-configure-windows-predicate))
51   "An alist mapping the names to configure/predicate functions."
52   :type 'list
53   :group 'riece-layout)
54
55 (defun riece-layout-option-set-function (symbol value)
56   "Function called when setting `riece-layout'."
57   (let ((layout (cdr (assoc value riece-layout-alist))))
58     (unless layout
59       (error "No such layout!"))
60     (setq riece-configure-windows-function (car layout)
61           riece-configure-windows-predicate (nth 1 layout))
62     (riece-redisplay-buffers t)))
63
64 (defun riece-command-change-layout (name)
65   "Select a layout-name from all current available layouts and change
66 the layout to the selected layout-name."
67   (interactive (list (completing-read "Layout: " riece-layout-alist)))
68   (customize-set-variable 'riece-layout name))
69
70 (defvar riece-dialogue-mode-map)
71
72 (defun riece-layout-insinuate ()
73   (define-key riece-dialogue-mode-map "\C-tl" #'riece-command-change-layout)
74   ;; Delay setting `riece-layout' using riece-layout-option-set-function.
75   (add-hook 'riece-startup-hook
76             (lambda ()
77               (put 'riece-layout 'custom-set
78                    'riece-layout-option-set-function)
79               (riece-layout-option-set-function 'riece-layout riece-layout))))
80
81 (provide 'riece-layout)
82
83 ;;; riece-layout.el ends here