Commit | Line | Data |
---|---|---|
5d5fa02f | 1 | ;;; crisp.el --- CRiSP/Brief Emacs emulator |
d21b2085 | 2 | |
3da6cc26 | 3 | ;; Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc. |
5e33ba39 | 4 | |
da061c5e | 5 | ;; Author: Gary D. Foster <Gary.Foster@Corp.Sun.COM> |
7aa5f6cf | 6 | ;; Keywords: emulations brief crisp |
5e33ba39 RS |
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 | ||
7aa5f6cf KH |
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. | |
5e33ba39 | 31 | |
7aa5f6cf KH |
32 | ;; Enable this package by putting (require 'crisp) in your .emacs and |
33 | ;; use M-x crisp-mode to toggle it on or off. | |
5e33ba39 | 34 | |
7aa5f6cf KH |
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. | |
5e33ba39 | 40 | |
7aa5f6cf KH |
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 | |
3da6cc26 RS |
45 | ;; interactively. The default setting is t, which means that M-x will |
46 | ;; by default run `save-buffers-kill-emacs' instead of the command | |
47 | ;; `execute-extended-command'. | |
5e33ba39 | 48 | |
d21b2085 RS |
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 | ||
5e33ba39 RS |
55 | ;; All these overrides should go *before* the (require 'crisp) statement. |
56 | ||
5d5fa02f | 57 | ;;; Code: |
7aa5f6cf | 58 | |
7aa5f6cf KH |
59 | ;; local variables |
60 | ||
0b5bb3ec SE |
61 | (defgroup crisp nil |
62 | "Emulator for CRiSP and Brief key bindings." | |
63 | :prefix "crisp-" | |
64 | :group 'emulations) | |
65 | ||
7aa5f6cf | 66 | (defvar crisp-mode-map (let ((map (make-sparse-keymap))) |
7aa5f6cf | 67 | map) |
d21b2085 | 68 | "Local keymap for CRiSP emulation mode. |
7aa5f6cf KH |
69 | All the bindings are done here instead of globally to try and be |
70 | nice to the world.") | |
5e33ba39 | 71 | |
0b5bb3ec | 72 | (defcustom crisp-mode-modeline-string " *CRiSP*" |
7aa5f6cf | 73 | "*String to display in the modeline when CRiSP emulation mode is enabled." |
0b5bb3ec SE |
74 | :type 'string |
75 | :group 'crisp) | |
d21b2085 | 76 | |
3da6cc26 RS |
77 | ;;;###autoload |
78 | (defcustom crisp-mode nil | |
d21b2085 RS |
79 | "Track status of CRiSP emulation mode. |
80 | A value of nil means CRiSP mode is not enabled. A value of t | |
3da6cc26 RS |
81 | indicates CRiSP mode is enabled. |
82 | ||
83 | Setting this variable directly does not take effect; | |
84 | use either M-x customize or the function `crisp-mode'." | |
85 | :set (lambda (symbol value) (crisp-mode (if value 1 0))) | |
6110ea0a | 86 | :initialize 'custom-initialize-default |
3da6cc26 RS |
87 | :require 'crisp |
88 | :version "20.4" | |
0b5bb3ec SE |
89 | :type 'boolean |
90 | :group 'crisp) | |
d21b2085 | 91 | |
0b5bb3ec | 92 | (defcustom crisp-override-meta-x t |
7aa5f6cf | 93 | "*Controls overriding the normal Emacs M-x key binding in the CRiSP emulator. |
28085971 | 94 | Normally the CRiSP emulator rebinds M-x to `save-buffers-exit-emacs', and |
7aa5f6cf KH |
95 | provides the usual M-x functionality on the F10 key. If this variable |
96 | is non-nil, M-x will exit Emacs." | |
0b5bb3ec SE |
97 | :type 'boolean |
98 | :group 'crisp) | |
5e33ba39 | 99 | |
7aa5f6cf KH |
100 | (defcustom crisp-load-scroll-all nil |
101 | "Controls loading of the Scroll Lock in the CRiSP emulator. | |
102 | Its default behavior is to load and enable the Scroll Lock minor mode | |
5e33ba39 RS |
103 | package when enabling the CRiSP emulator. |
104 | ||
105 | If this variable is nil when you start the CRiSP emulator, it | |
7aa5f6cf | 106 | does not load the scroll-all package." |
0b5bb3ec SE |
107 | :type 'boolean |
108 | :group 'crisp) | |
5e33ba39 | 109 | |
0b5bb3ec | 110 | (defcustom crisp-load-hook nil |
7aa5f6cf | 111 | "Hooks to run after loading the CRiSP emulator package." |
0b5bb3ec SE |
112 | :type 'hook |
113 | :group 'crisp) | |
d21b2085 | 114 | |
3da6cc26 RS |
115 | (defcustom crisp-mode-hook nil |
116 | "Hook run by the function `crisp-mode'." | |
117 | :type 'hook | |
118 | :group 'crisp) | |
119 | ||
120 | (defconst crisp-version "1.34" | |
7aa5f6cf | 121 | "The version of the CRiSP emulator.") |
d21b2085 | 122 | |
7aa5f6cf KH |
123 | (defconst crisp-mode-help-address "gfoster@suzieq.ml.org" |
124 | "The email address of the CRiSP mode author/maintainer.") | |
f4ff0fb4 | 125 | |
7aa5f6cf KH |
126 | ;; Silence the byte-compiler. |
127 | (defvar crisp-last-last-command nil | |
28085971 | 128 | "The previous value of `last-command'.") |
7aa5f6cf KH |
129 | |
130 | ;; The cut and paste routines are different between XEmacs and Emacs | |
131 | ;; so we need to set up aliases for the functions. | |
132 | ||
28085971 RS |
133 | (defalias 'crisp-set-clipboard |
134 | (if (fboundp 'clipboard-kill-ring-save) | |
135 | 'clipboard-kill-ring-save | |
136 | 'copy-primary-selection)) | |
137 | ||
138 | (defalias 'crisp-kill-region | |
139 | (if (fboundp 'clipboard-kill-region) | |
140 | 'clipboard-kill-region | |
141 | 'kill-primary-selection)) | |
142 | ||
143 | (defalias 'crisp-yank-clipboard | |
144 | (if (fboundp 'clipboard-yank) | |
145 | 'clipboard-yank | |
146 | 'yank-clipboard-selection)) | |
7aa5f6cf | 147 | |
28085971 | 148 | (defun crisp-region-active () |
7aa5f6cf KH |
149 | "Compatibility function to test for an active region." |
150 | (if (boundp 'zmacs-region-active-p) | |
151 | zmacs-region-active-p | |
152 | mark-active)) | |
5e33ba39 RS |
153 | |
154 | ;; and now the keymap defines | |
155 | ||
156 | (define-key crisp-mode-map [(f1)] 'other-window) | |
157 | ||
158 | (define-key crisp-mode-map [(f2) (down)] 'enlarge-window) | |
159 | (define-key crisp-mode-map [(f2) (left)] 'shrink-window-horizontally) | |
160 | (define-key crisp-mode-map [(f2) (right)] 'enlarge-window-horizontally) | |
161 | (define-key crisp-mode-map [(f2) (up)] 'shrink-window) | |
162 | (define-key crisp-mode-map [(f3) (down)] 'split-window-vertically) | |
163 | (define-key crisp-mode-map [(f3) (right)] 'split-window-horizontally) | |
164 | ||
165 | (define-key crisp-mode-map [(f4)] 'delete-window) | |
166 | (define-key crisp-mode-map [(control f4)] 'delete-other-windows) | |
167 | ||
168 | (define-key crisp-mode-map [(f5)] 'search-forward-regexp) | |
169 | (define-key crisp-mode-map [(f19)] 'search-forward-regexp) | |
7aa5f6cf | 170 | (define-key crisp-mode-map [(meta f5)] 'search-backward-regexp) |
5e33ba39 RS |
171 | |
172 | (define-key crisp-mode-map [(f6)] 'query-replace) | |
173 | ||
174 | (define-key crisp-mode-map [(f7)] 'start-kbd-macro) | |
7aa5f6cf | 175 | (define-key crisp-mode-map [(meta f7)] 'end-kbd-macro) |
5e33ba39 RS |
176 | |
177 | (define-key crisp-mode-map [(f8)] 'call-last-kbd-macro) | |
178 | (define-key crisp-mode-map [(meta f8)] 'save-kbd-macro) | |
179 | ||
180 | (define-key crisp-mode-map [(f9)] 'find-file) | |
7aa5f6cf | 181 | (define-key crisp-mode-map [(meta f9)] 'load-library) |
5e33ba39 RS |
182 | |
183 | (define-key crisp-mode-map [(f10)] 'execute-extended-command) | |
7aa5f6cf KH |
184 | (define-key crisp-mode-map [(meta f10)] 'compile) |
185 | ||
186 | (define-key crisp-mode-map [(SunF37)] 'kill-buffer) | |
187 | (define-key crisp-mode-map [(kp-add)] 'crisp-copy-line) | |
188 | (define-key crisp-mode-map [(kp-subtract)] 'crisp-kill-line) | |
189 | ;; just to cover all the bases (GNU Emacs, for instance) | |
190 | (define-key crisp-mode-map [(f24)] 'crisp-kill-line) | |
28085971 RS |
191 | (define-key crisp-mode-map [(insert)] 'crisp-yank-clipboard) |
192 | (define-key crisp-mode-map [(f16)] 'crisp-set-clipboard) ; copy on Sun5 kbd | |
3da6cc26 | 193 | (define-key crisp-mode-map [(f20)] 'crisp-kill-region) ; cut on Sun5 kbd |
28085971 | 194 | (define-key crisp-mode-map [(f18)] 'crisp-yank-clipboard) ; paste on Sun5 kbd |
7aa5f6cf KH |
195 | |
196 | (define-key crisp-mode-map [(control f)] 'fill-paragraph-or-region) | |
197 | (define-key crisp-mode-map [(meta d)] (lambda () | |
198 | (interactive) | |
199 | (beginning-of-line) (kill-line))) | |
5e33ba39 RS |
200 | (define-key crisp-mode-map [(meta e)] 'find-file) |
201 | (define-key crisp-mode-map [(meta g)] 'goto-line) | |
202 | (define-key crisp-mode-map [(meta h)] 'help) | |
203 | (define-key crisp-mode-map [(meta i)] 'overwrite-mode) | |
d21b2085 | 204 | (define-key crisp-mode-map [(meta j)] 'bookmark-jump) |
7aa5f6cf KH |
205 | (define-key crisp-mode-map [(meta l)] 'crisp-mark-line) |
206 | (define-key crisp-mode-map [(meta m)] 'set-mark-command) | |
207 | (define-key crisp-mode-map [(meta n)] 'bury-buffer) | |
208 | (define-key crisp-mode-map [(meta p)] 'crisp-unbury-buffer) | |
5e33ba39 RS |
209 | (define-key crisp-mode-map [(meta u)] 'advertised-undo) |
210 | (define-key crisp-mode-map [(f14)] 'advertised-undo) | |
211 | (define-key crisp-mode-map [(meta w)] 'save-buffer) | |
7aa5f6cf KH |
212 | (define-key crisp-mode-map [(meta x)] 'crisp-meta-x-wrapper) |
213 | (define-key crisp-mode-map [(meta ?0)] (lambda () | |
214 | (interactive) | |
215 | (bookmark-set "0"))) | |
216 | (define-key crisp-mode-map [(meta ?1)] (lambda () | |
217 | (interactive) | |
218 | (bookmark-set "1"))) | |
219 | (define-key crisp-mode-map [(meta ?2)] (lambda () | |
220 | (interactive) | |
221 | (bookmark-set "2"))) | |
222 | (define-key crisp-mode-map [(meta ?3)] (lambda () | |
223 | (interactive) | |
224 | (bookmark-set "3"))) | |
225 | (define-key crisp-mode-map [(meta ?4)] (lambda () | |
226 | (interactive) | |
227 | (bookmark-set "4"))) | |
228 | (define-key crisp-mode-map [(meta ?5)] (lambda () | |
229 | (interactive) | |
230 | (bookmark-set "5"))) | |
231 | (define-key crisp-mode-map [(meta ?6)] (lambda () | |
232 | (interactive) | |
233 | (bookmark-set "6"))) | |
234 | (define-key crisp-mode-map [(meta ?7)] (lambda () | |
235 | (interactive) | |
236 | (bookmark-set "7"))) | |
237 | (define-key crisp-mode-map [(meta ?8)] (lambda () | |
238 | (interactive) | |
239 | (bookmark-set "8"))) | |
240 | (define-key crisp-mode-map [(meta ?9)] (lambda () | |
241 | (interactive) | |
242 | (bookmark-set "9"))) | |
243 | ||
244 | (define-key crisp-mode-map [(shift delete)] 'kill-word) | |
5e33ba39 | 245 | (define-key crisp-mode-map [(shift backspace)] 'backward-kill-word) |
7aa5f6cf KH |
246 | (define-key crisp-mode-map [(control left)] 'backward-word) |
247 | (define-key crisp-mode-map [(control right)] 'forward-word) | |
248 | ||
249 | (define-key crisp-mode-map [(home)] 'crisp-home) | |
250 | (define-key crisp-mode-map [(control home)] (lambda () | |
251 | (interactive) | |
252 | (move-to-window-line 0))) | |
253 | (define-key crisp-mode-map [(meta home)] 'beginning-of-line) | |
254 | (define-key crisp-mode-map [(end)] 'crisp-end) | |
255 | (define-key crisp-mode-map [(control end)] (lambda () | |
256 | (interactive) | |
257 | (move-to-window-line -1))) | |
258 | (define-key crisp-mode-map [(meta end)] 'end-of-line) | |
259 | ||
7aa5f6cf KH |
260 | (defun crisp-version (&optional arg) |
261 | "Version number of the CRiSP emulator package. | |
262 | If ARG, insert results at point." | |
263 | (interactive "P") | |
264 | (let ((foo (concat "CRiSP version " crisp-version))) | |
265 | (if arg | |
266 | (insert (message foo)) | |
267 | (message foo)))) | |
268 | ||
269 | (defun crisp-mark-line (arg) | |
3da6cc26 RS |
270 | "Set mark at the end of the line. |
271 | Arg works as in `end-of-line'." | |
7aa5f6cf | 272 | (interactive "p") |
79b65a08 RS |
273 | (let (newmark) |
274 | (save-excursion | |
28085971 | 275 | (end-of-line arg) |
79b65a08 RS |
276 | (setq newmark (point))) |
277 | (push-mark newmark nil t))) | |
7aa5f6cf KH |
278 | |
279 | (defun crisp-kill-line (arg) | |
280 | "Mark and kill line(s). | |
281 | Marks from point to end of the current line (honoring prefix arguments), | |
282 | copies the region to the kill ring and clipboard, and then deletes it." | |
283 | (interactive "*p") | |
28085971 RS |
284 | (if (crisp-region-active) |
285 | (call-interactively 'crisp-kill-region) | |
7aa5f6cf | 286 | (crisp-mark-line arg) |
28085971 | 287 | (call-interactively 'crisp-kill-region))) |
7aa5f6cf KH |
288 | |
289 | (defun crisp-copy-line (arg) | |
290 | "Mark and copy line(s). | |
291 | Marks from point to end of the current line (honoring prefix arguments), | |
292 | copies the region to the kill ring and clipboard, and then deactivates | |
293 | the region." | |
294 | (interactive "*p") | |
28085971 RS |
295 | (if (crisp-region-active) |
296 | (call-interactively 'crisp-set-clipboard) | |
7aa5f6cf | 297 | (crisp-mark-line arg) |
28085971 | 298 | (call-interactively 'crisp-set-clipboard)) |
7aa5f6cf KH |
299 | ;; clear the region after the operation is complete |
300 | ;; XEmacs does this automagically, Emacs doesn't. | |
301 | (if (boundp 'mark-active) | |
302 | (setq mark-active nil))) | |
5e33ba39 | 303 | |
5e33ba39 | 304 | (defun crisp-home () |
7aa5f6cf | 305 | "\"Home\" the point, the way CRiSP would do it. |
5e33ba39 RS |
306 | The first use moves point to beginning of the line. Second |
307 | consecutive use moves point to beginning of the screen. Third | |
308 | consecutive use moves point to the beginning of the buffer." | |
309 | (interactive nil) | |
310 | (cond | |
f4ff0fb4 RS |
311 | ((and (eq last-command 'crisp-home) |
312 | (eq crisp-last-last-command 'crisp-home)) | |
d21b2085 | 313 | (goto-char (point-min))) |
5e33ba39 | 314 | ((eq last-command 'crisp-home) |
d21b2085 | 315 | (move-to-window-line 0)) |
5e33ba39 | 316 | (t |
d21b2085 | 317 | (beginning-of-line))) |
f4ff0fb4 | 318 | (setq crisp-last-last-command last-command)) |
5e33ba39 RS |
319 | |
320 | (defun crisp-end () | |
7aa5f6cf | 321 | "\"End\" the point, the way CRiSP would do it. |
5e33ba39 RS |
322 | The first use moves point to end of the line. Second |
323 | consecutive use moves point to the end of the screen. Third | |
324 | consecutive use moves point to the end of the buffer." | |
325 | (interactive nil) | |
326 | (cond | |
7aa5f6cf KH |
327 | ((and (eq last-command 'crisp-end) |
328 | (eq crisp-last-last-command 'crisp-end)) | |
d21b2085 | 329 | (goto-char (point-max))) |
5e33ba39 RS |
330 | ((eq last-command 'crisp-end) |
331 | (move-to-window-line -1) | |
d21b2085 | 332 | (end-of-line)) |
5e33ba39 | 333 | (t |
d21b2085 | 334 | (end-of-line))) |
f4ff0fb4 | 335 | (setq crisp-last-last-command last-command)) |
5e33ba39 | 336 | |
7aa5f6cf | 337 | (defun crisp-unbury-buffer () |
3da6cc26 | 338 | "Go back one buffer." |
7aa5f6cf KH |
339 | (interactive) |
340 | (switch-to-buffer (car (last (buffer-list))))) | |
a1506d29 | 341 | |
7aa5f6cf KH |
342 | (defun crisp-meta-x-wrapper () |
343 | "Wrapper function to conditionally override the normal M-x bindings. | |
344 | When `crisp-override-meta-x' is non-nil, M-x will exit Emacs (the | |
345 | normal CRiSP binding) and when it is nil M-x will run | |
346 | `execute-extended-command' (the normal Emacs binding)." | |
347 | (interactive) | |
348 | (if crisp-override-meta-x | |
349 | (save-buffers-kill-emacs) | |
350 | (call-interactively 'execute-extended-command))) | |
351 | ||
3da6cc26 | 352 | ;;;###autoload |
7aa5f6cf | 353 | (defun crisp-mode (&optional arg) |
4e968343 | 354 | "Toggle CRiSP/Brief emulation minor mode. |
7aa5f6cf KH |
355 | With ARG, turn CRiSP mode on if ARG is positive, off otherwise." |
356 | (interactive "P") | |
3da6cc26 RS |
357 | (setq crisp-mode (if (null arg) |
358 | (not crisp-mode) | |
359 | (> (prefix-numeric-value arg) 0))) | |
360 | (when crisp-mode | |
6110ea0a KH |
361 | ;; Force transient-mark-mode, so that the marking routines work as |
362 | ;; expected. If the user turns off transient mark mode, most | |
363 | ;; things will still work fine except the crisp-(copy|kill) | |
364 | ;; functions won't work quite as nicely when regions are marked | |
365 | ;; differently and could really confuse people. Caveat emptor. | |
366 | (if (fboundp 'transient-mark-mode) | |
367 | (transient-mark-mode t)) | |
a06e220d RS |
368 | (if crisp-load-scroll-all |
369 | (require 'scroll-all)) | |
370 | (if (featurep 'scroll-all) | |
371 | (define-key crisp-mode-map [(meta f1)] 'scroll-all-mode)) | |
6110ea0a | 372 | (run-hooks 'crisp-mode-hook))) |
5e33ba39 | 373 | |
4e968343 DL |
374 | ;; People might use Apropos on `brief'. |
375 | ;;;###autoload | |
376 | (defalias 'brief-mode 'crisp-mode) | |
377 | ||
7aa5f6cf | 378 | (if (fboundp 'add-minor-mode) |
3da6cc26 RS |
379 | (add-minor-mode 'crisp-mode 'crisp-mode-modeline-string |
380 | crisp-mode-map nil 'crisp-mode) | |
381 | (or (assq 'crisp-mode minor-mode-alist) | |
7aa5f6cf | 382 | (setq minor-mode-alist |
3da6cc26 RS |
383 | (cons '(crisp-mode crisp-mode-modeline-string) minor-mode-alist))) |
384 | (or (assq 'crisp-mode minor-mode-map-alist) | |
385 | (setq minor-mode-map-alist (cons (cons 'crisp-mode crisp-mode-map) | |
386 | minor-mode-map-alist)))) | |
7aa5f6cf | 387 | |
504feff5 KG |
388 | ;; Interaction with other packages. |
389 | (eval-after-load 'cua | |
6d91a595 KG |
390 | '(progn |
391 | (add-to-list 'cua--standard-movement-commands 'crisp-home) | |
392 | (add-to-list 'cua--standard-movement-commands 'crisp-end))) | |
504feff5 | 393 | |
6110ea0a | 394 | (run-hooks 'crisp-load-hook) |
5e33ba39 RS |
395 | (provide 'crisp) |
396 | ||
8c7d9baf | 397 | ;;; crisp.el ends here |