1 ;;; dui.el --- Dictionary user interface
3 ;; Copyright (C) 1998, 2002 Free Software Foundation, Inc.
5 ;; Author: Stephen J. Turnbull <stephen@xemacs.org>
6 ;; Keywords: mule, dictionary
9 ;; This file is part of XEmacs.
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.
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.
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.
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.
36 ;; 1998-03-27 Stephen Turnbull <stephen@xemacs.org>
37 ;; (created): broken out from monolithic edict.el
41 ;;; Dictionary lookup minor mode (dl-mode)
43 ;; User customization variables
46 "Customization group for dl-mode interface to edict.el."
49 ;; #### Customize me later!
50 (defvar dl-mode-prefix '[(control ?c) (?\$)]
51 "*Prefix key sequence for dl-mode command keys.
53 After loading, change the mode's prefix by using dl-mode-set-prefix;
54 setq'ing this variable can't work.")
56 (defcustom dl-mode-line-string " dl"
57 "*String indicating activation of dl minor mode in the modeline.
59 Set to nil to inhibit modeline display."
61 (const :tag "none" nil))
64 ;; A convention for modes; here honored by observance, not breach.
66 (defvar dl-mode-hook nil
67 "*A normal hook called at the end of the dl-mode activation process.
69 If you can think of a use for this, you're more clever than I.")
71 ;; Auxiliary customizations
73 (defcustom dl-conflict-warning "Binding conflict: %s -> %s."
74 "*Format string warning about key sequences with conflicting bindings.
76 Must contain two `%s' descriptors. The first formats the key sequence,
77 the second the description of the existing binding."
81 ;; #### Add code to check that the level is OK?
82 (defcustom dl-warn-conflict-verbosity 3
83 "*Controls verbosity of binding conflict warnings.
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.
91 Each positive level performs all actions of lower levels."
95 ;; The basic mode conventions.
97 ;; Mode flag and keymaps
99 (defvar dl-mode nil "Activation flag for dl-mode.")
101 (defvar dl-mode-submap nil
102 "Sub-keymap for dl-mode.
104 All key sequences are prefixed by the sequence defined in dl-mode-map.")
106 (defvar dl-mode-map nil
107 "Keymap for dl-mode. Holds the prefix key for dl-mode functions.
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.")
114 ;; The side effect is arguably not a feature :-)
117 (defun dl-mode (&optional arg)
118 "Minor mode for dictionary lookup, with interfaces to dictionary utilities.
120 Null ARG toggles the mode, positive ARG turns the mode on, negative ARG
123 When the mode is already off, (dl-mode -1) has the side effect of checking
124 and reporting any conflicting bindings.
130 ;; dl-warn-binding-conflicts doesn't make sense when the mode is active
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))
137 ;; Internal mode data
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)
153 ;; Set the mode prefix
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.
158 (defun dl-mode-set-prefix (key &optional context)
159 "Set the prefix key sequence for dl-mode to KEY.
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.
166 Example: `\\[dl-mode-set-prefix] C-q C-c $ RET' returns the prefix key
167 to the default `C-c $'.
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."
173 ;; Should read key events but I don't know how to make that work.
174 (interactive "Key sequence (quote control characters with ^Q): ")
176 (setq dl-mode-map (make-sparse-keymap))
177 (define-key dl-mode-map key 'dl-mode-submap)
178 (cond ((null context)