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