make thread_check_current_buffer return bool
[emacs.git] / lisp / emulation / ws-mode.el
blob03d7076195e3638e5243c1bec492c79da1226b6c
1 ;;; ws-mode.el --- WordStar emulation mode for GNU Emacs
3 ;; Copyright (C) 1991, 2001-2013 Free Software Foundation, Inc.
5 ;; Author: Juergen Nickelsen <nickel@cs.tu-berlin.de>
6 ;; Version: 0.7
7 ;; Keywords: emulations
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
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.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;; This emulates WordStar, with a major mode.
28 ;;; Code:
29 (defvar wordstar-C-k-map
30 (let ((map (make-keymap)))
31 (define-key map " " ())
32 (define-key map "0" 'ws-set-marker-0)
33 (define-key map "1" 'ws-set-marker-1)
34 (define-key map "2" 'ws-set-marker-2)
35 (define-key map "3" 'ws-set-marker-3)
36 (define-key map "4" 'ws-set-marker-4)
37 (define-key map "5" 'ws-set-marker-5)
38 (define-key map "6" 'ws-set-marker-6)
39 (define-key map "7" 'ws-set-marker-7)
40 (define-key map "8" 'ws-set-marker-8)
41 (define-key map "9" 'ws-set-marker-9)
42 (define-key map "b" 'ws-begin-block)
43 (define-key map "\C-b" 'ws-begin-block)
44 (define-key map "c" 'ws-copy-block)
45 (define-key map "\C-c" 'ws-copy-block)
46 (define-key map "d" 'save-buffers-kill-emacs)
47 (define-key map "\C-d" 'save-buffers-kill-emacs)
48 (define-key map "f" 'find-file)
49 (define-key map "\C-f" 'find-file)
50 (define-key map "h" 'ws-show-markers)
51 (define-key map "\C-h" 'ws-show-markers)
52 (define-key map "i" 'ws-indent-block)
53 (define-key map "\C-i" 'ws-indent-block)
54 (define-key map "k" 'ws-end-block)
55 (define-key map "\C-k" 'ws-end-block)
56 (define-key map "p" 'ws-print-block)
57 (define-key map "\C-p" 'ws-print-block)
58 (define-key map "q" 'kill-emacs)
59 (define-key map "\C-q" 'kill-emacs)
60 (define-key map "r" 'insert-file)
61 (define-key map "\C-r" 'insert-file)
62 (define-key map "s" 'save-some-buffers)
63 (define-key map "\C-s" 'save-some-buffers)
64 (define-key map "t" 'ws-mark-word)
65 (define-key map "\C-t" 'ws-mark-word)
66 (define-key map "u" 'ws-exdent-block)
67 (define-key map "\C-u" 'keyboard-quit)
68 (define-key map "v" 'ws-move-block)
69 (define-key map "\C-v" 'ws-move-block)
70 (define-key map "w" 'ws-write-block)
71 (define-key map "\C-w" 'ws-write-block)
72 (define-key map "x" 'save-buffers-kill-emacs)
73 (define-key map "\C-x" 'save-buffers-kill-emacs)
74 (define-key map "y" 'ws-delete-block)
75 (define-key map "\C-y" 'ws-delete-block)
76 map)
77 "")
79 (defvar wordstar-C-o-map
80 (let ((map (make-keymap)))
81 (define-key map " " ())
82 (define-key map "c" 'wordstar-center-line)
83 (define-key map "\C-c" 'wordstar-center-line)
84 (define-key map "b" 'switch-to-buffer)
85 (define-key map "\C-b" 'switch-to-buffer)
86 (define-key map "j" 'justify-current-line)
87 (define-key map "\C-j" 'justify-current-line)
88 (define-key map "k" 'kill-buffer)
89 (define-key map "\C-k" 'kill-buffer)
90 (define-key map "l" 'list-buffers)
91 (define-key map "\C-l" 'list-buffers)
92 (define-key map "m" 'auto-fill-mode)
93 (define-key map "\C-m" 'auto-fill-mode)
94 (define-key map "r" 'set-fill-column)
95 (define-key map "\C-r" 'set-fill-column)
96 (define-key map "\C-u" 'keyboard-quit)
97 (define-key map "wd" 'delete-other-windows)
98 (define-key map "wh" 'split-window-right)
99 (define-key map "wo" 'other-window)
100 (define-key map "wv" 'split-window-below)
101 map)
104 (defvar wordstar-C-q-map
105 (let ((map (make-keymap)))
106 (define-key map " " ())
107 (define-key map "0" 'ws-find-marker-0)
108 (define-key map "1" 'ws-find-marker-1)
109 (define-key map "2" 'ws-find-marker-2)
110 (define-key map "3" 'ws-find-marker-3)
111 (define-key map "4" 'ws-find-marker-4)
112 (define-key map "5" 'ws-find-marker-5)
113 (define-key map "6" 'ws-find-marker-6)
114 (define-key map "7" 'ws-find-marker-7)
115 (define-key map "8" 'ws-find-marker-8)
116 (define-key map "9" 'ws-find-marker-9)
117 (define-key map "a" 'ws-query-replace)
118 (define-key map "\C-a" 'ws-query-replace)
119 (define-key map "b" 'ws-goto-block-begin)
120 (define-key map "\C-b" 'ws-goto-block-begin)
121 (define-key map "c" 'end-of-buffer)
122 (define-key map "\C-c" 'end-of-buffer)
123 (define-key map "d" 'end-of-line)
124 (define-key map "\C-d" 'end-of-line)
125 (define-key map "f" 'ws-search)
126 (define-key map "\C-f" 'ws-search)
127 (define-key map "k" 'ws-goto-block-end)
128 (define-key map "\C-k" 'ws-goto-block-end)
129 (define-key map "l" 'ws-undo)
130 (define-key map "\C-l" 'ws-undo)
131 (define-key map "p" 'ws-last-cursorp)
132 (define-key map "\C-p" 'ws-last-cursorp)
133 (define-key map "r" 'beginning-of-buffer)
134 (define-key map "\C-r" 'beginning-of-buffer)
135 (define-key map "s" 'beginning-of-line)
136 (define-key map "\C-s" 'beginning-of-line)
137 (define-key map "\C-u" 'keyboard-quit)
138 (define-key map "w" 'ws-last-error)
139 (define-key map "\C-w" 'ws-last-error)
140 (define-key map "y" 'ws-kill-eol)
141 (define-key map "\C-y" 'ws-kill-eol)
142 (define-key map "\177" 'ws-kill-bol)
143 map)
146 (defvar wordstar-mode-map
147 (let ((map (make-keymap)))
148 (define-key map "\C-a" 'backward-word)
149 (define-key map "\C-b" 'fill-paragraph)
150 (define-key map "\C-c" 'scroll-up-command)
151 (define-key map "\C-d" 'forward-char)
152 (define-key map "\C-e" 'previous-line)
153 (define-key map "\C-f" 'forward-word)
154 (define-key map "\C-g" 'delete-char)
155 (define-key map "\C-h" 'backward-char)
156 (define-key map "\C-i" 'indent-for-tab-command)
157 (define-key map "\C-j" 'help-for-help)
158 (define-key map "\C-k" wordstar-C-k-map)
159 (define-key map "\C-l" 'ws-repeat-search)
160 (define-key map "\C-n" 'open-line)
161 (define-key map "\C-o" wordstar-C-o-map)
162 (define-key map "\C-p" 'quoted-insert)
163 (define-key map "\C-q" wordstar-C-q-map)
164 (define-key map "\C-r" 'scroll-down-command)
165 (define-key map "\C-s" 'backward-char)
166 (define-key map "\C-t" 'kill-word)
167 (define-key map "\C-u" 'keyboard-quit)
168 (define-key map "\C-v" 'overwrite-mode)
169 (define-key map "\C-w" 'scroll-down-line)
170 (define-key map "\C-x" 'next-line)
171 (define-key map "\C-y" 'kill-complete-line)
172 (define-key map "\C-z" 'scroll-up-line)
173 map)
176 ;; wordstar-C-j-map not yet implemented
177 (defvar wordstar-C-j-map nil "")
180 (put 'wordstar-mode 'mode-class 'special)
182 ;;;###autoload
183 (defun wordstar-mode ()
184 "Major mode with WordStar-like key bindings.
186 BUGS:
187 - Help menus with WordStar commands (C-j just calls help-for-help)
188 are not implemented
189 - Options for search and replace
190 - Show markers (C-k h) is somewhat strange
191 - Search and replace (C-q a) is only available in forward direction
193 No key bindings beginning with ESC are installed, they will work
194 Emacs-like.
196 The key bindings are:
198 C-a backward-word
199 C-b fill-paragraph
200 C-c scroll-up-line
201 C-d forward-char
202 C-e previous-line
203 C-f forward-word
204 C-g delete-char
205 C-h backward-char
206 C-i indent-for-tab-command
207 C-j help-for-help
208 C-k ordstar-C-k-map
209 C-l ws-repeat-search
210 C-n open-line
211 C-p quoted-insert
212 C-r scroll-down-line
213 C-s backward-char
214 C-t kill-word
215 C-u keyboard-quit
216 C-v overwrite-mode
217 C-w scroll-down
218 C-x next-line
219 C-y kill-complete-line
220 C-z scroll-up
222 C-k 0 ws-set-marker-0
223 C-k 1 ws-set-marker-1
224 C-k 2 ws-set-marker-2
225 C-k 3 ws-set-marker-3
226 C-k 4 ws-set-marker-4
227 C-k 5 ws-set-marker-5
228 C-k 6 ws-set-marker-6
229 C-k 7 ws-set-marker-7
230 C-k 8 ws-set-marker-8
231 C-k 9 ws-set-marker-9
232 C-k b ws-begin-block
233 C-k c ws-copy-block
234 C-k d save-buffers-kill-emacs
235 C-k f find-file
236 C-k h ws-show-markers
237 C-k i ws-indent-block
238 C-k k ws-end-block
239 C-k p ws-print-block
240 C-k q kill-emacs
241 C-k r insert-file
242 C-k s save-some-buffers
243 C-k t ws-mark-word
244 C-k u ws-exdent-block
245 C-k C-u keyboard-quit
246 C-k v ws-move-block
247 C-k w ws-write-block
248 C-k x kill-emacs
249 C-k y ws-delete-block
251 C-o c wordstar-center-line
252 C-o b switch-to-buffer
253 C-o j justify-current-line
254 C-o k kill-buffer
255 C-o l list-buffers
256 C-o m auto-fill-mode
257 C-o r set-fill-column
258 C-o C-u keyboard-quit
259 C-o wd delete-other-windows
260 C-o wh split-window-right
261 C-o wo other-window
262 C-o wv split-window-below
264 C-q 0 ws-find-marker-0
265 C-q 1 ws-find-marker-1
266 C-q 2 ws-find-marker-2
267 C-q 3 ws-find-marker-3
268 C-q 4 ws-find-marker-4
269 C-q 5 ws-find-marker-5
270 C-q 6 ws-find-marker-6
271 C-q 7 ws-find-marker-7
272 C-q 8 ws-find-marker-8
273 C-q 9 ws-find-marker-9
274 C-q a ws-query-replace
275 C-q b ws-to-block-begin
276 C-q c end-of-buffer
277 C-q d end-of-line
278 C-q f ws-search
279 C-q k ws-to-block-end
280 C-q l ws-undo
281 C-q p ws-last-cursorp
282 C-q r beginning-of-buffer
283 C-q C-u keyboard-quit
284 C-q w ws-last-error
285 C-q y ws-kill-eol
286 C-q DEL ws-kill-bol
288 (interactive)
289 (kill-all-local-variables)
290 (use-local-map wordstar-mode-map)
291 (setq mode-name "WordStar")
292 (setq major-mode 'wordstar-mode)
293 (run-mode-hooks 'wordstar-mode-hook))
296 (defun wordstar-center-paragraph ()
297 "Center each line in the paragraph at or after point.
298 See `wordstar-center-line' for more info."
299 (interactive)
300 (save-excursion
301 (forward-paragraph)
302 (or (bolp) (newline 1))
303 (let ((end (point)))
304 (backward-paragraph)
305 (wordstar-center-region (point) end))))
307 (defun wordstar-center-region (from to)
308 "Center each line starting in the region.
309 See `wordstar-center-line' for more info."
310 (interactive "r")
311 (if (> from to)
312 (let ((tem to))
313 (setq to from from tem)))
314 (save-excursion
315 (save-restriction
316 (narrow-to-region from to)
317 (goto-char from)
318 (while (not (eobp))
319 (wordstar-center-line)
320 (forward-line 1)))))
322 (defun wordstar-center-line ()
323 "Center the line point is on, within the width specified by `fill-column'.
324 This means adjusting the indentation to match
325 the distance between the end of the text and `fill-column'."
326 (interactive)
327 (save-excursion
328 (let (line-length)
329 (beginning-of-line)
330 (delete-horizontal-space)
331 (end-of-line)
332 (delete-horizontal-space)
333 (setq line-length (current-column))
334 (beginning-of-line)
335 (indent-to
336 (+ left-margin
337 (/ (- fill-column left-margin line-length) 2))))))
339 ;;;;;;;;;;;
340 ;; wordstar special variables:
342 (defvar ws-marker-0 nil "Position marker 0 in WordStar mode.")
343 (defvar ws-marker-1 nil "Position marker 1 in WordStar mode.")
344 (defvar ws-marker-2 nil "Position marker 2 in WordStar mode.")
345 (defvar ws-marker-3 nil "Position marker 3 in WordStar mode.")
346 (defvar ws-marker-4 nil "Position marker 4 in WordStar mode.")
347 (defvar ws-marker-5 nil "Position marker 5 in WordStar mode.")
348 (defvar ws-marker-6 nil "Position marker 6 in WordStar mode.")
349 (defvar ws-marker-7 nil "Position marker 7 in WordStar mode.")
350 (defvar ws-marker-8 nil "Position marker 8 in WordStar mode.")
351 (defvar ws-marker-9 nil "Position marker 9 in WordStar mode.")
353 (defvar ws-block-begin-marker nil "Beginning of \"Block\" in WordStar mode.")
354 (defvar ws-block-end-marker nil "End of \"Block\" in WordStar mode.")
356 (defvar ws-search-string nil "String of last search in WordStar mode.")
357 (defvar ws-search-direction t
358 "Direction of last search in WordStar mode. t if forward, nil if backward.")
360 (defvar ws-last-cursorposition nil
361 "Position before last search etc. in WordStar mode.")
363 (defvar ws-last-errormessage nil
364 "Last error message issued by a WordStar mode function.")
366 ;;;;;;;;;;;
367 ;; wordstar special functions:
369 (defun ws-error (string)
370 "Report error of a WordStar special function. Error message is saved
371 in ws-last-errormessage for recovery with C-q w."
372 (setq ws-last-errormessage string)
373 (error string))
375 (defun ws-set-marker-0 ()
376 "In WordStar mode: Set marker 0 to current cursor position."
377 (interactive)
378 (setq ws-marker-0 (point-marker))
379 (message "Marker 0 set"))
381 (defun ws-set-marker-1 ()
382 "In WordStar mode: Set marker 1 to current cursor position."
383 (interactive)
384 (setq ws-marker-1 (point-marker))
385 (message "Marker 1 set"))
387 (defun ws-set-marker-2 ()
388 "In WordStar mode: Set marker 2 to current cursor position."
389 (interactive)
390 (setq ws-marker-2 (point-marker))
391 (message "Marker 2 set"))
393 (defun ws-set-marker-3 ()
394 "In WordStar mode: Set marker 3 to current cursor position."
395 (interactive)
396 (setq ws-marker-3 (point-marker))
397 (message "Marker 3 set"))
399 (defun ws-set-marker-4 ()
400 "In WordStar mode: Set marker 4 to current cursor position."
401 (interactive)
402 (setq ws-marker-4 (point-marker))
403 (message "Marker 4 set"))
405 (defun ws-set-marker-5 ()
406 "In WordStar mode: Set marker 5 to current cursor position."
407 (interactive)
408 (setq ws-marker-5 (point-marker))
409 (message "Marker 5 set"))
411 (defun ws-set-marker-6 ()
412 "In WordStar mode: Set marker 6 to current cursor position."
413 (interactive)
414 (setq ws-marker-6 (point-marker))
415 (message "Marker 6 set"))
417 (defun ws-set-marker-7 ()
418 "In WordStar mode: Set marker 7 to current cursor position."
419 (interactive)
420 (setq ws-marker-7 (point-marker))
421 (message "Marker 7 set"))
423 (defun ws-set-marker-8 ()
424 "In WordStar mode: Set marker 8 to current cursor position."
425 (interactive)
426 (setq ws-marker-8 (point-marker))
427 (message "Marker 8 set"))
429 (defun ws-set-marker-9 ()
430 "In WordStar mode: Set marker 9 to current cursor position."
431 (interactive)
432 (setq ws-marker-9 (point-marker))
433 (message "Marker 9 set"))
435 (defun ws-begin-block ()
436 "In WordStar mode: Set block begin marker to current cursor position."
437 (interactive)
438 (setq ws-block-begin-marker (point-marker))
439 (message "Block begin marker set"))
441 (defun ws-show-markers ()
442 "In WordStar mode: Show block markers."
443 (interactive)
444 (if (or ws-block-begin-marker ws-block-end-marker)
445 (save-excursion
446 (if ws-block-begin-marker
447 (progn
448 (goto-char ws-block-begin-marker)
449 (message "Block begin marker")
450 (sit-for 2))
451 (message "Block begin marker not set")
452 (sit-for 2))
453 (if ws-block-end-marker
454 (progn
455 (goto-char ws-block-end-marker)
456 (message "Block end marker")
457 (sit-for 2))
458 (message "Block end marker not set"))
459 (message ""))
460 (message "Block markers not set")))
463 (defun ws-indent-block ()
464 "In WordStar mode: Indent block (not yet implemented)."
465 (interactive)
466 (ws-error "Indent block not yet implemented"))
468 (defun ws-end-block ()
469 "In WordStar mode: Set block end marker to current cursor position."
470 (interactive)
471 (setq ws-block-end-marker (point-marker))
472 (message "Block end marker set"))
474 (defun ws-print-block ()
475 "In WordStar mode: Print block."
476 (interactive)
477 (message "Don't do this. Write block to a file (C-k w) and print this file."))
479 (defun ws-mark-word ()
480 "In WordStar mode: Mark current word as block."
481 (interactive)
482 (save-excursion
483 (forward-word 1)
484 (sit-for 1)
485 (ws-end-block)
486 (forward-word -1)
487 (sit-for 1)
488 (ws-begin-block)))
490 (defun ws-exdent-block ()
491 "I don't know what this (C-k u) should do."
492 (interactive)
493 (ws-error "This won't be done -- not yet implemented."))
495 (defun ws-move-block ()
496 "In WordStar mode: Move block to current cursor position."
497 (interactive)
498 (if (and ws-block-begin-marker ws-block-end-marker)
499 (progn
500 (kill-region ws-block-begin-marker ws-block-end-marker)
501 (yank)
502 (save-excursion
503 (goto-char (region-beginning))
504 (setq ws-block-begin-marker (point-marker))
505 (goto-char (region-end))
506 (setq ws-block-end-marker (point-marker))))
507 (ws-error (cond (ws-block-begin-marker "Block end marker not set")
508 (ws-block-end-marker "Block begin marker not set")
509 (t "Block markers not set")))))
511 (defun ws-write-block ()
512 "In WordStar mode: Write block to file."
513 (interactive)
514 (if (and ws-block-begin-marker ws-block-end-marker)
515 (let ((filename (read-file-name "Write block to file: ")))
516 (write-region ws-block-begin-marker ws-block-end-marker filename))
517 (ws-error (cond (ws-block-begin-marker "Block end marker not set")
518 (ws-block-end-marker "Block begin marker not set")
519 (t "Block markers not set")))))
522 (defun ws-delete-block ()
523 "In WordStar mode: Delete block."
524 (interactive)
525 (if (and ws-block-begin-marker ws-block-end-marker)
526 (progn
527 (kill-region ws-block-begin-marker ws-block-end-marker)
528 (setq ws-block-end-marker nil)
529 (setq ws-block-begin-marker nil))
530 (ws-error (cond (ws-block-begin-marker "Block end marker not set")
531 (ws-block-end-marker "Block begin marker not set")
532 (t "Block markers not set")))))
534 (defun ws-find-marker-0 ()
535 "In WordStar mode: Go to marker 0."
536 (interactive)
537 (if ws-marker-0
538 (progn
539 (setq ws-last-cursorposition (point-marker))
540 (goto-char ws-marker-0))
541 (ws-error "Marker 0 not set")))
543 (defun ws-find-marker-1 ()
544 "In WordStar mode: Go to marker 1."
545 (interactive)
546 (if ws-marker-1
547 (progn
548 (setq ws-last-cursorposition (point-marker))
549 (goto-char ws-marker-1))
550 (ws-error "Marker 1 not set")))
552 (defun ws-find-marker-2 ()
553 "In WordStar mode: Go to marker 2."
554 (interactive)
555 (if ws-marker-2
556 (progn
557 (setq ws-last-cursorposition (point-marker))
558 (goto-char ws-marker-2))
559 (ws-error "Marker 2 not set")))
561 (defun ws-find-marker-3 ()
562 "In WordStar mode: Go to marker 3."
563 (interactive)
564 (if ws-marker-3
565 (progn
566 (setq ws-last-cursorposition (point-marker))
567 (goto-char ws-marker-3))
568 (ws-error "Marker 3 not set")))
570 (defun ws-find-marker-4 ()
571 "In WordStar mode: Go to marker 4."
572 (interactive)
573 (if ws-marker-4
574 (progn
575 (setq ws-last-cursorposition (point-marker))
576 (goto-char ws-marker-4))
577 (ws-error "Marker 4 not set")))
579 (defun ws-find-marker-5 ()
580 "In WordStar mode: Go to marker 5."
581 (interactive)
582 (if ws-marker-5
583 (progn
584 (setq ws-last-cursorposition (point-marker))
585 (goto-char ws-marker-5))
586 (ws-error "Marker 5 not set")))
588 (defun ws-find-marker-6 ()
589 "In WordStar mode: Go to marker 6."
590 (interactive)
591 (if ws-marker-6
592 (progn
593 (setq ws-last-cursorposition (point-marker))
594 (goto-char ws-marker-6))
595 (ws-error "Marker 6 not set")))
597 (defun ws-find-marker-7 ()
598 "In WordStar mode: Go to marker 7."
599 (interactive)
600 (if ws-marker-7
601 (progn
602 (setq ws-last-cursorposition (point-marker))
603 (goto-char ws-marker-7))
604 (ws-error "Marker 7 not set")))
606 (defun ws-find-marker-8 ()
607 "In WordStar mode: Go to marker 8."
608 (interactive)
609 (if ws-marker-8
610 (progn
611 (setq ws-last-cursorposition (point-marker))
612 (goto-char ws-marker-8))
613 (ws-error "Marker 8 not set")))
615 (defun ws-find-marker-9 ()
616 "In WordStar mode: Go to marker 9."
617 (interactive)
618 (if ws-marker-9
619 (progn
620 (setq ws-last-cursorposition (point-marker))
621 (goto-char ws-marker-9))
622 (ws-error "Marker 9 not set")))
624 (defun ws-goto-block-begin ()
625 "In WordStar mode: Go to block begin marker."
626 (interactive)
627 (if ws-block-begin-marker
628 (progn
629 (setq ws-last-cursorposition (point-marker))
630 (goto-char ws-block-begin-marker))
631 (ws-error "Block begin marker not set")))
633 (defun ws-search (string)
634 "In WordStar mode: Search string, remember string for repetition."
635 (interactive "sSearch for: ")
636 (message "Forward (f) or backward (b)")
637 (let ((direction
638 (read-char)))
639 (cond ((equal (upcase direction) ?F)
640 (setq ws-search-string string)
641 (setq ws-search-direction t)
642 (setq ws-last-cursorposition (point-marker))
643 (search-forward string))
644 ((equal (upcase direction) ?B)
645 (setq ws-search-string string)
646 (setq ws-search-direction nil)
647 (setq ws-last-cursorposition (point-marker))
648 (search-backward string))
649 (t (keyboard-quit)))))
651 (defun ws-goto-block-end ()
652 "In WordStar mode: Go to block end marker."
653 (interactive)
654 (if ws-block-end-marker
655 (progn
656 (setq ws-last-cursorposition (point-marker))
657 (goto-char ws-block-end-marker))
658 (ws-error "Block end marker not set")))
660 (defun ws-undo ()
661 "In WordStar mode: Undo and give message about undoing more changes."
662 (interactive)
663 (undo)
664 (message "Repeat C-q l to undo more changes."))
666 (defun ws-goto-last-cursorposition ()
667 "In WordStar mode: "
668 (interactive)
669 (if ws-last-cursorposition
670 (progn
671 (setq ws-last-cursorposition (point-marker))
672 (goto-char ws-last-cursorposition))
673 (ws-error "No last cursor position available.")))
675 (defun ws-last-error ()
676 "In WordStar mode: repeat last error message.
677 This will only work for errors raised by WordStar mode functions."
678 (interactive)
679 (if ws-last-errormessage
680 (message "%s" ws-last-errormessage)
681 (message "No WordStar error yet.")))
683 (defun ws-kill-eol ()
684 "In WordStar mode: Kill to end of line (like WordStar, not like Emacs)."
685 (interactive)
686 (let ((p (point)))
687 (end-of-line)
688 (kill-region p (point))))
690 (defun ws-kill-bol ()
691 "In WordStar mode: Kill to beginning of line
692 \(like WordStar, not like Emacs)."
693 (interactive)
694 (let ((p (point)))
695 (beginning-of-line)
696 (kill-region (point) p)))
698 (defun kill-complete-line ()
699 "Kill the complete line."
700 (interactive)
701 (beginning-of-line)
702 (if (eobp) (error "End of buffer"))
703 (let ((beg (point)))
704 (forward-line 1)
705 (kill-region beg (point))))
707 (defun ws-repeat-search ()
708 "In WordStar mode: Repeat last search."
709 (interactive)
710 (setq ws-last-cursorposition (point-marker))
711 (if ws-search-string
712 (if ws-search-direction
713 (search-forward ws-search-string)
714 (search-backward ws-search-string))
715 (ws-error "No search to repeat")))
717 (defun ws-query-replace (from to)
718 "In WordStar mode: Search string, remember string for repetition."
719 (interactive "sReplace: \n\
720 sWith: " )
721 (setq ws-search-string from)
722 (setq ws-search-direction t)
723 (setq ws-last-cursorposition (point-marker))
724 (query-replace from to))
726 (defun ws-copy-block ()
727 "In WordStar mode: Copy block to current cursor position."
728 (interactive)
729 (if (and ws-block-begin-marker ws-block-end-marker)
730 (progn
731 (copy-region-as-kill ws-block-begin-marker ws-block-end-marker)
732 (yank)
733 (save-excursion
734 (goto-char (region-beginning))
735 (setq ws-block-begin-marker (point-marker))
736 (goto-char (region-end))
737 (setq ws-block-end-marker (point-marker))))
738 (ws-error (cond (ws-block-begin-marker "Block end marker not set")
739 (ws-block-end-marker "Block begin marker not set")
740 (t "Block markers not set")))))
742 (provide 'ws-mode)
744 ;;; ws-mode.el ends here