Initial revision
[emacs.git] / lisp / emulation / crisp.el
blob93afde2b3cafe5a53006effb9ec74d57dd23b0d8
1 ;; crisp.el -- Emulator for CRiSP/Brief key bindings
3 ;; Author: Gary D. Foster <Gary.Foster@corp.sun.com>
4 ;; Keywords: emulations brief crisp
6 ;; This file is part of GNU Emacs.
8 ;; GNU Emacs is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
11 ;; any later version.
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs; see the file COPYING. If not, write to the
20 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 ;; Boston, MA 02111-1307, USA.
23 ;;; Commentary:
25 ;; This file provides keybindings and minor functions to duplicate the
26 ;; functionality and finger-feel of the CRiSP/Brief editor. This
27 ;; package is designed to facilitate transitioning from Brief to Emacs
28 ;; with a minimum amount of hassles.
30 ;; Enable this package by putting the following in your .emacs
31 ;; (require 'crisp)
33 ;; This package will automatically default to loading the scroll-lock.el
34 ;; package unless you put (setq crisp-load-scroll-lock nil) in your
35 ;; .emacs. If this feature is enabled, it will bind meta-f1 to the
36 ;; scroll-lock mode toggle.
38 ;; Also, the default keybindings for brief override the Meta-x key to
39 ;; exit the editor. If you don't like this functionality, you can
40 ;; prevent this key from being rebound with
41 ;; (setq crisp-override-meta-x nil) in your .emacs.
43 ;; All these overrides should go *before* the (require 'crisp) statement.
45 ;; local variables
47 (defvar crisp-mode-map (copy-keymap (current-global-map))
48 "Keymap for CRiSP emulation.
49 All the emulation bindings are done here instead of globally.")
51 (defvar crisp-override-meta-x t
52 "Controls overriding the normal Emacs M-x key binding in the CRiSP emulator.
53 Normally the CRiSP emulator rebinds M-x to save-buffers-exit-emacs
54 and provides the usual M-x functionality on the F10 key.
56 If this variable is nil when you start the CRiSP emulator, it
57 does not alter the binding of M-x.")
59 (defvar crisp-load-scroll-lock t
60 "Controls loading of Scroll Lock in the CRiSP emulator.
61 Its default behavior is to load and enable the Scroll Lock minor mode
62 package when enabling the CRiSP emulator.
64 If this variable is nil when you start the CRiSP emulator, it
65 does not load Scroll Lock.")
67 (defvar crisp-load-hook nil
68 "Hooks to run after loading the CRiSP emulator package.")
70 ;; and now the keymap defines
72 (define-key crisp-mode-map [(f1)] 'other-window)
74 (define-key crisp-mode-map [(f2) (down)] 'enlarge-window)
75 (define-key crisp-mode-map [(f2) (left)] 'shrink-window-horizontally)
76 (define-key crisp-mode-map [(f2) (right)] 'enlarge-window-horizontally)
77 (define-key crisp-mode-map [(f2) (up)] 'shrink-window)
78 (define-key crisp-mode-map [(f3) (down)] 'split-window-vertically)
79 (define-key crisp-mode-map [(f3) (right)] 'split-window-horizontally)
81 (define-key crisp-mode-map [(f4)] 'delete-window)
82 (define-key crisp-mode-map [(control f4)] 'delete-other-windows)
84 (define-key crisp-mode-map [(f5)] 'search-forward-regexp)
85 (define-key crisp-mode-map [(f19)] 'search-forward-regexp)
86 (define-key crisp-mode-map [(meta f5)] 'search-backward-regexp)
88 (define-key crisp-mode-map [(f6)] 'query-replace)
90 (define-key crisp-mode-map [(f7)] 'start-kbd-macro)
91 (define-key crisp-mode-map [(meta f7)] 'end-kbd-macro)
93 (define-key crisp-mode-map [(f8)] 'call-last-kbd-macro)
94 (define-key crisp-mode-map [(meta f8)] 'save-kbd-macro)
96 (define-key crisp-mode-map [(f9)] 'find-file)
97 (define-key crisp-mode-map [(meta f9)] 'load-library)
99 (define-key crisp-mode-map [(f10)] 'execute-extended-command)
100 (define-key crisp-mode-map [(meta f10)] 'compile)
102 (define-key crisp-mode-map [(SunF37)] 'kill-buffer)
103 (define-key crisp-mode-map [(kp_add)] 'x-copy-primary-selection)
104 (define-key crisp-mode-map [(kp_subtract)] 'x-kill-primary-selection)
105 (define-key crisp-mode-map [(insert)] 'x-yank-clipboard-selection)
106 (define-key crisp-mode-map [(f16)] 'x-copy-primary-selection) ; copy on Sun5 kbd
107 (define-key crisp-mode-map [(f20)] 'x-kill-primary-selection) ; cut on Sun5 kbd
108 (define-key crisp-mode-map [(f18)] 'x-yank-clipboard-selection) ; paste on Sun5 kbd
110 (define-key crisp-mode-map [(meta d)] (lambda () (interactive) (beginning-of-line) (kill-line)))
111 (define-key crisp-mode-map [(meta e)] 'find-file)
112 (define-key crisp-mode-map [(meta g)] 'goto-line)
113 (define-key crisp-mode-map [(meta h)] 'help)
114 (define-key crisp-mode-map [(meta i)] 'overwrite-mode)
115 (define-key crisp-mode-map [(meta u)] 'advertised-undo)
116 (define-key crisp-mode-map [(f14)] 'advertised-undo)
117 (define-key crisp-mode-map [(meta w)] 'save-buffer)
119 (eq crisp-override-meta-x 't)
120 (define-key crisp-mode-map [(meta x)] 'save-buffers-kill-emacs))
122 (define-key crisp-mode-map [(shift right)] 'fkey-forward-word)
123 (define-key crisp-mode-map [(shift left)] 'fkey-backward-word)
124 (define-key crisp-mode-map [(shift delete)] 'kill-word)
125 (define-key crisp-mode-map [(shift backspace)] 'backward-kill-word)
126 (define-key crisp-mode-map [(control left)] 'backward-word)
127 (define-key crisp-mode-map [(control right)] 'forward-word)
129 (define-key crisp-mode-map [(home)] 'crisp-home)
130 (define-key crisp-mode-map [(end)] 'crisp-end)
133 (defun crisp-home ()
134 "\"Home\" the point, the way CRiSP would do it.
135 The first use moves point to beginning of the line. Second
136 consecutive use moves point to beginning of the screen. Third
137 consecutive use moves point to the beginning of the buffer."
138 (interactive nil)
139 (cond
140 ((and (eq last-command 'crisp-home) (eq last-last-command 'crisp-home))
141 (goto-char (point-min))
143 ((eq last-command 'crisp-home)
144 (move-to-window-line 0)
147 (beginning-of-line)
150 (setq last-last-command last-command)
153 (defun crisp-end ()
154 "\"End\" the point, the way CRiSP would do it.
155 The first use moves point to end of the line. Second
156 consecutive use moves point to the end of the screen. Third
157 consecutive use moves point to the end of the buffer."
158 (interactive nil)
159 (cond
160 ((and (eq last-command 'crisp-end) (eq last-last-command 'crisp-end))
161 (goto-char (point-max))
163 ((eq last-command 'crisp-end)
164 (move-to-window-line -1)
165 (end-of-line)
168 (end-of-line)
171 (setq last-last-command last-command)
174 ;; Now enable the mode
176 (kill-all-local-variables)
177 (use-global-map crisp-mode-map)
179 (if (eq crisp-load-scroll-lock t)
180 (require 'scroll-lock))
182 (if (featurep 'scroll-lock)
183 (define-key crisp-mode-map [(meta f1)] 'scroll-lock-mode))
185 (run-hooks 'crisp-load-hook) ;; allow for hooks
187 (provide 'crisp)
189 ;; crisp.el ends here