view lisp/emulation/ws-mode.el @ 81166:4c7d6994e8d6

(org-export-region-as-html, org-replace-region-by-html) (org-number-to-letters, org-table-fedit-finish) (org-normalize-color, org-table-fedit-ref-right) (org-date-to-gregorian, org-table-fedit-move) (org-table-convert-refs-to-rc, org-calendar-holiday) (org-table-fedit-toggle-ref-type, org-write-agenda) (org-colgroup-info-to-vline-list, org-agenda-todo-previousset) (org-defkey, org-encode-for-stdout) (org-indent-line-function, org-export-as-html-to-buffer) (org-store-agenda-views, org-update-mode-line) (org-find-if, org-delete-all) (org-table-fedit-convert-buffer, org-emphasize) (org-uniquify, org-table-fedit-lisp-indent) (org-table-fedit-scroll, org-get-todo-sequence-head) (org-table-fedit-scroll-down, org-table-fedit-line-down) (org-table-fedit-ref-left, org-agenda-export-csv-mapper) (org-table-fedit-toggle-coordinates, org-dvipng-color) (org-table-fedit-line-up, org-table-fedit-ref-down) (org-table-formula-from-user, org-mode-flyspell-verify) (org-cycle-show-empty-lines, org-ctrl-c-ret) (org-table-formula-to-user, org-diary-to-ical-string) (orgtbl-export, org-table-fedit-post-command) (org-closed-in-range, org-shiftcontrolright) (org-table-convert-refs-to-an, org-table-hline-and-move) (org-table-formula-less-p, org-format-table-ascii) (org-agenda-get-sexps, org-shift-refpart) (org-diary-sexp-entry, org-time-string-to-absolute) (org-table-show-reference, org-letters-to-number) (org-fix-agenda-info, org-table-fedit-ref-up) (org-table-fedit-shift-reference, org-table-fedit-abort) (org-closest-date, org-shiftcontrolleft) (org-at-heading-or-item-p, org-rematch-and-replace) (org-agenda-todo-nextset, org-export-grab-title-from-buffer): New function. (org-table-edit-scroll-down, org-finish-edit-formulas) (org-table-edit-next-field, org-abort-edit-formulas) (org-font-lock-level, org-export-find-first-heading-line) (org-table-edit-line-down, org-table-edit-backward-field) (org-edit-formula-lisp-indent, org-table-edit-move) (org-check-log-option, org-this-word) (org-table-edit-line-up, org-table-edit-formulas-post-command) (org-agenda-file-to-end, org-expand-file-name) (org-fake-empty-table-line, org-table-edit-scroll) (org-toggle-log-option, org-show-reference): Function removed. (org-inhibit-invisibility, org-table-formula-make-cmp-string): New defsubst. (org-unmodified, org-batch-store-agenda-views) (org-batch-agenda-csv): New macro. (org-agenda-export): New customization group. (org-agenda-skip-deadline-if-done, org-agenda-remove-tags) (org-highest-priority, org-agenda-exporter-settings) (org-log-done-with-time, org-replace-disputed-keys) (org-format-latex-header, org-export-table-header-tags) (org-cycle-separator-lines, org-export-table-data-tags) (org-icalendar-include-sexps) (org-empty-line-terminates-plain-lists) (org-log-repeat, org-special-ctrl-a) (org-table-use-standard-references, org-disputed-keys) (org-export-skip-text-before-1st-heading, org-agenda-with-colors) (org-agenda-export-html-style): New option. (org-allow-auto-repeat, org-agenda-remove-tags-when-in-prefix) (org-CUA-compatible): Option removed. (org-agenda-structure, org-sexp-date): New face. (org-todo-keywords-for-agenda, org-not-done-keywords) (org-planning-or-clock-line-re, org-agenda-name) (org-table-colgroup-info, org-todo-sets) (constants-unit-system, org-clock-mode-line-entry) (org-mode-line-timer, org-table-current-begin-pos) (org-todo-keywords-1, org-mode-line-string) (org-table-clean-did-remove-column, org-table-fedit-map) (org-clock-heading, org-table-buffer-is-an) (org-agenda-info, org-done-keywords) (org-done-keywords-for-agenda, org-todo-heads) (org-todo-kwd-alist, org-clock-start-time): New variable. (org-todo-kwd-priority-p, org-edit-formulas-map) (org-repeat-re, org-todo-kwd-max-priority) (org-version, org-done-string) (org-table-clean-did-remove-column-1, org-disputed-keys): Variable removed. (org-table-translate-regexp, org-repeat-re, org-version): New constant. (org-ts-lengths): Constant removed. (org-follow-gnus-link): Don't ask how many articles to read. (org-export-find-first-export-line): Renamed from `org-export-find-first-heading'. Use `org-export-skip-text-before-1st-heading'. (org-table-fedit-post-command): Renamed from `org-table-edit-formulas-post-command'. (org-table-fedit-finish): Renamed from `org-finish-edit-formulas'. (org-table-fedit-abort): Renamed from `org-abort-edit-formulas'. (org-table-fedit-lisp-indent): Renamed from `org-edit-formula-lisp-indent'. (org-table-show-reference): Renamed from `org-show-reference'. (org-table-store-formulas): Use `org-table-formula-less-p'. (org-table-edit-formulas): Position cursor to current field equation. (org-update-checkbox-count, org-hide-archived-subtrees) (org-timestamp-up-day, org-timestamp-down-day) (org-shiftmetaleft, org-shiftmetaright, org-shiftmetaup) (org-shiftmetadown, org-metaleft, org-metaright, org-metaup) (org-metadown, org-shiftup, org-shiftdown, org-shiftright) (org-shiftleft, org-ctrl-c-ctrl-c, org-context): Let `org-on-heading-p' also check for invisible heading. (org-read-date): Match am/pm times. (org-eval-in-calendar): Fix default date in prompt.
author Carsten Dominik <dominik@science.uva.nl>
date Wed, 06 Jun 2007 15:13:27 +0000
parents 7a3f13e2dd57
children ac0efac52065 95d0cdf160ea
line wrap: on
line source

