Customized.
[emacs.git] / lisp / emulation / crisp.el
blob36287eb9eb5c99a8a7f54b45af272b827d61ed90
1 ;;; crisp.el --- Emulator for CRiSP and Brief key bindings
3 ;; Copyright (C) 1997 Free Software Foundation, Inc.
5 ;; Author: Gary D. Foster <Gary.Foster@corp.sun.com>
6 ;; Keywords: emulations
8 ;; This file is part of GNU Emacs.
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.
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.
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.
25 ;;; Commentary:
27 ;; This file provides keybindings and minor functions to duplicate the
28 ;; functionality and finger-feel of the CRiSP/Brief editor. This
29 ;; package is designed to facilitate transitioning from Brief to Emacs
30 ;; with a minimum amount of hassles.
32 ;; Enable this package by putting the following in your .emacs
33 ;; (require 'crisp)
34 ;; and use M-x crisp-mode to toggle it on or off.
36 ;; This package will automatically default to loading the scroll-all.el
37 ;; package unless you put (setq crisp-load-scroll-lock nil) in your
38 ;; .emacs. If this feature is enabled, it will bind Meta-F1 to the
39 ;; scroll-all mode toggle.
41 ;; Also, the default keybindings for this mode override the Meta-x key to
42 ;; make it exit the editor. If you don't like this change, you can
43 ;; prevent this key from being rebound with
44 ;; (setq crisp-override-meta-x nil) in your .emacs.
46 ;; Finally, if you want to change the string displayed in the modeline
47 ;; when this mode is in effect, override the definition of
48 ;; `crisp-mode-modeline-string' in your .emacs. The default value is
49 ;; " *Crisp*" which may be a bit lengthy if you have a lot of things
50 ;; being displayed there.
52 ;; All these overrides should go *before* the (require 'crisp) statement.
54 (defgroup crisp nil
55 "Emulator for CRiSP and Brief key bindings."
56 :prefix "crisp-"
57 :group 'emulations)
59 ;; local variables
61 (defvar crisp-mode-map (copy-keymap (current-global-map))
62 "Local keymap for CRiSP emulation mode.
63 All the emulation bindings are done here instead of globally.")
65 (defcustom crisp-mode-modeline-string " *CRiSP*"
66 "String to display in the modeline when CRiSP emulation mode is enabled."
67 :type 'string
68 :group 'crisp)
70 (defvar crisp-mode-original-keymap (copy-keymap (current-global-map))
71 "The original keymap before CRiSP emulation mode remaps anything.
72 This keymap is restored when CRiSP emulation mode is disabled.")
74 (defcustom crisp-mode-enabled nil
75 "Track status of CRiSP emulation mode.
76 A value of nil means CRiSP mode is not enabled. A value of t
77 indicates CRiSP mode is enabled."
78 :type 'boolean
79 :group 'crisp)
81 (defcustom crisp-override-meta-x t
82 "Controls overriding the normal Emacs M-x key binding in the CRiSP emulator.
83 Normally the CRiSP emulator rebinds M-x to save-buffers-exit-emacs
84 and provides the usual M-x functionality on the F10 key.
86 If this variable is nil when you start the CRiSP emulator, it
87 does not alter the binding of M-x."
88 :type 'boolean
89 :group 'crisp)
91 (defcustom crisp-load-scroll-all t
92 "Controls loading of the Scroll All mode in the CRiSP emulator.
93 Its Default behavior is to load and enable the Scroll All minor mode
94 package when enabling the CRiSP emulator.
96 If this variable is nil when you start the CRiSP emulator, it
97 does not load Scroll All."
98 :type 'boolean
99 :group 'crisp)
101 (defcustom crisp-load-hook nil
102 "Hooks to run after loadint the CRiSP emulator package."
103 :type 'hook
104 :group 'crisp)
106 (defvar crisp-version "crisp.el release 1.1/$Revision: 1.6 $"
107 "The release number and RCS version for the CRiSP emulator.")
109 (defvar crisp-last-last-command nil
110 "The command *before* the last command.")
112 (if (string-match "XEmacs\\Lucid" emacs-version)
113 (add-minor-mode 'crisp-mode-enabled crisp-mode-modeline-string)
114 (or (assq 'crisp-mode-enabled minor-mode-alist)
115 (setq minor-mode-alist
116 (cons '(crisp-mode-enabled crisp-mode-modeline-string) minor-mode-alist))))
118 ;; and now the keymap defines
120 (define-key crisp-mode-map [(f1)] 'other-window)
122 (define-key crisp-mode-map [(f2) (down)] 'enlarge-window)
123 (define-key crisp-mode-map [(f2) (left)] 'shrink-window-horizontally)
124 (define-key crisp-mode-map [(f2) (right)] 'enlarge-window-horizontally)
125 (define-key crisp-mode-map [(f2) (up)] 'shrink-window)
126 (define-key crisp-mode-map [(f3) (down)] 'split-window-vertically)
127 (define-key crisp-mode-map [(f3) (right)] 'split-window-horizontally)
129 (define-key crisp-mode-map [(f4)] 'delete-window)
130 (define-key crisp-mode-map [(control f4)] 'delete-other-windows)
132 (define-key crisp-mode-map [(f5)] 'search-forward-regexp)
133 (define-key crisp-mode-map [(f19)] 'search-forward-regexp)
134 (define-key crisp-mode-map [(meta f5)] 'search-backward-regexp)
136 (define-key crisp-mode-map [(f6)] 'query-replace)
138 (define-key crisp-mode-map [(f7)] 'start-kbd-macro)
139 (define-key crisp-mode-map [(meta f7)] 'end-kbd-macro)
141 (define-key crisp-mode-map [(f8)] 'call-last-kbd-macro)
142 (define-key crisp-mode-map [(meta f8)] 'save-kbd-macro)
144 (define-key crisp-mode-map [(f9)] 'find-file)
145 (define-key crisp-mode-map [(meta f9)] 'load-library)
147 (define-key crisp-mode-map [(f10)] 'execute-extended-command)
148 (define-key crisp-mode-map [(meta f10)] 'compile)
150 (define-key crisp-mode-map [(SunF37)] 'kill-buffer)
151 (define-key crisp-mode-map [(kp-add)] 'x-copy-primary-selection)
152 (define-key crisp-mode-map [(kp-subtract)] 'x-kill-primary-selection)
153 (define-key crisp-mode-map [(insert)] 'x-yank-clipboard-selection)
154 (define-key crisp-mode-map [(f16)] 'x-copy-primary-selection) ; copy on Sun5 kbd
155 (define-key crisp-mode-map [(f20)] 'x-kill-primary-selection) ; cut on Sun5 kbd
156 (define-key crisp-mode-map [(f18)] 'x-yank-clipboard-selection) ; paste on Sun5 kbd
158 (define-key crisp-mode-map [(meta d)] (lambda () (interactive) (beginning-of-line) (kill-line)))
159 (define-key crisp-mode-map [(meta e)] 'find-file)
160 (define-key crisp-mode-map [(meta g)] 'goto-line)
161 (define-key crisp-mode-map [(meta h)] 'help)
162 (define-key crisp-mode-map [(meta i)] 'overwrite-mode)
163 (define-key crisp-mode-map [(meta j)] 'bookmark-jump)
164 (define-key crisp-mode-map [(meta u)] 'advertised-undo)
165 (define-key crisp-mode-map [(f14)] 'advertised-undo)
166 (define-key crisp-mode-map [(meta w)] 'save-buffer)
168 (eq crisp-override-meta-x 't)
169 (define-key crisp-mode-map [(meta x)] 'save-buffers-kill-emacs))
170 (define-key crisp-mode-map [(meta ?0)] (lambda () (interactive) (bookmark-set "0")))
171 (define-key crisp-mode-map [(meta ?1)] (lambda () (interactive) (bookmark-set "1")))
172 (define-key crisp-mode-map [(meta ?2)] (lambda () (interactive) (bookmark-set "2")))
173 (define-key crisp-mode-map [(meta ?3)] (lambda () (interactive) (bookmark-set "3")))
174 (define-key crisp-mode-map [(meta ?4)] (lambda () (interactive) (bookmark-set "4")))
175 (define-key crisp-mode-map [(meta ?5)] (lambda () (interactive) (bookmark-set "5")))
176 (define-key crisp-mode-map [(meta ?6)] (lambda () (interactive) (bookmark-set "6")))
177 (define-key crisp-mode-map [(meta ?7)] (lambda () (interactive) (bookmark-set "7")))
178 (define-key crisp-mode-map [(meta ?8)] (lambda () (interactive) (bookmark-set "8")))
179 (define-key crisp-mode-map [(meta ?9)] (lambda () (interactive) (bookmark-set "9")))
181 (define-key crisp-mode-map [(shift right)] 'fkey-forward-word)
182 (define-key crisp-mode-map [(shift left)] 'fkey-backward-word)
183 (define-key crisp-mode-map [(shift delete)] 'kill-word)
184 (define-key crisp-mode-map [(shift backspace)] 'backward-kill-word)
185 (define-key crisp-mode-map [(control left)] 'backward-word)
186 (define-key crisp-mode-map [(control right)] 'forward-word)
188 (define-key crisp-mode-map [(home)] 'crisp-home)
189 (define-key crisp-mode-map [(end)] 'crisp-end)
191 (defun crisp-home ()
192 "\"Home\" point, the way CRiSP would do it.
193 The first use moves point to beginning of the line. Second
194 consecutive use moves point to beginning of the screen. Third
195 consecutive use moves point to the beginning of the buffer."
196 (interactive nil)
197 (cond
198 ((and (eq last-command 'crisp-home)
199 (eq crisp-last-last-command 'crisp-home))
200 (goto-char (point-min)))
201 ((eq last-command 'crisp-home)
202 (move-to-window-line 0))
204 (beginning-of-line)))
205 (setq crisp-last-last-command last-command))
207 (defun crisp-end ()
208 "\"End\" point, the way CRiSP would do it.
209 The first use moves point to end of the line. Second
210 consecutive use moves point to the end of the screen. Third
211 consecutive use moves point to the end of the buffer."
212 (interactive nil)
213 (cond
214 ((and (eq last-command 'crisp-end) (eq crisp-last-last-command 'crisp-end))
215 (goto-char (point-max)))
216 ((eq last-command 'crisp-end)
217 (move-to-window-line -1)
218 (end-of-line))
220 (end-of-line)))
221 (setq crisp-last-last-command last-command))
223 ;; Now enable the mode
225 ;;;###autoload
226 (defun crisp-mode ()
227 "Toggle CRiSP emulation minor mode."
228 (interactive nil)
229 (setq crisp-mode-enabled (not crisp-mode-enabled))
230 (cond
231 ((eq crisp-mode-enabled 't)
232 (use-global-map crisp-mode-map)
233 (if crisp-load-scroll-all
234 (require 'scroll-all))
235 (if (featurep 'scroll-all)
236 (define-key crisp-mode-map [(meta f1)] 'scroll-all-mode))
237 (run-hooks 'crisp-load-hook))
238 ((eq crisp-mode-enabled 'nil)
239 (use-global-map crisp-mode-original-keymap))))
241 (provide 'crisp)
243 ;;; crisp.el ends here