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 ;; Maintainer: Luke Lee <luke.yx.lee@gmail.com>
7 ;; Keywords: emulations brief crisp
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
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
32 ;; Enable this package by putting (require 'crisp) in your .emacs and
33 ;; use M-x crisp-mode to toggle it on or off.
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-all feature in CRiSP.
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 t, which means that M-x will
46 ;; by default run `save-buffers-kill-emacs' instead of the command
47 ;; `execute-extended-command'.
49 ;; Finally, if you want to change the string displayed in the mode
50 ;; line when this mode is in effect, override the definition of
51 ;; `crisp-mode-mode-line-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.
55 ;; All these overrides should go *before* the (require 'crisp) statement.
62 "Emulator for CRiSP and Brief key bindings."
66 (defvar crisp-mode-map
67 (let ((map (make-sparse-keymap)))
68 (define-key map [(f1)] 'other-window)
70 (define-key map [(f2) (down)] 'enlarge-window)
71 (define-key map [(f2) (left)] 'shrink-window-horizontally)
72 (define-key map [(f2) (right)] 'enlarge-window-horizontally)
73 (define-key map [(f2) (up)] 'shrink-window)
74 (define-key map [(f3) (down)] 'split-window-below)
75 (define-key map [(f3) (right)] 'split-window-right)
77 (define-key map [(f4)] 'delete-window)
78 (define-key map [(control f4)] 'delete-other-windows)
80 (define-key map [(f5)] 'search-forward-regexp)
81 (define-key map [(f19)] 'search-forward-regexp)
82 (define-key map [(meta f5)] 'search-backward-regexp)
84 (define-key map [(f6)] 'query-replace)
86 (define-key map [(f7)] 'start-kbd-macro)
87 (define-key map [(meta f7)] 'end-kbd-macro)
89 (define-key map [(f8)] 'call-last-kbd-macro)
90 (define-key map [(meta f8)] 'save-kbd-macro)
92 (define-key map [(f9)] 'find-file)
93 (define-key map [(meta f9)] 'load-library)
95 (define-key map [(f10)] 'execute-extended-command)
96 (define-key map [(meta f10)] 'compile)
98 (define-key map [(SunF37)] 'kill-buffer)
99 (define-key map [(kp-add)] 'crisp-copy-line)
100 (define-key map [(kp-subtract)] 'crisp-kill-line)
101 ;; just to cover all the bases (GNU Emacs, for instance)
102 (define-key map [(f24)] 'crisp-kill-line)
103 (define-key map [(insert)] 'crisp-yank-clipboard)
104 (define-key map [(f16)] 'crisp-set-clipboard) ; copy on Sun5 kbd
105 (define-key map [(f20)] 'crisp-kill-region) ; cut on Sun5 kbd
106 (define-key map [(f18)] 'crisp-yank-clipboard) ; paste on Sun5 kbd
108 (define-key map [(control f)] 'fill-paragraph-or-region)
109 (define-key map [(meta d)] (lambda ()
111 (beginning-of-line) (kill-line)))
112 (define-key map [(meta e)] 'find-file)
113 (define-key map [(meta g)] 'goto-line)
114 (define-key map [(meta h)] 'help)
115 (define-key map [(meta i)] 'overwrite-mode)
116 (define-key map [(meta j)] 'bookmark-jump)
117 (define-key map [(meta l)] 'crisp-mark-line)
118 (define-key map [(meta m)] 'set-mark-command)
119 (define-key map [(meta n)] 'bury-buffer)
120 (define-key map [(meta p)] 'crisp-unbury-buffer)
121 (define-key map [(meta u)] 'undo)
122 (define-key map [(f14)] 'undo)
123 (define-key map [(meta w)] 'save-buffer)
124 (define-key map [(meta x)] 'crisp-meta-x-wrapper)
125 (define-key map [(meta ?0)] (lambda ()
128 (define-key map [(meta ?1)] (lambda ()
131 (define-key map [(meta ?2)] (lambda ()
134 (define-key map [(meta ?3)] (lambda ()
137 (define-key map [(meta ?4)] (lambda ()
140 (define-key map [(meta ?5)] (lambda ()
143 (define-key map [(meta ?6)] (lambda ()
146 (define-key map [(meta ?7)] (lambda ()
149 (define-key map [(meta ?8)] (lambda ()
152 (define-key map [(meta ?9)] (lambda ()
156 (define-key map [(shift delete)] 'kill-word)
157 (define-key map [(shift backspace)] 'backward-kill-word)
158 (define-key map [(control left)] 'backward-word)
159 (define-key map [(control right)] 'forward-word)
161 (define-key map [(home)] 'crisp-home)
162 (define-key map [(control home)] (lambda ()
164 (move-to-window-line 0)))
165 (define-key map [(meta home)] 'beginning-of-line)
166 (define-key map [(end)] 'crisp-end)
167 (define-key map [(control end)] (lambda ()
169 (move-to-window-line -1)))
170 (define-key map [(meta end)] 'end-of-line)
172 "Local keymap for CRiSP emulation mode.
173 All the bindings are done here instead of globally to try and be
176 (define-obsolete-variable-alias 'crisp-mode-modeline-string
177 'crisp-mode-mode-line-string "24.3")
179 (defcustom crisp-mode-mode-line-string " *CRiSP*"
180 "String to display in the mode line when CRiSP emulation mode is enabled."
185 (defcustom crisp-mode nil
186 "Track status of CRiSP emulation mode.
187 A value of nil means CRiSP mode is not enabled. A value of t
188 indicates CRiSP mode is enabled.
190 Setting this variable directly does not take effect;
191 use either M-x customize or the function `crisp-mode'."
192 :set (lambda (symbol value) (crisp-mode (if value 1 0)))
193 :initialize 'custom-initialize-default
199 (defcustom crisp-override-meta-x t
200 "Controls overriding the normal Emacs M-x key binding in the CRiSP emulator.
201 Normally the CRiSP emulator rebinds M-x to `save-buffers-exit-emacs', and
202 provides the usual M-x functionality on the F10 key. If this variable
203 is non-nil, M-x will exit Emacs."
207 (defcustom crisp-load-scroll-all nil
208 "Controls loading of the Scroll Lock in the CRiSP emulator.
209 Its default behavior is to load and enable the Scroll Lock minor mode
210 package when enabling the CRiSP emulator.
212 If this variable is nil when you start the CRiSP emulator, it
213 does not load the scroll-all package."
217 (defcustom crisp-load-hook nil
218 "Hooks to run after loading the CRiSP emulator package."
222 (defcustom crisp-mode-hook nil
223 "Hook run by the function `crisp-mode'."
227 (defconst crisp-version "1.3.4"
228 "The version of the CRiSP emulator.")
230 (defconst crisp-mode-help-address "gfoster@suzieq.ml.org"
231 "The email address of the CRiSP mode author/maintainer.")
233 ;; Silence the byte-compiler.
234 (defvar crisp-last-last-command nil
235 "The previous value of `last-command'.")
237 ;; The cut and paste routines are different between XEmacs and Emacs
238 ;; so we need to set up aliases for the functions.
240 (defalias 'crisp-set-clipboard
241 (if (fboundp 'clipboard-kill-ring-save)
242 'clipboard-kill-ring-save
243 'copy-primary-selection))
245 (defalias 'crisp-kill-region
246 (if (fboundp 'clipboard-kill-region)
247 'clipboard-kill-region
248 'kill-primary-selection))
250 (defalias 'crisp-yank-clipboard
251 (if (fboundp 'clipboard-yank)
253 'yank-clipboard-selection))
255 (defun crisp-region-active ()
256 "Compatibility function to test for an active region."
257 (if (featurep 'xemacs)
258 zmacs-region-active-p
261 (defun crisp-version (&optional arg)
262 "Version number of the CRiSP emulator package.
263 If ARG, insert results at point."
265 (let ((foo (concat "CRiSP version " crisp-version)))
267 (insert (message foo))
270 (defun crisp-mark-line (arg)
271 "Set mark at the end of the line.
272 Arg works as in `end-of-line'."
277 (setq newmark (point)))
278 (push-mark newmark nil t)))
280 (defun crisp-kill-line (arg)
281 "Mark and kill line(s).
282 Marks from point to end of the current line (honoring prefix arguments),
283 copies the region to the kill ring and clipboard, and then deletes it."
285 (if (crisp-region-active)
286 (call-interactively 'crisp-kill-region)
287 (crisp-mark-line arg)
288 (call-interactively 'crisp-kill-region)))
290 (defun crisp-copy-line (arg)
291 "Mark and copy line(s).
292 Marks from point to end of the current line (honoring prefix arguments),
293 copies the region to the kill ring and clipboard, and then deactivates
296 (if (crisp-region-active)
297 (call-interactively 'crisp-set-clipboard)
298 (crisp-mark-line arg)
299 (call-interactively 'crisp-set-clipboard))
300 ;; clear the region after the operation is complete
301 ;; XEmacs does this automagically, Emacs doesn't.
302 (if (boundp 'mark-active)
303 (setq mark-active nil)))
306 "\"Home\" the point, the way CRiSP would do it.
307 The first use moves point to beginning of the line. Second
308 consecutive use moves point to beginning of the screen. Third
309 consecutive use moves point to the beginning of the buffer."
312 ((and (eq last-command 'crisp-home)
313 (eq crisp-last-last-command 'crisp-home))
314 (goto-char (point-min)))
315 ((eq last-command 'crisp-home)
316 (move-to-window-line 0))
318 (beginning-of-line)))
319 (setq crisp-last-last-command last-command))
322 "\"End\" the point, the way CRiSP would do it.
323 The first use moves point to end of the line. Second
324 consecutive use moves point to the end of the screen. Third
325 consecutive use moves point to the end of the buffer."
328 ((and (eq last-command 'crisp-end)
329 (eq crisp-last-last-command 'crisp-end))
330 (goto-char (point-max)))
331 ((eq last-command 'crisp-end)
332 (move-to-window-line -1)
336 (setq crisp-last-last-command last-command))
338 (defun crisp-unbury-buffer ()
339 "Go back one buffer."
341 (switch-to-buffer (car (last (buffer-list)))))
343 (defun crisp-meta-x-wrapper ()
344 "Wrapper function to conditionally override the normal M-x bindings.
345 When `crisp-override-meta-x' is non-nil, M-x will exit Emacs (the
346 normal CRiSP binding) and when it is nil M-x will run
347 `execute-extended-command' (the normal Emacs binding)."
349 (if crisp-override-meta-x
350 (save-buffers-kill-emacs)
351 (call-interactively 'execute-extended-command)))
354 (define-minor-mode crisp-mode
355 "Toggle CRiSP/Brief emulation (CRiSP mode).
356 With a prefix argument ARG, enable CRiSP mode if ARG is positive,
357 and disable it otherwise. If called from Lisp, enable the mode
358 if ARG is omitted or nil."
359 :keymap crisp-mode-map
360 :lighter crisp-mode-mode-line-string
362 ;; Make menu entries show M-u or f14 in preference to C-x u.
363 (put 'undo :advertised-binding
364 `([?\M-u] [f14] ,@(get 'undo :advertised-binding)))
365 ;; Force transient-mark-mode, so that the marking routines work as
366 ;; expected. If the user turns off transient mark mode, most
367 ;; things will still work fine except the crisp-(copy|kill)
368 ;; functions won't work quite as nicely when regions are marked
369 ;; differently and could really confuse people. Caveat emptor.
370 (if (fboundp 'transient-mark-mode)
371 (transient-mark-mode t))
372 (if crisp-load-scroll-all
373 (require 'scroll-all))
374 (if (featurep 'scroll-all)
375 (define-key crisp-mode-map [(meta f1)] 'scroll-all-mode))))
377 ;; People might use Apropos on `brief'.
379 (defalias 'brief-mode 'crisp-mode)
381 ;; Interaction with other packages.
382 (put 'crisp-home 'CUA 'move)
383 (put 'crisp-end 'CUA 'move)
385 (run-hooks 'crisp-load-hook)
388 ;;; crisp.el ends here