120
|
1 ;; @(#) crisp.el -- CRiSP/Brief Emacs emulator
|
4
|
2
|
|
3 ;; Author: Gary D. Foster <Gary.Foster@corp.sun.com>
|
173
|
4 ;; 1.19
|
4
|
5 ;; Keywords: emulations brief crisp
|
|
6
|
173
|
7 ;; This file is part of XEmacs.
|
4
|
8
|
173
|
9 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
10 ;; under the terms of the GNU General Public License as published by
|
4
|
11 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
12 ;; any later version.
|
|
13
|
173
|
14 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
17 ;; General Public License for more details.
|
4
|
18
|
|
19 ;; You should have received a copy of the GNU General Public License
|
173
|
20 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
|
21 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
22 ;; 02111-1307, USA.
|
|
23
|
|
24 ;; CRiSP is a registered trademark of Foxtrot Systems Ltd.
|
4
|
25
|
|
26 ;;; Commentary:
|
|
27
|
|
28 ;; Keybindings and minor functions to duplicate the functionality and
|
173
|
29 ;; finger-feel of the CRiSP/Brief editor. This package is designed to
|
4
|
30 ;; facilitate transitioning from Brief to (XE|E)macs with a minimum
|
|
31 ;; amount of hassles.
|
|
32
|
173
|
33 ;; Enable this package by putting (require 'crisp) in your .emacs and
|
|
34 ;; use M-x crisp-mode to toggle it on or off.
|
4
|
35
|
173
|
36 ;; This package will automatically load the scroll-lock.el package if
|
|
37 ;; you put (setq crisp-load-scroll-lock t) in your .emacs before
|
|
38 ;; loading this package. If this feature is enabled, it will bind
|
|
39 ;; meta-f1 to the scroll-lock mode toggle. The scroll-lock package
|
|
40 ;; duplicates the scroll-locking feature in CRiSP.
|
4
|
41
|
173
|
42 ;; Also, the default keybindings for brief/CRiSP override the M-x
|
|
43 ;; key to exit the editor. If you don't like this functionality, you
|
|
44 ;; can prevent this behavior (or redefine it dynamically) by setting
|
|
45 ;; the value of `crisp-override-meta-x' either in your .emacs or
|
|
46 ;; interactively. The default setting is nil, which means that M-x will
|
|
47 ;; by default run `execute-extended-command' instead of the command
|
|
48 ;; `save-buffers-kill-emacs'.
|
4
|
49
|
|
50 ;; Finally, if you want to change the string displayed in the modeline
|
|
51 ;; when this mode is in effect, override the definition of
|
|
52 ;; `crisp-mode-modeline-string' in your .emacs. The default value is
|
|
53 ;; " *Crisp*" which may be a bit lengthy if you have a lot of things
|
|
54 ;; being displayed there.
|
|
55
|
|
56 ;; All these overrides should go *before* the (require 'crisp) statement.
|
|
57
|
|
58 ;; local variables
|
|
59
|
173
|
60 (defgroup emulations-crisp nil
|
|
61 "CRiSP emulator customizable settings."
|
|
62 :group 'emulations)
|
|
63
|
4
|
64 (defvar crisp-mode-map (copy-keymap (current-global-map))
|
124
|
65 "Local keymap for CRiSP emulation mode.
|
4
|
66 All the bindings are done here instead of globally to try and be
|
|
67 nice to the world.")
|
|
68
|
173
|
69 (defcustom crisp-mode-modeline-string " *CRiSP*"
|
|
70 "*String to display in the modeline when CRiSP emulation mode is enabled."
|
|
71 :type 'string
|
|
72 :group 'emulations-crisp)
|
4
|
73
|
|
74 (defvar crisp-mode-original-keymap (copy-keymap (current-global-map))
|
124
|
75 "The original keymap before CRiSP emulation mode remaps anything.
|
|
76 This keymap is restored when CRiSP emulation mode is disabled.")
|
4
|
77
|
173
|
78 (defvar crisp-mode-enabled nil
|
124
|
79 "Track status of CRiSP emulation mode.
|
120
|
80 A value of nil means CRiSP mode is not enabled. A value of t
|
|
81 indicates CRiSP mode is enabled.")
|
4
|
82
|
173
|
83 (defcustom crisp-override-meta-x t
|
|
84 "*Controls overriding the normal Emacs M-x key binding in the CRiSP emulator.
|
|
85 Normally the CRiSP emulator rebinds M-x to save-buffers-exit-emacs and
|
|
86 provides the usual M-x functionality on the F10 key. If this variable
|
|
87 is non-nil, M-x will exit Emacs."
|
|
88 :type 'boolean
|
|
89 :group 'emulations-crisp)
|
124
|
90
|
173
|
91 (defvar crisp-load-scroll-lock nil
|
124
|
92 "Controls loading of the Scroll Lock in the CRiSP emulator.
|
|
93 Its Default behavior is to load and enable the Scroll Lock minor mode
|
|
94 package when enabling the CRiSP emulator.
|
|
95
|
|
96 If this variable is nil when you start the CRiSP emulator, it
|
173
|
97 does not load the scroll-lock package.")
|
4
|
98
|
|
99 (defvar crisp-load-hook nil
|
173
|
100 "Hooks to run after loading the CRiSP emulator package.")
|
4
|
101
|
173
|
102 (defconst crisp-version "crisp.el release 1.1/1.19"
|
124
|
103 "The release number and RCS version for the CRiSP emulator.")
|
4
|
104
|
124
|
105 (if (string-match "XEmacs\\Lucid" emacs-version)
|
4
|
106 (add-minor-mode 'crisp-mode-enabled crisp-mode-modeline-string)
|
|
107 (or (assq 'crisp-mode-enabled minor-mode-alist)
|
|
108 (setq minor-mode-alist
|
|
109 (cons '(crisp-mode-enabled crisp-mode-modeline-string) minor-mode-alist))))
|
|
110
|
|
111 ;; and now the keymap defines
|
|
112
|
|
113 (define-key crisp-mode-map [(f1)] 'other-window)
|
|
114
|
|
115 (define-key crisp-mode-map [(f2) (down)] 'enlarge-window)
|
|
116 (define-key crisp-mode-map [(f2) (left)] 'shrink-window-horizontally)
|
|
117 (define-key crisp-mode-map [(f2) (right)] 'enlarge-window-horizontally)
|
|
118 (define-key crisp-mode-map [(f2) (up)] 'shrink-window)
|
|
119 (define-key crisp-mode-map [(f3) (down)] 'split-window-vertically)
|
|
120 (define-key crisp-mode-map [(f3) (right)] 'split-window-horizontally)
|
|
121
|
|
122 (define-key crisp-mode-map [(f4)] 'delete-window)
|
|
123 (define-key crisp-mode-map [(control f4)] 'delete-other-windows)
|
|
124
|
|
125 (define-key crisp-mode-map [(f5)] 'search-forward-regexp)
|
|
126 (define-key crisp-mode-map [(f19)] 'search-forward-regexp)
|
|
127 (define-key crisp-mode-map [(meta f5)] 'search-backward-regexp)
|
|
128
|
|
129 (define-key crisp-mode-map [(f6)] 'query-replace)
|
|
130
|
|
131 (define-key crisp-mode-map [(f7)] 'start-kbd-macro)
|
|
132 (define-key crisp-mode-map [(meta f7)] 'end-kbd-macro)
|
|
133
|
|
134 (define-key crisp-mode-map [(f8)] 'call-last-kbd-macro)
|
|
135 (define-key crisp-mode-map [(meta f8)] 'save-kbd-macro)
|
|
136
|
|
137 (define-key crisp-mode-map [(f9)] 'find-file)
|
|
138 (define-key crisp-mode-map [(meta f9)] 'load-library)
|
|
139
|
|
140 (define-key crisp-mode-map [(f10)] 'execute-extended-command)
|
|
141 (define-key crisp-mode-map [(meta f10)] 'compile)
|
|
142
|
|
143 (define-key crisp-mode-map [(SunF37)] 'kill-buffer)
|
74
|
144 (define-key crisp-mode-map [(kp-add)] 'x-copy-primary-selection)
|
|
145 (define-key crisp-mode-map [(kp-subtract)] 'x-kill-primary-selection)
|
4
|
146 (define-key crisp-mode-map [(insert)] 'x-yank-clipboard-selection)
|
|
147 (define-key crisp-mode-map [(f16)] 'x-copy-primary-selection) ; copy on Sun5 kbd
|
|
148 (define-key crisp-mode-map [(f20)] 'x-kill-primary-selection) ; cut on Sun5 kbd
|
|
149 (define-key crisp-mode-map [(f18)] 'x-yank-clipboard-selection) ; paste on Sun5 kbd
|
|
150
|
|
151 (define-key crisp-mode-map [(meta d)] (lambda () (interactive) (beginning-of-line) (kill-line)))
|
|
152 (define-key crisp-mode-map [(meta e)] 'find-file)
|
|
153 (define-key crisp-mode-map [(meta g)] 'goto-line)
|
|
154 (define-key crisp-mode-map [(meta h)] 'help)
|
|
155 (define-key crisp-mode-map [(meta i)] 'overwrite-mode)
|
124
|
156 (define-key crisp-mode-map [(meta j)] 'bookmark-jump)
|
4
|
157 (define-key crisp-mode-map [(meta u)] 'advertised-undo)
|
|
158 (define-key crisp-mode-map [(f14)] 'advertised-undo)
|
|
159 (define-key crisp-mode-map [(meta w)] 'save-buffer)
|
173
|
160 (define-key crisp-mode-map [(meta x)] 'crisp-meta-x-wrapper)
|
124
|
161 (define-key crisp-mode-map [(meta ?0)] (lambda () (interactive) (bookmark-set "0")))
|
|
162 (define-key crisp-mode-map [(meta ?1)] (lambda () (interactive) (bookmark-set "1")))
|
|
163 (define-key crisp-mode-map [(meta ?2)] (lambda () (interactive) (bookmark-set "2")))
|
|
164 (define-key crisp-mode-map [(meta ?3)] (lambda () (interactive) (bookmark-set "3")))
|
|
165 (define-key crisp-mode-map [(meta ?4)] (lambda () (interactive) (bookmark-set "4")))
|
|
166 (define-key crisp-mode-map [(meta ?5)] (lambda () (interactive) (bookmark-set "5")))
|
|
167 (define-key crisp-mode-map [(meta ?6)] (lambda () (interactive) (bookmark-set "6")))
|
|
168 (define-key crisp-mode-map [(meta ?7)] (lambda () (interactive) (bookmark-set "7")))
|
|
169 (define-key crisp-mode-map [(meta ?8)] (lambda () (interactive) (bookmark-set "8")))
|
|
170 (define-key crisp-mode-map [(meta ?9)] (lambda () (interactive) (bookmark-set "9")))
|
4
|
171
|
|
172 (define-key crisp-mode-map [(shift right)] 'fkey-forward-word)
|
|
173 (define-key crisp-mode-map [(shift left)] 'fkey-backward-word)
|
|
174 (define-key crisp-mode-map [(shift delete)] 'kill-word)
|
|
175 (define-key crisp-mode-map [(shift backspace)] 'backward-kill-word)
|
|
176 (define-key crisp-mode-map [(control left)] 'backward-word)
|
|
177 (define-key crisp-mode-map [(control right)] 'forward-word)
|
|
178
|
|
179 (define-key crisp-mode-map [(home)] 'crisp-home)
|
|
180 (define-key crisp-mode-map [(end)] 'crisp-end)
|
|
181
|
|
182 (defun crisp-home ()
|
124
|
183 "\"Home\" the point, the way CRiSP would do it.
|
|
184 The first use moves point to beginning of the line. Second
|
|
185 consecutive use moves point to beginning of the screen. Third
|
|
186 consecutive use moves point to the beginning of the buffer."
|
4
|
187 (interactive nil)
|
|
188 (cond
|
|
189 ((and (eq last-command 'crisp-home) (eq last-last-command 'crisp-home))
|
|
190 (goto-char (point-min)))
|
|
191 ((eq last-command 'crisp-home)
|
|
192 (move-to-window-line 0))
|
|
193 (t
|
|
194 (beginning-of-line)))
|
|
195 (setq last-last-command last-command))
|
|
196
|
|
197 (defun crisp-end ()
|
124
|
198 "\"End\" the point, the way CRiSP would do it.
|
|
199 The first use moves point to end of the line. Second
|
|
200 consecutive use moves point to the end of the screen. Third
|
|
201 consecutive use moves point to the end of the buffer."
|
4
|
202 (interactive nil)
|
|
203 (cond
|
|
204 ((and (eq last-command 'crisp-end) (eq last-last-command 'crisp-end))
|
|
205 (goto-char (point-max)))
|
|
206 ((eq last-command 'crisp-end)
|
|
207 (move-to-window-line -1)
|
|
208 (end-of-line))
|
|
209 (t
|
|
210 (end-of-line)))
|
|
211 (setq last-last-command last-command))
|
|
212
|
173
|
213 (defun crisp-meta-x-wrapper ()
|
|
214 "Wrapper function to conditionally override the normal M-x bindings.
|
|
215 When `crisp-override-meta-x' is non-nil, M-x will exit Emacs (the
|
|
216 normal CRiSP binding) and when it is nil M-x will run
|
|
217 `execute-extended-command' (the normal Emacs binding)."
|
|
218 (interactive)
|
|
219 (if crisp-override-meta-x
|
|
220 (save-buffers-kill-emacs)
|
|
221 (call-interactively 'execute-extended-command)))
|
|
222
|
4
|
223 ;; Now enable the mode
|
|
224
|
|
225 (defun crisp-mode ()
|
124
|
226 "Toggle CRiSP emulation minor mode."
|
4
|
227 (interactive nil)
|
|
228 (setq crisp-mode-enabled (not crisp-mode-enabled))
|
|
229 (cond
|
|
230 ((eq crisp-mode-enabled 't)
|
|
231 (use-global-map crisp-mode-map)
|
|
232 (if crisp-load-scroll-lock
|
|
233 (require 'scroll-lock))
|
|
234 (if (featurep 'scroll-lock)
|
|
235 (define-key crisp-mode-map [(meta f1)] 'scroll-lock-mode))
|
|
236 (run-hooks 'crisp-load-hook))
|
|
237 ((eq crisp-mode-enabled 'nil)
|
|
238 (use-global-map crisp-mode-original-keymap))))
|
|
239
|
|
240 (provide 'crisp)
|
|
241
|
|
242 ;;; crisp.el ends here
|