]> code.delx.au - gnu-emacs/blob - lisp/emulation/crisp.el
Don't require cl.
[gnu-emacs] / lisp / emulation / crisp.el
1 ;; crisp.el --- CRiSP/Brief Emacs emulator
2
3 ;; Copyright (C) 1997, 1998 Free Software Foundation, Inc.
4
5 ;; Author: Gary D. Foster <gfoster@suzieq.ml.org>
6 ;; Keywords: emulations brief crisp
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;; Keybindings and minor functions to duplicate the functionality and
28 ;; finger-feel of the CRiSP/Brief editor. This package is designed to
29 ;; facilitate transitioning from Brief to (XE|E)macs with a minimum
30 ;; amount of hassles.
31
32 ;; Enable this package by putting (require 'crisp) in your .emacs and
33 ;; use M-x crisp-mode to toggle it on or off.
34
35 ;; This package will automatically load the scroll-all.el package if
36 ;; you put (setq crisp-load-scroll-all t) in your .emacs before
37 ;; loading this package. If this feature is enabled, it will bind
38 ;; meta-f1 to the scroll-all mode toggle. The scroll-all package
39 ;; duplicates the scroll-alling feature in CRiSP.
40
41 ;; Also, the default keybindings for brief/CRiSP override the M-x
42 ;; key to exit the editor. If you don't like this functionality, you
43 ;; can prevent this behavior (or redefine it dynamically) by setting
44 ;; the value of `crisp-override-meta-x' either in your .emacs or
45 ;; interactively. The default setting is nil, which means that M-x will
46 ;; by default run `execute-extended-command' instead of the command
47 ;; `save-buffers-kill-emacs'.
48
49 ;; Finally, if you want to change the string displayed in the modeline
50 ;; when this mode is in effect, override the definition of
51 ;; `crisp-mode-modeline-string' in your .emacs. The default value is
52 ;; " *Crisp*" which may be a bit lengthy if you have a lot of things
53 ;; being displayed there.
54
55 ;; All these overrides should go *before* the (require 'crisp) statement.
56
57 ;; Code:
58
59 ;; local variables
60
61 (defgroup crisp nil
62 "Emulator for CRiSP and Brief key bindings."
63 :prefix "crisp-"
64 :group 'emulations)
65
66 (defvar crisp-mode-map (let ((map (make-sparse-keymap)))
67 (set-keymap-parent map (current-global-map))
68 map)
69 "Local keymap for CRiSP emulation mode.
70 All the bindings are done here instead of globally to try and be
71 nice to the world.")
72
73 (defcustom crisp-mode-modeline-string " *CRiSP*"
74 "*String to display in the modeline when CRiSP emulation mode is enabled."
75 :type 'string
76 :group 'crisp)
77
78 (defvar crisp-mode-original-keymap (current-global-map)
79 "The original keymap before CRiSP emulation mode remaps anything.
80 This keymap is restored when CRiSP emulation mode is disabled.")
81
82 (defcustom crisp-mode-enabled nil
83 "Track status of CRiSP emulation mode.
84 A value of nil means CRiSP mode is not enabled. A value of t
85 indicates CRiSP mode is enabled."
86 :type 'boolean
87 :group 'crisp)
88
89 (defcustom crisp-override-meta-x t
90 "*Controls overriding the normal Emacs M-x key binding in the CRiSP emulator.
91 Normally the CRiSP emulator rebinds M-x to `save-buffers-exit-emacs', and
92 provides the usual M-x functionality on the F10 key. If this variable
93 is non-nil, M-x will exit Emacs."
94 :type 'boolean
95 :group 'crisp)
96
97 (defcustom crisp-load-scroll-all nil
98 "Controls loading of the Scroll Lock in the CRiSP emulator.
99 Its default behavior is to load and enable the Scroll Lock minor mode
100 package when enabling the CRiSP emulator.
101
102 If this variable is nil when you start the CRiSP emulator, it
103 does not load the scroll-all package."
104 :type 'boolean
105 :group 'crisp)
106
107 (defcustom crisp-load-hook nil
108 "Hooks to run after loading the CRiSP emulator package."
109 :type 'hook
110 :group 'crisp)
111
112 (defconst crisp-version "1.33"
113 "The version of the CRiSP emulator.")
114
115 (defconst crisp-mode-help-address "gfoster@suzieq.ml.org"
116 "The email address of the CRiSP mode author/maintainer.")
117
118 ;; Silence the byte-compiler.
119 (defvar crisp-last-last-command nil
120 "The previous value of `last-command'.")
121
122 ;; The cut and paste routines are different between XEmacs and Emacs
123 ;; so we need to set up aliases for the functions.
124
125 (defalias 'crisp-set-clipboard
126 (if (fboundp 'clipboard-kill-ring-save)
127 'clipboard-kill-ring-save
128 'copy-primary-selection))
129
130 (defalias 'crisp-kill-region
131 (if (fboundp 'clipboard-kill-region)
132 'clipboard-kill-region
133 'kill-primary-selection))
134
135 (defalias 'crisp-yank-clipboard
136 (if (fboundp 'clipboard-yank)
137 'clipboard-yank
138 'yank-clipboard-selection))
139
140 ;; force transient-mark-mode in Emacs, so that the marking routines
141 ;; work as expected. If the user turns off transient mark mode,
142 ;; most things will still work fine except the crisp-(copy|kill)
143 ;; functions won't work quite as nicely when regions are marked
144 ;; differently and could really confuse people. Caveat emptor.
145
146 (if (fboundp 'transient-mark-mode)
147 (transient-mark-mode t))
148
149 (defun crisp-region-active ()
150 "Compatibility function to test for an active region."
151 (if (boundp 'zmacs-region-active-p)
152 zmacs-region-active-p
153 mark-active))
154
155 ;; and now the keymap defines
156
157 (define-key crisp-mode-map [(f1)] 'other-window)
158
159 (define-key crisp-mode-map [(f2) (down)] 'enlarge-window)
160 (define-key crisp-mode-map [(f2) (left)] 'shrink-window-horizontally)
161 (define-key crisp-mode-map [(f2) (right)] 'enlarge-window-horizontally)
162 (define-key crisp-mode-map [(f2) (up)] 'shrink-window)
163 (define-key crisp-mode-map [(f3) (down)] 'split-window-vertically)
164 (define-key crisp-mode-map [(f3) (right)] 'split-window-horizontally)
165
166 (define-key crisp-mode-map [(f4)] 'delete-window)
167 (define-key crisp-mode-map [(control f4)] 'delete-other-windows)
168
169 (define-key crisp-mode-map [(f5)] 'search-forward-regexp)
170 (define-key crisp-mode-map [(f19)] 'search-forward-regexp)
171 (define-key crisp-mode-map [(meta f5)] 'search-backward-regexp)
172
173 (define-key crisp-mode-map [(f6)] 'query-replace)
174
175 (define-key crisp-mode-map [(f7)] 'start-kbd-macro)
176 (define-key crisp-mode-map [(meta f7)] 'end-kbd-macro)
177
178 (define-key crisp-mode-map [(f8)] 'call-last-kbd-macro)
179 (define-key crisp-mode-map [(meta f8)] 'save-kbd-macro)
180
181 (define-key crisp-mode-map [(f9)] 'find-file)
182 (define-key crisp-mode-map [(meta f9)] 'load-library)
183
184 (define-key crisp-mode-map [(f10)] 'execute-extended-command)
185 (define-key crisp-mode-map [(meta f10)] 'compile)
186
187 (define-key crisp-mode-map [(SunF37)] 'kill-buffer)
188 (define-key crisp-mode-map [(kp-add)] 'crisp-copy-line)
189 (define-key crisp-mode-map [(kp-subtract)] 'crisp-kill-line)
190 ;; just to cover all the bases (GNU Emacs, for instance)
191 (define-key crisp-mode-map [(f24)] 'crisp-kill-line)
192 (define-key crisp-mode-map [(insert)] 'crisp-yank-clipboard)
193 (define-key crisp-mode-map [(f16)] 'crisp-set-clipboard) ; copy on Sun5 kbd
194 (define-key crisp-mode-map [(f20)] 'crisp-kill-region) ; cut on Sun5 kbd
195 (define-key crisp-mode-map [(f18)] 'crisp-yank-clipboard) ; paste on Sun5 kbd
196
197 (define-key crisp-mode-map [(control f)] 'fill-paragraph-or-region)
198 (define-key crisp-mode-map [(meta d)] (lambda ()
199 (interactive)
200 (beginning-of-line) (kill-line)))
201 (define-key crisp-mode-map [(meta e)] 'find-file)
202 (define-key crisp-mode-map [(meta g)] 'goto-line)
203 (define-key crisp-mode-map [(meta h)] 'help)
204 (define-key crisp-mode-map [(meta i)] 'overwrite-mode)
205 (define-key crisp-mode-map [(meta j)] 'bookmark-jump)
206 (define-key crisp-mode-map [(meta l)] 'crisp-mark-line)
207 (define-key crisp-mode-map [(meta m)] 'set-mark-command)
208 (define-key crisp-mode-map [(meta n)] 'bury-buffer)
209 (define-key crisp-mode-map [(meta p)] 'crisp-unbury-buffer)
210 (define-key crisp-mode-map [(meta u)] 'advertised-undo)
211 (define-key crisp-mode-map [(f14)] 'advertised-undo)
212 (define-key crisp-mode-map [(meta w)] 'save-buffer)
213 (define-key crisp-mode-map [(meta x)] 'crisp-meta-x-wrapper)
214 (define-key crisp-mode-map [(meta ?0)] (lambda ()
215 (interactive)
216 (bookmark-set "0")))
217 (define-key crisp-mode-map [(meta ?1)] (lambda ()
218 (interactive)
219 (bookmark-set "1")))
220 (define-key crisp-mode-map [(meta ?2)] (lambda ()
221 (interactive)
222 (bookmark-set "2")))
223 (define-key crisp-mode-map [(meta ?3)] (lambda ()
224 (interactive)
225 (bookmark-set "3")))
226 (define-key crisp-mode-map [(meta ?4)] (lambda ()
227 (interactive)
228 (bookmark-set "4")))
229 (define-key crisp-mode-map [(meta ?5)] (lambda ()
230 (interactive)
231 (bookmark-set "5")))
232 (define-key crisp-mode-map [(meta ?6)] (lambda ()
233 (interactive)
234 (bookmark-set "6")))
235 (define-key crisp-mode-map [(meta ?7)] (lambda ()
236 (interactive)
237 (bookmark-set "7")))
238 (define-key crisp-mode-map [(meta ?8)] (lambda ()
239 (interactive)
240 (bookmark-set "8")))
241 (define-key crisp-mode-map [(meta ?9)] (lambda ()
242 (interactive)
243 (bookmark-set "9")))
244
245 (define-key crisp-mode-map [(shift delete)] 'kill-word)
246 (define-key crisp-mode-map [(shift backspace)] 'backward-kill-word)
247 (define-key crisp-mode-map [(control left)] 'backward-word)
248 (define-key crisp-mode-map [(control right)] 'forward-word)
249
250 (define-key crisp-mode-map [(home)] 'crisp-home)
251 (define-key crisp-mode-map [(control home)] (lambda ()
252 (interactive)
253 (move-to-window-line 0)))
254 (define-key crisp-mode-map [(meta home)] 'beginning-of-line)
255 (define-key crisp-mode-map [(end)] 'crisp-end)
256 (define-key crisp-mode-map [(control end)] (lambda ()
257 (interactive)
258 (move-to-window-line -1)))
259 (define-key crisp-mode-map [(meta end)] 'end-of-line)
260
261 (define-key crisp-mode-map [(control c) (b)] 'crisp-submit-bug-report)
262
263 (defun crisp-version (&optional arg)
264 "Version number of the CRiSP emulator package.
265 If ARG, insert results at point."
266 (interactive "P")
267 (let ((foo (concat "CRiSP version " crisp-version)))
268 (if arg
269 (insert (message foo))
270 (message foo))))
271
272 (defun crisp-mark-line (arg)
273 "Put mark at the end of line. Arg works as in `end-of-line'."
274 (interactive "p")
275 (save-excursion
276 (if (and (eq last-command 'crisp-mark-line) (mark))
277 ;; Extend the previous state in the same direction:
278 (progn
279 (if (< (mark) (point)) (setq arg (- arg)))
280 (goto-char (mark))
281 (end-of-line arg)
282 ;; Do not mess with the mark stack, but merely adjust the previous state:
283 (set-mark (point)))
284 (end-of-line arg)
285 (push-mark (point) nil t))))
286
287 (defun crisp-kill-line (arg)
288 "Mark and kill line(s).
289 Marks from point to end of the current line (honoring prefix arguments),
290 copies the region to the kill ring and clipboard, and then deletes it."
291 (interactive "*p")
292 (if (crisp-region-active)
293 (call-interactively 'crisp-kill-region)
294 (crisp-mark-line arg)
295 (call-interactively 'crisp-kill-region)))
296
297 (defun crisp-copy-line (arg)
298 "Mark and copy line(s).
299 Marks from point to end of the current line (honoring prefix arguments),
300 copies the region to the kill ring and clipboard, and then deactivates
301 the region."
302 (interactive "*p")
303 (if (crisp-region-active)
304 (call-interactively 'crisp-set-clipboard)
305 (crisp-mark-line arg)
306 (call-interactively 'crisp-set-clipboard))
307 ;; clear the region after the operation is complete
308 ;; XEmacs does this automagically, Emacs doesn't.
309 (if (boundp 'mark-active)
310 (setq mark-active nil)))
311
312 (defun crisp-home ()
313 "\"Home\" the point, the way CRiSP would do it.
314 The first use moves point to beginning of the line. Second
315 consecutive use moves point to beginning of the screen. Third
316 consecutive use moves point to the beginning of the buffer."
317 (interactive nil)
318 (cond
319 ((and (eq last-command 'crisp-home)
320 (eq crisp-last-last-command 'crisp-home))
321 (goto-char (point-min)))
322 ((eq last-command 'crisp-home)
323 (move-to-window-line 0))
324 (t
325 (beginning-of-line)))
326 (setq crisp-last-last-command last-command))
327
328 (defun crisp-end ()
329 "\"End\" the point, the way CRiSP would do it.
330 The first use moves point to end of the line. Second
331 consecutive use moves point to the end of the screen. Third
332 consecutive use moves point to the end of the buffer."
333 (interactive nil)
334 (cond
335 ((and (eq last-command 'crisp-end)
336 (eq crisp-last-last-command 'crisp-end))
337 (goto-char (point-max)))
338 ((eq last-command 'crisp-end)
339 (move-to-window-line -1)
340 (end-of-line))
341 (t
342 (end-of-line)))
343 (setq crisp-last-last-command last-command))
344
345 (defun crisp-unbury-buffer ()
346 "Go back one buffer"
347 (interactive)
348 (switch-to-buffer (car (last (buffer-list)))))
349
350 (defun crisp-meta-x-wrapper ()
351 "Wrapper function to conditionally override the normal M-x bindings.
352 When `crisp-override-meta-x' is non-nil, M-x will exit Emacs (the
353 normal CRiSP binding) and when it is nil M-x will run
354 `execute-extended-command' (the normal Emacs binding)."
355 (interactive)
356 (if crisp-override-meta-x
357 (save-buffers-kill-emacs)
358 (call-interactively 'execute-extended-command)))
359
360 ;; bug reporter
361
362 (defun crisp-submit-bug-report ()
363 "Submit via mail a bug report on CRiSP Mode."
364 (interactive)
365 ;; load in reporter
366 (let ((reporter-prompt-for-summary-p t)
367 (reporter-dont-compact-list '(c-offsets-alist)))
368 (and
369 (if (y-or-n-p "Do you want to submit a report on CRiSP Mode? ")
370 t (message "") nil)
371 (require 'reporter)
372 (reporter-submit-bug-report
373 crisp-mode-help-address
374 (concat "CRiSP Mode [" crisp-version "]")
375 nil
376 nil
377 nil
378 "Dear Gary,"
379 ))))
380
381 ;; Now enable the mode
382
383 (defun crisp-mode (&optional arg)
384 "Toggle CRiSP emulation minor mode.
385 With ARG, turn CRiSP mode on if ARG is positive, off otherwise."
386 (interactive "P")
387 (setq crisp-mode-enabled (if (null arg)
388 (not crisp-mode-enabled)
389 (> (prefix-numeric-value arg) 0)))
390 (cond
391 ((eq crisp-mode-enabled 't)
392 (use-global-map crisp-mode-map)
393 (if crisp-load-scroll-all
394 (require 'scroll-all))
395 (if (featurep 'scroll-all)
396 (define-key crisp-mode-map [(meta f1)] 'scroll-all-mode))
397 (run-hooks 'crisp-load-hook))
398 ((eq crisp-mode-enabled 'nil)
399 (use-global-map crisp-mode-original-keymap))))
400
401 (if (fboundp 'add-minor-mode)
402 (add-minor-mode 'crisp-mode-enabled 'crisp-mode-modeline-string
403 nil nil 'crisp-mode)
404 (or (assq 'crisp-mode-enabled minor-mode-alist)
405 (setq minor-mode-alist
406 (cons '(crisp-mode-enabled crisp-mode-modeline-string) minor-mode-alist))))
407
408 (provide 'crisp)
409
410 ;;; crisp.el ends here