annotate lisp/hyperbole/kotl/kotl-mode.el @ 114:8619ce7e4c50 r20-1b9

Import from CVS: tag r20-1b9
author cvs
date Mon, 13 Aug 2007 09:21:54 +0200
parents 4be1180a9e89
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;!emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; FILE: kotl-mode.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; SUMMARY: Major mode for editing koutlines and associated commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; USAGE: GNU Emacs Lisp Library
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; KEYWORDS: data, hypermedia, outlines, wp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; AUTHOR: Bob Weiner & Kellie Clark
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; ORIG-DATE: 6/30/93
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
11 ;; LAST-MOD: 6-Mar-97 at 01:15:42 by Bob Weiner
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; This file is part of Hyperbole.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; Available for use and distribution under the same terms as GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; Developed with support from Motorola Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; DESCRIPTION:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; DESCRIP-END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; Other required Lisp Libraries
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 (mapcar 'require '(hsite hmail kview kimport kvspec kotl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;; Public variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 (defvar kotl-mode:refill-flag nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 "*Automatically refill cells during move, copy, promotion and demotion operations when non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 Default value is nil. Cells with a `no-fill' attribute are never refilled
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 during such operations, regardless of the value of this flag.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;; Public functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (defun kotl-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 "The major mode used to edit and view koutlines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 It provides the following keys:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 \\{kotl-mode-map}"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (use-local-map kotl-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (set-syntax-table text-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; Turn off filladapt minor mode if on, so that it does not interfere with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;; the filling code in "kfill.el".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (and (boundp 'filladapt-mode) filladapt-mode (filladapt-mode -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (if (/= 3 (length (action:params (symbol-function 'fill-paragraph))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;; Some package such as filladapt has overwritten the primitives
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;; defined in kfill.el, so reload it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (load "kfill"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;; Ensure that outline structure data is saved when save-buffer is called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;; from save-some-buffers, {C-x s}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (add-hook 'local-write-file-hooks 'kotl-mode:update-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (mapcar 'make-local-variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 '(kotl-previous-mode indent-line-function indent-region-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 minor-mode-alist selective-display-ellipses))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;; Used by kimport.el functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (if (and (boundp 'kotl-previous-mode) kotl-previous-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (setq kotl-previous-mode major-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;; Remove outline indication due to selective-display.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 minor-mode-alist (copy-sequence minor-mode-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 minor-mode-alist (set:remove '(selective-display " Outline")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 minor-mode-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 minor-mode-alist (set:remove '(selective-display " Otl")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 minor-mode-alist)
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
72 ;; Remove indication that buffer is narrowed.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 mode-line-format (copy-sequence mode-line-format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 mode-line-format (set:remove "%n" mode-line-format)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (setq indent-line-function 'kotl-mode:indent-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 indent-region-function 'kotl-mode:indent-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 local-abbrev-table text-mode-abbrev-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 selective-display t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 selective-display-ellipses t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 paragraph-start "^[ \t]*$\\|^\^L"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 paragraph-separate "^[ \t]*$\\|^\^L")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;; This major-mode setting must come after the local variable settings but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;; before the koutline is formatted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (setq major-mode 'kotl-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 mode-name "Kotl"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 indent-tabs-mode nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;; If buffer has not yet been formatted for editing, format it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;; Koutline file that has been loaded and formatted for editing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ((kview:is-p kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;; The buffer might have been widened for inspection, so narrow to cells
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;; only.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (kfile:narrow-to-kcells))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ;; Koutline file that has been loaded but not yet formatted for editing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ((kfile:is-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (kfile:read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (current-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (and buffer-file-name (file-exists-p buffer-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (kvspec:activate))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ;; New koutline buffer or a foreign text buffer that must be converted to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;; koutline format.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (kfile:create (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (kvspec:activate)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ;; We have been converting a buffer from a foreign format to a koutline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;; Now that it is converted, ensure that kotl-previous-mode is set to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 ;; koutline now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (setq kotl-previous-mode 'kotl-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (run-hooks 'kotl-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (defun kotl-mode:find-file-hook ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (if (kview:is-p kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (kotl-mode:to-valid-position))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ;;; Ensure that point ends up at a valid position whenever a find-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ;;; is done on a kotl-file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (add-hook 'find-file-hooks 'kotl-mode:find-file-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ;;; Ensure that outline structure data is hidden from view after a file save.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (add-hook 'after-save-hook 'kfile:narrow-to-kcells)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 ;;; ------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ;;; Editing within a single kotl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 ;;; ------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (fset 'kotl-mode:backward-delete-char-untabify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 'kotl-mode:delete-backward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (fset 'kotl-mode:backward-delete-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 'kotl-mode:delete-backward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (defun kotl-mode:backward-kill-word (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 "Kill up to prefix ARG words preceding point within a single cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (or arg (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (cond ((< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (if (kotl-mode:eocp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (error "(kotl-mode:backward-kill-word): End of cell")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ((> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (if (kotl-mode:bocp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (error "(kotl-mode:backward-kill-word): Beginning of cell"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (if (= arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (narrow-to-region (kcell-view:start) (kcell-view:end-contents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (backward-kill-word arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (defun kotl-mode:center-line ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 "Center the line point is on, within the width specified by `fill-column'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 This means adjusting the indentation so that it equals the distance between
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 the end of the text and `fill-column'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (interactive "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (let ((indent (kcell-view:indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (opoint (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (bocp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 start)
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
160 (setq start (kotl-mode:start-of-line))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (if (setq bocp (kotl-mode:bocp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 ;; Add a temporary fill-prefix since this is the 1st line of the cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ;; where label could interfere with centering.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (insert "\n\n") (insert-char ?\ indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (center-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (if bocp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 ;; Delete temporary fill prefix.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (delete-region start (+ start indent 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 ;; Move to editable point if need be.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (kotl-mode:to-valid-position)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (defun kotl-mode:center-paragraph ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 "Center each nonblank line in the paragraph at or after point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 See `center-line' for more info."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (interactive "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (let ((indent (kcell-view:indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (opoint (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (backward-paragraph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (kotl-mode:to-valid-position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (setq start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 ;; Add a temporary fill-prefix for 1st line in cell which contains a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 ;; label, so is centered properly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (insert "\n\n") (insert-char ?\ indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (kcell-view:operate 'center-paragraph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 ;; Delete temporary fill prefix.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (delete-region start (+ start indent 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;; Return to original point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (goto-char (min opoint (kcell-view:end-contents)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 ;; Move to editable point if need be.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (kotl-mode:to-valid-position)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (defun kotl-mode:copy-region-as-kill (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 "Copy region between START and END within a single kcell to kill ring."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (interactive "r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (kotl-mode:kill-region start end t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (defun kotl-mode:copy-to-register (register start end &optional delete-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 "Copy into REGISTER the region START to END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 With optional prefix arg DELETE-FLAG, delete region."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (interactive "cCopy to register: \nr\nP")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (let ((indent (kcell-view:indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (set-register register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (hypb:replace-match-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (concat "^" (make-string indent ?\ ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (buffer-substring start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 "" t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (if delete-flag (delete-region start end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (defun kotl-mode:delete-backward-char (arg &optional kill-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 "Delete up to the preceding prefix ARG characters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 Return number of characters deleted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 Optional KILL-FLAG non-nil means save in kill ring instead of deleting.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 Does not delete across cell boundaries."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (if current-prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (setq kill-flag t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 arg (prefix-numeric-value current-prefix-arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (or arg (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (kotl-mode:delete-char (- arg) kill-flag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (defun kotl-mode:delete-blank-lines ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 "On blank line within a cell, delete all surrounding blank lines, leaving just one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 On isolated blank line, delete that one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 On nonblank line, delete all blank lines that follow it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 If nothing but whitespace follows point until the end of a cell, delete all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 whitespace at the end of the cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (interactive "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 ;; If nothing but whitespace from point until the end of cell, remove all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 ;; cell trailing whitespace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (let ((end (kcell-view:end-contents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (skip-chars-forward " \t\n\r" end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (not (kotl-mode:eocp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (kcell-view:operate (function (lambda () (delete-blank-lines))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (setq start (kcell-view:start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 ;; delete any preceding whitespace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (skip-chars-backward " \t\n\r" start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (delete-region (max start (point)) end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (kotl-mode:to-valid-position))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (defun kotl-mode:delete-char (arg &optional kill-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 "Delete up to prefix ARG characters following point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 Return number of characters deleted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 Optional KILL-FLAG non-nil means save in kill ring instead of deleting.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 Does not delete across cell boundaries."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (if current-prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (setq kill-flag t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 arg (prefix-numeric-value current-prefix-arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (or arg (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (let ((del-count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (indent (kcell-view:indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 count start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (cond ((> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (if (kotl-mode:eocp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (error "(kotl-mode:delete-char): End of cell")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (setq end (kcell-view:end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 arg (min arg (- end (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (while (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (if (kotl-mode:eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (if (/= ?\ (char-syntax (following-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (setq arg 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 del-count (1- del-count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (delete-char 1 kill-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 ;; There may be non-whitespace characters in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 ;; indent area. Don't delete them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (setq count indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (while (and (> count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (= ?\ (char-syntax (following-char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (setq count (1- count))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (delete-char 1 kill-flag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (setq arg (1- arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 del-count (1+ del-count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 ((< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (if (kotl-mode:bocp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (error "(kotl-mode:delete-char): Beginning of cell")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (setq start (kcell-view:start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 arg (max arg (- start (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (while (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (if (kotl-mode:bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (if (/= ?\ (char-syntax (preceding-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (setq arg 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 del-count (1- del-count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 ;; There may be non-whitespace characters in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 ;; indent area. Don't delete them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (setq count indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (while (and (> count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (= ?\ (char-syntax (preceding-char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (delete-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (setq count (1- count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (if (zerop count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (delete-char -1 kill-flag)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (delete-char -1 kill-flag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (setq arg (1+ arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 del-count (1+ del-count))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 del-count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (defun kotl-mode:delete-horizontal-space ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 "Delete all spaces and tabs around point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (interactive "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (narrow-to-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (kotl-mode:start-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (kotl-mode:finish-of-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (delete-horizontal-space)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (defun kotl-mode:delete-indentation (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 "Join this line to previous and fix up whitespace at join.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 If there is a fill prefix, delete it from the beginning of this line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 With argument, join this line to following line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (kcell-view:operate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (let ((opoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (if arg (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (if (eq (preceding-char) ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (delete-region (point) (1- (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 ;; If the second line started with the fill prefix,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 ;; delete the prefix.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (if (and fill-prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (<= (+ (point) (length fill-prefix)) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (string= fill-prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (buffer-substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (point) (+ (point) (length fill-prefix)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (delete-region (point) (+ (point) (length fill-prefix))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (fixup-whitespace))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (goto-char opoint)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (defun kotl-mode:fill-cell (&optional justify ignore-collapsed-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 "Fill current cell within current view if it does not have a non-nil `no-fill' attribute.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 With optional JUSTIFY, justify cell as well.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 IGNORE-COLLAPSED-P is used when caller has already expanded cell, indicating
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 it is not collapsed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (cond ((kcell-view:get-attr 'no-fill)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (progn (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (message "Current cell has a `do not fill' attribute.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 ((string-match "\\`[ \t\n\r]*\\'" (kcell-view:contents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 ;; Cell content is all whitespace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (t (let* ((indent (kcell-view:indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (opoint (set-marker (make-marker) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (start (kcell-view:start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (collapsed-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (end (kcell-view:end-contents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 temp-prefix prev-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 ;; Expand cell if collapsed so that filling is done properly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (if (and (not ignore-collapsed-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (setq collapsed-p (search-forward "\r" end t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (subst-char-in-region start end ?\r ?\n t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 ;; Add a temporary fill-prefix for first labeled line, so is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 ;; filled properly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (insert (setq temp-prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (concat "\n\n" (make-string indent ?\ ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (while (progn (fill-paragraph justify)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (setq prev-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (forward-paragraph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (and (/= (point) prev-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (< (point) (kcell-view:end-contents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (if (memq (preceding-char) '(?\n ?\r))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (not (looking-at "[\n\r]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 ;; Delete temporary fill prefix.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (if (looking-at temp-prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (replace-match "" t t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 ;; Return to original point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (setq end (kcell-view:end-contents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (goto-char (min opoint end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 ;; If cell was collapsed before filling, collapse it again.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (if collapsed-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (subst-char-in-region start end ?\n ?\r t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 ;; Remove markers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (set-marker opoint nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 ;; Move to editable point if need be.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (kotl-mode:to-valid-position))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (defun kotl-mode:fill-paragraph (&optional justify)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 "Fill the current paragraph within the cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 With optional JUSTIFY, justify the paragraph as well.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 Ignore any non-nil no-fill attribute attached to the cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (let ((indent (kcell-view:indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (opoint (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (backward-paragraph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (kotl-mode:to-valid-position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (setq start (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 ;; Add a temporary fill-prefix for 1st line in cell which contains a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 ;; label, so is filled properly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (insert "\n\n") (insert-char ?\ indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (setq end (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 ;; Return to original paragraph point. This is the correct formula,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 ;; considering the fill prefix that was just added.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (goto-char (min (max opoint (point)) (kcell-view:end-contents)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (fill-paragraph justify)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 ;; Delete temporary fill prefix.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (delete-region start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 ;; Return to original point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (goto-char (min opoint (kcell-view:end-contents)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 ;; Move to editable point if need be.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (kotl-mode:to-valid-position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 ;; Remove markers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (set-marker opoint nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (set-marker start nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (set-marker end nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 ;; XEmacs binds this to {M-q}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (fset 'kotl-mode:fill-paragraph-or-region 'kotl-mode:fill-paragraph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (defun kotl-mode:fill-tree (&optional top-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 "Refill each cell within the tree whose root is at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 Skip cells with a non-nil no-fill attribute.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 With optional prefix argument TOP-P non-nil, refill all cells in the outline."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 ;; Store list of which cells are presently collapsed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (let ((collapsed-cells
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (kview:map-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (function (lambda (view)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 ;; Use free variable label-sep-len bound in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 ;; kview:map-tree for speed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (kcell-view:collapsed-p nil label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 kview top-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 ;; Expand all cells in tree.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (if top-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (subst-char-in-region (point-min) (point-max) ?\r ?\n t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (kotl-mode:end-of-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (subst-char-in-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (point) (kcell-view:end-contents) ?\r ?\n t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 ;; Refill cells without no-fill property.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (kview:map-tree (function (lambda (view) (kotl-mode:fill-cell)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 kview top-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 ;; Collapse temporarily expanded cells.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (if (delq nil collapsed-cells)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (kview:map-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (lambda (view)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (if (car collapsed-cells)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 ;; Use free variable label-sep-len bound in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 ;; kview:map-tree for speed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (kcell-view:collapse nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (setq collapsed-cells (cdr collapsed-cells))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 kview top-p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (defun kotl-mode:insert-buffer (buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 "Insert after point the contents of BUFFER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 Puts mark after the inserted text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 BUFFER may be a buffer or a buffer name."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (interactive "*bInsert buffer: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (insert-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (kotl-mode:add-indent-to-region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (defun kotl-mode:insert-file (import-from children-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 "Insert each element in IMPORT-FROM as a separate cell in the current view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 Insert as sibling cells following the current cell unless prefix arg,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 CHILDREN-P is non-nil, then insert as the initial children of the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 IMPORT-FROM may be a buffer name or file name (file name completion is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 provided).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 See documentation for `kimport:file' for information on how the type of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 importation is determined."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (list (read-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (if current-prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 "Buffer or file to insert as children of current cell: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 "Buffer or file to insert as siblings of current cell: "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 current-prefix-arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (kimport:file import-from (current-buffer) children-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (defun kotl-mode:insert-file-contents (filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 "Insert contents of file FILENAME into current cell after point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 Set mark after the inserted text."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (interactive "*fInsert file: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (let ((tem (insert-file-contents filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (push-mark (+ (point) (car (cdr tem)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (kotl-mode:add-indent-to-region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (defun kotl-mode:insert-register (register &optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 "Insert contents of register REGISTER at point in current cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 REGISTER is a character naming the register to insert.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 Normally puts point before and mark after the inserted text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 If optional second arg is non-nil, puts mark before and point after.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 Interactively, second arg is non-nil if prefix arg is supplied."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (interactive "*cInsert register: \nP")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (push-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (let ((val (get-register register)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (cond ((consp val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (insert-rectangle val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 ((stringp val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (insert val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (kotl-mode:add-indent-to-region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 ((integerp val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (princ val (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 ((and (markerp val) (marker-position val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (princ (marker-position val) (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (t
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
525 (error "Register `%c' does not contain text" register))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (if (not arg) (exchange-point-and-mark)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (defun kotl-mode:just-one-space ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 "Delete all spaces and tabs around point and leave one space."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (interactive "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (narrow-to-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (kotl-mode:start-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (kotl-mode:finish-of-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (just-one-space)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (defun kotl-mode:kill-line (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 "Kill ARG lines from point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (if (and (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (kotl-mode:bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (boundp 'kill-whole-line) kill-whole-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (let ((indent (kcell-view:indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 ;; Kill whole line including newline, if any.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (kcell-view:operate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (let ((no-newline))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (kill-region (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (progn (setq no-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 (not (search-forward "\n" nil 'stay)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (or no-newline (delete-char indent)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 ;; Kill part of a line or multiple lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (let ((num-arg (prefix-numeric-value arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 ((and (null arg) (not (kotl-mode:eolp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 ;; kill to eol but not newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (kill-region (point) (setq arg (kotl-mode:finish-of-line))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 ((= num-arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 ;; kill to bol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 (kill-region (point) (setq arg (kotl-mode:start-of-line))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (t;; (/= num-arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 ;; Find start and end of region to kill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (let ((start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 (end (min (kcell-view:end-contents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 (save-excursion (forward-line num-arg) (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (kotl-mode:kill-region start end))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (setq last-command 'kill-region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (defun kotl-mode:kill-region (start end &optional copy-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 "Kill region between START and END within a single kcell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 With optional COPY-P equal to 't, copy region to kill ring but does not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 kill it. With COPY-P any other non-nil value, return region as a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 string without affecting kill ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 If the buffer is read-only and COPY-P is nil, the region will not be deleted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 but it will be copied to the kill ring and then an error will be signaled."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 (interactive "*r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (let ((read-only (and (not copy-p) buffer-read-only)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (if read-only (setq copy-p t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (if (and (number-or-marker-p start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (number-or-marker-p end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 (eq (kcell-view:cell start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (kcell-view:cell end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (let ((indent (kcell-view:indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 killed subst-str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 ;; Convert region to string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 ;; Convert all occurrences of newline + indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 ;; to just newline, eliminating indent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 ;; Then save to kill ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 (setq subst-str (concat "\\([\n\r]\\)" (make-string indent ?\ ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 killed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 (hypb:replace-match-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 subst-str (buffer-substring start end) "\\1"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (if copy-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 ;; If last char of region is a newline, then delete indent in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 ;; following line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (delete-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 start (+ end (if (memq (char-after (1- (max start end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 '(?\n ?\r))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (if (and copy-p (not (eq copy-p t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 ;; Return killed region as a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 killed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 (if (eq last-command 'kill-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 (kill-append killed (< end start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (kill-new killed))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (setq this-command 'kill-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (if read-only (barf-if-buffer-read-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 "(kotl-mode:kill-region): Bad region or not within a single kcell."))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 (fset 'kotl-mode:kill-ring-save 'kotl-mode:copy-region-as-kill)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (defun kotl-mode:kill-sentence (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 "Kill up to prefix ARG (or 1) sentences following point within a single cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 (or arg (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (cond ((> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (if (kotl-mode:eocp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (error "(kotl-mode:kill-sentence): End of cell")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 ((< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 (if (kotl-mode:bocp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 (error "(kotl-mode:kill-sentence): Beginning of cell"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 (if (= arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 (kotl-mode:kill-region (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (kotl-mode:forward-sentence arg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (defun kotl-mode:kill-word (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 "Kill up to prefix ARG words following point within a single cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (or arg (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (cond ((> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (if (kotl-mode:eocp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 (error "(kotl-mode:kill-word): End of cell")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 ((< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (if (kotl-mode:bocp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (error "(kotl-mode:kill-word): Beginning of cell"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (if (= arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (narrow-to-region (kcell-view:start) (kcell-view:end-contents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 (kill-word arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 (defun kotl-mode:newline (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 "Insert a newline. With ARG, insert ARG newlines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 In Auto Fill mode, if no numeric arg, break the preceding line if it is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 too long."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 (let ((indent (kcell-view:indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (if (equal arg 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 (insert ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (insert-char ?\ indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (do-auto-fill)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 (kotl-mode:start-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (while (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 (insert ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (insert-char ?\ indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 (setq arg (1- arg))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (fset 'kotl-mode:newline-and-indent 'kotl-mode:newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 (defun kotl-mode:open-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 "Insert a newline and leave point before it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 With arg N, insert N newlines."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 (let* ((bolp (and (kotl-mode:bolp) (not (kotl-mode:bocp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 (indent (kcell-view:indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (while (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (insert ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 (if (and (not bolp) fill-prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 (insert fill-prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 (insert-char ?\ indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 (setq arg (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 (if (and bolp fill-prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 (progn (delete-horizontal-space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 (insert fill-prefix)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 (defun kotl-mode:set-fill-prefix (turn-off)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 "Sets fill prefix to line up to point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 With prefix arg TURN-OFF or at begin of line, turns fill prefix off."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 (set-fill-prefix (or turn-off (kotl-mode:bolp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 (defun kotl-mode:transpose-chars (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 "Interchange characters around point, moving forward one character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 With prefix ARG, take character before point and drag it forward past ARG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 other characters (backward if ARG negative).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 If no prefix ARG and at end of line, the previous two characters are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 exchanged."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 (and (null arg) (kotl-mode:eolp) (kotl-mode:forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (transpose-subr 'kotl-mode:forward-char (prefix-numeric-value arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 (defun kotl-mode:transpose-lines (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 "Exchange current line and previous line, leaving point after both.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 If no previous line, exchange current with next line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 With prefix ARG, take previous line and move it past ARG lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 With prefix ARG = 0, interchange the line that contains point with the line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 that contains mark."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 ((and (kotl-mode:first-line-p) (kotl-mode:last-line-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 (error "(kotl-mode:transpose-lines): Only one line in outline"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 ;; Transpose current and previous lines or current and next lines, if no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 ;; previous line. Leave point after both exchanged lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 ((= arg 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 (let* ((point (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (mark (set-marker (make-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (if (kotl-mode:first-line-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 (kotl-mode:next-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 (kotl-mode:previous-line 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 (kotl-mode:transpose-lines-internal point mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 (goto-char (max point mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 (kotl-mode:next-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 (set-marker mark nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 ;; Transpose point and mark lines, leaving point on the line of text that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 ;; originally contained point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 ((= arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 (kotl-mode:transpose-lines-internal (point-marker) (hypb:mark-marker t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 ;; This is like exchange-point-and-mark, but doesn't activate the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 ;; mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 (goto-char (prog1 (hypb:mark t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (set-marker (hypb:mark-marker t) (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 ;; Move previous line past ARG next lines and leave point after previous
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 ;; line text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 (if (kotl-mode:first-line-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 (error "(kotl-mode:transpose-lines): No previous line to transpose"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 (kotl-mode:previous-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (let* ((mark (set-marker (make-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 (save-excursion (kotl-mode:next-line arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 (line-to-move (kotl-mode:delete-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 ;; Delete trailing newline if any, ignoring error.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 (kotl-mode:delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 (error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 (goto-char mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 (set-marker mark nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 (kotl-mode:finish-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 (insert-char ?\ (kcell-view:indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 (insert line-to-move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 (kotl-mode:start-of-line)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (defun kotl-mode:transpose-paragraphs (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 "Interchange this (or next) paragraph with previous one."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 (transpose-subr 'kotl-mode:forward-paragraph (prefix-numeric-value arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (defun kotl-mode:transpose-sentences (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 "Interchange this (next) and previous sentence."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 (transpose-subr 'kotl-mode:forward-sentence (prefix-numeric-value arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 (defun kotl-mode:transpose-words (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 "Interchange words around point, leaving point after both words.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 With prefix ARG, take word before or around point and drag it forward past
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 ARG other words (backward if ARG negative). If ARG is zero, the words around
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 or after point and around or after mark are interchanged."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (transpose-subr 'kotl-mode:forward-word (prefix-numeric-value arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 (defun kotl-mode:zap-to-char (arg char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 "Kill up to and including prefix ARG'th occurrence of CHAR.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 Goes backward if ARG is negative; error if CHAR not found."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 (interactive "*p\ncZap to char within current cell: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 (kcell-view:operate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 (function (lambda () (zap-to-char arg char)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 ;;; ------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 ;;; Editing across kotls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 ;;; ------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 (defun kotl-mode:append-cell (contents-cell append-to-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 "Append CONTENTS-CELL to APPEND-TO-CELL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 APPEND-TO-CELL is refilled if neither cell has a no-fill property and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 kotl-mode:refill-flag is enabled."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 (let* ((label (kcell-view:label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 (hargs:defaults (list label label)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 (hargs:iform-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 '(interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 "*+KAppend contents of cell: \n+KAppend contents of cell <%s> to cell: "))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 (kotl-mode:goto-cell contents-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 (let ((contents (kcell-view:contents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 (no-fill (kcell-view:get-attr 'no-fill)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 (kotl-mode:goto-cell append-to-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 (if no-fill nil (setq no-fill (kcell-view:get-attr 'no-fill)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 (goto-char (kcell-view:end-contents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 (let ((fill-prefix (make-string (kcell-view:indent) ?\ )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 (if (kotl-mode:bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 ;; Append contents of cell beginning on its own line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 (insert "\n" fill-prefix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 (kview:insert-contents (kcell-view:cell) contents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 (or no-fill (null kotl-mode:refill-flag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 fill-prefix)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 (defun kotl-mode:copy-after (from-cell-ref to-cell-ref child-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 "Copy tree rooted at FROM-CELL-REF to follow tree rooted at TO-CELL-REF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 If prefix arg CHILD-P is non-nil, make FROM-CELL-REF the first child of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 TO-CELL-REF, otherwise make it the sibling following TO-CELL-REF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 Leave point at the start of the root cell of the new tree."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 (let* ((label (kcell-view:label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 (hargs:defaults (list label label)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 (append
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 (hargs:iform-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 'interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 (format "*+KCopy tree: \n+KCopy tree <%%s> to follow as %s of cell: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 (if current-prefix-arg "child" "sibling"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 (list current-prefix-arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 ;; Copy tree in current view and leave point at the start of the copy.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 (goto-char (kotl-mode:move-after from-cell-ref to-cell-ref child-p t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 ;; Alter the copied tree so each cell appears to be newly created.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 (kview:map-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 (lambda (view)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 (kcell-view:set-cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 (kcell:create nil (kview:id-increment view)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 (defun kotl-mode:copy-before (from-cell-ref to-cell-ref parent-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 "Copy tree rooted at FROM-CELL-REF to precede tree rooted at TO-CELL-REF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 If prefix arg PARENT-P is non-nil, make FROM-CELL-REF the first child of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 TO-CELL-REF's parent, otherwise make it the preceding sibling of TO-CELL-REF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 Leave point at the start of the root cell of the new tree."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 (let* ((label (kcell-view:label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 (hargs:defaults (list label label)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 (append
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 (hargs:iform-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 (list 'interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 (format "*+KCopy tree: \n+KCopy tree <%%s> to be %s of cell: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 (if current-prefix-arg "first child of parent"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 "preceding sibling"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 (list current-prefix-arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 ;; Copy tree in current view and leave point at the start of the copy.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 (goto-char (kotl-mode:move-before from-cell-ref to-cell-ref parent-p t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 ;; Alter the copied tree so each cell appears to be newly created.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 (kview:map-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 (lambda (view)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (kcell-view:set-cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 (kcell:create nil (kview:id-increment view)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 (defun kotl-mode:copy-to-buffer (cell-ref buffer invisible-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 "Copy outline tree rooted at CELL-REF to a non-koutline BUFFER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 Invisible text is expanded and included in the copy only if INVISIBLE-FLAG is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 non-nil. The tree is inserted before point in BUFFER. Use \"0\" to copy the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 whole outline buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 (let ((label-default (kcell-view:label)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 (hargs:iform-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 '(interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 (hargs:read "Copy tree without attributes: (0 for whole outline) "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 nil label-default nil 'kcell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 (read-buffer "To buffer: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 (if (one-window-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 (select-frame (next-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 (other-window 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 (buffer-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 (y-or-n-p "Copy invisible text? "))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 (message "") ;; Erase last interactive prompt, if any.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 (setq buffer (get-buffer-create buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 (if (equal cell-ref "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 (hypb:insert-region buffer (point-min) (point-max) invisible-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 (let (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 (kotl-mode:goto-cell cell-ref t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 (save-excursion (beginning-of-line) (setq start (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 (setq end (kotl-mode:tree-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 (hypb:insert-region buffer start end invisible-flag))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 (defun kotl-mode:move-after (from-cell-ref to-cell-ref child-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 &optional copy-p fill-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 "Move tree rooted at FROM-CELL-REF to follow tree rooted at TO-CELL-REF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 If prefix arg CHILD-P is non-nil, make FROM-CELL-REF the first child of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 TO-CELL-REF, otherwise make it the sibling following TO-CELL-REF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 With optional COPY-P, copies tree rather than moving it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 Leave point at original location but return the tree's new start point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 (let* ((label (kcell-view:label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 (hargs:defaults (list label label)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 (append
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 (hargs:iform-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 'interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 (format "*+KMove tree: \n+KMove tree <%%s> to follow as %s of cell: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 (if current-prefix-arg "child" "sibling"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 (list current-prefix-arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 (if (and (not copy-p) (equal from-cell-ref to-cell-ref))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 (error "(kotl-mode:move-after): Can't move tree after itself"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 (let* ((orig (set-marker (make-marker) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 (label-sep-len (kview:label-separator-length kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 (move-to-point (set-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 (make-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 (kotl-mode:goto-cell to-cell-ref t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 (to-label (kcell-view:label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 (to-indent (kcell-view:indent nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 (from-label (progn (kotl-mode:goto-cell from-cell-ref t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 (kcell-view:label)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 (from-indent (kcell-view:indent nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 (start (kotl-mode:tree-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 (end (kotl-mode:tree-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 (sib-id (if (= 0 (kotl-mode:forward-cell 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 (kcell-view:idstamp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 new-tree-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 ;; We can't move a tree to a point within itself, so if that is the case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 ;; and this is not a copy operation, signal an error.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 (if (and (not copy-p) (>= move-to-point start) (<= move-to-point end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 (error "(kotl-mode:move-after): Can't move tree <%s> to within itself"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 from-label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 ;; If tree to move has a sibling, point is now at the start of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 ;; sibling cell. Mark its label with a property which will be deleted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 ;; whenever the cell label is renumbered. This tells us whether or not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 ;; to renumber the sibling separately from the tree to move.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 (if sib-id
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 ;; Move to middle of label and insert klabel-original temp property.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 (progn (goto-char (- (point) label-sep-len 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 (kproperty:set 'klabel-original t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 ;; Position for insertion before deletion of tree-to-move from old
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 ;; position, in case old position precedes new one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 ;; Skip past either cell or tree at move-to-point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 (goto-char move-to-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 (if child-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 ;; Move to insert position for first child of to-cell-ref.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 (progn (goto-char (kcell-view:end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 (setq to-label (klabel:child to-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 to-indent (+ to-indent (kview:level-indent kview))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 ;; Move to after to-cell-ref's tree for insertion as following sibling.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 (goto-char (kotl-mode:tree-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 (setq to-label (klabel:increment to-label)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 ;; Insert tree-to-move at new location
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 (kview:move start end (point) from-indent to-indent copy-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 (or fill-p kotl-mode:refill-flag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 ;; Ensure that point is within editable region of cell with to-label.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 (kotl-mode:to-valid-position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 (setq new-tree-start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 ;; Update current cell and new siblings' labels within view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 (klabel-type:update-labels to-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 (if copy-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 ;; Move to sibling of tree-to-move within view and update labels within
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 ;; view of tree-to-move's original siblings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 (if sib-id
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 (progn (kotl-mode:goto-cell sib-id t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 ;; Sibling labels may have already been updated if tree was
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 ;; moved somewhere preceding its siblings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 (let ((label-middle (- (point) label-sep-len 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 (if (kproperty:get label-middle 'klabel-original)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 (klabel-type:update-labels from-label))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 (goto-char orig)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 ;; Ensure that point is within editable region of a cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 (kotl-mode:to-valid-position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 (set-marker orig nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 (set-marker move-to-point nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 new-tree-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 (defun kotl-mode:move-before (from-cell-ref to-cell-ref parent-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 &optional copy-p fill-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 "Move tree rooted at FROM-CELL-REF to precede tree rooted at TO-CELL-REF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 If prefix arg PARENT-P is non-nil, make FROM-CELL-REF the first child of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 TO-CELL-REF's parent, otherwise make it the preceding sibling of TO-CELL-REF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 With optional COPY-P, copies tree rather than moving it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 Leave point at original location but return the tree's new start point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 (let* ((label (kcell-view:label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 (hargs:defaults (list label label)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 (append
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 (hargs:iform-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 (list 'interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 (format "*+KMove tree: \n+KMove tree <%%s> to be %s of cell: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 (if current-prefix-arg "first child of parent"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 "preceding sibling"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 (list current-prefix-arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 (if (and (not copy-p) (equal from-cell-ref to-cell-ref))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 (error "(kotl-mode:move-before): Can't move tree before itself"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 (let* ((orig (set-marker (make-marker) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 (label-sep-len (kview:label-separator-length kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 (move-to-point (set-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 (make-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 (kotl-mode:goto-cell to-cell-ref t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 (to-label (kcell-view:label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 (to-indent (kcell-view:indent nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 (from-label (progn (kotl-mode:goto-cell from-cell-ref t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 (kcell-view:label)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 (from-indent (kcell-view:indent nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 (start (kotl-mode:tree-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 (end (kotl-mode:tree-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 (sib-id (if (= 0 (kotl-mode:forward-cell 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 (kcell-view:idstamp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 new-tree-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 ;; We can't move a tree to a point within itself, so if that is the case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 ;; and this is not a copy operation, signal an error.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 (if (and (not copy-p) (>= move-to-point start) (<= move-to-point end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 (error "(kotl-mode:move-before): Can't move tree <%s> to within itself"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 from-label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 ;; If tree to move has a sibling, point is now at the start of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 ;; sibling cell. Mark its label with a property which will be deleted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 ;; whenever the cell label is renumbered. This tells us whether or not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 ;; to renumber the sibling separately from the tree to move.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 (if sib-id
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 ;; Move to middle of label and insert klabel-original temp property.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 (progn (goto-char (- (point) label-sep-len 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 (kproperty:set 'klabel-original t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 ;; Position for insertion at succeeding-tree, before deletion of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 ;; tree-to-move from old position, in case old position precedes new one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 (goto-char move-to-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 (if parent-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 ;; Move to insert position for first child of to-cell-ref's parent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 (if (kcell-view:parent nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 (progn (setq to-label (klabel:child (kcell-view:label)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 (goto-char (kcell-view:end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 (error "(kotl-mode:move-before): to-cell-ref's parent not in current view"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 ;; Move to before to-cell-ref for insertion as preceding sibling.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 (goto-char (kotl-mode:tree-start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 ;; Insert tree-to-move at new location
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 (kview:move start end (point) from-indent to-indent copy-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 (or fill-p kotl-mode:refill-flag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 ;; Ensure that point is within editable region of root of tree just moved.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 (kotl-mode:to-valid-position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 (setq new-tree-start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 ;; Update current cell and new siblings' labels within view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 (klabel-type:update-labels to-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 (if copy-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 ;; Move to sibling of tree-to-move within view and update labels within
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 ;; view of tree-to-move's original siblings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 (if sib-id
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 (kotl-mode:goto-cell sib-id t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 ;; Sibling labels may have already been updated if tree was
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 ;; moved somewhere preceding its siblings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 (let ((label-middle (- (point) label-sep-len 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 (if (kproperty:get label-middle 'klabel-original)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 (klabel-type:update-labels from-label))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 (goto-char orig)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 ;; Ensure that point is within editable region of a cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 (kotl-mode:to-valid-position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 (set-marker orig nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 (set-marker move-to-point nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 new-tree-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 (defun kotl-mode:yank (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 "Reinsert the last stretch of killed text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 More precisely, reinsert the stretch of killed text most recently
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 killed OR yanked. Put point at end, and set mark at beginning.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 With just C-u as argument, same but put point at beginning (and mark at end).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 With argument N, reinsert the Nth most recently killed stretch of killed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107 text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 See also the command \\[kotl-mode:yank-pop]."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 (push-mark (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 (let* ((yank-text (current-kill (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 ((listp arg) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 ((eq arg '-) -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 (t (1- arg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 (indent (kcell-view:indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 (indent-str (make-string indent ?\ )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 ;; Convert all occurrences of newline to newline + cell indent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 ;; Then insert into buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 (insert (hypb:replace-match-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 "[\n\r]" yank-text (concat "\\0" indent-str))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 (if (consp arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 ;; It is cleaner to avoid activation, even though the command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 ;; loop would deactivate the mark because we inserted text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 (goto-char (prog1 (mark t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 (set-marker (hypb:mark-marker t) (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 (defun kotl-mode:yank-pop (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 "Replace just-yanked stretch of killed text with a different stretch.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 This command is allowed only immediately after a `yank' or a `yank-pop'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 At such a time, the region contains a stretch of reinserted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 previously-killed text. `yank-pop' deletes that text and inserts in its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 place a different stretch of killed text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 With no argument, the previous kill is inserted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 With argument N, insert the Nth previous kill.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 If N is negative, this is a more recent kill.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 The sequence of kills wraps around, so that after the oldest one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 comes the newest one."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 (if (not (eq last-command 'kotl-mode:yank))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 (error "Previous command was not a yank"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 (setq this-command 'kotl-mode:yank)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 (let ((before (< (point) (mark t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 (delete-region (point) (mark t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 (set-marker (hypb:mark-marker t) (point) (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 (let* ((yank-text (current-kill arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 (indent (kcell-view:indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 (indent-str (make-string indent ?\ )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 ;; Convert all occurrences of newline to newline + cell indent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 ;; Then insert into buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 (insert (hypb:replace-match-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 "[\n\r]" yank-text (concat "\\0" indent-str))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 (if before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 ;; It is cleaner to avoid activation, even though the command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 ;; loop would deactivate the mark because we inserted text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 (goto-char (prog1 (mark t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 (set-marker (hypb:mark-marker t) (point) (current-buffer))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 ;;; ------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 ;;; Movement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 ;;; ------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 ;;; Cursor and keypad key functions aliases for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 (if (not (string-match "XEmacs\\|Lucid" emacs-version))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 (fset 'kotl-mode:fkey-backward-char 'kotl-mode:backward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 (fset 'kotl-mode:fkey-forward-char 'kotl-mode:forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 (fset 'kotl-mode:fkey-next-line 'kotl-mode:next-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 (fset 'kotl-mode:fkey-previous-line 'kotl-mode:previous-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 (fset 'kotl-mode:deprecated-scroll-down 'kotl-mode:scroll-down)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 (fset 'kotl-mode:deprecated-scroll-up 'kotl-mode:scroll-up)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 (fset 'kotl-mode:deprecated-bob 'kotl-mode:beginning-of-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 (fset 'kotl-mode:deprecated-eob 'kotl-mode:end-of-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 (defun kotl-mode:back-to-indentation ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 "Move point to the first non-read-only non-whitespace character on this line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 (kotl-mode:to-valid-position))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 (defun kotl-mode:backward-cell (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 "Move to prefix ARGth prior visible cell (same level) within current view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 Return number of cells left to move."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 (if (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 (kotl-mode:forward-cell (- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 (let ((prior (= arg 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 (label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 (while (and (> arg 0) (setq prior (kcell-view:backward t label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 (setq arg (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 (if (or prior (not (interactive-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 (error "(kotl-mode:backward-cell): No prior cell at same level")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 (defun kotl-mode:backward-char (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203 "Move point backward ARG (or 1) characters and return point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 (or arg (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 (if (>= arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 (while (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209 (cond ((kotl-mode:bobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 (error "(kotl-mode:backward-char): Beginning of buffer"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 ((kotl-mode:bocp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 (if (kcell-view:previous)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 (kotl-mode:end-of-cell)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 ((kotl-mode:bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 (if (re-search-backward "[\n\r]" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 (kotl-mode:to-valid-position t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 (t (backward-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 (setq arg (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 (kotl-mode:forward-char (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 (defun kotl-mode:backward-paragraph (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 "Move backward to start of paragraph.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 With arg N, do it N times; negative arg -N means move forward N paragraphs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 Return point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 A paragraph start is the beginning of a line which is a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 `first-line-of-paragraph' or which is ordinary text and follows a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 paragraph-separating line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 See `forward-paragraph' for more information."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 (setq arg (prefix-numeric-value arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 zmacs-region-stays t);; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 (kotl-mode:forward-paragraph (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 (fset 'kotl-mode:backward-para 'kotl-mode:backward-paragraph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 (defun kotl-mode:backward-sentence (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 "Move point backward ARG (or 1) sentences and return point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 (let* ((label-sep-len (kview:label-separator-length kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 ;; Setting fill prefix makes sentence commands properly recognize
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 ;; indented paragraphs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 (fill-prefix (make-string (kcell-view:indent nil label-sep-len) ?\ )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 (if (kotl-mode:bobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248 (error "(kotl-mode:backward-sentence): First sentence")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 (if (and (kotl-mode:bocp) (kcell-view:previous nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 (goto-char (kcell-view:end-contents)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 (or arg (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 (if (= arg 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 (narrow-to-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 (- (kcell-view:start nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 (kcell-view:indent nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257 (kcell-view:end-contents)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 (let ((opoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 (backward-sentence arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261 (if (= opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 (progn (kcell-view:previous nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 (backward-sentence arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 (kotl-mode:to-valid-position t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 (defun kotl-mode:backward-word (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 "Move point backward ARG (or 1) words and return point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 (or arg (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272 (if (>= arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 (while (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 (cond ((kotl-mode:bobp) (setq arg 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 ((kotl-mode:bocp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277 (kotl-mode:to-valid-position t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 (backward-word 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 (kotl-mode:to-valid-position t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 (setq arg (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 (kotl-mode:forward-word (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 (defun kotl-mode:beginning-of-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 "Move point to beginning of buffer and return point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290 ;; To move to cell start.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 (goto-char (kcell-view:start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 (defun kotl-mode:beginning-of-cell (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 "Move point to beginning of current or ARGth - 1 prior cell and return point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 (or arg (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 (or (integer-or-marker-p arg)
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
1299 (error "(kotl-mode:beginning-of-cell): Wrong type arg, integer-or-marker, `%s'" arg))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 (if (= arg 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 (goto-char (kcell-view:start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 (kotl-mode:backward-cell (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 ;;; Avoid XEmacs byte-compiler bug which inserts nil for calls to this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 ;;; function if named kotl-mode:beginning-of-line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308 (defun kotl-mode:start-of-line (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 "Move point to beginning of current or ARGth - 1 line and return point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 (or arg (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 (or (integer-or-marker-p arg)
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
1314 (error "(kotl-mode:start-of-line): Wrong type arg, integer-or-marker, `%s'" arg))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315 (forward-line (1- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 (if (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 (forward-char (prog1 (kcell-view:indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 (beginning-of-line))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
1322 ;;; This ensures that the key bound to `beginning-of-line' is replaced in
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
1323 ;;; kotl-mode.
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
1324 (fset 'kotl-mode:beginning-of-line 'kotl-mode:start-of-line)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 (defun kotl-mode:beginning-of-tree ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 "Move point to the level 1 root of the current cell's tree.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 Leave point at the start of the cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 (let ((label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 (if (/= (kcell-view:level nil label-sep-len) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 ;; Enable user to return to this previous position if desired.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 (push-mark nil 'no-msg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335 (while (and (/= (kcell-view:level nil label-sep-len) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 (kcell-view:parent nil label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 (kotl-mode:beginning-of-cell)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 (defun kotl-mode:down-level (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 "Move down prefix ARG levels lower within current tree."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 (if (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344 (kotl-mode:up-level (- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 ;; Enable user to return to this previous position if desired.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 (push-mark nil 'no-msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 (let ((child))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348 (while (and (> arg 0) (kcell-view:child))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 (or child (setq child t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 (setq arg (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 ;; Signal an error if couldn't move down at least 1 child level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 (or child
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 (goto-char (hypb:mark t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 (pop-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 (error "(kotl-mode:down-level): No child level to which to move")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 (defun kotl-mode:end-of-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 "Move point to end of buffer and return point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 ;; To move to cell end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 (kotl-mode:to-valid-position t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 (defun kotl-mode:end-of-cell (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 "Move point to end of current or ARGth - 1 succeeding cell and return point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 (or arg (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 (or (integer-or-marker-p arg)
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
1374 (error "(kotl-mode:end-of-cell): Wrong type arg, integer-or-marker, `%s'" arg))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 (if (= arg 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 (goto-char (kcell-view:end-contents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 (kotl-mode:forward-cell (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 ;;; Avoid XEmacs byte-compiler bug which inserts nil for calls to this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 ;;; function if named kotl-mode:end-of-line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 (defun kotl-mode:finish-of-line (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 "Move point to end of current or ARGth - 1 line and return point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 (or arg (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 (or (integer-or-marker-p arg)
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
1389 (error "(kotl-mode:finish-of-line): Wrong type arg, integer-or-marker, `%s'" arg))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 (forward-line (1- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 ;; May have to move backwards to before label if support labels
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 ;; at end of cells.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 (defalias 'kotl-mode:end-of-line 'kotl-mode:finish-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 (defun kotl-mode:end-of-tree ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 "Move point to the last cell in tree rooted at the current cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400 Leave point at the start of the cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 ;; Enable user to return to this previous position if desired.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404 (push-mark nil 'no-msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 (let ((label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406 (if (kcell-view:forward nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407 ;; Move to cell preceding start of next tree.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 (kcell-view:previous nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 ;; Otherwise, no next tree, so move until find last cell in tree.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 (let ((cell-indent (kcell-view:indent nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 (end-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 ;; Terminate when no further cells or when reach a cell at an equal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 ;; or higher level in the outline than the first cell that we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 ;; processed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 (while (and (kcell-view:next nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 (> (kcell-view:indent nil label-sep-len) cell-indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417 (setq end-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 (goto-char end-point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 (kotl-mode:beginning-of-cell)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 (defun kotl-mode:first-sibling ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422 "Move point to the first sibling of the present cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 Leave point at the start of the cell or at its present position if it is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 already within the first sibling cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 (let ((label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428 (if (save-excursion (kcell-view:backward nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429 ;; Enable user to return to this previous position if desired.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430 (push-mark nil 'no-msg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431 (while (kcell-view:backward nil label-sep-len))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 (defun kotl-mode:forward-cell (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 "Move to prefix ARGth following cell (same level) within current view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 Return number of cells left to move."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438 (if (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 (kotl-mode:backward-cell (- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 (let ((next (= arg 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 (label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 (while (and (> arg 0) (setq next (kcell-view:forward t label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443 (setq arg (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 (if (or next (not (interactive-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 (error "(kotl-mode:forward-cell): No following cell at same level")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 (defun kotl-mode:forward-char (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449 "Move point forward ARG (or 1) characters and return point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 (or arg (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 (if (>= arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 (while (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 (cond ((and (kotl-mode:eolp) (kotl-mode:last-line-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 (error "(kotl-mode:forward-char): End of buffer"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 ((kotl-mode:eocp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458 (skip-chars-forward "\n\r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459 (kotl-mode:start-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460 ((kotl-mode:eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 (forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462 (kotl-mode:start-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 (t (forward-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464 (setq arg (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465 (kotl-mode:backward-char (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 (defun kotl-mode:forward-paragraph (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469 "Move point forward until after the last character of the current paragraph.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470 With arg N, do it N times; negative arg -N means move backward N paragraphs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1471 Return point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473 A line which `paragraph-start' matches either separates paragraphs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474 \(if `paragraph-separate' matches it also) or is the first line of a paragraph.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475 A paragraph end is one character before the beginning of a line which is not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476 part of the paragraph, or the end of the buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1477 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1478 (setq arg (prefix-numeric-value arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479 zmacs-region-stays t);; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480 (if (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482 (if (kotl-mode:bocp) (setq arg (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483 (while (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484 (start-of-paragraph-text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485 (setq arg (1+ arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486 (while (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487 (end-of-paragraph-text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488 (setq arg (1- arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1489 (kotl-mode:to-valid-position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 (fset 'kotl-mode:forward-para 'kotl-mode:forward-paragraph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 (defun kotl-mode:forward-sentence (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 "Move point forward ARG (or 1) sentences and return point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498 (let* ((label-sep-len (kview:label-separator-length kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 ;; Setting fill prefix makes sentence commands properly recognize
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500 ;; indented paragraphs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 (fill-prefix (make-string (kcell-view:indent nil label-sep-len) ?\ )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 (if (kotl-mode:eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 (error "(kotl-mode:forward-sentence): Last sentence")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504 (if (kotl-mode:eocp) (kcell-view:next nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505 (or arg (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 (if (= arg 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508 (narrow-to-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509 (- (kcell-view:start nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510 (kcell-view:indent nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 (kcell-view:end-contents)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513 (let ((opoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514 (forward-sentence arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515 (if (= opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516 (progn (kcell-view:next nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517 (forward-sentence arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518 (kotl-mode:to-valid-position)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 (defun kotl-mode:forward-word (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 "Move point forward ARG (or 1) words and return point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 (or arg (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526 (if (>= arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 (while (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528 (cond ((kotl-mode:eobp) (setq arg 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529 ((kotl-mode:eocp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530 (skip-chars-forward "\n\r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 (kotl-mode:start-of-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 (forward-word 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 (kotl-mode:to-valid-position))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535 ;; If point is at beginning of a cell after moving forward a word,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536 ;; then we moved over something other than a word (some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537 ;; punctuation or an outline autonumber); therefore, leave counter as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538 ;; is in order to move forward over next word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539 (or (kotl-mode:bocp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540 (setq arg (1- arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541 (kotl-mode:backward-word (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1542 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1543
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1544 (defun kotl-mode:goto-cell (cell-ref &optional error-p)
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
1545 "Move point to start of cell given by CELL-REF. (See `kcell:ref-to-id'.)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1546 Return point iff CELL-REF is found within current view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1547 With a prefix argument, CELL-REF is assigned the argument value for use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1548 as an idstamp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1549
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1550 Optional second arg, ERROR-P, non-nil means signal an error if CELL-REF is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1551 not found within current view. Will signal same error if called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552 interactively when CELL-REF is not found."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554 (list (if current-prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555 (format "0%d" (prefix-numeric-value current-prefix-arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1556 (read-string "Goto cell label or id: "))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1557 (setq cell-ref
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 (or (kcell:ref-to-id cell-ref)
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
1559 (error "(kotl-mode:goto-cell): Invalid cell reference, `%s'" cell-ref)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560 (let* ((opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1561 (found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1562 cell-id kvspec)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563 (if (= ?| (aref cell-ref 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1564 ;; This is a standalone view spec, not a cell reference.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1565 (progn (kvspec:activate cell-ref) (setq found (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1566
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1567 ;; !! Remove any relative specs and view specs from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1568 ;; cell-ref to form cell-id. Really should account for relative
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1569 ;; specs here, but we don't yet support them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570 (if (string-match "\\(\\.[a-zA-Z]+\\)?\\([|:].*\\)\\|\\.[a-zA-Z]+"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571 cell-ref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572 (setq cell-id (substring cell-ref 0 (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573 kvspec (if (match-beginning 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1574 (substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1575 cell-ref (match-beginning 2) (match-end 2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1576 (setq cell-id cell-ref kvspec nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1577
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1578 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1579 (cond ((= ?0 (aref cell-id 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 ;; is an idstamp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581 (if (kview:goto-cell-id cell-id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582 (setq found (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583 ;; is a label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584 ((re-search-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585 (format "\\([\n\r][\n\r]\\|\\`\\)[ ]*%s%s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586 (regexp-quote cell-id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587 (regexp-quote (kview:label-separator kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1588 nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589 (setq found (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590 ;; no match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591 (t (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1592 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593 (if (and (not found) (or error-p (interactive-p)))
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
1594 (error "(kotl-mode:goto-cell): No `%s' cell in this view" cell-ref)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595 ;; Activate any viewspec associated with cell-ref.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596 (if kvspec (kvspec:activate kvspec))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599 (defun kotl-mode:head-cell ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600 "Move point to the start of the first visible cell at the same level as current cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601 If at head cell already, do nothing and return nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1603 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 (let ((moved)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605 (label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606 (while (kcell-view:backward t label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607 (setq moved t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608 moved))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610 (defun kotl-mode:last-sibling ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 "Move point to the last sibling of the present cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612 Leave point at the start of the cell or at its present position if it is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613 already within the last sibling cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 (let ((label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 (if (save-excursion (kcell-view:forward nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618 ;; Enable user to return to this previous position if desired.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619 (push-mark nil 'no-msg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620 (while (kcell-view:forward nil label-sep-len))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622 (defun kotl-mode:mark-paragraph ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1623 "Put point at beginning of this paragraph, mark at end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1624 The paragraph marked is the one that contains point or follows point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1625 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1626 (forward-paragraph 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627 (kotl-mode:to-valid-position t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628 (hypb:push-mark nil t t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1629 (backward-paragraph 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630 (kotl-mode:to-valid-position))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1631
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632 (defun kotl-mode:mark-whole-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633 "Put point at first editable character in buffer and mark at the last such character."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1635 (hypb:push-mark (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1636 (kotl-mode:end-of-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1637 (hypb:push-mark (point) nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1638 (kotl-mode:beginning-of-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1639
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1640 (defun kotl-mode:next-cell (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1641 "Move to prefix ARGth next cell (any level) within current view."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1642 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1644 (if (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1645 (kotl-mode:previous-cell (- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1646 (let ((next (= arg 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1647 (label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1648 (while (and (> arg 0) (setq next (kcell-view:next t label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649 (setq arg (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650 (if next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1651 arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652 (error "(kotl-mode:next-cell): Last cell")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1654 (defun kotl-mode:next-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1655 "Move point to ARGth next line and return point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1656 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1657 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658 (kotl-mode:set-temp-goal-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1659 (let ((orig-arg arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660 (cond ((> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661 (while (and (> arg 0) (= 0 (forward-line 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1662 (cond ((kotl-mode:eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1663 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1664 (goto-char (kcell-view:end-contents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665 (and (interactive-p) (= orig-arg arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666 (message "(kotl-mode:next-line): Last line") (beep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667 (setq arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1669 ((looking-at "^$");; blank line between cells
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670 nil);; Don't count this line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1671 (t (setq arg (1- arg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672 (kotl-mode:line-move 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1673 (kotl-mode:to-valid-position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675 ((< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676 (kotl-mode:previous-line (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1677 (t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1678 (setq this-command 'next-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1679 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1680
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1681 (defun kotl-mode:next-tree ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1682 "Move past current tree to next tree, or to last cell in tree if no next tree.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1683 Return non-nil iff there is a next tree within this koutline."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1684 (let ((start-indent (kcell-view:indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1685 (label-sep-len (kview:label-separator-length kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1686 (same-tree t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1687 (while (and (kcell-view:next nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1688 (setq same-tree (< start-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1689 (kcell-view:indent nil label-sep-len)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1690 (not same-tree)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1691
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1692 (defun kotl-mode:previous-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1693 "Move point to ARGth previous line and return point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1694 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1695 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1696 (kotl-mode:set-temp-goal-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1697 (cond ((> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1698 (while (and (> arg 0) (= 0 (forward-line -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1699 (cond ((kotl-mode:bobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1700 (kotl-mode:beginning-of-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1701 (setq arg 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1702 ((looking-at "^$") ;; blank line between cells
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1703 nil) ;; Don't count this line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1704 (t (setq arg (1- arg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1705 (kotl-mode:line-move 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1706 (kotl-mode:to-valid-position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1707 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1708 ((< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1709 (kotl-mode:next-line (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1710 (t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1711 (setq this-command 'previous-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1712 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1713
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1714 (defun kotl-mode:previous-cell (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1715 "Move to prefix ARGth previous cell (any level) within current view."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1716 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1717 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1718 (if (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1719 (kotl-mode:next-cell (- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1720 (let ((previous (= arg 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1721 (label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1722 (while (and (> arg 0) (setq previous
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1723 (kcell-view:previous t label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1724 (setq arg (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1725 (if previous
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1726 arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1727 (error "(kotl-mode:previous-cell): First cell")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1728
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1729 (defun kotl-mode:scroll-down (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1730 "Scroll text of current window downward ARG lines; or a windowful if no ARG."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1731 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1732 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1733 (scroll-down arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1734 (kotl-mode:to-valid-position t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1735
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1736 (defun kotl-mode:scroll-up (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1737 "Scroll text of current window upward ARG lines; or a windowful if no ARG."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1738 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1739 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1740 (scroll-up arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1741 (kotl-mode:to-valid-position))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1742
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1743 (defun kotl-mode:tail-cell ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1744 "Move point to the start of the last visible cell at the same level as current cell and return t.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1745 If at tail cell already, do nothing and return nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1746 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1747 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1748 (let ((moved)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1749 (label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1750 (while (kcell-view:forward t label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1751 (setq moved t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1752 moved))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1753
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1754 (defun kotl-mode:up-level (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1755 "Move up prefix ARG levels higher in current outline view."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1756 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1757 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1758 (if (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1759 (kotl-mode:down-level (- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1760 ;; Enable user to return to this previous position if desired.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1761 (push-mark nil 'no-msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1762 (let ((parent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1763 (label-sep-len (kview:label-separator-length kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1764 result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1765 (while (and (> arg 0) (setq result (kcell-view:parent t label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1766 (or parent (setq parent result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1767 (setq arg (if (eq result 0) 0 (1- arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1768 ;; Signal an error if couldn't move up at least 1 parent level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1769 (or (and parent (not (eq parent 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1770 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1771 (goto-char (hypb:mark t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1772 (pop-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1773 (error "(kotl-mode:up-level): No parent level to which to move")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1774 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1775
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1776 ;;; ------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1777 ;;; Predicates
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1778 ;;; ------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1779
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1780 (defun kotl-mode:bobp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1781 "Return point if at the start of the first cell in kview, else nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1782 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1783 (or (bobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1784 (and (not (save-excursion (re-search-backward "[\n\r]" nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1785 (kotl-mode:bolp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1786
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1787 (defun kotl-mode:bocp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1788 "Return point if at beginning of a kcell, else nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1789 (and (kotl-mode:bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1790 (let ((begin-point (kcell-view:plist-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1791 (bol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1792 (and begin-point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1793 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1794 ;; If first line-begin is less than cell begin point,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1795 ;; then we know we are on the first line of the cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1796 (if (setq bol (re-search-backward "^" nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1797 (<= bol begin-point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1798 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1799
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1800 (defun kotl-mode:bolp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1801 "Return point if at beginning of a kview line, else nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1802 (if (= (current-column) (kcell-view:indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1803 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1804
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1805 (defun kotl-mode:buffer-empty-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1806 "Return non-nil iff there are no outline cells within current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1807 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1808 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1809 (looking-at "[\n\r]*\\'")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1810
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1811 (defun kotl-mode:eobp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1812 "Return point if after the end of the last cell in kview, else nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1813 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1814 (if (looking-at "^[\n\r]*\\'") (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1815
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1816 (defun kotl-mode:eocp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1817 "Return point if at the end of a kview cell, else nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1818 (or (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1819 (looking-at "[\n\r]+\\'")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1820 (and (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1821 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1822 (skip-chars-forward "\n\r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1823 (kotl-mode:start-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1824 (kotl-mode:bocp)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1825
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1826 (fset 'kotl-mode:eolp 'eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1827
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1828 (defun kotl-mode:first-cell-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1829 "Return t iff point is on the first cell of the outline."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1830 (save-excursion (not (kcell-view:previous))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1831
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1832 (fset 'kotl-mode:first-line-p 'first-line-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1833
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1834 (defun kotl-mode:last-cell-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1835 "Return t iff point is on the last cell of the outline."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1836 (save-excursion (not (kcell-view:next))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1837
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1838 (defun kotl-mode:last-line-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1839 "Return t iff point is on the last line of the outline."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1840 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1841 (kotl-mode:finish-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1842 (looking-at "\n*\\'")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1843
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1844 ;;; ------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1845 ;;; Smart Key Support
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1846 ;;; ------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1847
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1848
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1849 (defun kotl-mode:action-key ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1850 "Collapses, expands, links to, and scrolls through koutline cells.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1851 Invoked via a key press when in kotl-mode. It assumes that its caller has
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1852 already checked that the key was pressed in an appropriate buffer and has
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1853 moved the cursor to the selected buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1854
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1855 If key is pressed:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1856 (1) at the end of buffer, uncollapse and unhide all cells in view;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1857 (2) within a cell, if its subtree is hidden then show it,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1858 otherwise hide it;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1859 (3) between cells or within the read-only indentation region to the left of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1860 a cell, then move point to prior location and begin creation of a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1861 klink to some other outline cell; hit the Action Key twice to select the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1862 link referent cell;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1863 (4) anywhere else, scroll up a windowful."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1864 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1865 (cond ((kotl-mode:eobp) (kotl-mode:show-all))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1866 ((kotl-mode:eolp) (smart-scroll-up))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1867 ((not (kview:valid-position-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1868 (if (markerp action-key-depress-prev-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1869 (progn (select-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1870 (get-buffer-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1871 (marker-buffer action-key-depress-prev-point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1872 (goto-char (marker-position action-key-depress-prev-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1873 (call-interactively 'klink:create))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1874 (kotl-mode:to-valid-position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1875 (error "(kotl-mode:action-key): Action Key released at invalid position")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1876 (t ;; On a cell line (not at the end of line).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1877 (if (smart-outline-subtree-hidden-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1878 (kotl-mode:show-tree (kcell-view:label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1879 (kotl-mode:hide-tree (kcell-view:label)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1880 (kotl-mode:to-valid-position))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1881
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1882 (defun kotl-mode:help-key ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1883 "Displays properties of koutline cells, collapses all cells, and scrolls back.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1884 Invoked via an assist-key press when in kotl-mode. It assumes that its caller
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1885 has already checked that the assist-key was pressed in an appropriate buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1886 and has moved the cursor to the selected buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1887
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1888 If assist-key is pressed:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1889 (1) at the end of buffer, collapse all cells and hide all non-level-one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1890 cells;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1891 (2) on a header line but not at the beginning or end, display properties of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1892 each cell in tree beginning at point;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1893 (3) between cells or within the read-only indentation region to the left of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1894 a cell, then move point to prior location and prompt to move one tree to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1895 a new location in the outline; hit the Action Key twice to select the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1896 tree to move and where to move it;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1897 (4) anywhere else, scroll down a windowful."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1898 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1899 (cond ((kotl-mode:eobp) (kotl-mode:overview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1900 ((kotl-mode:eolp) (smart-scroll-down))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1901 ((not (kview:valid-position-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1902 (if (markerp assist-key-depress-prev-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1903 (progn (select-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1904 (get-buffer-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1905 (marker-buffer assist-key-depress-prev-point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1906 (goto-char (marker-position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1907 assist-key-depress-prev-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1908 (call-interactively 'kotl-mode:move-after))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1909 (kotl-mode:to-valid-position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1910 (error "(kotl-mode:help-key): Help Key released at invalid position")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1911 ((not (bolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1912 ;; On an outline header line but not at the start/end of line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1913 ;; show attributes for tree at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1914 (kotl-mode:cell-help (kcell-view:label) (or current-prefix-arg 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1915 ((smart-scroll-down)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1916 (kotl-mode:to-valid-position))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1917
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1918 ;;; ------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1919 ;;; Structure Editing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1920 ;;; ------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1921
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1922 (defun kotl-mode:add-child ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1923 "Add a new cell to current kview as first child of current cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1924 (interactive "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1925 (kotl-mode:add-cell '(4)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1926
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1927 (defun kotl-mode:add-parent ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1928 "Add a new cell to current kview as sibling of current cell's parent."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1929 (interactive "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1930 (kotl-mode:add-cell -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1931
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1932 (defun kotl-mode:add-cell (&optional relative-level contents plist no-fill)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1933 "Add a cell following current cell at optional RELATIVE-LEVEL with CONTENTS string, attributes in PLIST, a property list, and NO-FILL flag to prevent any filling of CONTENTS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1934
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1935 Optional prefix arg RELATIVE-LEVEL means add as sibling if nil or >= 0, as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1936 child if equal to universal argument, {C-u}, and as sibling of current cell's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1937 parent, otherwise. If added as sibling of current level, RELATIVE-LEVEL is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1938 used as a repeat count for the number of cells to add.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1939
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1940 Return last newly added cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1941 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1942 (or (stringp contents) (setq contents nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1943 (let ((klabel (kcell-view:label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1944 (label-sep-len (kview:label-separator-length kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1945 cell-level new-cell sibling-p child-p start parent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1946 cells-to-add)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1947 (setq cell-level (kcell-view:level nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1948 child-p (equal relative-level '(4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1949 sibling-p (and (not child-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1950 (cond ((not relative-level) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1951 ((>= (prefix-numeric-value relative-level) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1952 (prefix-numeric-value relative-level))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1953 cells-to-add (or sibling-p 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1954 (if child-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1955 (setq cell-level (1+ cell-level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1956 (if sibling-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1957 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1958 ;; Add as following sibling of current cell's parent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1959 ;; Move to parent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1960 (setq cell-level (1- cell-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1961 start (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1962 parent (kcell-view:parent nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1963 (if (not (eq parent t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1964 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1965 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1966 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1967 "(kotl-mode:add-cell): No higher level at which to add cell.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1968 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1969 ;; Skip from point past any children to next cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1970 (if (kotl-mode:next-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1971 ;; If found a new tree, then move back to prior cell so can add
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1972 ;; new cell after it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1973 (kcell-view:previous nil label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1974 (goto-char (kcell-view:end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1975 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1976 ;; Insert new cells into view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1977 (if (= cells-to-add 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1978 (setq klabel
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1979 (cond (sibling-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1980 (klabel:increment klabel))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1981 (child-p (klabel:child klabel))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1982 ;; add as sibling of parent of current cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1983 (t (klabel:increment (klabel:parent klabel))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1984 new-cell (kview:add-cell klabel cell-level contents plist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1985 (or no-fill sibling-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1986 (not kotl-mode:refill-flag))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1987 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1988 ;; sibling-p must be true if we are looping here so there is no need to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1989 ;; conditionalize how to increment the labels.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1990 (while (>= (setq cells-to-add (1- cells-to-add)) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1991 (setq klabel (klabel:increment klabel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1992 ;; Since new cells are at the same level as old one, don't fill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1993 ;; any of their intial contents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1994 new-cell (kview:add-cell klabel cell-level contents plist t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1995 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1996 ;; Move back to last inserted cell and then move to its following
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1997 ;; sibling if any.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1998 (kotl-mode:to-valid-position t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1999 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2000 (if (kcell-view:forward t label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2001 ;; Update the labels of these siblings and their subtrees.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2002 (klabel-type:update-labels (klabel:increment klabel))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2003 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2004 ;; Leave point within last newly added cell and return this cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2005 (kotl-mode:beginning-of-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2006 new-cell))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2007
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2008 (defun kotl-mode:demote-tree (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2009 "Move current tree a maximum of prefix ARG levels lower in current view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2010 Each cell is refilled iff its `no-fill' attribute is nil and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2011 kotl-mode:refill-flag is non-nil. With prefix ARG = 0, cells are demoted up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2012 to one level and kotl-mode:refill-flag is treated as true."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2013 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2014 (if (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2015 (kotl-mode:promote-tree (- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2016 (let* ((label-sep-len (kview:label-separator-length kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2017 (orig-level (kcell-view:level nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2018 (orig-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2019 (orig-id (kcell-view:idstamp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2020 (fill-p (= arg 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2021 (orig-pos-in-cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2022 (- (point) (kcell-view:start nil label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2023 prev prev-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2024 (if fill-p (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2025 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2026 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2027 (backward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2028 (while (and (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2029 (setq prev
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2030 (kcell-view:previous nil label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2031 (if prev
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2032 (progn (setq prev-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2033 (kcell-view:level nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2034 (cond ((> prev-level (+ orig-level arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2035 ;; Don't want to demote this far
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2036 ;; so keep looking at prior nodes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2037 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2038 ((= arg (- prev-level orig-level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2039 ;; Demote to be sibling of this kcell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2040 (setq arg -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2041 ((< prev-level orig-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2042 ;; prev is at higher level then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2043 ;; orig, so can't demote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2044 (setq prev nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2045 arg 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2046 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2047 ;; Demote below this kcell. This is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2048 ;; as far we can demote, though it may
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2049 ;; not be the full amount of arg.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2050 (setq arg 0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2051 (if prev
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2052 (kotl-mode:move-after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2053 (kcell-view:label orig-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2054 (kcell-view:label) (= arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2055 nil fill-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2056 ;; Move to start of original cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2057 (kotl-mode:goto-cell orig-id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2058 ;; Move to original pos within cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2059 (forward-char orig-pos-in-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2060 (kotl-mode:to-valid-position))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2061 (if (not prev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2062 (error "(kotl-mode:demote-tree): Cannot demote any further")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2063
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2064 (defun kotl-mode:exchange-cells (cell-ref-1 cell-ref-2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2065 "Exchange CELL-REF-1 with CELL-REF-2 in current view. Don't move point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2066 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2067 (let ((hargs:defaults
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2068 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2069 (list (kcell-view:label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2070 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2071 ((kcell-view:previous t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2072 (kcell-view:label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2073 ((kcell-view:next t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2074 (kcell-view:label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2075 (t (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2076 "(kotl-mode:exchange-cells): No 2 visible cells")))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2077 (hargs:iform-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2078 '(interactive "*+KExchange cell: \n+KExchange cell <%s> with cell: "))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2079 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2080 (let (kcell-1 contents-1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2081 kcell-2 contents-2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2082 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2083 ;; Save cell-1 attributes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2084 (kotl-mode:goto-cell cell-ref-1 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2085 (setq kcell-1 (kcell-view:cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2086 contents-1 (kcell-view:contents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2087 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2088 ;; Save cell-2 attributes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2089 (kotl-mode:goto-cell cell-ref-2 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2090 (setq kcell-2 (kcell-view:cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2091 contents-2 (kcell-view:contents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2092 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2093 ;; Substitute cell-1 attributes into cell-2 location.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2094 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2095 ;; Set kcell properties.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2096 (kcell-view:set-cell kcell-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2097 ;; If idstamp labels are on, then must exchange labels in view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2098 (if (eq (kview:label-type kview) 'id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2099 (klabel:set (kcell-view:idstamp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2100 ;; Exchange cell contents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2101 (delete-region (kcell-view:start) (kcell-view:end-contents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2102 (insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2103 (hypb:replace-match-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2104 "\\([\n\r]\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2105 contents-1 (concat "\\1" (make-string (kcell-view:indent) ?\ ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2106 (if kotl-mode:refill-flag (kotl-mode:fill-cell))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2107 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2108 ;; Substitute cell-2 attributes into cell-1 location.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2109 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2110 ;; Set kcell properties.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2111 (kotl-mode:goto-cell cell-ref-1 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2112 (kcell-view:set-cell kcell-2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2113 ;; If idstamp labels are on, then must exchange labels in view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2114 (if (eq (kview:label-type kview) 'id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2115 (klabel:set (kcell-view:idstamp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2116 ;; Exchange cell contents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2117 (delete-region (kcell-view:start) (kcell-view:end-contents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2118 ;; Add indentation to all but first line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2119 (insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2120 (hypb:replace-match-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2121 "\\([\n\r]\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2122 contents-2 (concat "\\1" (make-string (kcell-view:indent) ?\ ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2123 (if kotl-mode:refill-flag (kotl-mode:fill-cell)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2125 (defun kotl-mode:kill-contents (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2126 "Kill contents of cell from point to cell end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2127 With prefix ARG, kill entire cell contents."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2128 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2129 (kotl-mode:kill-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2130 (if arg (kcell-view:start) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2131 (kcell-view:end-contents)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2133 (defun kotl-mode:kill-tree (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2134 "Kill ARG following trees starting with tree rooted at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2135 If ARG is not a non-positive number, nothing is done."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2136 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2137 (or (integerp arg) (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2138 (let ((killed) (label (kcell-view:label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2139 (label-sep-len (kview:label-separator-length kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2140 start end sib)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2141 (while (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2142 (setq start (kotl-mode:tree-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2143 end (kotl-mode:tree-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2144 sib (kcell-view:sibling-p nil nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2145 arg (1- arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2146 killed t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2147 ;; Don't want to delete any prior cells, so if on last cell, ensure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2148 ;; this is the last one killed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2149 (if (kotl-mode:last-cell-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2150 (progn (setq arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2151 (kview:delete-region start end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2152 (kview:delete-region start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2153 (kotl-mode:to-valid-position)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2154 (if killed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2155 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2156 (cond (sib (klabel-type:update-labels label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2157 ((kotl-mode:buffer-empty-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2158 ;; Always leave at least 1 visible cell within a view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2159 (kview:add-cell "1" 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2160 (kotl-mode:to-valid-position)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2161
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2162 (defun kotl-mode:mail-tree (cell-ref invisible-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2163 "Mail outline tree rooted at CELL-REF. Use \"0\" for whole outline buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2164 Invisible text is expanded and included in the mail only if INVISIBLE-FLAG is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2165 non-nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2166 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2167 (let ((label-default (kcell-view:label)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2168 (hargs:iform-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2169 '(interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2170 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2171 (hargs:read "Mail tree: (0 for whole outline) "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2172 nil label-default nil 'kcell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2173 (y-or-n-p "Include invisible text? "))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2174 (if (equal cell-ref "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2175 (hmail:buffer nil invisible-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2176 (let (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2177 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2178 (kotl-mode:goto-cell cell-ref t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2179 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2180 (setq start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2181 (or (= (kotl-mode:forward-cell 1) 0) (goto-char (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2182 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2183 (setq end (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2184 (hmail:region start end nil invisible-flag))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2186 (defun kotl-mode:promote-tree (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2187 "Move current tree a maximum of prefix ARG levels higher in current view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2188 Each cell is refilled iff its `no-fill' attribute is nil and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2189 kotl-mode:refill-flag is non-nil. With prefix ARG = 0, cells are promoted up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2190 to one level and kotl-mode:refill-flag is treated as true."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2191 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2192 (if (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2193 (kotl-mode:demote-tree (- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2194 (let* ((parent) (result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2195 (label-sep-len (kview:label-separator-length kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2196 (orig-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2197 (orig-id (kcell-view:idstamp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2198 (fill-p (= arg 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2199 (orig-pos-in-cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2200 (- (point) (kcell-view:start nil label-sep-len))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2201 (if fill-p (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2202 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2203 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2204 (backward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2205 (while (and (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2206 (setq result (kcell-view:parent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2207 nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2208 (not (eq result 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2209 (setq parent result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2210 arg (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2211 (if parent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2212 (kotl-mode:move-after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2213 (kcell-view:label orig-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2214 (kcell-view:label) nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2215 nil fill-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2216 ;; Move to start of original cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2217 (kotl-mode:goto-cell orig-id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2218 ;; Move to original pos within cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2219 (forward-char orig-pos-in-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2220 (kotl-mode:to-valid-position))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2221 (if (not parent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2222 (error "(kotl-mode:promote-tree): Cannot promote any further")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2224 (defun kotl-mode:set-cell-attribute (attribute value &optional pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2225 "Include ATTRIBUTE VALUE with the current cell or the cell at optional POS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2226 Replaces any existing value that ATTRIBUTE has.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2227 When called interactively, it displays the setting in the minibuffer as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2228 confirmation."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2229 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2230 (let* ((plist (copy-sequence (kcell-view:plist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2231 (existing-attributes plist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2232 attribute value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2233 (barf-if-buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2234 ;; Remove attribute values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2235 (while plist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2236 (setcdr plist (cdr (cdr plist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2237 (setq plist (cdr plist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2238 ;; Remove read-only attributes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2239 (setq existing-attributes (set:create existing-attributes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2240 existing-attributes (set:difference
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2241 existing-attributes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2242 kcell:read-only-attributes))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2244 (while (zerop (length (setq attribute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2245 (completing-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2246 "Current cell attribute to set: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2247 (mapcar 'list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2248 (mapcar 'symbol-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2249 existing-attributes))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2250 (beep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2251 (setq attribute (intern attribute)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2252 value (kcell-view:get-attr attribute))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2253 (if value
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
2254 (setq value (read-minibuffer
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2255 (format "Change value of \"%s\" to: " attribute)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2256 (prin1-to-string value)))
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
2257 (setq value (read-minibuffer
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2258 (format "Set value of \"%s\" to: " attribute))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2259 (list attribute value nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2260 (kcell-view:set-attr attribute value pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2261 ;; Note that buffer needs to be saved to store new attribute value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2262 (set-buffer-modified-p t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2263 (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2264 (message "Attribute \"%s\" set to `%s' in cell <%s>."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2265 attribute value (kcell-view:label pos))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2267 (defun kotl-mode:split-cell (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2268 "Split the current cell into two cells and move to the new cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2269 The cell contents after point become part of the newly created cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2270 The default is to create the new cell as a sibling of the current cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2271 With optional universal ARG, {C-u}, the new cell is added as the child of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2272 the current cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2273 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2274 (let ((new-cell-contents (kotl-mode:kill-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2275 (point) (kcell-view:end-contents) 'string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2276 (start (kcell-view:start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2277 ;; delete any preceding whitespace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2278 (skip-chars-backward " \t\n\r" start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2279 (delete-region (max start (point)) (kcell-view:end-contents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2280 (kotl-mode:add-cell arg new-cell-contents (kcell-view:plist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2281
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2282 (defun kotl-mode:transpose-cells (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2283 "Exchange current and previous visible cells, leaving point after both.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2284 If no previous cell, exchange current with next cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2285 With prefix ARG, take current tree and move it past ARG visible cells.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2286 With prefix ARG = 0, interchange the cell that contains point with the cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2287 that contains mark."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2288 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2289 (let ((label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2290 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2291 ((save-excursion (not (or (kcell-view:next t label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2292 (kcell-view:previous t label-sep-len))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2293 (error "(kotl-mode:transpose-cells): Only one visible cell in outline"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2294 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2295 ;; Transpose current and previous cells or current and next cells, if no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2296 ;; previous cell. Leave point after both exchanged cells or within last
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2297 ;; visible cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2298 ((= arg 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2299 (let ((label-1 (kcell-view:label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2300 (prev (kcell-view:previous t label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2301 label-2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2302 (or prev (kcell-view:next t label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2303 (setq label-2 (kcell-view:label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2304 (kotl-mode:exchange-cells label-1 label-2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2305 (kcell-view:next t label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2306 (if prev (kcell-view:next t label-sep-len))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2307 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2308 ;; Transpose point and mark cells, moving point to the new location of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2309 ;; cell which originally contained point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2310 ((= arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2311 (let ((label-1 (kcell-view:label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2312 label-2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2313 ;; This is like exchange-point-and-mark, but doesn't activate the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2314 ;; mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2315 (goto-char (prog1 (hypb:mark t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2316 (set-marker (hypb:mark-marker t) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2317 (setq label-2 (kcell-view:label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2318 (kotl-mode:exchange-cells label-1 label-2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2319 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2320 ;; Move current tree past ARG next visible cells and leave point after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2321 ;; original cell text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2322 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2323 (let ((mark (set-marker (make-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2324 (save-excursion (kotl-mode:next-line arg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2325 (kotl-mode:move-after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2326 (kcell-view:label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2327 (progn (while (and (> arg 0) (kcell-view:next t label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2328 (setq arg (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2329 (kcell-view:label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2330 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2331 (goto-char mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2332 (set-marker mark nil))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2333
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2334 ;;; ------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2335 ;;; Structure Viewing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2336 ;;; ------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2338 (defun kotl-mode:collapse-tree (&optional all-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2339 "Collapse to one line each visible cell of tree rooted at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2340 With optional ALL-FLAG non-nil, collapse all cells visible within the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2341 view."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2342 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2343 (kotl-mode:is-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2344 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2345 (if all-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2346 (progn (kvspec:show-lines-per-cell 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2347 (kvspec:update t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2348 (kview:map-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2349 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2350 (lambda (kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2351 ;; Use free variable label-sep-len bound in kview:map-tree for speed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2352 (goto-char (kcell-view:start nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2353 (subst-char-in-region (point) (kcell-view:end-contents) ?\n ?\r t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2354 kview nil t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2355
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2356 (defun kotl-mode:expand-tree (&optional all-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2357 "Expand each visible cell of tree rooted at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2358 With optional ALL-FLAG non-nil, expand all cells visible within the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2359 view."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2360 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2361 (kotl-mode:is-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2362 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2363 (if all-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2364 (progn (kvspec:show-lines-per-cell 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2365 (kvspec:update t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2366 (kview:map-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2367 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2368 (lambda (kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2369 ;; Use free variable label-sep-len bound in kview:map-tree for speed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2370 (goto-char (kcell-view:start nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2371 (subst-char-in-region (point) (kcell-view:end-contents) ?\r ?\n t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2372 kview nil t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2374 (defun kotl-mode:toggle-tree-expansion (&optional all-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2375 "Collapse or expand each cell of tree rooted at point or all visible cells if optional prefix arg ALL-FLAG is given.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2376 If current cell is collapsed, cells will be expanded, otherwise they will be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2377 collapsed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2378 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2379 (if (kcell-view:collapsed-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2380 ;; expand cells
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2381 (kotl-mode:expand-tree all-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2382 (kotl-mode:collapse-tree all-flag)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2383
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2384 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2385 (defun kotl-mode:overview ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2386 "Show the first line of each cell without blank line separators."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2387 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2388 (kotl-mode:show-all)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2389 (if (string-match "b" kvspec:current)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2390 (kvspec:toggle-blank-lines))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2391 (kotl-mode:collapse-tree t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2393 (defun kotl-mode:show-all ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2394 "Show (expand) all cells in current view."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2395 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2396 (if (kotl-mode:is-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2397 (progn (kview:set-attr kview 'levels-to-show 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2398 (kview:set-attr kview 'lines-to-show 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2399 (show-all)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2400 (kvspec:update t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2401
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2402 (defun kotl-mode:top-cells ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2403 "Collapse all level 1 cells in view and hide any deeper sublevels."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2404 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2405 (kotl-mode:is-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2406 (let ((modified-p (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2407 (buffer-read-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2408 (kvspec:levels-to-show 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2409 (kvspec:show-lines-per-cell 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2410 (kvspec:update t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2411 ;; Restore buffer modification status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2412 (set-buffer-modified-p modified-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2413
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2414 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2415 (defun kotl-mode:hide-sublevels (levels-to-keep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2416 "Hide all cells in outline at levels deeper than LEVELS-TO-KEEP (a number).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2417 Shows any hidden cells within LEVELS-TO-KEEP. 1 is the first level. 0 means
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2418 display all levels of cells."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2419 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2420 (kvspec:levels-to-show levels-to-keep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2421 ;; The prior call might have shown more lines per cell than the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2422 ;; viewspec supports, so reset lines per cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2423 (kvspec:lines-to-show)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2424 (kvspec:update t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2426 (defun kotl-mode:hide-subtree (&optional cell-ref show-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2427 "Hide subtree, ignoring root, at optional CELL-REF (defaults to cell at point)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2428 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2429 (kotl-mode:is-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2430 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2431 (if cell-ref
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2432 (kotl-mode:goto-cell cell-ref t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2433 (kotl-mode:beginning-of-cell))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2434 (let ((start (kcell-view:end-contents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2435 (end (kotl-mode:tree-end t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2436 (buffer-read-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2437 (if show-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2438 (subst-char-in-region start end ?\r ?\n t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2439 (subst-char-in-region start end ?\n ?\r t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2440
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2441 (defun kotl-mode:show-subtree (&optional cell-ref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2442 "Show subtree, ignoring root, at optional CELL-REF (defaults to cell at point)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2443 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2444 (kotl-mode:hide-subtree cell-ref t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2445
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2446 (defun kotl-mode:hide-tree (&optional cell-ref show-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2447 "Collapse tree rooted at optional CELL-REF (defaults to cell at point)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2448 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2449 (kotl-mode:is-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2450 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2451 (let ((start (if cell-ref
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2452 (kotl-mode:goto-cell cell-ref t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2453 (kotl-mode:beginning-of-cell)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2454 (end (kotl-mode:tree-end t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2455 (buffer-read-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2456 (if show-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2457 (subst-char-in-region start end ?\r ?\n t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2458 (subst-char-in-region start end ?\n ?\r t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2459
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2460 (defun kotl-mode:show-tree (&optional cell-ref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2461 "Display fully expanded tree rooted at CELL-REF."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2462 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2463 (kotl-mode:hide-tree cell-ref t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2464
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2465 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2466 (defun kotl-mode:cell-attributes (all-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2467 "Display a temporary buffer with the attributes of the current kcell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2468 With prefix arg ALL-FLAG non-nil, display the attributes of all visible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2469 kcells in the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2470
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2471 See also the documentation for `kotl-mode:cell-help'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2472 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2473 (with-output-to-temp-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2474 (hypb:help-buf-name "Kotl")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2475 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2476 (if (not all-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2477 (kotl-mode:print-attributes kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2478 (let ((label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2479 (kotl-mode:beginning-of-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2480 (while (progn (kotl-mode:print-attributes kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2481 (kcell-view:next t label-sep-len))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2482
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2483 (defun kotl-mode:cell-help (&optional cell-ref cells-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2484 "Display a temporary buffer with CELL-REF's attributes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2485 CELL-REF defaults to current cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2486 Optional prefix arg CELLS-FLAG selects the cells to print:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2487 If = 1, print CELL-REF's cell only;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2488 If > 1, print CELL-REF's visible tree (the tree rooted at CELL-REF);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2489 If < 1, print all visible cells in current view (CELL-REF is not used).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2490
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2491 See also the documentation for `kotl-mode:cell-attributes'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2492 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2493 (let* ((label (kcell-view:label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2494 (hargs:defaults (list label label)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2495 (append
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2496 (let ((arg (prefix-numeric-value current-prefix-arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2497 (if (< arg 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2498 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2499 (hargs:iform-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2500 (list 'interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2501 (format "+KDisplay properties of koutline %s: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2502 (if (= arg 1) "cell" "tree"))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2503 (list current-prefix-arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2504 (or (integerp cells-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2505 (setq cells-flag (prefix-numeric-value cells-flag)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2506 (or (stringp cell-ref) (setq cell-ref (kcell-view:label)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2507 (with-output-to-temp-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2508 (hypb:help-buf-name "Koutline")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2509 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2510 (if (equal cell-ref "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2511 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2512 (hattr:report (kcell:plist (kview:top-cell kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2513 (terpri)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2514 (cond ((= cells-flag 1) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2515 ((> cells-flag 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2516 (kview:map-tree 'kotl-mode:print-attributes kview t t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2517 ;; (< cells-flag 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2518 (t (kotl-mode:cell-attributes t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2519 (cond ((= cells-flag 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2520 (kotl-mode:goto-cell cell-ref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2521 (kotl-mode:print-attributes kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2522 ((> cells-flag 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2523 (kotl-mode:goto-cell cell-ref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2524 (kview:map-tree 'kotl-mode:print-attributes kview nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2525 ;; (< cells-flag 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2526 (t (kotl-mode:cell-attributes t)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2527
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2528 (defun kotl-mode:get-cell-attribute (attribute &optional pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2529 "Return ATTRIBUTE's value for the current cell or the cell at optional POS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2530 When called interactively, it displays the value in the minibuffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2531 (interactive "SCurrent cell attribute to get: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2532 (let ((value (kcell-view:get-attr attribute pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2533 (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2534 (message "Attribute \"%s\" = `%s' in cell <%s>."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2535 attribute value (kcell-view:label pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2536 value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2537
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2538 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2539 ;;; Private functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2540 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2541
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2542 (defun kotl-mode:add-indent-to-region (&optional indent start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2543 "Add current cell's indent to current region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2544 Optionally, INDENT and region START and END may be given."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2545 (or (integerp indent) (setq indent (kcell-view:indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2546 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2547 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2548 (narrow-to-region (or start (point)) (or end (hypb:mark t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2549 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2550 (replace-regexp "\n" (concat "\n" (make-string indent ?\ ))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2551
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2552 (defun kotl-mode:delete-line (&optional pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2553 "Delete and return contents of cell line at point or optional POS as a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2554 Does not delete newline at end of line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2555 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2556 (if pos (goto-char pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2557 (if (kview:valid-position-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2558 (let ((bol (kotl-mode:start-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2559 (eol (kotl-mode:finish-of-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2560 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2561 (buffer-substring bol eol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2562 (delete-region bol eol)))
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
2563 (error "(kotl-mode:delete-line): Invalid position, `%d'" (point)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2564
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2565 (defun kotl-mode:indent-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2566 ;; Disallow the indent-line command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2567 (error "(kotl-mode:indent-line): Insert spaces to indent each line."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2568
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2569 (defun kotl-mode:indent-region (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2570 ;; User might try to indent across cells. This would be bad, so disallow
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2571 ;; the indent-region command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2572 (error "(kotl-mode:indent-region): Insert spaces to indent each line."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2573
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2574 (defun kotl-mode:is-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2575 "Signal an error if current buffer is not a Hyperbole outline, else return t."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2576 (if (kview:is-p kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2577 t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2578 (hypb:error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2579 "(kotl-mode:is-p): Command requires a current Hyperbole outline.")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2580
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2581 (defun kotl-mode:tree-end (&optional omit-end-newlines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2582 "Return end point of current cell's tree within this view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2583 If optional OMIT-END-NEWLINES is non-nil, point returned precedes any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2584 newlines at end of tree."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2585 (let* ((label-sep-len (kview:label-separator-length kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2586 (start-indent (kcell-view:indent nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2587 (next))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2588 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2589 (while (and (setq next (kcell-view:next nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2590 (< start-indent (kcell-view:indent nil label-sep-len))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2591 (cond (next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2592 (goto-char (progn (kcell-view:previous nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2593 (kcell-view:end))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2594 ;; Avoid skipping too far at end of file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2595 ((re-search-forward "[\n\r][\n\r]" nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2596 (t (goto-char (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2597 (if omit-end-newlines (skip-chars-backward "\n\r"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2598 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2599
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2600 (defun kotl-mode:tree-start ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2601 "Return beginning of line position preceding current cell's start point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2602 (save-excursion (goto-char (kcell-view:start)) (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2603 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2604
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2605 (defun kotl-mode:line-move (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2606 "Move point ARG visible lines forward within an outline."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2607 (if (not (integerp selective-display))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2608 (forward-line arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2609 ;; Move by arg lines, but ignore invisible ones.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2610 (while (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2611 (vertical-motion 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2612 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2613 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2614 (setq arg (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2615 (while (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2616 (vertical-motion -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2617 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2618 (setq arg (1+ arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2619 (move-to-column (or goal-column temporary-goal-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2620 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2621
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2622 (defun kotl-mode:print-attributes (kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2623 "Print to the `standard-output' stream the attributes of the current visible kcell.
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
2624 Takes argument KVIEW (so it can be used with `kview:map-tree' and so that
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2625 KVIEW is bound correctly) but always operates upon the current view."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2626 ;; Move to start of visible cell to avoid printing attributes for an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2627 ;; invisible kcell which point may be over.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2628 ;; Print first line of cell for reference.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2629 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2630 (princ
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2631 (buffer-substring (progn (beginning-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2632 (progn (kview:end-of-actual-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2633 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2634 (terpri)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2635 (hattr:report (kcell:plist (kcell-view:cell)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2636 (terpri))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2637
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2638 (defun kotl-mode:set-temp-goal-column ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2639 (if (not (or (eq last-command 'next-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2640 (eq last-command 'previous-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2641 (setq temporary-goal-column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2642 (if (and track-eol (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2643 ;; Don't count beg of empty line as end of line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2644 ;; unless we just did explicit end-of-line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2645 (or (not (bolp)) (eq last-command 'end-of-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2646 9999
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2647 (current-column)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2648
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2649 (defun kotl-mode:to-valid-position (&optional backward-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2650 "Move point to the nearest non-read-only position within current koutline view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2651 With optional BACKWARD-P, move backward if possible to get to valid position."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2652 (if (kview:valid-position-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2653 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2654 (let ((label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2655 (cond ((kotl-mode:bobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2656 (goto-char (kcell-view:start nil label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2657 ((kotl-mode:eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2658 (skip-chars-backward "\n\r"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2659 (t (let ((indent (kcell-view:indent nil label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2660 (if (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2661 (if backward-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2662 (skip-chars-backward "\n\r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2663 (skip-chars-forward "\n\r")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2664 (setq indent (kcell-view:indent nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2665 (if (< (current-column) indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2666 (move-to-column indent))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2667
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2668 (defun kotl-mode:transpose-lines-internal (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2669 "Transpose lines at START and END markers within an outline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2670 Leave point at end of line now residing at START."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2671 (if (and start end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2672 (kview:valid-position-p start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2673 (kview:valid-position-p end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2674 (let* ((pline (kotl-mode:delete-line start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2675 mline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2676 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2677 (setq mline (kotl-mode:delete-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2678 (insert pline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2679 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2680 (insert mline))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2681 ;; Set non-point and non-mark markers to point nowhere before signalling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2682 ;; an error.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2683 (or (eq start (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2684 (eq start (hypb:mark-marker t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2685 (set-marker start nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2686 (or (eq end (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2687 (eq end (hypb:mark-marker t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2688 (set-marker start nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2689 (error "(kotl-mode:transpose-lines): Point or mark is at an invalid position")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2690
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2691 (defun kotl-mode:update-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2692 "Update current view buffer in preparation for saving."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2693 (if (kview:is-p kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2694 (let ((mod-p (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2695 (start (window-start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2696 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2697 (kfile:update)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2698 (set-buffer-modified-p mod-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2699 (set-window-start nil (max (point-min) start) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2700 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2701
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2702 ;;; ------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2703
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2704 (defvar kotl-mode-map nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2705 "Keymap containing koutliner editing and viewing commands.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2706 (if kotl-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2707 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2708 (setq kotl-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2709 (if (string-match "XEmacs\\|Lucid" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2710 (make-keymap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2711 (copy-keymap indented-text-mode-map)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2712 ;; Overload edit keys to deal with structure and labels.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2713 (let (local-cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2714 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2715 (if (string-match "XEmacs\\|Lucid" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2716 ;; XEmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2717 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2718 (lambda (cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2719 (setq local-cmd (intern-soft
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2720 (concat "kotl-mode:" (symbol-name cmd))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2721 ;; Only bind key locally if kotl-mode local-cmd has already
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2722 ;; been defined and cmd is a valid function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2723 (if (and local-cmd (fboundp cmd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2724 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2725 ;; Make local-cmd have the same property list as cmd,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2726 ;; e.g. so pending-delete property is the same.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2727 (setplist local-cmd (symbol-plist cmd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2728 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2729 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2730 (lambda (key) (define-key kotl-mode-map key local-cmd)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2731 (where-is-internal cmd))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2732 ;; GNU Emacs 19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2733 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2734 (lambda (cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2735 (setq local-cmd (intern-soft
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2736 (concat "kotl-mode:" (symbol-name cmd))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2737 ;; Only bind key locally if kotl-mode local-cmd has already
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2738 ;; been defined and cmd is a valid function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2739 (if (and local-cmd (fboundp cmd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2740 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2741 ;; Make local-cmd have the same property list as cmd,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2742 ;; e.g. so pending-delete property is the same.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2743 (setplist local-cmd (symbol-plist cmd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2744 (substitute-key-definition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2745 cmd local-cmd kotl-mode-map global-map))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2746 '(
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2747 back-to-indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2748 backward-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2749 backward-delete-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2750 backward-delete-char-untabify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2751 backward-kill-word
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2752 backward-para
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2753 backward-paragraph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2754 backward-sentence
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2755 backward-word
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2756 beginning-of-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2757 beginning-of-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2758 copy-region-as-kill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2759 copy-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2760 delete-blank-lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2761 delete-backward-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2762 delete-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2763 delete-horizontal-space
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2764 delete-indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2765 end-of-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2766 end-of-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2767 fill-paragraph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2768 fill-paragraph-or-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2769 ;; cursor keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2770 fkey-backward-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2771 fkey-forward-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2772 fkey-next-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2773 fkey-previous-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2774 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2775 forward-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2776 forward-word
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2777 forward-para
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2778 forward-paragraph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2779 forward-sentence
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2780 insert-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2781 insert-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2782 insert-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2783 just-one-space
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2784 kill-word
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2785 kill-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2786 kill-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2787 kill-ring-save
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2788 kill-sentence
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2789 mark-paragraph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2790 mark-whole-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2791 newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2792 newline-and-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2793 next-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2794 open-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2795 previous-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2796 scroll-down
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2797 scroll-up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2798 set-fill-prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2799 transpose-chars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2800 transpose-lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2801 transpose-paragraphs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2802 transpose-sentences
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2803 transpose-words
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2804 yank
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2805 yank-pop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2806 zap-to-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2807 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2808
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2809
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2810 ;; kotl-mode keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2811 (define-key kotl-mode-map "\C-c@" 'kotl-mode:mail-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2812 (define-key kotl-mode-map "\C-c+" 'kotl-mode:append-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2813 (define-key kotl-mode-map "\C-c," 'kotl-mode:beginning-of-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2814 (define-key kotl-mode-map "\C-c." 'kotl-mode:end-of-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2815 (define-key kotl-mode-map "\C-c<" 'kotl-mode:first-sibling)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2816 (define-key kotl-mode-map "\C-c>" 'kotl-mode:last-sibling)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2817 (define-key kotl-mode-map "\C-c^" 'kotl-mode:beginning-of-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2818 (define-key kotl-mode-map "\C-c$" 'kotl-mode:end-of-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2819 (define-key kotl-mode-map "\C-ca" 'kotl-mode:add-child)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2820 (define-key kotl-mode-map "\C-c\C-a" 'kotl-mode:show-all)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2821 (define-key kotl-mode-map "\C-cb" 'kvspec:toggle-blank-lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2822 (define-key kotl-mode-map "\C-c\C-b" 'kotl-mode:backward-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2823 (define-key kotl-mode-map "\C-cc" 'kotl-mode:copy-after)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2824 (define-key kotl-mode-map "\C-c\C-c" 'kotl-mode:copy-before)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2825 (define-key kotl-mode-map "\C-c\M-c" 'kotl-mode:copy-to-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2826 (define-key kotl-mode-map "\C-cd" 'kotl-mode:down-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2827 (define-key kotl-mode-map "\C-c\C-d" 'kotl-mode:down-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2828 (define-key kotl-mode-map "\C-ce" 'kotl-mode:exchange-cells)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2829 (define-key kotl-mode-map "\C-c\C-f" 'kotl-mode:forward-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2830 (define-key kotl-mode-map "\C-cg" 'kotl-mode:goto-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2831 (define-key kotl-mode-map "\C-ch" 'kotl-mode:cell-help)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2832 (define-key kotl-mode-map "\C-c\C-h" 'kotl-mode:hide-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2833 (define-key kotl-mode-map "\M-\C-h" 'kotl-mode:hide-subtree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2834 ;; Override this global binding for set-selective-display with a similar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2835 ;; function appropriate for kotl-mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2836 (define-key kotl-mode-map "\C-x$" 'kotl-mode:hide-sublevels)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2837 (define-key kotl-mode-map "\C-i" 'kotl-mode:demote-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2838 (define-key kotl-mode-map "\M-\C-i" 'kotl-mode:promote-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2839 (define-key kotl-mode-map "\C-j" 'kotl-mode:add-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2840 (define-key kotl-mode-map "\M-j" 'kotl-mode:fill-paragraph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2841 (define-key kotl-mode-map "\C-c\M-j" 'kotl-mode:fill-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2842 (define-key kotl-mode-map "\M-\C-j" 'kotl-mode:fill-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2843 (define-key kotl-mode-map "\C-c\C-k" 'kotl-mode:kill-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2844 (define-key kotl-mode-map "\C-ck" 'kotl-mode:kill-contents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2845 (define-key kotl-mode-map "\C-c\C-i" 'kotl-mode:set-cell-attribute)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2846 (define-key kotl-mode-map "\C-cl" 'klink:create)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2847 (define-key kotl-mode-map "\C-c\C-l" 'kview:set-label-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2848 (define-key kotl-mode-map "\C-c\M-l" 'kview:set-label-separator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2849 (define-key kotl-mode-map "\C-m" 'kotl-mode:newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2850 (define-key kotl-mode-map "\C-cm" 'kotl-mode:move-after)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2851 (define-key kotl-mode-map "\C-c\C-m" 'kotl-mode:move-before)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2852 (define-key kotl-mode-map "\C-c\C-n" 'kotl-mode:next-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2853 (define-key kotl-mode-map "\C-c\C-o" 'kotl-mode:overview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2854 (define-key kotl-mode-map "\C-c\C-p" 'kotl-mode:previous-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2855 (define-key kotl-mode-map "\C-cp" 'kotl-mode:add-parent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2856 (if (memq (global-key-binding "\M-q") '(fill-paragraph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2857 fill-paragraph-or-region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2858 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2859 (define-key kotl-mode-map "\C-c\M-q" 'kotl-mode:fill-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2860 (define-key kotl-mode-map "\M-\C-q" 'kotl-mode:fill-tree)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2861 (define-key kotl-mode-map "\C-cs" 'kotl-mode:split-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2862 (define-key kotl-mode-map "\C-c\C-s" 'kotl-mode:show-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2863 (define-key kotl-mode-map "\C-c\C-\\" 'kotl-mode:show-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2864 (define-key kotl-mode-map "\M-s" 'kotl-mode:center-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2865 (define-key kotl-mode-map "\M-S" 'kotl-mode:center-paragraph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2866 (define-key kotl-mode-map "\C-ct" 'kotl-mode:transpose-cells)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2867 (define-key kotl-mode-map "\C-c\C-t" 'kotl-mode:top-cells)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2868 (define-key kotl-mode-map "\C-cu" 'kotl-mode:up-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2869 (define-key kotl-mode-map "\C-c\C-u" 'kotl-mode:up-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2870 (define-key kotl-mode-map "\C-c\C-v" 'kvspec:activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2871 (define-key kotl-mode-map "\C-x\C-w" 'kfile:write))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2872
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2873 (provide 'kotl-mode)