HideIfDef mode bug fixes and enhancements. This is #2 of 3 patches based
[bpt/emacs.git] / lisp / obsolete / crisp.el
CommitLineData
5d5fa02f 1;;; crisp.el --- CRiSP/Brief Emacs emulator
d21b2085 2
ba318903 3;; Copyright (C) 1997-1999, 2001-2014 Free Software Foundation, Inc.
5e33ba39 4
da061c5e 5;; Author: Gary D. Foster <Gary.Foster@Corp.Sun.COM>
7aa5f6cf 6;; Keywords: emulations brief crisp
4982861a 7;; Obsolete-since: 24.5
5e33ba39
RS
8
9;; This file is part of GNU Emacs.
10
ed0f493f 11;; GNU Emacs is free software: you can redistribute it and/or modify
5e33ba39 12;; it under the terms of the GNU General Public License as published by
ed0f493f
GM
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
5e33ba39
RS
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
ed0f493f 22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
5e33ba39
RS
23
24;;; Commentary:
25
7aa5f6cf
KH
26;; Keybindings and minor functions to duplicate the functionality and
27;; finger-feel of the CRiSP/Brief editor. This package is designed to
28;; facilitate transitioning from Brief to (XE|E)macs with a minimum
29;; amount of hassles.
5e33ba39 30
7aa5f6cf
KH
31;; Enable this package by putting (require 'crisp) in your .emacs and
32;; use M-x crisp-mode to toggle it on or off.
5e33ba39 33
7aa5f6cf
KH
34;; This package will automatically load the scroll-all.el package if
35;; you put (setq crisp-load-scroll-all t) in your .emacs before
36;; loading this package. If this feature is enabled, it will bind
37;; meta-f1 to the scroll-all mode toggle. The scroll-all package
91af3942 38;; duplicates the scroll-all feature in CRiSP.
5e33ba39 39
7aa5f6cf
KH
40;; Also, the default keybindings for brief/CRiSP override the M-x
41;; key to exit the editor. If you don't like this functionality, you
42;; can prevent this behavior (or redefine it dynamically) by setting
43;; the value of `crisp-override-meta-x' either in your .emacs or
3da6cc26
RS
44;; interactively. The default setting is t, which means that M-x will
45;; by default run `save-buffers-kill-emacs' instead of the command
46;; `execute-extended-command'.
5e33ba39 47
37269466
CY
48;; Finally, if you want to change the string displayed in the mode
49;; line when this mode is in effect, override the definition of
50;; `crisp-mode-mode-line-string' in your .emacs. The default value is
d21b2085
RS
51;; " *Crisp*" which may be a bit lengthy if you have a lot of things
52;; being displayed there.
53
5e33ba39
RS
54;; All these overrides should go *before* the (require 'crisp) statement.
55
5d5fa02f 56;;; Code:
7aa5f6cf 57
7aa5f6cf
KH
58;; local variables
59
0b5bb3ec
SE
60(defgroup crisp nil
61 "Emulator for CRiSP and Brief key bindings."
62 :prefix "crisp-"
63 :group 'emulations)
64
726a4d09
SM
65(defvar crisp-mode-map
66 (let ((map (make-sparse-keymap)))
67 (define-key map [(f1)] 'other-window)
68
69 (define-key map [(f2) (down)] 'enlarge-window)
70 (define-key map [(f2) (left)] 'shrink-window-horizontally)
71 (define-key map [(f2) (right)] 'enlarge-window-horizontally)
72 (define-key map [(f2) (up)] 'shrink-window)
2d197ffb
CY
73 (define-key map [(f3) (down)] 'split-window-below)
74 (define-key map [(f3) (right)] 'split-window-right)
726a4d09
SM
75
76 (define-key map [(f4)] 'delete-window)
77 (define-key map [(control f4)] 'delete-other-windows)
78
79 (define-key map [(f5)] 'search-forward-regexp)
80 (define-key map [(f19)] 'search-forward-regexp)
81 (define-key map [(meta f5)] 'search-backward-regexp)
82
83 (define-key map [(f6)] 'query-replace)
84
85 (define-key map [(f7)] 'start-kbd-macro)
86 (define-key map [(meta f7)] 'end-kbd-macro)
87
88 (define-key map [(f8)] 'call-last-kbd-macro)
89 (define-key map [(meta f8)] 'save-kbd-macro)
90
91 (define-key map [(f9)] 'find-file)
92 (define-key map [(meta f9)] 'load-library)
93
94 (define-key map [(f10)] 'execute-extended-command)
95 (define-key map [(meta f10)] 'compile)
96
97 (define-key map [(SunF37)] 'kill-buffer)
98 (define-key map [(kp-add)] 'crisp-copy-line)
99 (define-key map [(kp-subtract)] 'crisp-kill-line)
100 ;; just to cover all the bases (GNU Emacs, for instance)
101 (define-key map [(f24)] 'crisp-kill-line)
102 (define-key map [(insert)] 'crisp-yank-clipboard)
103 (define-key map [(f16)] 'crisp-set-clipboard) ; copy on Sun5 kbd
104 (define-key map [(f20)] 'crisp-kill-region) ; cut on Sun5 kbd
105 (define-key map [(f18)] 'crisp-yank-clipboard) ; paste on Sun5 kbd
106
107 (define-key map [(control f)] 'fill-paragraph-or-region)
108 (define-key map [(meta d)] (lambda ()
109 (interactive)
110 (beginning-of-line) (kill-line)))
111 (define-key map [(meta e)] 'find-file)
112 (define-key map [(meta g)] 'goto-line)
113 (define-key map [(meta h)] 'help)
114 (define-key map [(meta i)] 'overwrite-mode)
115 (define-key map [(meta j)] 'bookmark-jump)
116 (define-key map [(meta l)] 'crisp-mark-line)
117 (define-key map [(meta m)] 'set-mark-command)
118 (define-key map [(meta n)] 'bury-buffer)
119 (define-key map [(meta p)] 'crisp-unbury-buffer)
120 (define-key map [(meta u)] 'undo)
121 (define-key map [(f14)] 'undo)
122 (define-key map [(meta w)] 'save-buffer)
123 (define-key map [(meta x)] 'crisp-meta-x-wrapper)
124 (define-key map [(meta ?0)] (lambda ()
125 (interactive)
126 (bookmark-set "0")))
127 (define-key map [(meta ?1)] (lambda ()
128 (interactive)
129 (bookmark-set "1")))
130 (define-key map [(meta ?2)] (lambda ()
131 (interactive)
132 (bookmark-set "2")))
133 (define-key map [(meta ?3)] (lambda ()
134 (interactive)
135 (bookmark-set "3")))
136 (define-key map [(meta ?4)] (lambda ()
137 (interactive)
138 (bookmark-set "4")))
139 (define-key map [(meta ?5)] (lambda ()
140 (interactive)
141 (bookmark-set "5")))
142 (define-key map [(meta ?6)] (lambda ()
143 (interactive)
144 (bookmark-set "6")))
145 (define-key map [(meta ?7)] (lambda ()
146 (interactive)
147 (bookmark-set "7")))
148 (define-key map [(meta ?8)] (lambda ()
149 (interactive)
150 (bookmark-set "8")))
151 (define-key map [(meta ?9)] (lambda ()
152 (interactive)
153 (bookmark-set "9")))
154
155 (define-key map [(shift delete)] 'kill-word)
156 (define-key map [(shift backspace)] 'backward-kill-word)
157 (define-key map [(control left)] 'backward-word)
158 (define-key map [(control right)] 'forward-word)
159
160 (define-key map [(home)] 'crisp-home)
161 (define-key map [(control home)] (lambda ()
162 (interactive)
163 (move-to-window-line 0)))
164 (define-key map [(meta home)] 'beginning-of-line)
165 (define-key map [(end)] 'crisp-end)
166 (define-key map [(control end)] (lambda ()
167 (interactive)
168 (move-to-window-line -1)))
169 (define-key map [(meta end)] 'end-of-line)
170 map)
d21b2085 171 "Local keymap for CRiSP emulation mode.
7aa5f6cf
KH
172All the bindings are done here instead of globally to try and be
173nice to the world.")
5e33ba39 174
d1aae614
GM
175(define-obsolete-variable-alias 'crisp-mode-modeline-string
176 'crisp-mode-mode-line-string "24.3")
177
37269466
CY
178(defcustom crisp-mode-mode-line-string " *CRiSP*"
179 "String to display in the mode line when CRiSP emulation mode is enabled."
0b5bb3ec
SE
180 :type 'string
181 :group 'crisp)
d21b2085 182
3da6cc26
RS
183;;;###autoload
184(defcustom crisp-mode nil
d21b2085
RS
185 "Track status of CRiSP emulation mode.
186A value of nil means CRiSP mode is not enabled. A value of t
3da6cc26
RS
187indicates CRiSP mode is enabled.
188
189Setting this variable directly does not take effect;
190use either M-x customize or the function `crisp-mode'."
191 :set (lambda (symbol value) (crisp-mode (if value 1 0)))
6110ea0a 192 :initialize 'custom-initialize-default
3da6cc26
RS
193 :require 'crisp
194 :version "20.4"
0b5bb3ec
SE
195 :type 'boolean
196 :group 'crisp)
d21b2085 197
0b5bb3ec 198(defcustom crisp-override-meta-x t
1fc7dabf 199 "Controls overriding the normal Emacs M-x key binding in the CRiSP emulator.
28085971 200Normally the CRiSP emulator rebinds M-x to `save-buffers-exit-emacs', and
7aa5f6cf
KH
201provides the usual M-x functionality on the F10 key. If this variable
202is non-nil, M-x will exit Emacs."
0b5bb3ec
SE
203 :type 'boolean
204 :group 'crisp)
5e33ba39 205
7aa5f6cf
KH
206(defcustom crisp-load-scroll-all nil
207 "Controls loading of the Scroll Lock in the CRiSP emulator.
208Its default behavior is to load and enable the Scroll Lock minor mode
5e33ba39
RS
209package when enabling the CRiSP emulator.
210
211If this variable is nil when you start the CRiSP emulator, it
7aa5f6cf 212does not load the scroll-all package."
0b5bb3ec
SE
213 :type 'boolean
214 :group 'crisp)
5e33ba39 215
0b5bb3ec 216(defcustom crisp-load-hook nil
7aa5f6cf 217 "Hooks to run after loading the CRiSP emulator package."
0b5bb3ec
SE
218 :type 'hook
219 :group 'crisp)
d21b2085 220
3da6cc26
RS
221(defcustom crisp-mode-hook nil
222 "Hook run by the function `crisp-mode'."
223 :type 'hook
224 :group 'crisp)
225
226(defconst crisp-version "1.34"
7aa5f6cf 227 "The version of the CRiSP emulator.")
d21b2085 228
7aa5f6cf
KH
229(defconst crisp-mode-help-address "gfoster@suzieq.ml.org"
230 "The email address of the CRiSP mode author/maintainer.")
f4ff0fb4 231
7aa5f6cf
KH
232;; Silence the byte-compiler.
233(defvar crisp-last-last-command nil
28085971 234 "The previous value of `last-command'.")
7aa5f6cf
KH
235
236;; The cut and paste routines are different between XEmacs and Emacs
237;; so we need to set up aliases for the functions.
238
28085971
RS
239(defalias 'crisp-set-clipboard
240 (if (fboundp 'clipboard-kill-ring-save)
241 'clipboard-kill-ring-save
242 'copy-primary-selection))
243
244(defalias 'crisp-kill-region
245 (if (fboundp 'clipboard-kill-region)
246 'clipboard-kill-region
247 'kill-primary-selection))
248
249(defalias 'crisp-yank-clipboard
250 (if (fboundp 'clipboard-yank)
251 'clipboard-yank
252 'yank-clipboard-selection))
7aa5f6cf 253
28085971 254(defun crisp-region-active ()
7aa5f6cf 255 "Compatibility function to test for an active region."
a445370f 256 (if (featurep 'xemacs)
7aa5f6cf
KH
257 zmacs-region-active-p
258 mark-active))
5e33ba39 259
7aa5f6cf
KH
260(defun crisp-version (&optional arg)
261 "Version number of the CRiSP emulator package.
262If ARG, insert results at point."
263 (interactive "P")
264 (let ((foo (concat "CRiSP version " crisp-version)))
265 (if arg
266 (insert (message foo))
267 (message foo))))
268
269(defun crisp-mark-line (arg)
3da6cc26
RS
270 "Set mark at the end of the line.
271Arg works as in `end-of-line'."
7aa5f6cf 272 (interactive "p")
79b65a08
RS
273 (let (newmark)
274 (save-excursion
28085971 275 (end-of-line arg)
79b65a08
RS
276 (setq newmark (point)))
277 (push-mark newmark nil t)))
7aa5f6cf
KH
278
279(defun crisp-kill-line (arg)
280 "Mark and kill line(s).
281Marks from point to end of the current line (honoring prefix arguments),
282copies the region to the kill ring and clipboard, and then deletes it."
283 (interactive "*p")
28085971
RS
284 (if (crisp-region-active)
285 (call-interactively 'crisp-kill-region)
7aa5f6cf 286 (crisp-mark-line arg)
28085971 287 (call-interactively 'crisp-kill-region)))
7aa5f6cf
KH
288
289(defun crisp-copy-line (arg)
290 "Mark and copy line(s).
291Marks from point to end of the current line (honoring prefix arguments),
292copies the region to the kill ring and clipboard, and then deactivates
293the region."
294 (interactive "*p")
28085971
RS
295 (if (crisp-region-active)
296 (call-interactively 'crisp-set-clipboard)
7aa5f6cf 297 (crisp-mark-line arg)
28085971 298 (call-interactively 'crisp-set-clipboard))
7aa5f6cf
KH
299 ;; clear the region after the operation is complete
300 ;; XEmacs does this automagically, Emacs doesn't.
301 (if (boundp 'mark-active)
302 (setq mark-active nil)))
5e33ba39 303
5e33ba39 304(defun crisp-home ()
7aa5f6cf 305 "\"Home\" the point, the way CRiSP would do it.
5e33ba39
RS
306The first use moves point to beginning of the line. Second
307consecutive use moves point to beginning of the screen. Third
308consecutive use moves point to the beginning of the buffer."
309 (interactive nil)
310 (cond
f4ff0fb4
RS
311 ((and (eq last-command 'crisp-home)
312 (eq crisp-last-last-command 'crisp-home))
d21b2085 313 (goto-char (point-min)))
5e33ba39 314 ((eq last-command 'crisp-home)
d21b2085 315 (move-to-window-line 0))
5e33ba39 316 (t
d21b2085 317 (beginning-of-line)))
f4ff0fb4 318 (setq crisp-last-last-command last-command))
5e33ba39
RS
319
320(defun crisp-end ()
7aa5f6cf 321 "\"End\" the point, the way CRiSP would do it.
5e33ba39
RS
322The first use moves point to end of the line. Second
323consecutive use moves point to the end of the screen. Third
324consecutive use moves point to the end of the buffer."
325 (interactive nil)
326 (cond
7aa5f6cf
KH
327 ((and (eq last-command 'crisp-end)
328 (eq crisp-last-last-command 'crisp-end))
d21b2085 329 (goto-char (point-max)))
5e33ba39
RS
330 ((eq last-command 'crisp-end)
331 (move-to-window-line -1)
d21b2085 332 (end-of-line))
5e33ba39 333 (t
d21b2085 334 (end-of-line)))
f4ff0fb4 335 (setq crisp-last-last-command last-command))
5e33ba39 336
7aa5f6cf 337(defun crisp-unbury-buffer ()
3da6cc26 338 "Go back one buffer."
7aa5f6cf
KH
339 (interactive)
340 (switch-to-buffer (car (last (buffer-list)))))
a1506d29 341
7aa5f6cf
KH
342(defun crisp-meta-x-wrapper ()
343 "Wrapper function to conditionally override the normal M-x bindings.
344When `crisp-override-meta-x' is non-nil, M-x will exit Emacs (the
345normal CRiSP binding) and when it is nil M-x will run
346`execute-extended-command' (the normal Emacs binding)."
347 (interactive)
348 (if crisp-override-meta-x
349 (save-buffers-kill-emacs)
350 (call-interactively 'execute-extended-command)))
351
3da6cc26 352;;;###autoload
726a4d09 353(define-minor-mode crisp-mode
ac6c8639
CY
354 "Toggle CRiSP/Brief emulation (CRiSP mode).
355With a prefix argument ARG, enable CRiSP mode if ARG is positive,
356and disable it otherwise. If called from Lisp, enable the mode
357if ARG is omitted or nil."
726a4d09 358 :keymap crisp-mode-map
37269466 359 :lighter crisp-mode-mode-line-string
3da6cc26 360 (when crisp-mode
8cb95edf
SM
361 ;; Make menu entries show M-u or f14 in preference to C-x u.
362 (put 'undo :advertised-binding
f58e0fd5 363 `([?\M-u] [f14] ,@(get 'undo :advertised-binding)))
6110ea0a
KH
364 ;; Force transient-mark-mode, so that the marking routines work as
365 ;; expected. If the user turns off transient mark mode, most
366 ;; things will still work fine except the crisp-(copy|kill)
367 ;; functions won't work quite as nicely when regions are marked
368 ;; differently and could really confuse people. Caveat emptor.
369 (if (fboundp 'transient-mark-mode)
370 (transient-mark-mode t))
a06e220d
RS
371 (if crisp-load-scroll-all
372 (require 'scroll-all))
373 (if (featurep 'scroll-all)
726a4d09 374 (define-key crisp-mode-map [(meta f1)] 'scroll-all-mode))))
5e33ba39 375
4e968343
DL
376;; People might use Apropos on `brief'.
377;;;###autoload
378(defalias 'brief-mode 'crisp-mode)
379
504feff5 380;; Interaction with other packages.
34e99b2e
KS
381(put 'crisp-home 'CUA 'move)
382(put 'crisp-end 'CUA 'move)
504feff5 383
6110ea0a 384(run-hooks 'crisp-load-hook)
5e33ba39
RS
385(provide 'crisp)
386
8c7d9baf 387;;; crisp.el ends here