120
|
1 ;; @(#) crisp.el -- CRiSP/Brief Emacs emulator
|
4
|
2
|
|
3 ;; Author: Gary D. Foster <Gary.Foster@corp.sun.com>
|
185
|
4 ;; Created: 01 Mar 1996
|
211
|
5 ;; Version: $Revision: 1.7 $
|
4
|
6 ;; Keywords: emulations brief crisp
|
185
|
7 ;; X-Modified-by:
|
211
|
8 ;; $Log: crisp.el,v $
|
|
9 ;; Revision 1.7 1997/11/12 07:09:59 steve
|
|
10 ;; Patches to beta4
|
|
11 ;;
|
|
12 ;; Revision 1.23 1997/11/11 19:47:02 gfoster
|
|
13 ;; Merged changes suggested by Hrvoje Niksic
|
|
14 ;; make crisp-mode-map a sparse keymap parented from current-global-map
|
|
15 ;; don't copy the keymap in (crisp-mode-original-keymap)
|
|
16 ;; declare last-last-command to shut up the byte-compiler
|
|
17 ;; make (crisp-mode) honor ARG
|
|
18 ;;
|
|
19 ;; Revision 1.22 1997/11/11 19:37:44 gfoster
|
|
20 ;; kp-add/minus now copy/kill the current line if there is no highlighted
|
|
21 ;; region. These also honor the universal prefix argument conventions.
|
|
22 ;;
|
|
23 ;; Revision 1.21 1997/10/16 18:52:54 gfoster
|
|
24 ;; Fixed bogus XEmacs/Lucid string-match checking
|
|
25 ;; made modeline entry mouse2-able
|
|
26 ;;
|
185
|
27 ;; Revision 1.20 1997/08/22 18:49:11 gfoster
|
|
28 ;; Added next-buffer/previous-buffer keybindings (bound to M-n/M-p)
|
|
29 ;; Added crisp-unbury-buffer function
|
|
30 ;; Standardized headers for Steve
|
|
31 ;;
|
4
|
32
|
173
|
33 ;; This file is part of XEmacs.
|
4
|
34
|
173
|
35 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
36 ;; under the terms of the GNU General Public License as published by
|
4
|
37 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
38 ;; any later version.
|
|
39
|
173
|
40 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
41 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
42 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
43 ;; General Public License for more details.
|
4
|
44
|
|
45 ;; You should have received a copy of the GNU General Public License
|
173
|
46 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
|
47 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
48 ;; 02111-1307, USA.
|
|
49
|
|
50 ;; CRiSP is a registered trademark of Foxtrot Systems Ltd.
|
4
|
51
|
|
52 ;;; Commentary:
|
|
53
|
|
54 ;; Keybindings and minor functions to duplicate the functionality and
|
173
|
55 ;; finger-feel of the CRiSP/Brief editor. This package is designed to
|
4
|
56 ;; facilitate transitioning from Brief to (XE|E)macs with a minimum
|
|
57 ;; amount of hassles.
|
|
58
|
173
|
59 ;; Enable this package by putting (require 'crisp) in your .emacs and
|
|
60 ;; use M-x crisp-mode to toggle it on or off.
|
4
|
61
|
173
|
62 ;; This package will automatically load the scroll-lock.el package if
|
|
63 ;; you put (setq crisp-load-scroll-lock t) in your .emacs before
|
|
64 ;; loading this package. If this feature is enabled, it will bind
|
|
65 ;; meta-f1 to the scroll-lock mode toggle. The scroll-lock package
|
|
66 ;; duplicates the scroll-locking feature in CRiSP.
|
4
|
67
|
173
|
68 ;; Also, the default keybindings for brief/CRiSP override the M-x
|
|
69 ;; key to exit the editor. If you don't like this functionality, you
|
|
70 ;; can prevent this behavior (or redefine it dynamically) by setting
|
|
71 ;; the value of `crisp-override-meta-x' either in your .emacs or
|
|
72 ;; interactively. The default setting is nil, which means that M-x will
|
|
73 ;; by default run `execute-extended-command' instead of the command
|
|
74 ;; `save-buffers-kill-emacs'.
|
4
|
75
|
|
76 ;; Finally, if you want to change the string displayed in the modeline
|
|
77 ;; when this mode is in effect, override the definition of
|
|
78 ;; `crisp-mode-modeline-string' in your .emacs. The default value is
|
|
79 ;; " *Crisp*" which may be a bit lengthy if you have a lot of things
|
|
80 ;; being displayed there.
|
|
81
|
|
82 ;; All these overrides should go *before* the (require 'crisp) statement.
|
|
83
|
185
|
84 ;; Code:
|
|
85
|
|
86 (require 'cl)
|
|
87
|
4
|
88 ;; local variables
|
|
89
|
211
|
90 (defgroup crisp nil
|
173
|
91 "CRiSP emulator customizable settings."
|
|
92 :group 'emulations)
|
|
93
|
211
|
94 (defvar crisp-mode-map (let ((map (make-sparse-keymap)))
|
|
95 (set-keymap-parent map (current-global-map))
|
|
96 map)
|
124
|
97 "Local keymap for CRiSP emulation mode.
|
4
|
98 All the bindings are done here instead of globally to try and be
|
|
99 nice to the world.")
|
|
100
|
173
|
101 (defcustom crisp-mode-modeline-string " *CRiSP*"
|
|
102 "*String to display in the modeline when CRiSP emulation mode is enabled."
|
|
103 :type 'string
|
211
|
104 :group 'crisp)
|
4
|
105
|
211
|
106 (defvar crisp-mode-original-keymap (current-global-map)
|
124
|
107 "The original keymap before CRiSP emulation mode remaps anything.
|
|
108 This keymap is restored when CRiSP emulation mode is disabled.")
|
4
|
109
|
173
|
110 (defvar crisp-mode-enabled nil
|
124
|
111 "Track status of CRiSP emulation mode.
|
120
|
112 A value of nil means CRiSP mode is not enabled. A value of t
|
|
113 indicates CRiSP mode is enabled.")
|
4
|
114
|
173
|
115 (defcustom crisp-override-meta-x t
|
|
116 "*Controls overriding the normal Emacs M-x key binding in the CRiSP emulator.
|
|
117 Normally the CRiSP emulator rebinds M-x to save-buffers-exit-emacs and
|
|
118 provides the usual M-x functionality on the F10 key. If this variable
|
|
119 is non-nil, M-x will exit Emacs."
|
|
120 :type 'boolean
|
211
|
121 :group 'crisp)
|
124
|
122
|
173
|
123 (defvar crisp-load-scroll-lock nil
|
124
|
124 "Controls loading of the Scroll Lock in the CRiSP emulator.
|
|
125 Its Default behavior is to load and enable the Scroll Lock minor mode
|
|
126 package when enabling the CRiSP emulator.
|
|
127
|
|
128 If this variable is nil when you start the CRiSP emulator, it
|
173
|
129 does not load the scroll-lock package.")
|
4
|
130
|
|
131 (defvar crisp-load-hook nil
|
173
|
132 "Hooks to run after loading the CRiSP emulator package.")
|
4
|
133
|
211
|
134 (defconst crisp-version "crisp.el release 1.1/$Revision: 1.7 $"
|
124
|
135 "The release number and RCS version for the CRiSP emulator.")
|
4
|
136
|
211
|
137 ;; Silence the byte-compiler.
|
|
138 (defvar last-last-command)
|
|
139
|
4
|
140 ;; and now the keymap defines
|
|
141
|
|
142 (define-key crisp-mode-map [(f1)] 'other-window)
|
|
143
|
|
144 (define-key crisp-mode-map [(f2) (down)] 'enlarge-window)
|
|
145 (define-key crisp-mode-map [(f2) (left)] 'shrink-window-horizontally)
|
|
146 (define-key crisp-mode-map [(f2) (right)] 'enlarge-window-horizontally)
|
|
147 (define-key crisp-mode-map [(f2) (up)] 'shrink-window)
|
|
148 (define-key crisp-mode-map [(f3) (down)] 'split-window-vertically)
|
|
149 (define-key crisp-mode-map [(f3) (right)] 'split-window-horizontally)
|
|
150
|
|
151 (define-key crisp-mode-map [(f4)] 'delete-window)
|
|
152 (define-key crisp-mode-map [(control f4)] 'delete-other-windows)
|
|
153
|
|
154 (define-key crisp-mode-map [(f5)] 'search-forward-regexp)
|
|
155 (define-key crisp-mode-map [(f19)] 'search-forward-regexp)
|
|
156 (define-key crisp-mode-map [(meta f5)] 'search-backward-regexp)
|
|
157
|
|
158 (define-key crisp-mode-map [(f6)] 'query-replace)
|
|
159
|
|
160 (define-key crisp-mode-map [(f7)] 'start-kbd-macro)
|
|
161 (define-key crisp-mode-map [(meta f7)] 'end-kbd-macro)
|
|
162
|
|
163 (define-key crisp-mode-map [(f8)] 'call-last-kbd-macro)
|
|
164 (define-key crisp-mode-map [(meta f8)] 'save-kbd-macro)
|
|
165
|
|
166 (define-key crisp-mode-map [(f9)] 'find-file)
|
|
167 (define-key crisp-mode-map [(meta f9)] 'load-library)
|
|
168
|
|
169 (define-key crisp-mode-map [(f10)] 'execute-extended-command)
|
|
170 (define-key crisp-mode-map [(meta f10)] 'compile)
|
|
171
|
|
172 (define-key crisp-mode-map [(SunF37)] 'kill-buffer)
|
211
|
173 (define-key crisp-mode-map [(kp-add)] 'crisp-copy-line)
|
|
174 (define-key crisp-mode-map [(kp-subtract)] 'crisp-kill-line)
|
4
|
175 (define-key crisp-mode-map [(insert)] 'x-yank-clipboard-selection)
|
|
176 (define-key crisp-mode-map [(f16)] 'x-copy-primary-selection) ; copy on Sun5 kbd
|
|
177 (define-key crisp-mode-map [(f20)] 'x-kill-primary-selection) ; cut on Sun5 kbd
|
|
178 (define-key crisp-mode-map [(f18)] 'x-yank-clipboard-selection) ; paste on Sun5 kbd
|
|
179
|
|
180 (define-key crisp-mode-map [(meta d)] (lambda () (interactive) (beginning-of-line) (kill-line)))
|
|
181 (define-key crisp-mode-map [(meta e)] 'find-file)
|
|
182 (define-key crisp-mode-map [(meta g)] 'goto-line)
|
|
183 (define-key crisp-mode-map [(meta h)] 'help)
|
|
184 (define-key crisp-mode-map [(meta i)] 'overwrite-mode)
|
124
|
185 (define-key crisp-mode-map [(meta j)] 'bookmark-jump)
|
185
|
186 (define-key crisp-mode-map [(meta n)] 'bury-buffer)
|
|
187 (define-key crisp-mode-map [(meta p)] 'crisp-unbury-buffer)
|
4
|
188 (define-key crisp-mode-map [(meta u)] 'advertised-undo)
|
|
189 (define-key crisp-mode-map [(f14)] 'advertised-undo)
|
|
190 (define-key crisp-mode-map [(meta w)] 'save-buffer)
|
173
|
191 (define-key crisp-mode-map [(meta x)] 'crisp-meta-x-wrapper)
|
124
|
192 (define-key crisp-mode-map [(meta ?0)] (lambda () (interactive) (bookmark-set "0")))
|
|
193 (define-key crisp-mode-map [(meta ?1)] (lambda () (interactive) (bookmark-set "1")))
|
|
194 (define-key crisp-mode-map [(meta ?2)] (lambda () (interactive) (bookmark-set "2")))
|
|
195 (define-key crisp-mode-map [(meta ?3)] (lambda () (interactive) (bookmark-set "3")))
|
|
196 (define-key crisp-mode-map [(meta ?4)] (lambda () (interactive) (bookmark-set "4")))
|
|
197 (define-key crisp-mode-map [(meta ?5)] (lambda () (interactive) (bookmark-set "5")))
|
|
198 (define-key crisp-mode-map [(meta ?6)] (lambda () (interactive) (bookmark-set "6")))
|
|
199 (define-key crisp-mode-map [(meta ?7)] (lambda () (interactive) (bookmark-set "7")))
|
|
200 (define-key crisp-mode-map [(meta ?8)] (lambda () (interactive) (bookmark-set "8")))
|
|
201 (define-key crisp-mode-map [(meta ?9)] (lambda () (interactive) (bookmark-set "9")))
|
4
|
202
|
|
203 (define-key crisp-mode-map [(shift right)] 'fkey-forward-word)
|
|
204 (define-key crisp-mode-map [(shift left)] 'fkey-backward-word)
|
|
205 (define-key crisp-mode-map [(shift delete)] 'kill-word)
|
|
206 (define-key crisp-mode-map [(shift backspace)] 'backward-kill-word)
|
|
207 (define-key crisp-mode-map [(control left)] 'backward-word)
|
|
208 (define-key crisp-mode-map [(control right)] 'forward-word)
|
|
209
|
|
210 (define-key crisp-mode-map [(home)] 'crisp-home)
|
|
211 (define-key crisp-mode-map [(end)] 'crisp-end)
|
|
212
|
211
|
213 (defun crisp-mark-line (arg)
|
|
214 "Put mark at the end of line. Arg works as in `end-of-line'."
|
|
215 (interactive "p")
|
|
216 (mark-something 'crisp-mark-line 'end-of-line arg))
|
|
217
|
|
218 (defun crisp-kill-line (arg)
|
|
219 "Mark and kill line(s).
|
|
220 Marks the entire current line (honoring prefix arguments), copies the
|
|
221 region to the kill ring and clipboard, and then deletes it."
|
|
222 (interactive "*p")
|
|
223 (if zmacs-region-active-p
|
|
224 (x-kill-primary-selection)
|
|
225 (beginning-of-line)
|
|
226 (crisp-mark-line arg)
|
|
227 (x-kill-primary-selection)))
|
|
228
|
|
229 (defun crisp-copy-line (arg)
|
|
230 "Mark and copy entire current line (honoring prefix arguments), copies the
|
|
231 region to the kill ring and clipboard, and then deactivates the region."
|
|
232 (interactive "*p")
|
|
233 (let ((curpos (point)))
|
|
234 (if zmacs-region-active-p
|
|
235 (x-copy-primary-selection)
|
|
236 (beginning-of-line)
|
|
237 (crisp-mark-line arg)
|
|
238 (x-copy-primary-selection)
|
|
239 (goto-char curpos))))
|
|
240
|
4
|
241 (defun crisp-home ()
|
124
|
242 "\"Home\" the point, the way CRiSP would do it.
|
|
243 The first use moves point to beginning of the line. Second
|
|
244 consecutive use moves point to beginning of the screen. Third
|
|
245 consecutive use moves point to the beginning of the buffer."
|
4
|
246 (interactive nil)
|
|
247 (cond
|
|
248 ((and (eq last-command 'crisp-home) (eq last-last-command 'crisp-home))
|
|
249 (goto-char (point-min)))
|
|
250 ((eq last-command 'crisp-home)
|
|
251 (move-to-window-line 0))
|
|
252 (t
|
|
253 (beginning-of-line)))
|
|
254 (setq last-last-command last-command))
|
|
255
|
|
256 (defun crisp-end ()
|
124
|
257 "\"End\" the point, the way CRiSP would do it.
|
|
258 The first use moves point to end of the line. Second
|
|
259 consecutive use moves point to the end of the screen. Third
|
|
260 consecutive use moves point to the end of the buffer."
|
4
|
261 (interactive nil)
|
|
262 (cond
|
|
263 ((and (eq last-command 'crisp-end) (eq last-last-command 'crisp-end))
|
|
264 (goto-char (point-max)))
|
|
265 ((eq last-command 'crisp-end)
|
|
266 (move-to-window-line -1)
|
|
267 (end-of-line))
|
|
268 (t
|
|
269 (end-of-line)))
|
|
270 (setq last-last-command last-command))
|
|
271
|
185
|
272 (defun crisp-unbury-buffer ()
|
|
273 "Go back one buffer"
|
|
274 (interactive)
|
|
275 (switch-to-buffer (car (last (buffer-list)))))
|
|
276
|
173
|
277 (defun crisp-meta-x-wrapper ()
|
|
278 "Wrapper function to conditionally override the normal M-x bindings.
|
|
279 When `crisp-override-meta-x' is non-nil, M-x will exit Emacs (the
|
|
280 normal CRiSP binding) and when it is nil M-x will run
|
|
281 `execute-extended-command' (the normal Emacs binding)."
|
|
282 (interactive)
|
|
283 (if crisp-override-meta-x
|
|
284 (save-buffers-kill-emacs)
|
|
285 (call-interactively 'execute-extended-command)))
|
|
286
|
4
|
287 ;; Now enable the mode
|
|
288
|
211
|
289 (defun crisp-mode (&optional arg)
|
|
290 "Toggle CRiSP emulation minor mode.
|
|
291 With ARG, turn CRiSP mode on if ARG is positive, off otherwise."
|
|
292 (interactive "P")
|
|
293 (setq crisp-mode-enabled (if (null arg)
|
|
294 (not crisp-mode-enabled)
|
|
295 (> (prefix-numeric-value arg) 0)))
|
4
|
296 (cond
|
|
297 ((eq crisp-mode-enabled 't)
|
|
298 (use-global-map crisp-mode-map)
|
|
299 (if crisp-load-scroll-lock
|
|
300 (require 'scroll-lock))
|
|
301 (if (featurep 'scroll-lock)
|
|
302 (define-key crisp-mode-map [(meta f1)] 'scroll-lock-mode))
|
|
303 (run-hooks 'crisp-load-hook))
|
|
304 ((eq crisp-mode-enabled 'nil)
|
|
305 (use-global-map crisp-mode-original-keymap))))
|
|
306
|
211
|
307 (if (fboundp 'add-minor-mode)
|
207
|
308 (add-minor-mode 'crisp-mode-enabled 'crisp-mode-modeline-string
|
|
309 nil nil 'crisp-mode)
|
|
310 (or (assq 'crisp-mode-enabled minor-mode-alist)
|
|
311 (setq minor-mode-alist
|
|
312 (cons '(crisp-mode-enabled crisp-mode-modeline-string) minor-mode-alist))))
|
|
313
|
4
|
314 (provide 'crisp)
|
|
315
|
|
316 ;;; crisp.el ends here
|