Initial Commit
[packages] / xemacs-packages / xwem / lisp / xwem-modes.el
1 ;;; xwem-modes.el --- Minor modes support for XWEM.
2
3 ;; Copyright (C) 2004,2005 by XWEM Org.
4
5 ;; Author: Zajcev Evgeny <zevlg@yandex.ru>
6 ;; Created: Mon Oct 18 22:36:23 MSD 2004
7 ;; Keywords: xwem
8 ;; X-CVS: $Id: xwem-modes.el,v 1.4 2005-04-04 19:54:14 lg Exp $
9
10 ;; This file is part of XWEM.
11
12 ;; XWEM is free software; you can redistribute it and/or modify it
13 ;; under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; XWEM is distributed in the hope that it will be useful, but WITHOUT
18 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 ;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
20 ;; License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with XEmacs; see the file COPYING.  If not, write to the Free
24 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 ;; 02111-1307, USA.
26
27 ;;; Synched up with: Not in FSF
28
29 ;;; Commentary:
30
31 ;; 
32
33 ;;; Code:
34 \f
35 (require 'xwem-load)
36
37 ;;;###xwem-autoload
38 (defvar xwem-minor-mode-alist nil
39   "Alist saying how to show minor modes.
40 Each element is a list which looks like (VAR STRING).
41 STRING is shown when VAR is non-nil.")
42
43 ;;;###xwem-autoload
44 (defvar xwem-minor-mode-map-alist nil
45   "Alist of keymaps for use of minor modes.
46 Each element looks like (VAR . KEYMAP).")
47
48 ;;;###xwem-autoload(autoload 'xwem-add-minor-mode "xwem-modes")
49 (defun xwem-add-minor-mode (toggle name &optional keymap)
50   "Add a minor mode to `xwem-minor-mode-alist'.
51 For TOGGLE, NAME, KEYMAP, usage take a look at `add-minor-mode'."
52   (setq xwem-minor-mode-alist
53         (put-alist toggle (list name) xwem-minor-mode-alist))
54
55   (when keymap
56     (setq xwem-minor-mode-map-alist
57           (put-alist toggle keymap xwem-minor-mode-map-alist))))
58
59 ;;;###xwem-autoload
60 (defun xwem-turn-on-minor-mode (cl mm-toggle)
61   "On CL, turn on minor mode MM-TOGGLE."
62   (unless (if (xwem-client-local-variable-p mm-toggle)
63               (xwem-client-local-variable-value cl mm-toggle)
64             (symbol-value mm-toggle))
65     (let* ((km-sym (cdr (assq mm-toggle xwem-minor-mode-map-alist)))
66            (kmap (if (xwem-client-local-variable-p km-sym)
67                      (xwem-client-local-variable-value cl km-sym)
68                    (symbol-value km-sym))))
69       (when (keymapp kmap)
70         (xwem-kbd-install-grab kmap (xwem-cl-xwin cl))))
71
72     (if (xwem-client-local-variable-p mm-toggle)
73         (xwem-client-local-variable-set cl mm-toggle t)
74       (set-variable mm-toggle t))))
75
76 ;;;###xwem-autoload
77 (defun xwem-turn-off-minor-mode (cl mm-toggle)
78   "On CL, turn off minor mode MM-TOGGLE."
79   (when (if (xwem-client-local-variable-p mm-toggle)
80             (xwem-client-local-variable-value cl mm-toggle)
81           (symbol-value mm-toggle))
82     (let* ((km-sym (cdr (assq mm-toggle xwem-minor-mode-map-alist)))
83            (kmap (if (xwem-client-local-variable-p km-sym)
84                      (xwem-client-local-variable-value cl km-sym)
85                    (symbol-value km-sym))))
86       (when (keymapp kmap)
87         (xwem-kbd-uninstall-grab kmap (xwem-cl-xwin cl))))
88     (if (xwem-client-local-variable-p mm-toggle)
89         (xwem-client-local-variable-set cl mm-toggle nil)
90       (set-variable mm-toggle nil))))
91
92 \f
93 (provide 'xwem-modes)
94
95 ;;; xwem-modes.el ends here