| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
(defgroup crisp nil |
|---|
| 63 |
"Emulator for CRiSP and Brief key bindings." |
|---|
| 64 |
:prefix "crisp-" |
|---|
| 65 |
:group 'emulations) |
|---|
| 66 |
|
|---|
| 67 |
(defvar crisp-mode-map (let ((map (make-sparse-keymap))) |
|---|
| 68 |
map) |
|---|
| 69 |
"Local keymap for CRiSP emulation mode. |
|---|
| 70 |
All the bindings are done here instead of globally to try and be |
|---|
| 71 |
nice to the world.") |
|---|
| 72 |
|
|---|
| 73 |
(defcustom crisp-mode-modeline-string " *CRiSP*" |
|---|
| 74 |
"*String to display in the modeline when CRiSP emulation mode is enabled." |
|---|
| 75 |
:type 'string |
|---|
| 76 |
:group 'crisp) |
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
(defcustom crisp-mode nil |
|---|
| 80 |
"Track status of CRiSP emulation mode. |
|---|
| 81 |
A value of nil means CRiSP mode is not enabled. A value of t |
|---|
| 82 |
indicates CRiSP mode is enabled. |
|---|
| 83 |
|
|---|
| 84 |
Setting this variable directly does not take effect; |
|---|
| 85 |
use either M-x customize or the function `crisp-mode'." |
|---|
| 86 |
:set (lambda (symbol value) (crisp-mode (if value 1 0))) |
|---|
| 87 |
:initialize 'custom-initialize-default |
|---|
| 88 |
:require 'crisp |
|---|
| 89 |
:version "20.4" |
|---|
| 90 |
:type 'boolean |
|---|
| 91 |
:group 'crisp) |
|---|
| 92 |
|
|---|
| 93 |
(defcustom crisp-override-meta-x t |
|---|
| 94 |
"*Controls overriding the normal Emacs M-x key binding in the CRiSP emulator. |
|---|
| 95 |
Normally the CRiSP emulator rebinds M-x to `save-buffers-exit-emacs', and |
|---|
| 96 |
provides the usual M-x functionality on the F10 key. If this variable |
|---|
| 97 |
is non-nil, M-x will exit Emacs." |
|---|
| 98 |
:type 'boolean |
|---|
| 99 |
:group 'crisp) |
|---|
| 100 |
|
|---|
| 101 |
(defcustom crisp-load-scroll-all nil |
|---|
| 102 |
"Controls loading of the Scroll Lock in the CRiSP emulator. |
|---|
| 103 |
Its default behavior is to load and enable the Scroll Lock minor mode |
|---|
| 104 |
package when enabling the CRiSP emulator. |
|---|
| 105 |
|
|---|
| 106 |
If this variable is nil when you start the CRiSP emulator, it |
|---|
| 107 |
does not load the scroll-all package." |
|---|
| 108 |
:type 'boolean |
|---|
| 109 |
:group 'crisp) |
|---|
| 110 |
|
|---|
| 111 |
(defcustom crisp-load-hook nil |
|---|
| 112 |
"Hooks to run after loading the CRiSP emulator package." |
|---|
| 113 |
:type 'hook |
|---|
| 114 |
:group 'crisp) |
|---|
| 115 |
|
|---|
| 116 |
(defcustom crisp-mode-hook nil |
|---|
| 117 |
"Hook run by the function `crisp-mode'." |
|---|
| 118 |
:type 'hook |
|---|
| 119 |
:group 'crisp) |
|---|
| 120 |
|
|---|
| 121 |
(defconst crisp-version "1.34" |
|---|
| 122 |
"The version of the CRiSP emulator.") |
|---|
| 123 |
|
|---|
| 124 |
(defconst crisp-mode-help-address "gfoster@suzieq.ml.org" |
|---|
| 125 |
"The email address of the CRiSP mode author/maintainer.") |
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
(defvar crisp-last-last-command nil |
|---|
| 129 |
"The previous value of `last-command'.") |
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
(defalias 'crisp-set-clipboard |
|---|
| 135 |
(if (fboundp 'clipboard-kill-ring-save) |
|---|
| 136 |
'clipboard-kill-ring-save |
|---|
| 137 |
'copy-primary-selection)) |
|---|
| 138 |
|
|---|
| 139 |
(defalias 'crisp-kill-region |
|---|
| 140 |
(if (fboundp 'clipboard-kill-region) |
|---|
| 141 |
'clipboard-kill-region |
|---|
| 142 |
'kill-primary-selection)) |
|---|
| 143 |
|
|---|
| 144 |
(defalias 'crisp-yank-clipboard |
|---|
| 145 |
(if (fboundp 'clipboard-yank) |
|---|
| 146 |
'clipboard-yank |
|---|
| 147 |
'yank-clipboard-selection)) |
|---|
| 148 |
|
|---|
| 149 |
(defun crisp-region-active () |
|---|
| 150 |
"Compatibility function to test for an active region." |
|---|
| 151 |
(if (boundp 'zmacs-region-active-p) |
|---|
| 152 |
zmacs-region-active-p |
|---|
| 153 |
mark-active)) |
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
(define-key crisp-mode-map [(f1)] 'other-window) |
|---|
| 158 |
|
|---|
| 159 |
(define-key crisp-mode-map [(f2) (down)] 'enlarge-window) |
|---|
| 160 |
(define-key crisp-mode-map [(f2) (left)] 'shrink-window-horizontally) |
|---|
| 161 |
(define-key crisp-mode-map [(f2) (right)] 'enlarge-window-horizontally) |
|---|
| 162 |
(define-key crisp-mode-map [(f2) (up)] 'shrink-window) |
|---|
| 163 |
(define-key crisp-mode-map [(f3) (down)] 'split-window-vertically) |
|---|
| 164 |
(define-key crisp-mode-map [(f3) (right)] 'split-window-horizontally) |
|---|
| 165 |
|
|---|
| 166 |
(define-key crisp-mode-map [(f4)] 'delete-window) |
|---|
| 167 |
(define-key crisp-mode-map [(control f4)] 'delete-other-windows) |
|---|
| 168 |
|
|---|
| 169 |
(define-key crisp-mode-map [(f5)] 'search-forward-regexp) |
|---|
| 170 |
(define-key crisp-mode-map [(f19)] 'search-forward-regexp) |
|---|
| 171 |
(define-key crisp-mode-map [(meta f5)] 'search-backward-regexp) |
|---|
| 172 |
|
|---|
| 173 |
(define-key crisp-mode-map [(f6)] 'query-replace) |
|---|
| 174 |
|
|---|
| 175 |
(define-key crisp-mode-map [(f7)] 'start-kbd-macro) |
|---|
| 176 |
(define-key crisp-mode-map [(meta f7)] 'end-kbd-macro) |
|---|
| 177 |
|
|---|
| 178 |
(define-key crisp-mode-map [(f8)] 'call-last-kbd-macro) |
|---|
| 179 |
(define-key crisp-mode-map [(meta f8)] 'save-kbd-macro) |
|---|
| 180 |
|
|---|
| 181 |
(define-key crisp-mode-map [(f9)] 'find-file) |
|---|
| 182 |
(define-key crisp-mode-map [(meta f9)] 'load-library) |
|---|
| 183 |
|
|---|
| 184 |
(define-key crisp-mode-map [(f10)] 'execute-extended-command) |
|---|
| 185 |
(define-key crisp-mode-map [(meta f10)] 'compile) |
|---|
| 186 |
|
|---|
| 187 |
(define-key crisp-mode-map [(SunF37)] 'kill-buffer) |
|---|
| 188 |
(define-key crisp-mode-map [(kp-add)] 'crisp-copy-line) |
|---|
| 189 |
(define-key crisp-mode-map [(kp-subtract)] 'crisp-kill-line) |
|---|
| 190 |
|
|---|
| 191 |
(define-key crisp-mode-map [(f24)] 'crisp-kill-line) |
|---|
| 192 |
(define-key crisp-mode-map [(insert)] 'crisp-yank-clipboard) |
|---|
| 193 |
(define-key crisp-mode-map [(f16)] 'crisp-set-clipboard) |
|---|
| 194 |
(define-key crisp-mode-map [(f20)] 'crisp-kill-region) |
|---|
| 195 |
(define-key crisp-mode-map [(f18)] 'crisp-yank-clipboard) |
|---|
| 196 |
|
|---|
| 197 |
(define-key crisp-mode-map [(control f)] 'fill-paragraph-or-region) |
|---|
| 198 |
(define-key crisp-mode-map [(meta d)] (lambda () |
|---|
| 199 |
(interactive) |
|---|
| 200 |
(beginning-of-line) (kill-line))) |
|---|
| 201 |
(define-key crisp-mode-map [(meta e)] 'find-file) |
|---|
| 202 |
(define-key crisp-mode-map [(meta g)] 'goto-line) |
|---|
| 203 |
(define-key crisp-mode-map [(meta h)] 'help) |
|---|
| 204 |
(define-key crisp-mode-map [(meta i)] 'overwrite-mode) |
|---|
| 205 |
(define-key crisp-mode-map [(meta j)] 'bookmark-jump) |
|---|
| 206 |
(define-key crisp-mode-map [(meta l)] 'crisp-mark-line) |
|---|
| 207 |
(define-key crisp-mode-map [(meta m)] 'set-mark-command) |
|---|
| 208 |
(define-key crisp-mode-map [(meta n)] 'bury-buffer) |
|---|
| 209 |
(define-key crisp-mode-map [(meta p)] 'crisp-unbury-buffer) |
|---|
| 210 |
(define-key crisp-mode-map [(meta u)] 'advertised-undo) |
|---|
| 211 |
(define-key crisp-mode-map [(f14)] 'advertised-undo) |
|---|
| 212 |
(define-key crisp-mode-map [(meta w)] 'save-buffer) |
|---|
| 213 |
(define-key crisp-mode-map [(meta x)] 'crisp-meta-x-wrapper) |
|---|
| 214 |
(define-key crisp-mode-map [(meta ?0)] (lambda () |
|---|
| 215 |
(interactive) |
|---|
| 216 |
(bookmark-set "0"))) |
|---|
| 217 |
(define-key crisp-mode-map [(meta ?1)] (lambda () |
|---|
| 218 |
(interactive) |
|---|
| 219 |
(bookmark-set "1"))) |
|---|
| 220 |
(define-key crisp-mode-map [(meta ?2)] (lambda () |
|---|
| 221 |
(interactive) |
|---|
| 222 |
(bookmark-set "2"))) |
|---|
| 223 |
(define-key crisp-mode-map [(meta ?3)] (lambda () |
|---|
| 224 |
(interactive) |
|---|
| 225 |
(bookmark-set "3"))) |
|---|
| 226 |
(define-key crisp-mode-map [(meta ?4)] (lambda () |
|---|
| 227 |
(interactive) |
|---|
| 228 |
(bookmark-set "4"))) |
|---|
| 229 |
(define-key crisp-mode-map [(meta ?5)] (lambda () |
|---|
| 230 |
(interactive) |
|---|
| 231 |
(bookmark-set "5"))) |
|---|
| 232 |
(define-key crisp-mode-map [(meta ?6)] (lambda () |
|---|
| 233 |
(interactive) |
|---|
| 234 |
(bookmark-set "6"))) |
|---|
| 235 |
(define-key crisp-mode-map [(meta ?7)] (lambda () |
|---|
| 236 |
(interactive) |
|---|
| 237 |
(bookmark-set "7"))) |
|---|
| 238 |
(define-key crisp-mode-map [(meta ?8)] (lambda () |
|---|
| 239 |
(interactive) |
|---|
| 240 |
(bookmark-set "8"))) |
|---|
| 241 |
(define-key crisp-mode-map [(meta ?9)] (lambda () |
|---|
| 242 |
(interactive) |
|---|
| 243 |
(bookmark-set "9"))) |
|---|
| 244 |
|
|---|
| 245 |
(define-key crisp-mode-map [(shift delete)] 'kill-word) |
|---|
| 246 |
(define-key crisp-mode-map [(shift backspace)] 'backward-kill-word) |
|---|
| 247 |
(define-key crisp-mode-map [(control left)] 'backward-word) |
|---|
| 248 |
(define-key crisp-mode-map [(control right)] 'forward-word) |
|---|
| 249 |
|
|---|
| 250 |
(define-key crisp-mode-map [(home)] 'crisp-home) |
|---|
| 251 |
(define-key crisp-mode-map [(control home)] (lambda () |
|---|
| 252 |
(interactive) |
|---|
| 253 |
(move-to-window-line 0))) |
|---|
| 254 |
(define-key crisp-mode-map [(meta home)] 'beginning-of-line) |
|---|
| 255 |
(define-key crisp-mode-map [(end)] 'crisp-end) |
|---|
| 256 |
(define-key crisp-mode-map [(control end)] (lambda () |
|---|
| 257 |
(interactive) |
|---|
| 258 |
(move-to-window-line -1))) |
|---|
| 259 |
(define-key crisp-mode-map [(meta end)] 'end-of-line) |
|---|
| 260 |
|
|---|
| 261 |
(defun crisp-version (&optional arg) |
|---|
| 262 |
"Version number of the CRiSP emulator package. |
|---|
| 263 |
If ARG, insert results at point." |
|---|
| 264 |
(interactive "P") |
|---|
| 265 |
(let ((foo (concat "CRiSP version " crisp-version))) |
|---|
| 266 |
(if arg |
|---|
| 267 |
(insert (message foo)) |
|---|
| 268 |
(message foo)))) |
|---|
| 269 |
|
|---|
| 270 |
(defun crisp-mark-line (arg) |
|---|
| 271 |
"Set mark at the end of the line. |
|---|
| 272 |
Arg works as in `end-of-line'." |
|---|
| 273 |
(interactive "p") |
|---|
| 274 |
(let (newmark) |
|---|
| 275 |
(save-excursion |
|---|
| 276 |
(end-of-line arg) |
|---|
| 277 |
(setq newmark (point))) |
|---|
| 278 |
(push-mark newmark nil t))) |
|---|
| 279 |
|
|---|
| 280 |
(defun crisp-kill-line (arg) |
|---|
| 281 |
"Mark and kill line(s). |
|---|
| 282 |
Marks from point to end of the current line (honoring prefix arguments), |
|---|
| 283 |
copies the region to the kill ring and clipboard, and then deletes it." |
|---|
| 284 |
(interactive "*p") |
|---|
| 285 |
(if (crisp-region-active) |
|---|
| 286 |
(call-interactively 'crisp-kill-region) |
|---|
| 287 |
(crisp-mark-line arg) |
|---|
| 288 |
(call-interactively 'crisp-kill-region))) |
|---|
| 289 |
|
|---|
| 290 |
(defun crisp-copy-line (arg) |
|---|
| 291 |
"Mark and copy line(s). |
|---|
| 292 |
Marks from point to end of the current line (honoring prefix arguments), |
|---|
| 293 |
copies the region to the kill ring and clipboard, and then deactivates |
|---|
| 294 |
the region." |
|---|
| 295 |
(interactive "*p") |
|---|
| 296 |
(if (crisp-region-active) |
|---|
| 297 |
(call-interactively 'crisp-set-clipboard) |
|---|
| 298 |
(crisp-mark-line arg) |
|---|
| 299 |
(call-interactively 'crisp-set-clipboard)) |
|---|
| 300 |
|
|---|
| 301 |
|
|---|
| 302 |
(if (boundp 'mark-active) |
|---|
| 303 |
(setq mark-active nil))) |
|---|
| 304 |
|
|---|
| 305 |
(defun crisp-home () |
|---|
| 306 |
"\"Home\" the point, the way CRiSP would do it. |
|---|
| 307 |
The first use moves point to beginning of the line. Second |
|---|
| 308 |
consecutive use moves point to beginning of the screen. Third |
|---|
| 309 |
consecutive use moves point to the beginning of the buffer." |
|---|
| 310 |
(interactive nil) |
|---|
| 311 |
(cond |
|---|
| 312 |
((and (eq last-command 'crisp-home) |
|---|
| 313 |
(eq crisp-last-last-command 'crisp-home)) |
|---|
| 314 |
(goto-char (point-min))) |
|---|
| 315 |
((eq last-command 'crisp-home) |
|---|
| 316 |
(move-to-window-line 0)) |
|---|
| 317 |
(t |
|---|
| 318 |
(beginning-of-line))) |
|---|
| 319 |
(setq crisp-last-last-command last-command)) |
|---|
| 320 |
|
|---|
| 321 |
(defun crisp-end () |
|---|
| 322 |
"\"End\" the point, the way CRiSP would do it. |
|---|
| 323 |
The first use moves point to end of the line. Second |
|---|
| 324 |
consecutive use moves point to the end of the screen. Third |
|---|
| 325 |
consecutive use moves point to the end of the buffer." |
|---|
| 326 |
(interactive nil) |
|---|
| 327 |
(cond |
|---|
| 328 |
((and (eq last-command 'crisp-end) |
|---|
| 329 |
(eq crisp-last-last-command 'crisp-end)) |
|---|
| 330 |
(goto-char (point-max))) |
|---|
| 331 |
((eq last-command 'crisp-end) |
|---|
| 332 |
(move-to-window-line -1) |
|---|
| 333 |
(end-of-line)) |
|---|
| 334 |
(t |
|---|
| 335 |
(end-of-line))) |
|---|
| 336 |
(setq crisp-last-last-command last-command)) |
|---|
| 337 |
|
|---|
| 338 |
(defun crisp-unbury-buffer () |
|---|
| 339 |
"Go back one buffer." |
|---|
| 340 |
(interactive) |
|---|
| 341 |
(switch-to-buffer (car (last (buffer-list))))) |
|---|
| 342 |
|
|---|
| 343 |
(defun crisp-meta-x-wrapper () |
|---|
| 344 |
"Wrapper function to conditionally override the normal M-x bindings. |
|---|
| 345 |
When `crisp-override-meta-x' is non-nil, M-x will exit Emacs (the |
|---|
| 346 |
normal CRiSP binding) and when it is nil M-x will run |
|---|
| 347 |
`execute-extended-command' (the normal Emacs binding)." |
|---|
| 348 |
(interactive) |
|---|
| 349 |
(if crisp-override-meta-x |
|---|
| 350 |
(save-buffers-kill-emacs) |
|---|
| 351 |
(call-interactively 'execute-extended-command))) |
|---|
| 352 |
|
|---|
| 353 |
|
|---|
| 354 |
(defun crisp-mode (&optional arg) |
|---|
| 355 |
"Toggle CRiSP/Brief emulation minor mode. |
|---|
| 356 |
With ARG, turn CRiSP mode on if ARG is positive, off otherwise." |
|---|
| 357 |
(interactive "P") |
|---|
| 358 |
(setq crisp-mode (if (null arg) |
|---|
| 359 |
(not crisp-mode) |
|---|
| 360 |
(> (prefix-numeric-value arg) 0))) |
|---|
| 361 |
(when crisp-mode |
|---|
| 362 |
|
|---|
| 363 |
|
|---|
| 364 |
|
|---|
| 365 |
|
|---|
| 366 |
|
|---|
| 367 |
(if (fboundp 'transient-mark-mode) |
|---|
| 368 |
(transient-mark-mode t)) |
|---|
| 369 |
(if crisp-load-scroll-all |
|---|
| 370 |
(require 'scroll-all)) |
|---|
| 371 |
(if (featurep 'scroll-all) |
|---|
| 372 |
(define-key crisp-mode-map [(meta f1)] 'scroll-all-mode)) |
|---|
| 373 |
(run-hooks 'crisp-mode-hook))) |
|---|
| 374 |
|
|---|
| 375 |
|
|---|
| 376 |
|
|---|
| 377 |
(defalias 'brief-mode 'crisp-mode) |
|---|
| 378 |
|
|---|
| 379 |
(if (fboundp 'add-minor-mode) |
|---|
| 380 |
(add-minor-mode 'crisp-mode 'crisp-mode-modeline-string |
|---|
| 381 |
crisp-mode-map nil 'crisp-mode) |
|---|
| 382 |
(or (assq 'crisp-mode minor-mode-alist) |
|---|
| 383 |
(setq minor-mode-alist |
|---|
| 384 |
(cons '(crisp-mode crisp-mode-modeline-string) minor-mode-alist))) |
|---|
| 385 |
(or (assq 'crisp-mode minor-mode-map-alist) |
|---|
| 386 |
(setq minor-mode-map-alist (cons (cons 'crisp-mode crisp-mode-map) |
|---|
| 387 |
minor-mode-map-alist)))) |
|---|
| 388 |
|
|---|
| 389 |
|
|---|
| 390 |
(put 'crisp-home 'CUA 'move) |
|---|
| 391 |
(put 'crisp-end 'CUA 'move) |
|---|
| 392 |
|
|---|
| 393 |
(run-hooks 'crisp-load-hook) |
|---|
| 394 |
(provide 'crisp) |
|---|
| 395 |
|
|---|
| 396 |
|
|---|
| 397 |
|
|---|
| 398 |
|
|---|