Initial Commit
[packages] / mule-packages / edict / dui.el
1 ;;; dui.el --- Dictionary user interface
2
3 ;; Copyright (C) 1998, 2002 Free Software Foundation, Inc.
4
5 ;; Author:      Stephen J. Turnbull <stephen@xemacs.org>
6 ;; Keywords:    mule, dictionary
7 ;; Version:     0.6
8
9 ;;   This file is part of XEmacs.
10
11 ;;   XEmacs is free software; you can redistribute it and/or modify it
12 ;;   under the terms of the GNU General Public License as published by
13 ;;   the Free Software Foundation; either version 2, or (at your
14 ;;   option) any later version.
15
16 ;;   XEmacs is distributed in the hope that it will be useful, but
17 ;;   WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 ;;   General Public License for more details.
20 ;; 
21 ;;   You should have received a copy of the GNU General Public License
22 ;;   along with XEmacs; if not, write to the Free Software Foundation,
23 ;;   Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24
25 ;;; Commentary:
26
27 ;; Some code that provides support for dictionary lookup and manipulations
28 ;; (such as inserting definitions and maintaining a private dictionary).
29 ;; Originally written in support of edict.el, by Per Hammarlund
30 ;; <perham@nada.kth.se>, but since generalized.
31
32 ;;; To do:
33
34 ;;; Changelog:
35
36 ;; 1998-03-27  Stephen Turnbull  <stephen@xemacs.org>
37 ;;        (created):  broken out from monolithic edict.el
38
39 ;;; Code:
40
41 ;;; Dictionary lookup minor mode (dl-mode)
42
43 ;; User customization variables
44
45 (defgroup dl nil
46   "Customization group for dl-mode interface to edict.el."
47   :group 'edict)
48
49 ;; #### Customize me later!
50 (defvar dl-mode-prefix '[(control ?c) (?\$)]
51   "*Prefix key sequence for dl-mode command keys.
52
53 After loading, change the mode's prefix by using dl-mode-set-prefix;
54 setq'ing this variable can't work.")
55
56 (defcustom dl-mode-line-string " dl"
57   "*String indicating activation of dl minor mode in the modeline.
58
59 Set to nil to inhibit modeline display."
60   :type '(choice string
61                  (const :tag "none" nil))
62   :group 'dl)
63
64 ;; A convention for modes; here honored by observance, not breach.
65 ;;
66 (defvar dl-mode-hook nil
67   "*A normal hook called at the end of the dl-mode activation process.
68
69 If you can think of a use for this, you're more clever than I.")
70
71 ;; Auxiliary customizations
72
73 (defcustom dl-conflict-warning "Binding conflict: %s -> %s."
74   "*Format string warning about key sequences with conflicting bindings.
75
76 Must contain two `%s' descriptors.  The first formats the key sequence,
77 the second the description of the existing binding."
78   :type 'string
79   :group 'dl)
80
81 ;; #### Add code to check that the level is OK?
82 (defcustom dl-warn-conflict-verbosity 3
83   "*Controls verbosity of binding conflict warnings.
84
85 0   turns off warnings entirely.
86 1   issues a warning for each binding conflict (including sub-keymaps).
87 2   prints a summary message with a count of conflicts (not including
88     sub-keymaps, only keys in those maps that have conflicts).
89 3   adds verbose detail about what is being done.
90
91 Each positive level performs all actions of lower levels."
92   :type 'integer
93   :group 'dl)
94
95 ;; The basic mode conventions.
96
97 ;; Mode flag and keymaps
98 ;;
99 (defvar dl-mode nil "Activation flag for dl-mode.")
100
101 (defvar dl-mode-submap nil
102   "Sub-keymap for dl-mode.
103
104 All key sequences are prefixed by the sequence defined in dl-mode-map.")
105
106 (defvar dl-mode-map nil
107   "Keymap for dl-mode.  Holds the prefix key for dl-mode functions.
108
109 Its value will be installed into minor-mode-map-alist.  Prefix cannot
110 be altered by setq'ing dl-mode-map.  Use dl-mode-set-prefix instead.")
111
112 ;; Mode toggle
113 ;;
114 ;; The side effect is arguably not a feature :-)
115 ;
116 ;;;###autoload
117 (defun dl-mode (&optional arg)
118   "Minor mode for dictionary lookup, with interfaces to dictionary utilities.
119
120 Null ARG toggles the mode, positive ARG turns the mode on, negative ARG
121 turns the mode off.
122
123 When the mode is already off, (dl-mode -1) has the side effect of checking
124 and reporting any conflicting bindings.
125
126 \\{dl-mode-map}"
127
128   (interactive "P")
129
130   ;; dl-warn-binding-conflicts doesn't make sense when the mode is active
131   (if (null dl-mode)
132       (dl-warn-binding-conflicts dl-mode-map))
133   (setq dl-mode (if (null arg) (not dl-mode)
134                   (> (prefix-numeric-value arg) 0)))
135   (run-hooks dl-mode-hook))
136
137 ;; Internal mode data
138
139 ;; Main keymap
140 ;;
141 (or dl-mode-submap
142     (progn
143      (define-prefix-command 'dl-mode-submap) ;
144      (define-key dl-mode-submap '[ ?s ] 'dui-invoke-search-method)
145      (define-key dl-mode-submap '[ ?i ] 'dui-invoke-insert-method)
146      ;; Hmm ... I don't think there are any of these :-P
147      ;;(define-key dl-mode-submap '[ ?e ] 'dui-invoke-edit-method)
148      (define-key dl-mode-submap '[ ?d ] 'dui-describe-method)
149      ))
150
151 ;; Helper functions
152
153 ;; Set the mode prefix
154 ;;
155 ;; This can't be done simply by setq'ing dl-mode-map; minor-mode-map-alist
156 ;; does not refer to that variable but contains a copy of its value.
157 ;;
158 (defun dl-mode-set-prefix (key &optional context)
159   "Set the prefix key sequence for dl-mode to KEY.
160
161 Return the new dl-mode-map.  When called interactively read KEY from
162 the minibuffer (as a string; keys not bound to `self-insert' must be
163 quoted with C-q).  If you need more flexibility than ASCII gives, you'll
164 have to use the `eval-expression' interface.
165
166 Example: `\\[dl-mode-set-prefix] C-q C-c $ RET' returns the prefix key
167 to the default `C-c $'.
168
169 Allowed values of CONTEXT:
170 NIL                substitute a map containing KEY in minor-mode-map-alist.
171 adding-minor-mode  manipulation of minor-mode-map-alist is done elsewhere."
172
173   ;; Should read key events but I don't know how to make that work.
174   (interactive "Key sequence (quote control characters with ^Q): ")
175
176   (setq dl-mode-map (make-sparse-keymap))
177   (define-key dl-mode-map key 'dl-mode-submap)
178   (cond ((null context)