Initial Commit
[packages] / xemacs-packages / ilisp / ilisp-key.el
1 ;;; -*- Mode: Emacs-Lisp -*-
2
3 ;;; ilisp-key.el --
4 ;;; ILISP keybinding definitions.
5 ;;;
6 ;;; This file is part of ILISP.
7 ;;; Please refer to the file COPYING for copyrights and licensing
8 ;;; information.
9 ;;; Please refer to the file ACKNOWLEGDEMENTS for an (incomplete) list
10 ;;; of present and past contributors.
11 ;;;
12 ;;; $Id: ilisp-key.el,v 1.4 2002-06-03 23:37:01 wbd Exp $
13
14 ;;; ilisp-where-is --
15 ;;; New version provided by yusuf@SPD-13.ils.nwu.edu (Yusuf Pisan)
16 ;;; Note: this used to be in 'ilisp-cpat'. Its definition did not make
17 ;;;       much sense. Yusuf noted this and I decided to move it in
18 ;;;       this file (where I think is more approriate).
19 ;;;       11/24/94: Marco Antoniotti
20
21 (defun ilisp-where-is (command)
22   (let ((cmd (where-is-internal command nil t)))
23     (when cmd
24       (key-description cmd))))
25
26
27 ;;;
28 ;;;%Bindings
29 (defun ilisp-safe-define-key (keymap key command &optional fsf-key)
30   "In KEYMAP, bind KEY to COMMAND.
31 If optional fourth argument FSF-KEY is non-nil, then iff
32 `ilisp-*use-fsf-compliant-keybindings*' is non-nil, bind FSF-KEY
33 instead of KEY, unless FSF-KEY is a symbol, in which case do nothing."
34   ;; Check boundp as well as nilp -- paranoia always pays, and this
35   ;; code only gets run at setup time anyway:
36   (if (and fsf-key
37            (boundp 'ilisp-*use-fsf-compliant-keybindings*)
38            ilisp-*use-fsf-compliant-keybindings*)
39       (setq key fsf-key))
40   (unless (symbolp key)
41     (define-key keymap key command)))
42
43 (defun ilisp-bind-ilisp-key-for-map (keymap key command &optional fsf-key)
44   "In KEYMAP, bind ilisp-*prefix*+KEY to COMMAND.
45 If optional fourth argument FSF-KEY is non-nil, then iff
46 `ilisp-*use-fsf-compliant-keybindings*' is non-nil, bind FSF-KEY
47 instead of KEY, unless FSF-KEY is a symbol, in which case do nothing."
48   (let ((prefix-map (lookup-key keymap ilisp-*prefix*)))
49     (unless (keymapp prefix-map)
50       (setq prefix-map
51             (define-key keymap ilisp-*prefix* (make-sparse-keymap))))
52     (ilisp-safe-define-key prefix-map key command fsf-key)))
53
54
55 (defun defkey-ilisp (key command &optional inferior-only-p fsf-key)
56   "Define KEY as COMMAND in 'ilisp-mode-map' and 'lisp-mode-map'.
57 The change happens only if optional INFERIOR-ONLY-P is NIL.  If the maps
58 do not exist they will be created.  This should only be called after
59 ilisp-*prefix* is set to the desired prefix."
60   (unless ilisp-mode-map (ilisp-bindings))
61   (ilisp-safe-define-key ilisp-mode-map key command fsf-key)
62   (unless inferior-only-p
63     (ilisp-safe-define-key lisp-mode-map key command fsf-key)))
64
65 ;;;
66 (defun lisp-bindings (keymap &optional inferior-p)
67   "Sets up the bindings for interacting with an inferior LISP in KEYMAP."
68   (cond (inferior-p
69          (define-key keymap "\C-m" 'return-ilisp)
70          (define-key keymap "\C-a" 'bol-ilisp)
71          (define-key keymap "\C-c\C-c" 'interrupt-subjob-ilisp)
72          (define-key keymap "\C-d" 'delete-char-or-pop-ilisp)
73          ;; note: "#" is technically a violation of FSF keybinding
74          ;; conventions, but we won't pass an alternate here because
75          ;; it's not likely to cause a conflict in practice:
76          (ilisp-bind-ilisp-key-for-map keymap "#" 'raw-keys-ilisp))
77         (t
78          (ilisp-bind-ilisp-key-for-map
79           keymap "\C-c" 'compile-defun-and-go-lisp "\M-c")
80          (define-key keymap "\C-m" 'newline-and-indent-lisp)))
81
82   ;; 19990901 Martin Atzmueller
83   ;; 20000203 Karl Fogel: it's already bound to M-TAB anyway:
84   (ilisp-safe-define-key keymap "\C-c\t" 'complete-lisp 'no-fsf-key)
85   (define-key keymap [?\C-c return] `complete)
86
87   ;; 20000401 Martin Atzmueller
88   ;; Reinstated the ilisp-arglist-message-lisp-space by adding
89   ;; a customization. C-c C-SPACE is _not_ the intended behavior.
90   
91   ;; 19991214 Martin Atzmueller
92
93   ;; 20000203 Karl Fogel: C-c C-SPACE in the FSF-universe, I guess.
94   ;; (ilisp-safe-define-key
95   ;; keymap " "  'ilisp-arglist-message-lisp-space [?\C-c?\C- ])
96   (when ilisp-bindings-*bind-space-p*
97     (define-key keymap " "  'ilisp-arglist-message-lisp-space))
98
99   ;; 20000203 Karl Fogel
100   ;; This binding of ] causes many complaints, because lisp hackers
101   ;; frequently need literal square braces in their code.  The
102   ;; 'close-all-lisp function is a neat idea, but I think it needs to
103   ;; be bound to something not used for any other purpose.  -karl
104   ;; (define-key   keymap "]"        'close-all-lisp)
105   ;;
106   ;; 20000213 Marco Antoniotti
107   ;; Reinstated the 'close-all' lisp by adding a programmable
108   ;; customization.
109   (when ilisp-bindings-*bind-right-bracket-p*
110     (define-key   keymap "]"        'close-all-lisp))
111
112   (define-key   keymap "\M-q"              'reindent-lisp)
113   (ilisp-safe-define-key keymap "\C-]"     'close-and-send-lisp 'no-fsf-key)
114   (define-key   keymap "\t"                'indent-line-ilisp)
115   (define-key   keymap "\n"                'newline-and-indent-lisp)
116   (define-key   keymap "\M-\C-q"           'indent-sexp-ilisp)
117   (ilisp-bind-ilisp-key-for-map keymap ";" 'comment-region-lisp)
118
119   ;; note: again, a technical violation of FSF keybinding policy, but
120   ;; safe & useful enough that I think it's best to leave it as is:
121   (ilisp-bind-ilisp-key-for-map keymap ")"        'find-unbalanced-lisp)
122
123   (define-key   keymap "\M-\C-a"  'beginning-of-defun-lisp)
124   (define-key   keymap "\M-\C-e"  'end-of-defun-lisp)
125   (ilisp-safe-define-key keymap "\C-\M-r" 'reposition-window-lisp 'no-fsf-key)
126
127   ;; This series of bindings was very non-FSF-compliant, but was also
128   ;; hard to fit into any consistent binding scheme.  I saved them for
129   ;; last and then bound them to whatever was available.  -Karl Fogel
130   (ilisp-bind-ilisp-key-for-map keymap "i" 'describe-lisp      "\C-i")
131   (ilisp-bind-ilisp-key-for-map keymap "I" 'inspect-lisp       "\M-i")
132   (ilisp-bind-ilisp-key-for-map keymap "a" 'arglist-lisp       "\C-q")
133   (ilisp-bind-ilisp-key-for-map keymap "d" 'documentation-lisp "\C-f")
134   (ilisp-bind-ilisp-key-for-map keymap "m" 'macroexpand-1-lisp "\M-1")
135   (ilisp-bind-ilisp-key-for-map keymap "M" 'macroexpand-lisp   "\M-0")
136
137   (ilisp-safe-define-key keymap "\M-," 'next-definition-lisp 'no-fsf-key)
138   (ilisp-safe-define-key keymap "\M-." 'edit-definitions-lisp 'no-fsf-key)
139   (ilisp-safe-define-key keymap "\M-?" 'search-lisp 'no-fsf-key)
140   (ilisp-safe-define-key keymap "\M-\"" 'replace-lisp 'no-fsf-key)
141   (ilisp-bind-ilisp-key-for-map keymap "^" 'edit-callers-lisp 'no-fsf-key)
142   (ilisp-safe-define-key keymap "\M-`" 'next-caller-lisp 'no-fsf-key)
143   (define-key keymap "\M-\t" 'complete-lisp)
144
145   ;; note: another technical fsf keybinding policy violation.  But
146   ;; M-return is unbound in the FSF Emacs 20.5 distribution, and I
147   ;; think a lot of people might like this binding.  I don't know,
148   ;; really, it's just a judgement call.  -karl
149   (define-key keymap "\M-\C-m"  'complete)
150
151   (ilisp-bind-ilisp-key-for-map keymap "r"       'eval-region-lisp "\C-r")
152   (ilisp-safe-define-key        keymap "\M-\C-x" 'eval-defun-lisp) ; like Gnu
153   (ilisp-bind-ilisp-key-for-map keymap "e"       'eval-defun-lisp "\C-e")
154   (ilisp-bind-ilisp-key-for-map keymap "n"       'eval-next-sexp-lisp "\C-n")
155   
156   ;; Changed as per Martin Atzmueller suggestions.
157   ;; Original version
158   ;; (ilisp-bind-ilisp-key-for-map keymap "p"        'package-lisp)
159   ;;
160   ;; todo: will there ever be `*-previous-*' functions defined,
161   ;; analogous to `eval-next-sexp' etc?  If so, then the binding of
162   ;; p/C-p below will be problematic.  -karl
163   (ilisp-bind-ilisp-key-for-map keymap "p" 'set-buffer-package-lisp "\C-p")
164
165   (ilisp-bind-ilisp-key-for-map keymap "P" 'set-package-lisp "\M-p")
166   (ilisp-bind-ilisp-key-for-map keymap "w" 'compile-region-lisp "\C-w")
167   ;; MA 09/01/1999:
168   (ilisp-bind-ilisp-key-for-map keymap "\C-b" 'ilisp-compile-buffer)
169   (ilisp-bind-ilisp-key-for-map keymap "c"    'compile-defun-lisp     "\C-c")
170   (ilisp-bind-ilisp-key-for-map keymap "\C-r" 'eval-region-and-go-lisp "\M-r")
171   (ilisp-bind-ilisp-key-for-map keymap "\C-e" 'eval-defun-and-go-lisp "\M-e")
172   (ilisp-bind-ilisp-key-for-map keymap "\C-n"
173                                 'eval-next-sexp-and-go-lisp
174                                 "\M-n")
175   (ilisp-bind-ilisp-key-for-map keymap "\C-w"
176                                 'compile-region-and-go-lisp
177                                 "\M-w")
178   (ilisp-bind-ilisp-key-for-map keymap "t" 'trace-defun-lisp "\C-t")
179   (ilisp-bind-ilisp-key-for-map keymap "!" 'default-directory-lisp 'no-fsf-key)
180   (ilisp-bind-ilisp-key-for-map keymap " " 'mark-change-lisp 'no-fsf-key)
181
182   ;; These four are under the further "*"/"8" prefix:
183   (ilisp-bind-ilisp-key-for-map keymap "*l" 'list-changes-lisp "8l")
184   (ilisp-bind-ilisp-key-for-map keymap "*e" 'eval-changes-lisp "8e")
185   (ilisp-bind-ilisp-key-for-map keymap "*c" 'compile-changes-lisp "8c")
186   (ilisp-bind-ilisp-key-for-map keymap "*0" 'clear-changes-lisp "80")
187
188   (ilisp-bind-ilisp-key-for-map keymap "b" 'switch-to-lisp "\M-b")
189   (ilisp-bind-ilisp-key-for-map keymap "y" 'call-defun-lisp "\C-y")
190   (ilisp-bind-ilisp-key-for-map keymap "z" 'reset-ilisp "\C-z")
191   (ilisp-bind-ilisp-key-for-map keymap "g" 'abort-commands-lisp "\C-g")
192   (ilisp-bind-ilisp-key-for-map keymap "s" 'status-lisp "\C-s")
193   (ilisp-bind-ilisp-key-for-map keymap "S" 'select-ilisp "\M-s")
194   (define-key   keymap "\C-x\C-f" 'find-file-lisp)
195   (ilisp-bind-ilisp-key-for-map keymap "l" 'load-file-lisp "\C-l")
196   (ilisp-bind-ilisp-key-for-map keymap "k" 'compile-file-lisp "\C-k")
197
198   ;; Conditionalized definitions of these keybindings, using the
199   ;; appropriate flags.
200   ;;
201   ;; 19990824 Marco Antoniotti
202
203   (when ilisp-*use-fi-clman-interface-p*
204     (ilisp-bind-ilisp-key-for-map keymap "A" 'fi:clman-apropos "\M-a")
205     (ilisp-bind-ilisp-key-for-map keymap "D" 'fi:clman "\M-d"))
206   (when ilisp-*use-hyperspec-interface-p*
207     (ilisp-bind-ilisp-key-for-map keymap "H" 'hyperspec-lookup "\M-h"))
208   (when ilisp-*use-cltl2-interface-p*
209     (ilisp-bind-ilisp-key-for-map keymap "L" 'cltl2-lookup "\M-l")))
210
211
212 ;;
213 (defun ilisp-lispm-bindings ()
214   "Setup additional Lisp Machine-like bindings for some ilisp commands"
215   (interactive)
216   ;; Note: Changed the 'ilisp-emacs-version-id' to
217   ;;       '+ilisp-emacs-version-id+' and the 'gnu-*' to 'fsf-*'.
218   ;;       25/11/94 Marco Antoniotti
219   ;;
220   ;; Note: these bindings do not have to be FSF-compliant, because the
221   ;;       user doesn't get them unless she asks for them, in which
222   ;;       case she presumably knows what she wants. -Karl Fogel, 3 Feb 2000
223   (cond ((eq +ilisp-emacs-version-id+ 'fsf-18))
224         ((or (eq +ilisp-emacs-version-id+ 'fsf-19)
225              (eq +ilisp-emacs-version-id+ 'fsf-20)
226              (eq +ilisp-emacs-version-id+ 'fsf-21))
227          (defkey-ilisp (read "[?\\S-\\C-a]") 'arglist-lisp)
228          (defkey-ilisp (read "[?\\S-\\C-c]") 'compile-defun-lisp)
229          (defkey-ilisp (read "[?\\S-\\C-d]") 'documentation-lisp)
230          (defkey-ilisp (read "[?\\S-\\C-e]") 'eval-defun-lisp)
231          (defkey-ilisp (read "[?\\S-\\C-m]") 'macroexpand-1-lisp)
232          (defkey-ilisp (read "[?\\M-M]") 'macroexpand-lisp))
233         (t
234          (defkey-ilisp '(control A) 'arglist-lisp)
235          (defkey-ilisp '(control C) 'compile-defun-lisp)
236          (defkey-ilisp '(control D) 'documentation-lisp)
237          (defkey-ilisp '(control E) 'eval-defun-lisp)
238          (defkey-ilisp '(control M) 'macroexpand-1-lisp)
239          (defkey-ilisp '(meta M) 'macroexpand-lisp))))
240
241 ;; Unfortunately, the read kludges are needed for this function to work
242 ;; for GNU emacs 19 when it was compiled by Lucid.
243
244
245 ;;;
246 (defun ilisp-bindings ()
247   "Set up the key bindings for LISP and ILISP buffers."
248   (cond ((fboundp 'set-keymap-parent) 
249          (setq ilisp-mode-map (make-sparse-keymap))
250          (set-keymap-parent ilisp-mode-map comint-mode-map))
251         (t (setq ilisp-mode-map (copy-keymap comint-mode-map))))
252
253   ;; Remove stop and quit subjob from comint
254   (define-key ilisp-mode-map "\C-c\C-z" nil)
255   (define-key ilisp-mode-map "\C-c\C-\\" nil)
256
257   (when (fboundp 'lisp-mode-commands)
258     (lisp-mode-commands ilisp-mode-map))
259   (lisp-bindings ilisp-mode-map t)
260   (when (boundp 'lisp-mode-map)
261     (lisp-bindings lisp-mode-map))
262   (when (boundp 'scheme-mode-map) 
263     (lisp-bindings scheme-mode-map))
264   (ilisp-bind-ilisp-key-for-map emacs-lisp-mode-map ";" 'comment-region-lisp)
265
266   (ilisp-bind-ilisp-key-for-map global-map "\C-t"
267                                 'trace-defun-lisp-break
268                                 "\M-t")
269   (ilisp-bind-ilisp-key-for-map global-map "b" 'switch-to-lisp 'no-fsf-key)
270
271   ;; Globally defined output-control commands.
272   (ilisp-bind-ilisp-key-for-map global-map "1" 'ilisp-bury-output)
273   (ilisp-bind-ilisp-key-for-map global-map "v" 'ilisp-scroll-output "\C-v")
274   (ilisp-bind-ilisp-key-for-map global-map "G" 'ilisp-grow-output "\M-g")
275
276   ;; Added test to conditionalize the loading of the fi:clman map.
277   ;;
278   ;; 19990824 Marco Antoniotti
279
280   (when ilisp-*use-fi-clman-interface-p*
281     (unless (boundp 'fi:clman-mode-map)
282       (setq fi:clman-mode-map (make-sparse-keymap)))
283     (ilisp-bind-ilisp-key-for-map fi:clman-mode-map "D"
284                                   'fi:clman
285                                   "\M-d")
286     (ilisp-bind-ilisp-key-for-map fi:clman-mode-map "A"
287                                   'fi:clman-apropos
288                                   "\M-a")))
289
290 (provide 'ilisp-key)
291
292 ;;; end of file -- ilisp-key.el --