Merge from emacs-24; up to 2014-06-06T02:22:40Z!monnier@iro.umontreal.ca
[emacs.git] / lisp / obsolete / crisp.el
blob47cf898190bf25a9a7ae081f365f3a6a0f4540de
1 ;;; crisp.el --- CRiSP/Brief Emacs emulator
3 ;; Copyright (C) 1997-1999, 2001-2014 Free Software Foundation, Inc.
5 ;; Author: Gary D. Foster <Gary.Foster@Corp.Sun.COM>
6 ;; Keywords: emulations brief crisp
7 ;; Obsolete-since: 24.5
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;; Keybindings and minor functions to duplicate the functionality and
27 ;; finger-feel of the CRiSP/Brief editor. This package is designed to
28 ;; facilitate transitioning from Brief to (XE|E)macs with a minimum
29 ;; amount of hassles.
31 ;; Enable this package by putting (require 'crisp) in your .emacs and
32 ;; use M-x crisp-mode to toggle it on or off.
34 ;; This package will automatically load the scroll-all.el package if
35 ;; you put (setq crisp-load-scroll-all t) in your .emacs before
36 ;; loading this package. If this feature is enabled, it will bind
37 ;; meta-f1 to the scroll-all mode toggle. The scroll-all package
38 ;; duplicates the scroll-all feature in CRiSP.
40 ;; Also, the default keybindings for brief/CRiSP override the M-x
41 ;; key to exit the editor. If you don't like this functionality, you
42 ;; can prevent this behavior (or redefine it dynamically) by setting
43 ;; the value of `crisp-override-meta-x' either in your .emacs or
44 ;; interactively. The default setting is t, which means that M-x will
45 ;; by default run `save-buffers-kill-emacs' instead of the command
46 ;; `execute-extended-command'.
48 ;; Finally, if you want to change the string displayed in the mode
49 ;; line when this mode is in effect, override the definition of
50 ;; `crisp-mode-mode-line-string' in your .emacs. The default value is
51 ;; " *Crisp*" which may be a bit lengthy if you have a lot of things
52 ;; being displayed there.
54 ;; All these overrides should go *before* the (require 'crisp) statement.
56 ;;; Code:
58 ;; local variables
60 (defgroup crisp nil
61 "Emulator for CRiSP and Brief key bindings."
62 :prefix "crisp-"
63 :group 'emulations)
65 (defvar crisp-mode-map
66 (let ((map (make-sparse-keymap)))
67 (define-key map [(f1)] 'other-window)
69 (define-key map [(f2) (down)] 'enlarge-window)
70 (define-key map [(f2) (left)] 'shrink-window-horizontally)
71 (define-key map [(f2) (right)] 'enlarge-window-horizontally)
72 (define-key map [(f2) (up)] 'shrink-window)
73 (define-key map [(f3) (down)] 'split-window-below)
74 (define-key map [(f3) (right)] 'split-window-right)
76 (define-key map [(f4)] 'delete-window)
77 (define-key map [(control f4)] 'delete-other-windows)
79 (define-key map [(f5)] 'search-forward-regexp)
80 (define-key map [(f19)] 'search-forward-regexp)
81 (define-key map [(meta f5)] 'search-backward-regexp)
83 (define-key map [(f6)] 'query-replace)
85 (define-key map [(f7)] 'start-kbd-macro)
86 (define-key map [(meta f7)] 'end-kbd-macro)
88 (define-key map [(f8)] 'call-last-kbd-macro)
89 (define-key map [(meta f8)] 'save-kbd-macro)
91 (define-key map [(f9)] 'find-file)
92 (define-key map [(meta f9)] 'load-library)
94 (define-key map [(f10)] 'execute-extended-command)
95 (define-key map [(meta f10)] 'compile)
97 (define-key map [(SunF37)] 'kill-buffer)
98 (define-key map [(kp-add)] 'crisp-copy-line)
99 (define-key map [(kp-subtract)] 'crisp-kill-line)
100 ;; just to cover all the bases (GNU Emacs, for instance)
101 (define-key map [(f24)] 'crisp-kill-line)
102 (define-key map [(insert)] 'crisp-yank-clipboard)
103 (define-key map [(f16)] 'crisp-set-clipboard) ; copy on Sun5 kbd
104 (define-key map [(f20)] 'crisp-kill-region) ; cut on Sun5 kbd
105 (define-key map [(f18)] 'crisp-yank-clipboard) ; paste on Sun5 kbd
107 (define-key map [(control f)] 'fill-paragraph-or-region)
108 (define-key map [(meta d)] (lambda ()
109 (interactive)
110 (beginning-of-line) (kill-line)))
111 (define-key map [(meta e)] 'find-file)
112 (define-key map [(meta g)] 'goto-line)
113 (define-key map [(meta h)] 'help)
114 (define-key map [(meta i)] 'overwrite-mode)
115 (define-key map [(meta j)] 'bookmark-jump)
116 (define-key map [(meta l)] 'crisp-mark-line)
117 (define-key map [(meta m)] 'set-mark-command)
118 (define-key map [(meta n)] 'bury-buffer)
119 (define-key map [(meta p)] 'crisp-unbury-buffer)
120 (define-key map [(meta u)] 'undo)
121 (define-key map [(f14)] 'undo)
122 (define-key map [(meta w)] 'save-buffer)
123 (define-key map [(meta x)] 'crisp-meta-x-wrapper)
124 (define-key map [(meta ?0)] (lambda ()
125 (interactive)
126 (bookmark-set "0")))
127 (define-key map [(meta ?1)] (lambda ()
128 (interactive)
129 (bookmark-set "1")))
130 (define-key map [(meta ?2)] (lambda ()
131 (interactive)
132 (bookmark-set "2")))
133 (define-key map [(meta ?3)] (lambda ()
134 (interactive)
135 (bookmark-set "3")))
136 (define-key map [(meta ?4)] (lambda ()
137 (interactive)
138 (bookmark-set "4")))
139 (define-key map [(meta ?5)] (lambda ()
140 (interactive)
141 (bookmark-set "5")))
142 (define-key map [(meta ?6)] (lambda ()
143 (interactive)
144 (bookmark-set "6")))
145 (define-key map [(meta ?7)] (lambda ()
146 (interactive)
147 (bookmark-set "7")))
148 (define-key map [(meta ?8)] (lambda ()
149 (interactive)
150 (bookmark-set "8")))
151 (define-key map [(meta ?9)] (lambda ()
152 (interactive)
153 (bookmark-set "9")))
155 (define-key map [(shift delete)] 'kill-word)
156 (define-key map [(shift backspace)] 'backward-kill-word)
157 (define-key map [(control left)] 'backward-word)
158 (define-key map [(control right)] 'forward-word)
160 (define-key map [(home)] 'crisp-home)
161 (define-key map [(control home)] (lambda ()
162 (interactive)
163 (move-to-window-line 0)))
164 (define-key map [(meta home)] 'beginning-of-line)
165 (define-key map [(end)] 'crisp-end)
166 (define-key map [(control end)] (lambda ()
167 (interactive)
168 (move-to-window-line -1)))
169 (define-key map [(meta end)] 'end-of-line)
170 map)
171 "Local keymap for CRiSP emulation mode.
172 All the bindings are done here instead of globally to try and be
173 nice to the world.")
175 (define-obsolete-variable-alias 'crisp-mode-modeline-string
176 'crisp-mode-mode-line-string "24.3")
178 (defcustom crisp-mode-mode-line-string " *CRiSP*"
179 "String to display in the mode line when CRiSP emulation mode is enabled."
180 :type 'string
181 :group 'crisp)
183 ;;;###autoload
184 (defcustom crisp-mode nil
185 "Track status of CRiSP emulation mode.
186 A value of nil means CRiSP mode is not enabled. A value of t
187 indicates CRiSP mode is enabled.
189 Setting this variable directly does not take effect;
190 use either M-x customize or the function `crisp-mode'."
191 :set (lambda (symbol value) (crisp-mode (if value 1 0)))
192 :initialize 'custom-initialize-default
193 :require 'crisp
194 :version "20.4"
195 :type 'boolean
196 :group 'crisp)
198 (defcustom crisp-override-meta-x t
199 "Controls overriding the normal Emacs M-x key binding in the CRiSP emulator.
200 Normally the CRiSP emulator rebinds M-x to `save-buffers-exit-emacs', and
201 provides the usual M-x functionality on the F10 key. If this variable
202 is non-nil, M-x will exit Emacs."
203 :type 'boolean
204 :group 'crisp)
206 (defcustom crisp-load-scroll-all nil
207 "Controls loading of the Scroll Lock in the CRiSP emulator.
208 Its default behavior is to load and enable the Scroll Lock minor mode
209 package when enabling the CRiSP emulator.
211 If this variable is nil when you start the CRiSP emulator, it
212 does not load the scroll-all package."
213 :type 'boolean
214 :group 'crisp)
216 (defcustom crisp-load-hook nil
217 "Hooks to run after loading the CRiSP emulator package."
218 :type 'hook
219 :group 'crisp)
221 (defcustom crisp-mode-hook nil
222 "Hook run by the function `crisp-mode'."
223 :type 'hook
224 :group 'crisp)
226 (defconst crisp-version "1.34"
227 "The version of the CRiSP emulator.")
229 (defconst crisp-mode-help-address "gfoster@suzieq.ml.org"
230 "The email address of the CRiSP mode author/maintainer.")
232 ;; Silence the byte-compiler.
233 (defvar crisp-last-last-command nil
234 "The previous value of `last-command'.")
236 ;; The cut and paste routines are different between XEmacs and Emacs
237 ;; so we need to set up aliases for the functions.
239 (defalias 'crisp-set-clipboard
240 (if (fboundp 'clipboard-kill-ring-save)
241 'clipboard-kill-ring-save
242 'copy-primary-selection))
244 (defalias 'crisp-kill-region
245 (if (fboundp 'clipboard-kill-region)
246 'clipboard-kill-region
247 'kill-primary-selection))
249 (defalias 'crisp-yank-clipboard
250 (if (fboundp 'clipboard-yank)
251 'clipboard-yank
252 'yank-clipboard-selection))
254 (defun crisp-region-active ()
255 "Compatibility function to test for an active region."
256 (if (featurep 'xemacs)
257 zmacs-region-active-p
258 mark-active))
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))))
269 (defun crisp-mark-line (arg)
270 "Set mark at the end of the line.
271 Arg works as in `end-of-line'."
272 (interactive "p")
273 (let (newmark)
274 (save-excursion
275 (end-of-line arg)
276 (setq newmark (point)))
277 (push-mark newmark nil t)))
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")
284 (if (crisp-region-active)
285 (call-interactively 'crisp-kill-region)
286 (crisp-mark-line arg)
287 (call-interactively 'crisp-kill-region)))
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")
295 (if (crisp-region-active)
296 (call-interactively 'crisp-set-clipboard)
297 (crisp-mark-line arg)
298 (call-interactively 'crisp-set-clipboard))
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)))
304 (defun crisp-home ()
305 "\"Home\" the point, the way CRiSP would do it.
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
311 ((and (eq last-command 'crisp-home)
312 (eq crisp-last-last-command 'crisp-home))
313 (goto-char (point-min)))
314 ((eq last-command 'crisp-home)
315 (move-to-window-line 0))
317 (beginning-of-line)))
318 (setq crisp-last-last-command last-command))
320 (defun crisp-end ()
321 "\"End\" the point, the way CRiSP would do it.
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
327 ((and (eq last-command 'crisp-end)
328 (eq crisp-last-last-command 'crisp-end))
329 (goto-char (point-max)))
330 ((eq last-command 'crisp-end)
331 (move-to-window-line -1)
332 (end-of-line))
334 (end-of-line)))
335 (setq crisp-last-last-command last-command))
337 (defun crisp-unbury-buffer ()
338 "Go back one buffer."
339 (interactive)
340 (switch-to-buffer (car (last (buffer-list)))))
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)))
352 ;;;###autoload
353 (define-minor-mode crisp-mode
354 "Toggle CRiSP/Brief emulation (CRiSP mode).
355 With a prefix argument ARG, enable CRiSP mode if ARG is positive,
356 and disable it otherwise. If called from Lisp, enable the mode
357 if ARG is omitted or nil."
358 :keymap crisp-mode-map
359 :lighter crisp-mode-mode-line-string
360 (when crisp-mode
361 ;; Make menu entries show M-u or f14 in preference to C-x u.
362 (put 'undo :advertised-binding
363 `([?\M-u] [f14] ,@(get 'undo :advertised-binding)))
364 ;; Force transient-mark-mode, so that the marking routines work as
365 ;; expected. If the user turns off transient mark mode, most
366 ;; things will still work fine except the crisp-(copy|kill)
367 ;; functions won't work quite as nicely when regions are marked
368 ;; differently and could really confuse people. Caveat emptor.
369 (if (fboundp 'transient-mark-mode)
370 (transient-mark-mode t))
371 (if crisp-load-scroll-all
372 (require 'scroll-all))
373 (if (featurep 'scroll-all)
374 (define-key crisp-mode-map [(meta f1)] 'scroll-all-mode))))
376 ;; People might use Apropos on `brief'.
377 ;;;###autoload
378 (defalias 'brief-mode 'crisp-mode)
380 ;; Interaction with other packages.
381 (put 'crisp-home 'CUA 'move)
382 (put 'crisp-end 'CUA 'move)
384 (run-hooks 'crisp-load-hook)
385 (provide 'crisp)
387 ;;; crisp.el ends here