Mercurial > hg > xemacs-beta
comparison lisp/emulators/ws-mode.el @ 72:b9518feda344 r20-0b31
Import from CVS: tag r20-0b31
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:03:46 +0200 |
parents | 131b0175ea99 |
children |
comparison
equal
deleted
inserted
replaced
71:bae944334fa4 | 72:b9518feda344 |
---|---|
1 ;;; ws-mode.el --- WordStar emulation mode for GNU Emacs | 1 ;;; ws-mode.el --- WordStar emulation mode for GNU Emacs |
2 | 2 |
3 ;; Author: Juergen Nickelsen <nickel@cs.tu-berlin.de> | |
4 ;; Created: 13 Feb 1991 | |
5 ;; Version: 0.7 | |
6 | |
7 ;; Copyright (C) 1991 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1991 Free Software Foundation, Inc. |
8 | 4 |
9 ;; This file is distributed in the hope that it will be useful, | 5 ;; Author: Juergen Nickelsen <nickel@cs.tu-berlin.de> |
10 ;; but WITHOUT ANY WARRANTY. No author or distributor | 6 ;; Version: 0.7 |
11 ;; accepts responsibility to anyone for the consequences of using it | 7 ;; Keywords: emulations |
12 ;; or for whether it serves any particular purpose or works at all, | 8 |
13 ;; unless he says so in writing. Refer to the GNU Emacs General Public | 9 ;; This file is part of XEmacs. |
14 ;; License for full details. | 10 |
15 | 11 ;; XEmacs is free software; you can redistribute it and/or modify it |
16 ;; Everyone is granted permission to copy, modify and redistribute | 12 ;; under the terms of the GNU General Public License as published by |
17 ;; this file, but only under the conditions described in the | 13 ;; the Free Software Foundation; either version 2, or (at your option) |
18 ;; GNU Emacs General Public License. A copy of this license is | 14 ;; any later version. |
19 ;; supposed to have been given to you along with GNU Emacs so you | 15 |
20 ;; can know your rights and responsibilities. It should be in a | 16 ;; XEmacs is distributed in the hope that it will be useful, but |
21 ;; file named COPYING. Among other things, the copyright notice | 17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of |
22 ;; and this notice must be preserved on all copies. | 18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
23 | 19 ;; General Public License for more details. |
24 | 20 |
25 ;; How to install ws-mode.el: | 21 ;; You should have received a copy of the GNU General Public License |
26 ;; | 22 ;; along with XEmacs; see the file COPYING. If not, write to the Free |
27 ;; either you | 23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
28 ;; put the following line into your default.el (usually | 24 ;; 02111-1307, USA. |
29 ;; /usr/local/emacs/lisp/default.el): | 25 |
30 ;; (autoload 'wordstar-mode "ws-mode.el" "WordStar emulation mode." t) | 26 ;;; Synched up with: FSF 19.34 |
31 ;; put ws-mode.el into a directory in your Emacs load-path (usually | 27 |
32 ;; /usr/local/emacs/local/lisp). | 28 ;;; Commentary: |
33 ;; | 29 |
34 ;; or you | 30 ;; This emulates WordStar, with a major mode. |
35 ;; put ws-mode.el into your directory $HOME/lib/emacs (or something | 31 |
36 ;; like that) | 32 ;;; Code: |
37 ;; put the following two lines into your file $HOME/.emacs | |
38 ;; (autoload 'wordstar-mode (expand-file-name "~/lib/emacs/ws-mode.el") | |
39 ;; "WordStar emulation mode." t) | |
40 ;; | |
41 ;; You can then invoke wordstar-mode for a buffer by typing | |
42 ;; M-x wordstar-mode | |
43 ;; | |
44 ;; If you want to use Emacs in wordstar-mode by default, put the | |
45 ;; following line in addition into your file $HOME/.emacs : | |
46 ;; (setq default-major-mode 'wordstar-mode) | |
47 ;; | |
48 ;; If you want to use Emacs *always* in wordstar-mode, even when the | |
49 ;; file type would indicate another mode, put the follwoing line in | |
50 ;; addition into your file $HOME/.emacs : | |
51 ;; (setq auto-mode-alist nil) | |
52 ;; | |
53 ;; Enjoy! | |
54 | |
55 | |
56 | |
57 (defun wordstar-mode () | |
58 "Major mode with WordStar-like key bindings. | |
59 | |
60 BUGS: | |
61 - Help menus with WordStar commands (C-j just calls help-for-help) | |
62 are not implemented | |
63 - Options for search and replace | |
64 - Show markers (C-k h) is somewhat strange | |
65 - Search and replace (C-q a) is only available in forward direction | |
66 | |
67 No key bindings beginning with ESC are installed, they will work | |
68 Emacs-like. | |
69 | |
70 The key bindings are: | |
71 | |
72 C-a backward-word | |
73 C-b fill-paragraph | |
74 C-c scroll-up-line | |
75 C-d forward-char | |
76 C-e previous-line | |
77 C-f forward-word | |
78 C-g delete-char | |
79 C-h backward-char | |
80 C-i indent-for-tab-command | |
81 C-j help-for-help | |
82 C-k ordstar-C-k-map | |
83 C-l ws-repeat-search | |
84 C-n open-line | |
85 C-p quoted-insert | |
86 C-r scroll-down-line | |
87 C-s backward-char | |
88 C-t kill-word | |
89 C-u keyboard-quit | |
90 C-v overwrite-mode | |
91 C-w scroll-down | |
92 C-x next-line | |
93 C-y kill-complete-line | |
94 C-z scroll-up | |
95 | |
96 C-k 0 ws-set-marker-0 | |
97 C-k 1 ws-set-marker-1 | |
98 C-k 2 ws-set-marker-2 | |
99 C-k 3 ws-set-marker-3 | |
100 C-k 4 ws-set-marker-4 | |
101 C-k 5 ws-set-marker-5 | |
102 C-k 6 ws-set-marker-6 | |
103 C-k 7 ws-set-marker-7 | |
104 C-k 8 ws-set-marker-8 | |
105 C-k 9 ws-set-marker-9 | |
106 C-k b ws-begin-block | |
107 C-k c ws-copy-block | |
108 C-k d save-buffers-kill-emacs | |
109 C-k f find-file | |
110 C-k h ws-show-markers | |
111 C-k i ws-indent-block | |
112 C-k k ws-end-block | |
113 C-k p ws-print-block | |
114 C-k q kill-emacs | |
115 C-k r insert-file | |
116 C-k s save-some-buffers | |
117 C-k t ws-mark-word | |
118 C-k u ws-exdent-block | |
119 C-k C-u keyboard-quit | |
120 C-k v ws-move-block | |
121 C-k w ws-write-block | |
122 C-k x kill-emacs | |
123 C-k y ws-delete-block | |
124 | |
125 C-o c center-line | |
126 C-o b switch-to-buffer | |
127 C-o j justify-current-line | |
128 C-o k kill-buffer | |
129 C-o l list-buffers | |
130 C-o m auto-fill-mode | |
131 C-o r set-fill-column | |
132 C-o C-u keyboard-quit | |
133 C-o wd delete-other-windows | |
134 C-o wh split-window-horizontally | |
135 C-o wo other-window | |
136 C-o wv split-window-vertically | |
137 | |
138 C-q 0 ws-find-marker-0 | |
139 C-q 1 ws-find-marker-1 | |
140 C-q 2 ws-find-marker-2 | |
141 C-q 3 ws-find-marker-3 | |
142 C-q 4 ws-find-marker-4 | |
143 C-q 5 ws-find-marker-5 | |
144 C-q 6 ws-find-marker-6 | |
145 C-q 7 ws-find-marker-7 | |
146 C-q 8 ws-find-marker-8 | |
147 C-q 9 ws-find-marker-9 | |
148 C-q a ws-query-replace | |
149 C-q b ws-to-block-begin | |
150 C-q c end-of-buffer | |
151 C-q d end-of-line | |
152 C-q f ws-search | |
153 C-q k ws-to-block-end | |
154 C-q l ws-undo | |
155 C-q p ws-last-cursorp | |
156 C-q r beginning-of-buffer | |
157 C-q C-u keyboard-quit | |
158 C-q w ws-last-error | |
159 C-q y ws-kill-eol | |
160 C-q DEL ws-kill-bol | |
161 " | |
162 (interactive) | |
163 (kill-all-local-variables) | |
164 (use-local-map wordstar-mode-map) | |
165 (setq mode-name "WordStar") | |
166 (setq major-mode 'wordstar-mode)) | |
167 | 33 |
168 (defvar wordstar-mode-map nil "") | 34 (defvar wordstar-mode-map nil "") |
169 (defvar wordstar-C-j-map nil "") | 35 (defvar wordstar-C-j-map nil "") |
170 (defvar wordstar-C-k-map nil "") | 36 (defvar wordstar-C-k-map nil "") |
171 (defvar wordstar-C-o-map nil "") | 37 (defvar wordstar-C-o-map nil "") |
256 ;; wordstar-C-j-map not yet implemented | 122 ;; wordstar-C-j-map not yet implemented |
257 | 123 |
258 ;; wordstar-C-o-map | 124 ;; wordstar-C-o-map |
259 | 125 |
260 (define-key wordstar-C-o-map " " ()) | 126 (define-key wordstar-C-o-map " " ()) |
261 (define-key wordstar-C-o-map "c" 'center-line) | 127 (define-key wordstar-C-o-map "c" 'wordstar-center-line) |
262 (define-key wordstar-C-o-map "\C-c" 'center-line) | 128 (define-key wordstar-C-o-map "\C-c" 'wordstar-center-line) |
263 (define-key wordstar-C-o-map "b" 'switch-to-buffer) | 129 (define-key wordstar-C-o-map "b" 'switch-to-buffer) |
264 (define-key wordstar-C-o-map "\C-b" 'switch-to-buffer) | 130 (define-key wordstar-C-o-map "\C-b" 'switch-to-buffer) |
265 (define-key wordstar-C-o-map "j" 'justify-current-line) | 131 (define-key wordstar-C-o-map "j" 'justify-current-line) |
266 (define-key wordstar-C-o-map "\C-j" 'justify-current-line) | 132 (define-key wordstar-C-o-map "\C-j" 'justify-current-line) |
267 (define-key wordstar-C-o-map "k" 'kill-buffer) | 133 (define-key wordstar-C-o-map "k" 'kill-buffer) |
315 (define-key wordstar-C-q-map "\C-w" 'ws-last-error) | 181 (define-key wordstar-C-q-map "\C-w" 'ws-last-error) |
316 (define-key wordstar-C-q-map "y" 'ws-kill-eol) | 182 (define-key wordstar-C-q-map "y" 'ws-kill-eol) |
317 (define-key wordstar-C-q-map "\C-y" 'ws-kill-eol) | 183 (define-key wordstar-C-q-map "\C-y" 'ws-kill-eol) |
318 (define-key wordstar-C-q-map "\177" 'ws-kill-bol)) | 184 (define-key wordstar-C-q-map "\177" 'ws-kill-bol)) |
319 | 185 |
320 | 186 ;;;###autoload |
321 (defun center-paragraph () | 187 (defun wordstar-mode () |
188 "Major mode with WordStar-like key bindings. | |
189 | |
190 BUGS: | |
191 - Help menus with WordStar commands (C-j just calls help-for-help) | |
192 are not implemented | |
193 - Options for search and replace | |
194 - Show markers (C-k h) is somewhat strange | |
195 - Search and replace (C-q a) is only available in forward direction | |
196 | |
197 No key bindings beginning with ESC are installed, they will work | |
198 Emacs-like. | |
199 | |
200 The key bindings are: | |
201 | |
202 C-a backward-word | |
203 C-b fill-paragraph | |
204 C-c scroll-up-line | |
205 C-d forward-char | |
206 C-e previous-line | |
207 C-f forward-word | |
208 C-g delete-char | |
209 C-h backward-char | |
210 C-i indent-for-tab-command | |
211 C-j help-for-help | |
212 C-k ordstar-C-k-map | |
213 C-l ws-repeat-search | |
214 C-n open-line | |
215 C-p quoted-insert | |
216 C-r scroll-down-line | |
217 C-s backward-char | |
218 C-t kill-word | |
219 C-u keyboard-quit | |
220 C-v overwrite-mode | |
221 C-w scroll-down | |
222 C-x next-line | |
223 C-y kill-complete-line | |
224 C-z scroll-up | |
225 | |
226 C-k 0 ws-set-marker-0 | |
227 C-k 1 ws-set-marker-1 | |
228 C-k 2 ws-set-marker-2 | |
229 C-k 3 ws-set-marker-3 | |
230 C-k 4 ws-set-marker-4 | |
231 C-k 5 ws-set-marker-5 | |
232 C-k 6 ws-set-marker-6 | |
233 C-k 7 ws-set-marker-7 | |
234 C-k 8 ws-set-marker-8 | |
235 C-k 9 ws-set-marker-9 | |
236 C-k b ws-begin-block | |
237 C-k c ws-copy-block | |
238 C-k d save-buffers-kill-emacs | |
239 C-k f find-file | |
240 C-k h ws-show-markers | |
241 C-k i ws-indent-block | |
242 C-k k ws-end-block | |
243 C-k p ws-print-block | |
244 C-k q kill-emacs | |
245 C-k r insert-file | |
246 C-k s save-some-buffers | |
247 C-k t ws-mark-word | |
248 C-k u ws-exdent-block | |
249 C-k C-u keyboard-quit | |
250 C-k v ws-move-block | |
251 C-k w ws-write-block | |
252 C-k x kill-emacs | |
253 C-k y ws-delete-block | |
254 | |
255 C-o c wordstar-center-line | |
256 C-o b switch-to-buffer | |
257 C-o j justify-current-line | |
258 C-o k kill-buffer | |
259 C-o l list-buffers | |
260 C-o m auto-fill-mode | |
261 C-o r set-fill-column | |
262 C-o C-u keyboard-quit | |
263 C-o wd delete-other-windows | |
264 C-o wh split-window-horizontally | |
265 C-o wo other-window | |
266 C-o wv split-window-vertically | |
267 | |
268 C-q 0 ws-find-marker-0 | |
269 C-q 1 ws-find-marker-1 | |
270 C-q 2 ws-find-marker-2 | |
271 C-q 3 ws-find-marker-3 | |
272 C-q 4 ws-find-marker-4 | |
273 C-q 5 ws-find-marker-5 | |
274 C-q 6 ws-find-marker-6 | |
275 C-q 7 ws-find-marker-7 | |
276 C-q 8 ws-find-marker-8 | |
277 C-q 9 ws-find-marker-9 | |
278 C-q a ws-query-replace | |
279 C-q b ws-to-block-begin | |
280 C-q c end-of-buffer | |
281 C-q d end-of-line | |
282 C-q f ws-search | |
283 C-q k ws-to-block-end | |
284 C-q l ws-undo | |
285 C-q p ws-last-cursorp | |
286 C-q r beginning-of-buffer | |
287 C-q C-u keyboard-quit | |
288 C-q w ws-last-error | |
289 C-q y ws-kill-eol | |
290 C-q DEL ws-kill-bol | |
291 " | |
292 (interactive) | |
293 (kill-all-local-variables) | |
294 (use-local-map wordstar-mode-map) | |
295 (setq mode-name "WordStar") | |
296 (setq major-mode 'wordstar-mode)) | |
297 | |
298 | |
299 (defun wordstar-center-paragraph () | |
322 "Center each line in the paragraph at or after point. | 300 "Center each line in the paragraph at or after point. |
323 See center-line for more info." | 301 See `wordstar-center-line' for more info." |
324 (interactive) | 302 (interactive) |
325 (save-excursion | 303 (save-excursion |
326 (forward-paragraph) | 304 (forward-paragraph) |
327 (or (bolp) (newline 1)) | 305 (or (bolp) (newline 1)) |
328 (let ((end (point))) | 306 (let ((end (point))) |
329 (backward-paragraph) | 307 (backward-paragraph) |
330 (center-region (point) end)))) | 308 (wordstar-center-region (point) end)))) |
331 | 309 |
332 (defun center-region (from to) | 310 (defun wordstar-center-region (from to) |
333 "Center each line starting in the region. | 311 "Center each line starting in the region. |
334 See center-line for more info." | 312 See `wordstar-center-line' for more info." |
335 (interactive "r") | 313 (interactive "r") |
336 (if (> from to) | 314 (if (> from to) |
337 (let ((tem to)) | 315 (let ((tem to)) |
338 (setq to from from tem))) | 316 (setq to from from tem))) |
339 (save-excursion | 317 (save-excursion |
340 (save-restriction | 318 (save-restriction |
341 (narrow-to-region from to) | 319 (narrow-to-region from to) |
342 (goto-char from) | 320 (goto-char from) |
343 (while (not (eobp)) | 321 (while (not (eobp)) |
344 (center-line) | 322 (wordstar-center-line) |
345 (forward-line 1))))) | 323 (forward-line 1))))) |
346 | 324 |
347 (defun center-line () | 325 (defun wordstar-center-line () |
348 "Center the line point is on, within the width specified by `fill-column'. | 326 "Center the line point is on, within the width specified by `fill-column'. |
349 This means adjusting the indentation to match | 327 This means adjusting the indentation to match |
350 the distance between the end of the text and `fill-column'." | 328 the distance between the end of the text and `fill-column'." |
351 (interactive) | 329 (interactive) |
352 (save-excursion | 330 (save-excursion |
494 (message "")) | 472 (message "")) |
495 (message "Block markers not set"))) | 473 (message "Block markers not set"))) |
496 | 474 |
497 | 475 |
498 (defun ws-indent-block () | 476 (defun ws-indent-block () |
499 "In WordStar mode: Indent block (not yet implemeted)." | 477 "In WordStar mode: Indent block (not yet implemented)." |
500 (interactive) | 478 (interactive) |
501 (ws-error "Indent block not yet implemented")) | 479 (ws-error "Indent block not yet implemented")) |
502 | 480 |
503 (defun ws-end-block () | 481 (defun ws-end-block () |
504 "In WordStar mode: Set block end marker to current cursor position." | 482 "In WordStar mode: Set block end marker to current cursor position." |
513 | 491 |
514 (defun ws-mark-word () | 492 (defun ws-mark-word () |
515 "In WordStar mode: Mark current word as block." | 493 "In WordStar mode: Mark current word as block." |
516 (interactive) | 494 (interactive) |
517 (save-excursion | 495 (save-excursion |
518 (forward-word) | 496 (forward-word 1) |
519 (sit-for 1) | 497 (sit-for 1) |
520 (ws-end-block) | 498 (ws-end-block) |
521 (backward-word) | 499 (forward-word -1) |
522 (sit-for 1) | 500 (sit-for 1) |
523 (ws-begin-block))) | 501 (ws-begin-block))) |
524 | 502 |
525 (defun ws-exdent-block () | 503 (defun ws-exdent-block () |
526 "I don't know what this (C-k u) should do." | 504 "I don't know what this (C-k u) should do." |
529 | 507 |
530 (defun ws-move-block () | 508 (defun ws-move-block () |
531 "In WordStar mode: Move block to current cursor position." | 509 "In WordStar mode: Move block to current cursor position." |
532 (interactive) | 510 (interactive) |
533 (if (and ws-block-begin-marker ws-block-end-marker) | 511 (if (and ws-block-begin-marker ws-block-end-marker) |
534 (let () | 512 (let () |
513 ;; XEmacs | |
535 (kill-region ws-block-begin-marker ws-block-end-marker 'silent) | 514 (kill-region ws-block-begin-marker ws-block-end-marker 'silent) |
536 (yank) | 515 (yank) |
537 (save-excursion | 516 (save-excursion |
538 (goto-char (region-beginning)) | 517 (goto-char (region-beginning)) |
539 (setq ws-block-begin-marker (point-marker)) | 518 (setq ws-block-begin-marker (point-marker)) |
722 (end-of-line) | 701 (end-of-line) |
723 (kill-region p (point)))) | 702 (kill-region p (point)))) |
724 | 703 |
725 (defun ws-kill-bol () | 704 (defun ws-kill-bol () |
726 "In WordStar mode: Kill to beginning of line | 705 "In WordStar mode: Kill to beginning of line |
727 (like WordStar, not like Emacs)." | 706 \(like WordStar, not like Emacs)." |
728 (interactive) | 707 (interactive) |
729 (let ((p (point))) | 708 (let ((p (point))) |
730 (beginning-of-line) | 709 (beginning-of-line) |
731 (kill-region (point) p))) | 710 (kill-region (point) p))) |
732 | 711 |