;;; ws-mode.el --- WordStar emulation mode for GNU Emacs

;; Copyright (C) 1991, 2001, 2002, 2003, 2004, 2005,
;;   2006, 2007 Free Software Foundation, Inc.

;; Author: Juergen Nickelsen <nickel@cs.tu-berlin.de>
;; Version: 0.7
;; Keywords: emulations

;; This file is part of GNU Emacs.

;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.

;;; Commentary:

;; This emulates WordStar, with a major mode.

;;; Code:

(defvar wordstar-mode-map nil "")
(defvar wordstar-C-j-map nil "")
(defvar wordstar-C-k-map nil "")
(defvar wordstar-C-o-map nil "")
(defvar wordstar-C-q-map nil "")

(if wordstar-mode-map
    ()
  (setq wordstar-mode-map (make-keymap))
  ;;  (setq wordstar-C-j-map (make-keymap)) ; later, perhaps
  (setq wordstar-C-k-map (make-keymap))
  (setq wordstar-C-o-map (make-keymap))
  (setq wordstar-C-q-map (make-keymap))

  (define-key wordstar-mode-map "\C-a" 'backward-word)
  (define-key wordstar-mode-map "\C-b" 'fill-paragraph)
  (define-key wordstar-mode-map "\C-c" 'scroll-up)
  (define-key wordstar-mode-map "\C-d" 'forward-char)
  (define-key wordstar-mode-map "\C-e" 'previous-line)
  (define-key wordstar-mode-map "\C-f" 'forward-word)
  (define-key wordstar-mode-map "\C-g" 'delete-char)
  (define-key wordstar-mode-map "\C-h" 'backward-char)
  (define-key wordstar-mode-map "\C-i" 'indent-for-tab-command)
  (define-key wordstar-mode-map "\C-j" 'help-for-help)
  (define-key wordstar-mode-map "\C-k" wordstar-C-k-map)
  (define-key wordstar-mode-map "\C-l" 'ws-repeat-search)
  (define-key wordstar-mode-map "\C-n" 'open-line)
  (define-key wordstar-mode-map "\C-o" wordstar-C-o-map)
  (define-key wordstar-mode-map "\C-p" 'quoted-insert)
  (define-key wordstar-mode-map "\C-q" wordstar-C-q-map)
  (define-key wordstar-mode-map "\C-r" 'scroll-down)
  (define-key wordstar-mode-map "\C-s" 'backward-char)
  (define-key wordstar-mode-map "\C-t" 'kill-word)
  (define-key wordstar-mode-map "\C-u" 'keyboard-quit)
  (define-key wordstar-mode-map "\C-v" 'overwrite-mode)
  (define-key wordstar-mode-map "\C-w" 'scroll-down-line)
  (define-key wordstar-mode-map "\C-x" 'next-line)
  (define-key wordstar-mode-map "\C-y" 'kill-complete-line)
  (define-key wordstar-mode-map "\C-z" 'scroll-up-line)

  ;; wordstar-C-k-map

  (define-key wordstar-C-k-map " " ())
  (define-key wordstar-C-k-map "0" 'ws-set-marker-0)
  (define-key wordstar-C-k-map "1" 'ws-set-marker-1)
  (define-key wordstar-C-k-map "2" 'ws-set-marker-2)
  (define-key wordstar-C-k-map "3" 'ws-set-marker-3)
  (define-key wordstar-C-k-map "4" 'ws-set-marker-4)
  (define-key wordstar-C-k-map "5" 'ws-set-marker-5)
  (define-key wordstar-C-k-map "6" 'ws-set-marker-6)
  (define-key wordstar-C-k-map "7" 'ws-set-marker-7)
  (define-key wordstar-C-k-map "8" 'ws-set-marker-8)
  (define-key wordstar-C-k-map "9" 'ws-set-marker-9)
  (define-key wordstar-C-k-map "b" 'ws-begin-block)
  (define-key wordstar-C-k-map "\C-b" 'ws-begin-block)
  (define-key wordstar-C-k-map "c" 'ws-copy-block)
  (define-key wordstar-C-k-map "\C-c" 'ws-copy-block)
  (define-key wordstar-C-k-map "d" 'save-buffers-kill-emacs)
  (define-key wordstar-C-k-map "\C-d" 'save-buffers-kill-emacs)
  (define-key wordstar-C-k-map "f" 'find-file)
  (define-key wordstar-C-k-map "\C-f" 'find-file)
  (define-key wordstar-C-k-map "h" 'ws-show-markers)
  (define-key wordstar-C-k-map "\C-h" 'ws-show-markers)
  (define-key wordstar-C-k-map "i" 'ws-indent-block)
  (define-key wordstar-C-k-map "\C-i" 'ws-indent-block)
  (define-key wordstar-C-k-map "k" 'ws-end-block)
  (define-key wordstar-C-k-map "\C-k" 'ws-end-block)
  (define-key wordstar-C-k-map "p" 'ws-print-block)
  (define-key wordstar-C-k-map "\C-p" 'ws-print-block)
  (define-key wordstar-C-k-map "q" 'kill-emacs)
  (define-key wordstar-C-k-map "\C-q" 'kill-emacs)
  (define-key wordstar-C-k-map "r" 'insert-file)
  (define-key wordstar-C-k-map "\C-r" 'insert-file)
  (define-key wordstar-C-k-map "s" 'save-some-buffers)
  (define-key wordstar-C-k-map "\C-s" 'save-some-buffers)
  (define-key wordstar-C-k-map "t" 'ws-mark-word)
  (define-key wordstar-C-k-map "\C-t" 'ws-mark-word)
  (define-key wordstar-C-k-map "u" 'ws-exdent-block)
  (define-key wordstar-C-k-map "\C-u" 'keyboard-quit)
  (define-key wordstar-C-k-map "v" 'ws-move-block)
  (define-key wordstar-C-k-map "\C-v" 'ws-move-block)
  (define-key wordstar-C-k-map "w" 'ws-write-block)
  (define-key wordstar-C-k-map "\C-w" 'ws-write-block)
  (define-key wordstar-C-k-map "x" 'save-buffers-kill-emacs)
  (define-key wordstar-C-k-map "\C-x" 'save-buffers-kill-emacs)
  (define-key wordstar-C-k-map "y" 'ws-delete-block)
  (define-key wordstar-C-k-map "\C-y" 'ws-delete-block)

  ;; wordstar-C-j-map not yet implemented

  ;; wordstar-C-o-map

  (define-key wordstar-C-o-map " " ())
  (define-key wordstar-C-o-map "c" 'wordstar-center-line)
  (define-key wordstar-C-o-map "\C-c" 'wordstar-center-line)
  (define-key wordstar-C-o-map "b" 'switch-to-buffer)
  (define-key wordstar-C-o-map "\C-b" 'switch-to-buffer)
  (define-key wordstar-C-o-map "j" 'justify-current-line)
  (define-key wordstar-C-o-map "\C-j" 'justify-current-line)
  (define-key wordstar-C-o-map "k" 'kill-buffer)
  (define-key wordstar-C-o-map "\C-k" 'kill-buffer)
  (define-key wordstar-C-o-map "l" 'list-buffers)
  (define-key wordstar-C-o-map "\C-l" 'list-buffers)
  (define-key wordstar-C-o-map "m" 'auto-fill-mode)
  (define-key wordstar-C-o-map "\C-m" 'auto-fill-mode)
  (define-key wordstar-C-o-map "r" 'set-fill-column)
  (define-key wordstar-C-o-map "\C-r" 'set-fill-column)
  (define-key wordstar-C-o-map "\C-u" 'keyboard-quit)
  (define-key wordstar-C-o-map "wd" 'delete-other-windows)
  (define-key wordstar-C-o-map "wh" 'split-window-horizontally)
  (define-key wordstar-C-o-map "wo" 'other-window)
  (define-key wordstar-C-o-map "wv" 'split-window-vertically)

  ;; wordstar-C-q-map
  (define-key wordstar-C-q-map " " ())
  (define-key wordstar-C-q-map "0" 'ws-find-marker-0)
  (define-key wordstar-C-q-map "1" 'ws-find-marker-1)
  (define-key wordstar-C-q-map "2" 'ws-find-marker-2)
  (define-key wordstar-C-q-map "3" 'ws-find-marker-3)
  (define-key wordstar-C-q-map "4" 'ws-find-marker-4)
  (define-key wordstar-C-q-map "5" 'ws-find-marker-5)
  (define-key wordstar-C-q-map "6" 'ws-find-marker-6)
  (define-key wordstar-C-q-map "7" 'ws-find-marker-7)
  (define-key wordstar-C-q-map "8" 'ws-find-marker-8)
  (define-key wordstar-C-q-map "9" 'ws-find-marker-9)
  (define-key wordstar-C-q-map "a" 'ws-query-replace)
  (define-key wordstar-C-q-map "\C-a" 'ws-query-replace)
  (define-key wordstar-C-q-map "b" 'ws-goto-block-begin)
  (define-key wordstar-C-q-map "\C-b" 'ws-goto-block-begin)
  (define-key wordstar-C-q-map "c" 'end-of-buffer)
  (define-key wordstar-C-q-map "\C-c" 'end-of-buffer)
  (define-key wordstar-C-q-map "d" 'end-of-line)
  (define-key wordstar-C-q-map "\C-d" 'end-of-line)
  (define-key wordstar-C-q-map "f" 'ws-search)
  (define-key wordstar-C-q-map "\C-f" 'ws-search)
  (define-key wordstar-C-q-map "k" 'ws-goto-block-end)
  (define-key wordstar-C-q-map "\C-k" 'ws-goto-block-end)
  (define-key wordstar-C-q-map "l" 'ws-undo)
  (define-key wordstar-C-q-map "\C-l" 'ws-undo)
  (define-key wordstar-C-q-map "p" 'ws-last-cursorp)
  (define-key wordstar-C-q-map "\C-p" 'ws-last-cursorp)
  (define-key wordstar-C-q-map "r" 'beginning-of-buffer)
  (define-key wordstar-C-q-map "\C-r" 'beginning-of-buffer)
  (define-key wordstar-C-q-map "s" 'beginning-of-line)
  (define-key wordstar-C-q-map "\C-s" 'beginning-of-line)
  (define-key wordstar-C-q-map "\C-u" 'keyboard-quit)
  (define-key wordstar-C-q-map "w" 'ws-last-error)
  (define-key wordstar-C-q-map "\C-w" 'ws-last-error)
  (define-key wordstar-C-q-map "y" 'ws-kill-eol)
  (define-key wordstar-C-q-map "\C-y" 'ws-kill-eol)
  (define-key wordstar-C-q-map "\177" 'ws-kill-bol))

(put 'wordstar-mode 'mode-class 'special)

;;;###autoload
(defun wordstar-mode ()
  "Major mode with WordStar-like key bindings.

BUGS:
 - Help menus with WordStar commands (C-j just calls help-for-help)
   are not implemented
 - Options for search and replace
 - Show markers (C-k h) is somewhat strange
 - Search and replace (C-q a) is only available in forward direction

No key bindings beginning with ESC are installed, they will work
Emacs-like.

The key bindings are:

  C-a		backward-word
  C-b		fill-paragraph
  C-c		scroll-up-line
  C-d		forward-char
  C-e		previous-line
  C-f		forward-word
  C-g		delete-char
  C-h		backward-char
  C-i		indent-for-tab-command
  C-j		help-for-help
  C-k		ordstar-C-k-map
  C-l		ws-repeat-search
  C-n		open-line
  C-p		quoted-insert
  C-r		scroll-down-line
  C-s		backward-char
  C-t		kill-word
  C-u		keyboard-quit
  C-v		overwrite-mode
  C-w		scroll-down
  C-x		next-line
  C-y		kill-complete-line
  C-z		scroll-up

  C-k 0		ws-set-marker-0
  C-k 1		ws-set-marker-1
  C-k 2		ws-set-marker-2
  C-k 3		ws-set-marker-3
  C-k 4		ws-set-marker-4
  C-k 5		ws-set-marker-5
  C-k 6		ws-set-marker-6
  C-k 7		ws-set-marker-7
  C-k 8		ws-set-marker-8
  C-k 9		ws-set-marker-9
  C-k b		ws-begin-block
  C-k c		ws-copy-block
  C-k d		save-buffers-kill-emacs
  C-k f		find-file
  C-k h		ws-show-markers
  C-k i		ws-indent-block
  C-k k		ws-end-block
  C-k p		ws-print-block
  C-k q		kill-emacs
  C-k r		insert-file
  C-k s		save-some-buffers
  C-k t		ws-mark-word
  C-k u		ws-exdent-block
  C-k C-u	keyboard-quit
  C-k v		ws-move-block
  C-k w		ws-write-block
  C-k x		kill-emacs
  C-k y		ws-delete-block

  C-o c		wordstar-center-line
  C-o b		switch-to-buffer
  C-o j		justify-current-line
  C-o k		kill-buffer
  C-o l		list-buffers
  C-o m		auto-fill-mode
  C-o r		set-fill-column
  C-o C-u	keyboard-quit
  C-o wd	delete-other-windows
  C-o wh	split-window-horizontally
  C-o wo	other-window
  C-o wv	split-window-vertically

  C-q 0		ws-find-marker-0
  C-q 1		ws-find-marker-1
  C-q 2		ws-find-marker-2
  C-q 3		ws-find-marker-3
  C-q 4		ws-find-marker-4
  C-q 5		ws-find-marker-5
  C-q 6		ws-find-marker-6
  C-q 7		ws-find-marker-7
  C-q 8		ws-find-marker-8
  C-q 9		ws-find-marker-9
  C-q a		ws-query-replace
  C-q b		ws-to-block-begin
  C-q c		end-of-buffer
  C-q d		end-of-line
  C-q f		ws-search
  C-q k		ws-to-block-end
  C-q l		ws-undo
  C-q p		ws-last-cursorp
  C-q r		beginning-of-buffer
  C-q C-u	keyboard-quit
  C-q w		ws-last-error
  C-q y		ws-kill-eol
  C-q DEL	ws-kill-bol
"
  (interactive)
  (kill-all-local-variables)
  (use-local-map wordstar-mode-map)
  (setq mode-name "WordStar")
  (setq major-mode 'wordstar-mode)
  (run-mode-hooks 'wordstar-mode-hook))


(defun wordstar-center-paragraph ()
  "Center each line in the paragraph at or after point.
See `wordstar-center-line' for more info."
  (interactive)
  (save-excursion
    (forward-paragraph)
    (or (bolp) (newline 1))
    (let ((end (point)))
      (backward-paragraph)
      (wordstar-center-region (point) end))))

(defun wordstar-center-region (from to)
  "Center each line starting in the region.
See `wordstar-center-line' for more info."
  (interactive "r")
  (if (> from to)
      (let ((tem to))
	(setq to from from tem)))
  (save-excursion
    (save-restriction
      (narrow-to-region from to)
      (goto-char from)
      (while (not (eobp))
	(wordstar-center-line)
	(forward-line 1)))))

(defun wordstar-center-line ()
  "Center the line point is on, within the width specified by `fill-column'.
This means adjusting the indentation to match
the distance between the end of the text and `fill-column'."
  (interactive)
  (save-excursion
    (let (line-length)
      (beginning-of-line)
      (delete-horizontal-space)
      (end-of-line)
      (delete-horizontal-space)
      (setq line-length (current-column))
      (beginning-of-line)
      (indent-to
       (+ left-margin
	  (/ (- fill-column left-margin line-length) 2))))))

(defun scroll-down-line ()
  "Scroll one line down."
  (interactive)
  (scroll-down 1))

(defun scroll-up-line ()
  "Scroll one line up."
  (interactive)
  (scroll-up 1))

;;;;;;;;;;;
;; wordstar special variables:

(defvar ws-marker-0 nil "Position marker 0 in WordStar mode.")
(defvar ws-marker-1 nil "Position marker 1 in WordStar mode.")
(defvar ws-marker-2 nil "Position marker 2 in WordStar mode.")
(defvar ws-marker-3 nil "Position marker 3 in WordStar mode.")
(defvar ws-marker-4 nil "Position marker 4 in WordStar mode.")
(defvar ws-marker-5 nil "Position marker 5 in WordStar mode.")
(defvar ws-marker-6 nil "Position marker 6 in WordStar mode.")
(defvar ws-marker-7 nil "Position marker 7 in WordStar mode.")
(defvar ws-marker-8 nil "Position marker 8 in WordStar mode.")
(defvar ws-marker-9 nil "Position marker 9 in WordStar mode.")

(defvar ws-block-begin-marker nil "Beginning of \"Block\" in WordStar mode.")
(defvar ws-block-end-marker nil "End of \"Block\" in WordStar mode.")

(defvar ws-search-string nil "String of last search in WordStar mode.")
(defvar ws-search-direction t
  "Direction of last search in WordStar mode. t if forward, nil if backward.")

(defvar ws-last-cursorposition nil
  "Position before last search etc. in WordStar mode.")

(defvar ws-last-errormessage nil
  "Last error message issued by a WordStar mode function.")

;;;;;;;;;;;
;; wordstar special functions:

(defun ws-error (string)
  "Report error of a WordStar special function. Error message is saved
in ws-last-errormessage for recovery with C-q w."
  (setq ws-last-errormessage string)
  (error string))

(defun ws-set-marker-0 ()
  "In WordStar mode: Set marker 0 to current cursor position."
  (interactive)
  (setq ws-marker-0 (point-marker))
  (message "Marker 0 set"))

(defun ws-set-marker-1 ()
  "In WordStar mode: Set marker 1 to current cursor position."
  (interactive)
  (setq ws-marker-1 (point-marker))
  (message "Marker 1 set"))

(defun ws-set-marker-2 ()
  "In WordStar mode: Set marker 2 to current cursor position."
  (interactive)
  (setq ws-marker-2 (point-marker))
  (message "Marker 2 set"))

(defun ws-set-marker-3 ()
  "In WordStar mode: Set marker 3 to current cursor position."
  (interactive)
  (setq ws-marker-3 (point-marker))
  (message "Marker 3 set"))

(defun ws-set-marker-4 ()
  "In WordStar mode: Set marker 4 to current cursor position."
  (interactive)
  (setq ws-marker-4 (point-marker))
  (message "Marker 4 set"))

(defun ws-set-marker-5 ()
  "In WordStar mode: Set marker 5 to current cursor position."
  (interactive)
  (setq ws-marker-5 (point-marker))
  (message "Marker 5 set"))

(defun ws-set-marker-6 ()
  "In WordStar mode: Set marker 6 to current cursor position."
  (interactive)
  (setq ws-marker-6 (point-marker))
  (message "Marker 6 set"))

(defun ws-set-marker-7 ()
  "In WordStar mode: Set marker 7 to current cursor position."
  (interactive)
  (setq ws-marker-7 (point-marker))
  (message "Marker 7 set"))

(defun ws-set-marker-8 ()
  "In WordStar mode: Set marker 8 to current cursor position."
  (interactive)
  (setq ws-marker-8 (point-marker))
  (message "Marker 8 set"))

(defun ws-set-marker-9 ()
  "In WordStar mode: Set marker 9 to current cursor position."
  (interactive)
  (setq ws-marker-9 (point-marker))
  (message "Marker 9 set"))

(defun ws-begin-block ()
  "In WordStar mode: Set block begin marker to current cursor position."
  (interactive)
  (setq ws-block-begin-marker (point-marker))
  (message "Block begin marker set"))

(defun ws-show-markers ()
  "In WordStar mode: Show block markers."
  (interactive)
  (if (or ws-block-begin-marker ws-block-end-marker)
      (save-excursion
	(if ws-block-begin-marker
	    (let ()
	      (goto-char ws-block-begin-marker)
	      (message "Block begin marker")
	      (sit-for 2))
	  (message "Block begin marker not set")
	  (sit-for 2))
	(if ws-block-end-marker
	    (let ()
	      (goto-char ws-block-end-marker)
	      (message "Block end marker")
	      (sit-for 2))
	  (message "Block end marker not set"))
	(message ""))
    (message "Block markers not set")))


(defun ws-indent-block ()
  "In WordStar mode: Indent block (not yet implemented)."
  (interactive)
  (ws-error "Indent block not yet implemented"))

(defun ws-end-block ()
  "In WordStar mode: Set block end marker to current cursor position."
  (interactive)
  (setq ws-block-end-marker (point-marker))
  (message "Block end marker set"))

(defun ws-print-block ()
  "In WordStar mode: Print block."
  (interactive)
  (message "Don't do this. Write block to a file (C-k w) and print this file."))

(defun ws-mark-word ()
  "In WordStar mode: Mark current word as block."
  (interactive)
  (save-excursion
    (forward-word 1)
    (sit-for 1)
    (ws-end-block)
    (forward-word -1)
    (sit-for 1)
    (ws-begin-block)))

(defun ws-exdent-block ()
  "I don't know what this (C-k u) should do."
  (interactive)
  (ws-error "This won't be done -- not yet implemented."))

(defun ws-move-block ()
  "In WordStar mode: Move block to current cursor position."
  (interactive)
  (if (and ws-block-begin-marker ws-block-end-marker)
      (let ()
	(kill-region ws-block-begin-marker ws-block-end-marker)
	(yank)
	(save-excursion
	  (goto-char (region-beginning))
	  (setq ws-block-begin-marker (point-marker))
	  (goto-char (region-end))
	  (setq ws-block-end-marker (point-marker))))
    (ws-error (cond (ws-block-begin-marker "Block end marker not set")
		    (ws-block-end-marker "Block begin marker not set")
		    (t "Block markers not set")))))

(defun ws-write-block ()
  "In WordStar mode: Write block to file."
  (interactive)
  (if (and ws-block-begin-marker ws-block-end-marker)
      (let ((filename (read-file-name "Write block to file: ")))
	(write-region ws-block-begin-marker ws-block-end-marker filename))
    (ws-error (cond (ws-block-begin-marker "Block end marker not set")
		    (ws-block-end-marker "Block begin marker not set")
		    (t "Block markers not set")))))


(defun ws-delete-block ()
  "In WordStar mode: Delete block."
  (interactive)
  (if (and ws-block-begin-marker ws-block-end-marker)
      (let ()
	(kill-region ws-block-begin-marker ws-block-end-marker)
	(setq ws-block-end-marker nil)
	(setq ws-block-begin-marker nil))
    (ws-error (cond (ws-block-begin-marker "Block end marker not set")
		    (ws-block-end-marker "Block begin marker not set")
		    (t "Block markers not set")))))

(defun ws-find-marker-0 ()
  "In WordStar mode: Go to marker 0."
  (interactive)
  (if ws-marker-0
      (let ()
	(setq ws-last-cursorposition (point-marker))
	(goto-char ws-marker-0))
    (ws-error "Marker 0 not set")))

(defun ws-find-marker-1 ()
  "In WordStar mode: Go to marker 1."
  (interactive)
  (if ws-marker-1
      (let ()
	(setq ws-last-cursorposition (point-marker))
	(goto-char ws-marker-1))
    (ws-error "Marker 1 not set")))

(defun ws-find-marker-2 ()
  "In WordStar mode: Go to marker 2."
  (interactive)
  (if ws-marker-2
      (let ()
	(setq ws-last-cursorposition (point-marker))
	(goto-char ws-marker-2))
    (ws-error "Marker 2 not set")))

(defun ws-find-marker-3 ()
  "In WordStar mode: Go to marker 3."
  (interactive)
  (if ws-marker-3
      (let ()
	(setq ws-last-cursorposition (point-marker))
	(goto-char ws-marker-3))
    (ws-error "Marker 3 not set")))

(defun ws-find-marker-4 ()
  "In WordStar mode: Go to marker 4."
  (interactive)
  (if ws-marker-4
      (let ()
	(setq ws-last-cursorposition (point-marker))
	(goto-char ws-marker-4))
    (ws-error "Marker 4 not set")))

(defun ws-find-marker-5 ()
  "In WordStar mode: Go to marker 5."
  (interactive)
  (if ws-marker-5
      (let ()
	(setq ws-last-cursorposition (point-marker))
	(goto-char ws-marker-5))
    (ws-error "Marker 5 not set")))

(defun ws-find-marker-6 ()
  "In WordStar mode: Go to marker 6."
  (interactive)
  (if ws-marker-6
      (let ()
	(setq ws-last-cursorposition (point-marker))
	(goto-char ws-marker-6))
    (ws-error "Marker 6 not set")))

(defun ws-find-marker-7 ()
  "In WordStar mode: Go to marker 7."
  (interactive)
  (if ws-marker-7
      (let ()
	(setq ws-last-cursorposition (point-marker))
	(goto-char ws-marker-7))
    (ws-error "Marker 7 not set")))

(defun ws-find-marker-8 ()
  "In WordStar mode: Go to marker 8."
  (interactive)
  (if ws-marker-8
      (let ()
	(setq ws-last-cursorposition (point-marker))
	(goto-char ws-marker-8))
    (ws-error "Marker 8 not set")))

(defun ws-find-marker-9 ()
  "In WordStar mode: Go to marker 9."
  (interactive)
  (if ws-marker-9
      (let ()
	(setq ws-last-cursorposition (point-marker))
	(goto-char ws-marker-9))
    (ws-error "Marker 9 not set")))

(defun ws-goto-block-begin ()
  "In WordStar mode: Go to block begin marker."
  (interactive)
  (if ws-block-begin-marker
      (let ()
	(setq ws-last-cursorposition (point-marker))
	(goto-char ws-block-begin-marker))
    (ws-error "Block begin marker not set")))

(defun ws-search (string)
  "In WordStar mode: Search string, remember string for repetition."
  (interactive "sSearch for: ")
  (message "Forward (f) or backward (b)")
  (let ((direction
	 (read-char)))
    (cond ((equal (upcase direction) ?F)
	   (setq ws-search-string string)
	   (setq ws-search-direction t)
	   (setq ws-last-cursorposition (point-marker))
	   (search-forward string))
	  ((equal (upcase direction) ?B)
	   (setq ws-search-string string)
	   (setq ws-search-direction nil)
	   (setq ws-last-cursorposition (point-marker))
	   (search-backward string))
	  (t (keyboard-quit)))))

(defun ws-goto-block-end ()
  "In WordStar mode: Go to block end marker."
  (interactive)
  (if ws-block-end-marker
      (let ()
	(setq ws-last-cursorposition (point-marker))
	(goto-char ws-block-end-marker))
    (ws-error "Block end marker not set")))

(defun ws-undo ()
  "In WordStar mode: Undo and give message about undoing more changes."
  (interactive)
  (undo)
  (message "Repeat C-q l to undo more changes."))

(defun ws-goto-last-cursorposition ()
  "In WordStar mode: "
  (interactive)
  (if ws-last-cursorposition
      (let ()
	(setq ws-last-cursorposition (point-marker))
	(goto-char ws-last-cursorposition))
    (ws-error "No last cursor position available.")))

(defun ws-last-error ()
  "In WordStar mode: repeat last error message.
This will only work for errors raised by WordStar mode functions."
  (interactive)
  (if ws-last-errormessage
      (message "%s" ws-last-errormessage)
    (message "No WordStar error yet.")))

(defun ws-kill-eol ()
  "In WordStar mode: Kill to end of line (like WordStar, not like Emacs)."
  (interactive)
  (let ((p (point)))
    (end-of-line)
    (kill-region p (point))))

(defun ws-kill-bol ()
  "In WordStar mode: Kill to beginning of line
\(like WordStar, not like Emacs)."
  (interactive)
  (let ((p (point)))
    (beginning-of-line)
    (kill-region (point) p)))

(defun kill-complete-line ()
  "Kill the complete line."
  (interactive)
  (beginning-of-line)
  (if (eobp) (error "End of buffer"))
  (let ((beg (point)))
    (forward-line 1)
    (kill-region beg (point))))

(defun ws-repeat-search ()
  "In WordStar mode: Repeat last search."
  (interactive)
  (setq ws-last-cursorposition (point-marker))
  (if ws-search-string
      (if ws-search-direction
	  (search-forward ws-search-string)
	(search-backward ws-search-string))
    (ws-error "No search to repeat")))

(defun ws-query-replace (from to)
  "In WordStar mode: Search string, remember string for repetition."
  (interactive "sReplace:
sWith: " )
  (setq ws-search-string from)
  (setq ws-search-direction t)
  (setq ws-last-cursorposition (point-marker))
  (query-replace from to))

(defun ws-copy-block ()
  "In WordStar mode: Copy block to current cursor position."
  (interactive)
  (if (and ws-block-begin-marker ws-block-end-marker)
      (let ()
	(copy-region-as-kill ws-block-begin-marker ws-block-end-marker)
	(yank)
	(save-excursion
	  (goto-char (region-beginning))
	  (setq ws-block-begin-marker (point-marker))
	  (goto-char (region-end))
	  (setq ws-block-end-marker (point-marker))))
    (ws-error (cond (ws-block-begin-marker "Block end marker not set")
		    (ws-block-end-marker "Block begin marker not set")
		    (t "Block markers not set")))))

(provide 'ws-mode)

;;; arch-tag: 6dd864bf-2ccb-4d59-af6e-492eba2890a3
;;; ws-mode.el ends here