annotate lisp/hyperbole/kotl/kotl-mode.el @ 70:131b0175ea99 r20-0b30

Import from CVS: tag r20-0b30
author cvs
date Mon, 13 Aug 2007 09:02:59 +0200
parents c53a95d3c46d
children 4be1180a9e89
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
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 36
diff changeset
11 ;; LAST-MOD: 3-Nov-95 at 19:25:57 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)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 36
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)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 36
diff changeset
160 (setq start (kotl-mode:beginning-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
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 36
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)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 36
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)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 36
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
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 36
diff changeset
1322 (defalias 'kotl-mode:beginning-of-line 'kotl-mode:start-of-line)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 (defun kotl-mode:beginning-of-tree ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 "Move point to the level 1 root of the current cell's tree.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 Leave point at the start of the cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 (let ((label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 (if (/= (kcell-view:level nil label-sep-len) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 ;; Enable user to return to this previous position if desired.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 (push-mark nil 'no-msg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 (while (and (/= (kcell-view:level nil label-sep-len) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 (kcell-view:parent nil label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335 (kotl-mode:beginning-of-cell)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 (defun kotl-mode:down-level (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 "Move down prefix ARG levels lower within current tree."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 (if (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 (kotl-mode:up-level (- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 ;; Enable user to return to this previous position if desired.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344 (push-mark nil 'no-msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 (let ((child))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 (while (and (> arg 0) (kcell-view:child))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 (or child (setq child t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348 (setq arg (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 ;; Signal an error if couldn't move down at least 1 child level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 (or child
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 (goto-char (hypb:mark t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 (pop-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 (error "(kotl-mode:down-level): No child level to which to move")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 (defun kotl-mode:end-of-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 "Move point to end of buffer and return point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 ;; To move to cell end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 (kotl-mode:to-valid-position t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 (defun kotl-mode:end-of-cell (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 "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
1368 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 (or arg (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 (or (integer-or-marker-p arg)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 36
diff changeset
1372 (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
1373 (if (= arg 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 (goto-char (kcell-view:end-contents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 (kotl-mode:forward-cell (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 ;;; Avoid XEmacs byte-compiler bug which inserts nil for calls to this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 ;;; function if named kotl-mode:end-of-line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 (defun kotl-mode:finish-of-line (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 "Move point to end of current or ARGth - 1 line and return point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 (or arg (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 (or (integer-or-marker-p arg)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 36
diff changeset
1387 (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
1388 (forward-line (1- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 ;; May have to move backwards to before label if support labels
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 ;; at end of cells.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 (defalias 'kotl-mode:end-of-line 'kotl-mode:finish-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 (defun kotl-mode:end-of-tree ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397 "Move point to the last cell in tree rooted at the current cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 Leave point at the start of the cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 ;; Enable user to return to this previous position if desired.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 (push-mark nil 'no-msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 (let ((label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404 (if (kcell-view:forward nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 ;; Move to cell preceding start of next tree.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406 (kcell-view:previous nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407 ;; Otherwise, no next tree, so move until find last cell in tree.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 (let ((cell-indent (kcell-view:indent nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 (end-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 ;; Terminate when no further cells or when reach a cell at an equal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 ;; or higher level in the outline than the first cell that we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 ;; processed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 (while (and (kcell-view:next nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 (> (kcell-view:indent nil label-sep-len) cell-indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 (setq end-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 (goto-char end-point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417 (kotl-mode:beginning-of-cell)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 (defun kotl-mode:first-sibling ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420 "Move point to the first sibling of the present cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 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
1422 already within the first sibling cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 (let ((label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426 (if (save-excursion (kcell-view:backward nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 ;; Enable user to return to this previous position if desired.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428 (push-mark nil 'no-msg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429 (while (kcell-view:backward nil label-sep-len))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431 (defun kotl-mode:forward-cell (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432 "Move to prefix ARGth following cell (same level) within current view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 Return number of cells left to move."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 (if (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 (kotl-mode:backward-cell (- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438 (let ((next (= arg 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 (label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 (while (and (> arg 0) (setq next (kcell-view:forward t label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 (setq arg (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 (if (or next (not (interactive-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443 arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 (error "(kotl-mode:forward-cell): No following cell at same level")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 (defun kotl-mode:forward-char (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447 "Move point forward ARG (or 1) characters and return point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 (or arg (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451 (if (>= arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 (while (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 (cond ((and (kotl-mode:eolp) (kotl-mode:last-line-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 (error "(kotl-mode:forward-char): End of buffer"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 ((kotl-mode:eocp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 (skip-chars-forward "\n\r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 (kotl-mode:start-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458 ((kotl-mode:eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459 (forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460 (kotl-mode:start-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 (t (forward-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462 (setq arg (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 (kotl-mode:backward-char (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 (defun kotl-mode:forward-paragraph (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467 "Move point forward until after the last character of the current paragraph.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 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
1469 Return point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1471 A line which `paragraph-start' matches either separates paragraphs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472 \(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
1473 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
1474 part of the paragraph, or the end of the buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476 (setq arg (prefix-numeric-value arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1477 zmacs-region-stays t);; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1478 (if (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480 (if (kotl-mode:bocp) (setq arg (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481 (while (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482 (start-of-paragraph-text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483 (setq arg (1+ arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484 (while (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485 (end-of-paragraph-text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486 (setq arg (1- arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487 (kotl-mode:to-valid-position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1489
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490 (fset 'kotl-mode:forward-para 'kotl-mode:forward-paragraph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 (defun kotl-mode:forward-sentence (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 "Move point forward ARG (or 1) sentences and return point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496 (let* ((label-sep-len (kview:label-separator-length kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497 ;; Setting fill prefix makes sentence commands properly recognize
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498 ;; indented paragraphs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 (fill-prefix (make-string (kcell-view:indent nil label-sep-len) ?\ )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500 (if (kotl-mode:eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 (error "(kotl-mode:forward-sentence): Last sentence")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 (if (kotl-mode:eocp) (kcell-view:next nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 (or arg (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505 (if (= arg 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 (narrow-to-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 (- (kcell-view:start nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508 (kcell-view:indent nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509 (kcell-view:end-contents)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 (let ((opoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512 (forward-sentence arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513 (if (= opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514 (progn (kcell-view:next nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515 (forward-sentence arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516 (kotl-mode:to-valid-position)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519 (defun kotl-mode:forward-word (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520 "Move point forward ARG (or 1) words and return point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 (or arg (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 (if (>= arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 (while (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526 (cond ((kotl-mode:eobp) (setq arg 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 ((kotl-mode:eocp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528 (skip-chars-forward "\n\r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529 (kotl-mode:start-of-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 (forward-word 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532 (kotl-mode:to-valid-position))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 ;; If point is at beginning of a cell after moving forward a word,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 ;; then we moved over something other than a word (some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535 ;; punctuation or an outline autonumber); therefore, leave counter as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536 ;; is in order to move forward over next word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537 (or (kotl-mode:bocp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538 (setq arg (1- arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539 (kotl-mode:backward-word (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1542 (defun kotl-mode:goto-cell (cell-ref &optional error-p)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 36
diff changeset
1543 "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
1544 Return point iff CELL-REF is found within current view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1545 With a prefix argument, CELL-REF is assigned the argument value for use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1546 as an idstamp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1547
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1548 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
1549 not found within current view. Will signal same error if called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1550 interactively when CELL-REF is not found."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1551 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552 (list (if current-prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553 (format "0%d" (prefix-numeric-value current-prefix-arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554 (read-string "Goto cell label or id: "))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555 (setq cell-ref
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1556 (or (kcell:ref-to-id cell-ref)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 36
diff changeset
1557 (error "(kotl-mode:goto-cell): Invalid cell reference, '%s'" cell-ref)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 (let* ((opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1559 (found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560 cell-id kvspec)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1561 (if (= ?| (aref cell-ref 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1562 ;; This is a standalone view spec, not a cell reference.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563 (progn (kvspec:activate cell-ref) (setq found (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1564
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1565 ;; !! Remove any relative specs and view specs from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1566 ;; cell-ref to form cell-id. Really should account for relative
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1567 ;; specs here, but we don't yet support them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1568 (if (string-match "\\(\\.[a-zA-Z]+\\)?\\([|:].*\\)\\|\\.[a-zA-Z]+"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1569 cell-ref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570 (setq cell-id (substring cell-ref 0 (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571 kvspec (if (match-beginning 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572 (substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573 cell-ref (match-beginning 2) (match-end 2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1574 (setq cell-id cell-ref kvspec nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1575
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1576 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1577 (cond ((= ?0 (aref cell-id 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1578 ;; is an idstamp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1579 (if (kview:goto-cell-id cell-id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 (setq found (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581 ;; is a label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582 ((re-search-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583 (format "\\([\n\r][\n\r]\\|\\`\\)[ ]*%s%s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584 (regexp-quote cell-id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585 (regexp-quote (kview:label-separator kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586 nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587 (setq found (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1588 ;; no match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589 (t (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591 (if (and (not found) (or error-p (interactive-p)))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 36
diff changeset
1592 (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
1593 ;; Activate any viewspec associated with cell-ref.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 (if kvspec (kvspec:activate kvspec))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595 found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 (defun kotl-mode:head-cell ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598 "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
1599 If at head cell already, do nothing and return nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602 (let ((moved)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1603 (label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 (while (kcell-view:backward t label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605 (setq moved t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606 moved))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608 (defun kotl-mode:last-sibling ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609 "Move point to the last sibling of the present cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610 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
1611 already within the last sibling cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614 (let ((label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615 (if (save-excursion (kcell-view:forward nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 ;; Enable user to return to this previous position if desired.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 (push-mark nil 'no-msg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618 (while (kcell-view:forward nil label-sep-len))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620 (defun kotl-mode:mark-paragraph ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621 "Put point at beginning of this paragraph, mark at end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622 The paragraph marked is the one that contains point or follows point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1623 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1624 (forward-paragraph 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1625 (kotl-mode:to-valid-position t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1626 (hypb:push-mark nil t t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627 (backward-paragraph 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628 (kotl-mode:to-valid-position))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1629
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630 (defun kotl-mode:mark-whole-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1631 "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
1632 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633 (hypb:push-mark (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634 (kotl-mode:end-of-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1635 (hypb:push-mark (point) nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1636 (kotl-mode:beginning-of-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1637
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1638 (defun kotl-mode:next-cell (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1639 "Move to prefix ARGth next cell (any level) within current view."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1640 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1641 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1642 (if (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643 (kotl-mode:previous-cell (- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1644 (let ((next (= arg 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1645 (label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1646 (while (and (> arg 0) (setq next (kcell-view:next t label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1647 (setq arg (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1648 (if next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649 arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650 (error "(kotl-mode:next-cell): Last cell")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1651
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652 (defun kotl-mode:next-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653 "Move point to ARGth next line and return point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1654 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1655 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1656 (kotl-mode:set-temp-goal-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1657 (let ((orig-arg arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658 (cond ((> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1659 (while (and (> arg 0) (= 0 (forward-line 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660 (cond ((kotl-mode:eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1662 (goto-char (kcell-view:end-contents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1663 (and (interactive-p) (= orig-arg arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1664 (message "(kotl-mode:next-line): Last line") (beep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665 (setq arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667 ((looking-at "^$");; blank line between cells
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668 nil);; Don't count this line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1669 (t (setq arg (1- arg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670 (kotl-mode:line-move 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1671 (kotl-mode:to-valid-position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1673 ((< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674 (kotl-mode:previous-line (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675 (t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676 (setq this-command 'next-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1677 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1678
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1679 (defun kotl-mode:next-tree ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1680 "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
1681 Return non-nil iff there is a next tree within this koutline."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1682 (let ((start-indent (kcell-view:indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1683 (label-sep-len (kview:label-separator-length kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1684 (same-tree t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1685 (while (and (kcell-view:next nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1686 (setq same-tree (< start-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1687 (kcell-view:indent nil label-sep-len)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1688 (not same-tree)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1689
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1690 (defun kotl-mode:previous-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1691 "Move point to ARGth previous line and return point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1692 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1693 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1694 (kotl-mode:set-temp-goal-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1695 (cond ((> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1696 (while (and (> arg 0) (= 0 (forward-line -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1697 (cond ((kotl-mode:bobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1698 (kotl-mode:beginning-of-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1699 (setq arg 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1700 ((looking-at "^$") ;; blank line between cells
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1701 nil) ;; Don't count this line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1702 (t (setq arg (1- arg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1703 (kotl-mode:line-move 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1704 (kotl-mode:to-valid-position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1705 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1706 ((< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1707 (kotl-mode:next-line (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1708 (t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1709 (setq this-command 'previous-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1710 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1711
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1712 (defun kotl-mode:previous-cell (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1713 "Move to prefix ARGth previous cell (any level) within current view."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1714 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1715 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1716 (if (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1717 (kotl-mode:next-cell (- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1718 (let ((previous (= arg 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1719 (label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1720 (while (and (> arg 0) (setq previous
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1721 (kcell-view:previous t label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1722 (setq arg (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1723 (if previous
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1724 arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1725 (error "(kotl-mode:previous-cell): First cell")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1726
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1727 (defun kotl-mode:scroll-down (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1728 "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
1729 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1730 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1731 (scroll-down arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1732 (kotl-mode:to-valid-position t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1733
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1734 (defun kotl-mode:scroll-up (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1735 "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
1736 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1737 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1738 (scroll-up arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1739 (kotl-mode:to-valid-position))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1740
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1741 (defun kotl-mode:tail-cell ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1742 "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
1743 If at tail cell already, do nothing and return nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1744 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1745 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1746 (let ((moved)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1747 (label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1748 (while (kcell-view:forward t label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1749 (setq moved t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1750 moved))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1751
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1752 (defun kotl-mode:up-level (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1753 "Move up prefix ARG levels higher in current outline view."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1754 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1755 (setq zmacs-region-stays t) ;; Maintain region highlight for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1756 (if (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1757 (kotl-mode:down-level (- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1758 ;; Enable user to return to this previous position if desired.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1759 (push-mark nil 'no-msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1760 (let ((parent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1761 (label-sep-len (kview:label-separator-length kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1762 result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1763 (while (and (> arg 0) (setq result (kcell-view:parent t label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1764 (or parent (setq parent result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1765 (setq arg (if (eq result 0) 0 (1- arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1766 ;; Signal an error if couldn't move up at least 1 parent level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1767 (or (and parent (not (eq parent 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1768 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1769 (goto-char (hypb:mark t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1770 (pop-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1771 (error "(kotl-mode:up-level): No parent level to which to move")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1772 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1773
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1774 ;;; ------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1775 ;;; Predicates
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1776 ;;; ------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1777
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1778 (defun kotl-mode:bobp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1779 "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
1780 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1781 (or (bobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1782 (and (not (save-excursion (re-search-backward "[\n\r]" nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1783 (kotl-mode:bolp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1784
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1785 (defun kotl-mode:bocp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1786 "Return point if at beginning of a kcell, else nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1787 (and (kotl-mode:bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1788 (let ((begin-point (kcell-view:plist-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1789 (bol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1790 (and begin-point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1791 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1792 ;; If first line-begin is less than cell begin point,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1793 ;; then we know we are on the first line of the cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1794 (if (setq bol (re-search-backward "^" nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1795 (<= bol begin-point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1796 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1797
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1798 (defun kotl-mode:bolp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1799 "Return point if at beginning of a kview line, else nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1800 (if (= (current-column) (kcell-view:indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1801 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1802
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1803 (defun kotl-mode:buffer-empty-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1804 "Return non-nil iff there are no outline cells within current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1805 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1806 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1807 (looking-at "[\n\r]*\\'")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1808
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1809 (defun kotl-mode:eobp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1810 "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
1811 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1812 (if (looking-at "^[\n\r]*\\'") (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1813
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1814 (defun kotl-mode:eocp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1815 "Return point if at the end of a kview cell, else nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1816 (or (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1817 (looking-at "[\n\r]+\\'")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1818 (and (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1819 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1820 (skip-chars-forward "\n\r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1821 (kotl-mode:start-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1822 (kotl-mode:bocp)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1823
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1824 (fset 'kotl-mode:eolp 'eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1825
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1826 (defun kotl-mode:first-cell-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1827 "Return t iff point is on the first cell of the outline."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1828 (save-excursion (not (kcell-view:previous))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1829
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1830 (fset 'kotl-mode:first-line-p 'first-line-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1831
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1832 (defun kotl-mode:last-cell-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1833 "Return t iff point is on the last cell of the outline."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1834 (save-excursion (not (kcell-view:next))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1835
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1836 (defun kotl-mode:last-line-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1837 "Return t iff point is on the last line of the outline."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1838 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1839 (kotl-mode:finish-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1840 (looking-at "\n*\\'")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1841
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1842 ;;; ------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1843 ;;; Smart Key Support
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1844 ;;; ------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1845
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1846
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1847 (defun kotl-mode:action-key ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1848 "Collapses, expands, links to, and scrolls through koutline cells.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1849 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
1850 already checked that the key was pressed in an appropriate buffer and has
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1851 moved the cursor to the selected buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1852
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1853 If key is pressed:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1854 (1) at the end of buffer, uncollapse and unhide all cells in view;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1855 (2) within a cell, if its subtree is hidden then show it,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1856 otherwise hide it;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1857 (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
1858 a cell, then move point to prior location and begin creation of a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1859 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
1860 link referent cell;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1861 (4) anywhere else, scroll up a windowful."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1862 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1863 (cond ((kotl-mode:eobp) (kotl-mode:show-all))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1864 ((kotl-mode:eolp) (smart-scroll-up))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1865 ((not (kview:valid-position-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1866 (if (markerp action-key-depress-prev-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1867 (progn (select-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1868 (get-buffer-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1869 (marker-buffer action-key-depress-prev-point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1870 (goto-char (marker-position action-key-depress-prev-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1871 (call-interactively 'klink:create))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1872 (kotl-mode:to-valid-position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1873 (error "(kotl-mode:action-key): Action Key released at invalid position")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1874 (t ;; On a cell line (not at the end of line).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1875 (if (smart-outline-subtree-hidden-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1876 (kotl-mode:show-tree (kcell-view:label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1877 (kotl-mode:hide-tree (kcell-view:label)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1878 (kotl-mode:to-valid-position))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1879
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1880 (defun kotl-mode:help-key ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1881 "Displays properties of koutline cells, collapses all cells, and scrolls back.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1882 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
1883 has already checked that the assist-key was pressed in an appropriate buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1884 and has moved the cursor to the selected buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1885
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1886 If assist-key is pressed:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1887 (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
1888 cells;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1889 (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
1890 each cell in tree beginning at point;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1891 (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
1892 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
1893 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
1894 tree to move and where to move it;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1895 (4) anywhere else, scroll down a windowful."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1896 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1897 (cond ((kotl-mode:eobp) (kotl-mode:overview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1898 ((kotl-mode:eolp) (smart-scroll-down))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1899 ((not (kview:valid-position-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1900 (if (markerp assist-key-depress-prev-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1901 (progn (select-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1902 (get-buffer-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1903 (marker-buffer assist-key-depress-prev-point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1904 (goto-char (marker-position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1905 assist-key-depress-prev-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1906 (call-interactively 'kotl-mode:move-after))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1907 (kotl-mode:to-valid-position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1908 (error "(kotl-mode:help-key): Help Key released at invalid position")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1909 ((not (bolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1910 ;; On an outline header line but not at the start/end of line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1911 ;; show attributes for tree at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1912 (kotl-mode:cell-help (kcell-view:label) (or current-prefix-arg 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1913 ((smart-scroll-down)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1914 (kotl-mode:to-valid-position))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1915
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1916 ;;; ------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1917 ;;; Structure Editing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1918 ;;; ------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1919
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1920 (defun kotl-mode:add-child ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1921 "Add a new cell to current kview as first child of current cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1922 (interactive "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1923 (kotl-mode:add-cell '(4)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1924
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1925 (defun kotl-mode:add-parent ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1926 "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
1927 (interactive "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1928 (kotl-mode:add-cell -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1929
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1930 (defun kotl-mode:add-cell (&optional relative-level contents plist no-fill)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1931 "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
1932
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1933 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
1934 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
1935 parent, otherwise. If added as sibling of current level, RELATIVE-LEVEL is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1936 used as a repeat count for the number of cells to add.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1937
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1938 Return last newly added cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1939 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1940 (or (stringp contents) (setq contents nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1941 (let ((klabel (kcell-view:label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1942 (label-sep-len (kview:label-separator-length kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1943 cell-level new-cell sibling-p child-p start parent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1944 cells-to-add)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1945 (setq cell-level (kcell-view:level nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1946 child-p (equal relative-level '(4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1947 sibling-p (and (not child-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1948 (cond ((not relative-level) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1949 ((>= (prefix-numeric-value relative-level) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1950 (prefix-numeric-value relative-level))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1951 cells-to-add (or sibling-p 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1952 (if child-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1953 (setq cell-level (1+ cell-level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1954 (if sibling-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1955 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1956 ;; Add as following sibling of current cell's parent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1957 ;; Move to parent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1958 (setq cell-level (1- cell-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1959 start (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1960 parent (kcell-view:parent nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1961 (if (not (eq parent t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1962 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1963 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1964 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1965 "(kotl-mode:add-cell): No higher level at which to add cell.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1966 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1967 ;; Skip from point past any children to next cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1968 (if (kotl-mode:next-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1969 ;; 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
1970 ;; new cell after it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1971 (kcell-view:previous nil label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1972 (goto-char (kcell-view:end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1973 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1974 ;; Insert new cells into view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1975 (if (= cells-to-add 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1976 (setq klabel
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1977 (cond (sibling-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1978 (klabel:increment klabel))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1979 (child-p (klabel:child klabel))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1980 ;; add as sibling of parent of current cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1981 (t (klabel:increment (klabel:parent klabel))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1982 new-cell (kview:add-cell klabel cell-level contents plist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1983 (or no-fill sibling-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1984 (not kotl-mode:refill-flag))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1985 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1986 ;; 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
1987 ;; conditionalize how to increment the labels.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1988 (while (>= (setq cells-to-add (1- cells-to-add)) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1989 (setq klabel (klabel:increment klabel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1990 ;; 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
1991 ;; any of their intial contents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1992 new-cell (kview:add-cell klabel cell-level contents plist t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1993 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1994 ;; Move back to last inserted cell and then move to its following
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1995 ;; sibling if any.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1996 (kotl-mode:to-valid-position t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1997 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1998 (if (kcell-view:forward t label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1999 ;; Update the labels of these siblings and their subtrees.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2000 (klabel-type:update-labels (klabel:increment klabel))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2001 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2002 ;; Leave point within last newly added cell and return this cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2003 (kotl-mode:beginning-of-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2004 new-cell))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2005
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2006 (defun kotl-mode:demote-tree (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2007 "Move current tree a maximum of prefix ARG levels lower in current view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2008 Each cell is refilled iff its `no-fill' attribute is nil and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2009 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
2010 to one level and kotl-mode:refill-flag is treated as true."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2011 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2012 (if (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2013 (kotl-mode:promote-tree (- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2014 (let* ((label-sep-len (kview:label-separator-length kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2015 (orig-level (kcell-view:level nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2016 (orig-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2017 (orig-id (kcell-view:idstamp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2018 (fill-p (= arg 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2019 (orig-pos-in-cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2020 (- (point) (kcell-view:start nil label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2021 prev prev-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2022 (if fill-p (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2023 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2024 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2025 (backward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2026 (while (and (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2027 (setq prev
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2028 (kcell-view:previous nil label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2029 (if prev
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2030 (progn (setq prev-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2031 (kcell-view:level nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2032 (cond ((> prev-level (+ orig-level arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2033 ;; Don't want to demote this far
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2034 ;; so keep looking at prior nodes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2035 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2036 ((= arg (- prev-level orig-level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2037 ;; Demote to be sibling of this kcell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2038 (setq arg -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2039 ((< prev-level orig-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2040 ;; prev is at higher level then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2041 ;; orig, so can't demote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2042 (setq prev nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2043 arg 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2044 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2045 ;; Demote below this kcell. This is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2046 ;; as far we can demote, though it may
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2047 ;; not be the full amount of arg.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2048 (setq arg 0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2049 (if prev
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2050 (kotl-mode:move-after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2051 (kcell-view:label orig-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2052 (kcell-view:label) (= arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2053 nil fill-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2054 ;; Move to start of original cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2055 (kotl-mode:goto-cell orig-id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2056 ;; Move to original pos within cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2057 (forward-char orig-pos-in-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2058 (kotl-mode:to-valid-position))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2059 (if (not prev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2060 (error "(kotl-mode:demote-tree): Cannot demote any further")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2061
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2062 (defun kotl-mode:exchange-cells (cell-ref-1 cell-ref-2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2063 "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
2064 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2065 (let ((hargs:defaults
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2066 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2067 (list (kcell-view:label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2068 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2069 ((kcell-view:previous t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2070 (kcell-view:label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2071 ((kcell-view:next 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 (t (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2074 "(kotl-mode:exchange-cells): No 2 visible cells")))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2075 (hargs:iform-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2076 '(interactive "*+KExchange cell: \n+KExchange cell <%s> with cell: "))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2077 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2078 (let (kcell-1 contents-1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2079 kcell-2 contents-2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2080 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2081 ;; Save cell-1 attributes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2082 (kotl-mode:goto-cell cell-ref-1 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2083 (setq kcell-1 (kcell-view:cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2084 contents-1 (kcell-view:contents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2085 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2086 ;; Save cell-2 attributes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2087 (kotl-mode:goto-cell cell-ref-2 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2088 (setq kcell-2 (kcell-view:cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2089 contents-2 (kcell-view:contents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2090 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2091 ;; Substitute cell-1 attributes into cell-2 location.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2092 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2093 ;; Set kcell properties.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2094 (kcell-view:set-cell kcell-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2095 ;; If idstamp labels are on, then must exchange labels in view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2096 (if (eq (kview:label-type kview) 'id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2097 (klabel:set (kcell-view:idstamp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2098 ;; Exchange cell contents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2099 (delete-region (kcell-view:start) (kcell-view:end-contents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2100 (insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2101 (hypb:replace-match-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2102 "\\([\n\r]\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2103 contents-1 (concat "\\1" (make-string (kcell-view:indent) ?\ ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2104 (if kotl-mode:refill-flag (kotl-mode:fill-cell))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2105 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2106 ;; Substitute cell-2 attributes into cell-1 location.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2107 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2108 ;; Set kcell properties.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2109 (kotl-mode:goto-cell cell-ref-1 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2110 (kcell-view:set-cell kcell-2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2111 ;; If idstamp labels are on, then must exchange labels in view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2112 (if (eq (kview:label-type kview) 'id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2113 (klabel:set (kcell-view:idstamp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2114 ;; Exchange cell contents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2115 (delete-region (kcell-view:start) (kcell-view:end-contents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2116 ;; Add indentation to all but first line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2117 (insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2118 (hypb:replace-match-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2119 "\\([\n\r]\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2120 contents-2 (concat "\\1" (make-string (kcell-view:indent) ?\ ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2121 (if kotl-mode:refill-flag (kotl-mode:fill-cell)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2123 (defun kotl-mode:kill-contents (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2124 "Kill contents of cell from point to cell end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2125 With prefix ARG, kill entire cell contents."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2126 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2127 (kotl-mode:kill-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2128 (if arg (kcell-view:start) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2129 (kcell-view:end-contents)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2131 (defun kotl-mode:kill-tree (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2132 "Kill ARG following trees starting with tree rooted at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2133 If ARG is not a non-positive number, nothing is done."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2134 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2135 (or (integerp arg) (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2136 (let ((killed) (label (kcell-view:label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2137 (label-sep-len (kview:label-separator-length kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2138 start end sib)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2139 (while (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2140 (setq start (kotl-mode:tree-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2141 end (kotl-mode:tree-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2142 sib (kcell-view:sibling-p nil nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2143 arg (1- arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2144 killed t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2145 ;; 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
2146 ;; this is the last one killed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2147 (if (kotl-mode:last-cell-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2148 (progn (setq arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2149 (kview:delete-region start end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2150 (kview:delete-region start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2151 (kotl-mode:to-valid-position)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2152 (if killed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2153 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2154 (cond (sib (klabel-type:update-labels label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2155 ((kotl-mode:buffer-empty-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2156 ;; Always leave at least 1 visible cell within a view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2157 (kview:add-cell "1" 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2158 (kotl-mode:to-valid-position)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2160 (defun kotl-mode:mail-tree (cell-ref invisible-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2161 "Mail outline tree rooted at CELL-REF. Use \"0\" for whole outline buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2162 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
2163 non-nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2164 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2165 (let ((label-default (kcell-view:label)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2166 (hargs:iform-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2167 '(interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2168 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2169 (hargs:read "Mail tree: (0 for whole outline) "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2170 nil label-default nil 'kcell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2171 (y-or-n-p "Include invisible text? "))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2172 (if (equal cell-ref "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2173 (hmail:buffer nil invisible-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2174 (let (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2175 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2176 (kotl-mode:goto-cell cell-ref t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2177 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2178 (setq start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2179 (or (= (kotl-mode:forward-cell 1) 0) (goto-char (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2180 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2181 (setq end (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2182 (hmail:region start end nil invisible-flag))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2184 (defun kotl-mode:promote-tree (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2185 "Move current tree a maximum of prefix ARG levels higher in current view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2186 Each cell is refilled iff its `no-fill' attribute is nil and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2187 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
2188 to one level and kotl-mode:refill-flag is treated as true."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2189 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2190 (if (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2191 (kotl-mode:demote-tree (- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2192 (let* ((parent) (result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2193 (label-sep-len (kview:label-separator-length kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2194 (orig-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2195 (orig-id (kcell-view:idstamp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2196 (fill-p (= arg 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2197 (orig-pos-in-cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2198 (- (point) (kcell-view:start nil label-sep-len))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2199 (if fill-p (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2200 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2201 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2202 (backward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2203 (while (and (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2204 (setq result (kcell-view:parent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2205 nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2206 (not (eq result 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2207 (setq parent result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2208 arg (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2209 (if parent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2210 (kotl-mode:move-after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2211 (kcell-view:label orig-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2212 (kcell-view:label) nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2213 nil fill-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2214 ;; Move to start of original cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2215 (kotl-mode:goto-cell orig-id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2216 ;; Move to original pos within cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2217 (forward-char orig-pos-in-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2218 (kotl-mode:to-valid-position))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2219 (if (not parent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2220 (error "(kotl-mode:promote-tree): Cannot promote any further")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2222 (defun kotl-mode:set-cell-attribute (attribute value &optional pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2223 "Include ATTRIBUTE VALUE with the current cell or the cell at optional POS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2224 Replaces any existing value that ATTRIBUTE has.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2225 When called interactively, it displays the setting in the minibuffer as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2226 confirmation."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2227 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2228 (let* ((plist (copy-sequence (kcell-view:plist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2229 (existing-attributes plist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2230 attribute value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2231 (barf-if-buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2232 ;; Remove attribute values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2233 (while plist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2234 (setcdr plist (cdr (cdr plist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2235 (setq plist (cdr plist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2236 ;; Remove read-only attributes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2237 (setq existing-attributes (set:create existing-attributes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2238 existing-attributes (set:difference
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2239 existing-attributes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2240 kcell:read-only-attributes))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2242 (while (zerop (length (setq attribute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2243 (completing-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2244 "Current cell attribute to set: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2245 (mapcar 'list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2246 (mapcar 'symbol-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2247 existing-attributes))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2248 (beep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2249 (setq attribute (intern attribute)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2250 value (kcell-view:get-attr attribute))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2251 (if value
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 36
diff changeset
2252 (setq value (read-expression
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2253 (format "Change value of \"%s\" to: " attribute)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2254 (prin1-to-string value)))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 36
diff changeset
2255 (setq value (read-expression
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2256 (format "Set value of \"%s\" to: " attribute))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2257 (list attribute value nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2258 (kcell-view:set-attr attribute value pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2259 ;; Note that buffer needs to be saved to store new attribute value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2260 (set-buffer-modified-p t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2261 (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2262 (message "Attribute \"%s\" set to `%s' in cell <%s>."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2263 attribute value (kcell-view:label pos))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2265 (defun kotl-mode:split-cell (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2266 "Split the current cell into two cells and move to the new cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2267 The cell contents after point become part of the newly created cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2268 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
2269 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
2270 the current cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2271 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2272 (let ((new-cell-contents (kotl-mode:kill-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2273 (point) (kcell-view:end-contents) 'string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2274 (start (kcell-view:start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2275 ;; delete any preceding whitespace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2276 (skip-chars-backward " \t\n\r" start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2277 (delete-region (max start (point)) (kcell-view:end-contents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2278 (kotl-mode:add-cell arg new-cell-contents (kcell-view:plist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2279
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2280 (defun kotl-mode:transpose-cells (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2281 "Exchange current and previous visible cells, leaving point after both.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2282 If no previous cell, exchange current with next cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2283 With prefix ARG, take current tree and move it past ARG visible cells.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2284 With prefix ARG = 0, interchange the cell that contains point with the cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2285 that contains mark."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2286 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2287 (let ((label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2288 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2289 ((save-excursion (not (or (kcell-view:next t label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2290 (kcell-view:previous t label-sep-len))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2291 (error "(kotl-mode:transpose-cells): Only one visible cell in outline"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2292 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2293 ;; Transpose current and previous cells or current and next cells, if no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2294 ;; previous cell. Leave point after both exchanged cells or within last
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2295 ;; visible cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2296 ((= arg 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2297 (let ((label-1 (kcell-view:label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2298 (prev (kcell-view:previous t label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2299 label-2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2300 (or prev (kcell-view:next t label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2301 (setq label-2 (kcell-view:label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2302 (kotl-mode:exchange-cells label-1 label-2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2303 (kcell-view:next t label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2304 (if prev (kcell-view:next t label-sep-len))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2305 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2306 ;; Transpose point and mark cells, moving point to the new location of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2307 ;; cell which originally contained point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2308 ((= arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2309 (let ((label-1 (kcell-view:label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2310 label-2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2311 ;; This is like exchange-point-and-mark, but doesn't activate the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2312 ;; mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2313 (goto-char (prog1 (hypb:mark t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2314 (set-marker (hypb:mark-marker t) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2315 (setq label-2 (kcell-view:label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2316 (kotl-mode:exchange-cells label-1 label-2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2317 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2318 ;; Move current tree past ARG next visible cells and leave point after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2319 ;; original cell text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2320 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2321 (let ((mark (set-marker (make-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2322 (save-excursion (kotl-mode:next-line arg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2323 (kotl-mode:move-after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2324 (kcell-view:label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2325 (progn (while (and (> arg 0) (kcell-view:next t label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2326 (setq arg (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2327 (kcell-view:label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2328 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2329 (goto-char mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2330 (set-marker mark nil))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2331
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2332 ;;; ------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2333 ;;; Structure Viewing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2334 ;;; ------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2336 (defun kotl-mode:collapse-tree (&optional all-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2337 "Collapse to one line each visible cell of tree rooted at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2338 With optional ALL-FLAG non-nil, collapse all cells visible within the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2339 view."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2340 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2341 (kotl-mode:is-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2342 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2343 (if all-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2344 (progn (kvspec:show-lines-per-cell 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2345 (kvspec:update t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2346 (kview:map-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2347 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2348 (lambda (kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2349 ;; Use free variable label-sep-len bound in kview:map-tree for speed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2350 (goto-char (kcell-view:start nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2351 (subst-char-in-region (point) (kcell-view:end-contents) ?\n ?\r t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2352 kview nil t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2354 (defun kotl-mode:expand-tree (&optional all-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2355 "Expand each visible cell of tree rooted at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2356 With optional ALL-FLAG non-nil, expand all cells visible within the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2357 view."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2358 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2359 (kotl-mode:is-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2360 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2361 (if all-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2362 (progn (kvspec:show-lines-per-cell 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2363 (kvspec:update t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2364 (kview:map-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2365 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2366 (lambda (kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2367 ;; Use free variable label-sep-len bound in kview:map-tree for speed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2368 (goto-char (kcell-view:start nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2369 (subst-char-in-region (point) (kcell-view:end-contents) ?\r ?\n t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2370 kview nil t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2372 (defun kotl-mode:toggle-tree-expansion (&optional all-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2373 "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
2374 If current cell is collapsed, cells will be expanded, otherwise they will be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2375 collapsed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2376 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2377 (if (kcell-view:collapsed-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2378 ;; expand cells
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2379 (kotl-mode:expand-tree all-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2380 (kotl-mode:collapse-tree all-flag)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2381
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2382 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2383 (defun kotl-mode:overview ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2384 "Show the first line of each cell without blank line separators."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2385 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2386 (kotl-mode:show-all)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2387 (if (string-match "b" kvspec:current)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2388 (kvspec:toggle-blank-lines))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2389 (kotl-mode:collapse-tree t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2390
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2391 (defun kotl-mode:show-all ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2392 "Show (expand) all cells in current view."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2393 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2394 (if (kotl-mode:is-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2395 (progn (kview:set-attr kview 'levels-to-show 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2396 (kview:set-attr kview 'lines-to-show 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2397 (show-all)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2398 (kvspec:update t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2399
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2400 (defun kotl-mode:top-cells ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2401 "Collapse all level 1 cells in view and hide any deeper sublevels."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2402 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2403 (kotl-mode:is-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2404 (let ((modified-p (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2405 (buffer-read-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2406 (kvspec:levels-to-show 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2407 (kvspec:show-lines-per-cell 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2408 (kvspec:update t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2409 ;; Restore buffer modification status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2410 (set-buffer-modified-p modified-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2412 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2413 (defun kotl-mode:hide-sublevels (levels-to-keep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2414 "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
2415 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
2416 display all levels of cells."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2417 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2418 (kvspec:levels-to-show levels-to-keep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2419 ;; The prior call might have shown more lines per cell than the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2420 ;; viewspec supports, so reset lines per cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2421 (kvspec:lines-to-show)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2422 (kvspec:update t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2423
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2424 (defun kotl-mode:hide-subtree (&optional cell-ref show-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2425 "Hide subtree, ignoring root, at optional CELL-REF (defaults to cell at point)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2426 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2427 (kotl-mode:is-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2428 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2429 (if cell-ref
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2430 (kotl-mode:goto-cell cell-ref t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2431 (kotl-mode:beginning-of-cell))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2432 (let ((start (kcell-view:end-contents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2433 (end (kotl-mode:tree-end t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2434 (buffer-read-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2435 (if show-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2436 (subst-char-in-region start end ?\r ?\n t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2437 (subst-char-in-region start end ?\n ?\r t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2438
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2439 (defun kotl-mode:show-subtree (&optional cell-ref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2440 "Show subtree, ignoring root, at optional CELL-REF (defaults to cell at point)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2441 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2442 (kotl-mode:hide-subtree cell-ref t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2444 (defun kotl-mode:hide-tree (&optional cell-ref show-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2445 "Collapse tree rooted at optional CELL-REF (defaults to cell at point)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2446 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2447 (kotl-mode:is-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2448 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2449 (let ((start (if cell-ref
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2450 (kotl-mode:goto-cell cell-ref t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2451 (kotl-mode:beginning-of-cell)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2452 (end (kotl-mode:tree-end t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2453 (buffer-read-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2454 (if show-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2455 (subst-char-in-region start end ?\r ?\n t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2456 (subst-char-in-region start end ?\n ?\r t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2458 (defun kotl-mode:show-tree (&optional cell-ref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2459 "Display fully expanded tree rooted at CELL-REF."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2460 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2461 (kotl-mode:hide-tree cell-ref t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2462
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2463 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2464 (defun kotl-mode:cell-attributes (all-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2465 "Display a temporary buffer with the attributes of the current kcell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2466 With prefix arg ALL-FLAG non-nil, display the attributes of all visible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2467 kcells in the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2468
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2469 See also the documentation for `kotl-mode:cell-help'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2470 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2471 (with-output-to-temp-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2472 (hypb:help-buf-name "Kotl")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2473 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2474 (if (not all-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2475 (kotl-mode:print-attributes kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2476 (let ((label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2477 (kotl-mode:beginning-of-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2478 (while (progn (kotl-mode:print-attributes kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2479 (kcell-view:next t label-sep-len))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2480
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2481 (defun kotl-mode:cell-help (&optional cell-ref cells-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2482 "Display a temporary buffer with CELL-REF's attributes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2483 CELL-REF defaults to current cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2484 Optional prefix arg CELLS-FLAG selects the cells to print:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2485 If = 1, print CELL-REF's cell only;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2486 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
2487 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
2488
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2489 See also the documentation for `kotl-mode:cell-attributes'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2490 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2491 (let* ((label (kcell-view:label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2492 (hargs:defaults (list label label)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2493 (append
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2494 (let ((arg (prefix-numeric-value current-prefix-arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2495 (if (< arg 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2496 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2497 (hargs:iform-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2498 (list 'interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2499 (format "+KDisplay properties of koutline %s: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2500 (if (= arg 1) "cell" "tree"))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2501 (list current-prefix-arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2502 (or (integerp cells-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2503 (setq cells-flag (prefix-numeric-value cells-flag)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2504 (or (stringp cell-ref) (setq cell-ref (kcell-view:label)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2505 (with-output-to-temp-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2506 (hypb:help-buf-name "Koutline")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2507 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2508 (if (equal cell-ref "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2509 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2510 (hattr:report (kcell:plist (kview:top-cell kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2511 (terpri)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2512 (cond ((= cells-flag 1) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2513 ((> cells-flag 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2514 (kview:map-tree 'kotl-mode:print-attributes kview t t))
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 (t (kotl-mode:cell-attributes t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2517 (cond ((= cells-flag 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2518 (kotl-mode:goto-cell cell-ref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2519 (kotl-mode:print-attributes kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2520 ((> cells-flag 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2521 (kotl-mode:goto-cell cell-ref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2522 (kview:map-tree 'kotl-mode:print-attributes kview nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2523 ;; (< cells-flag 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2524 (t (kotl-mode:cell-attributes t)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2525
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2526 (defun kotl-mode:get-cell-attribute (attribute &optional pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2527 "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
2528 When called interactively, it displays the value in the minibuffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2529 (interactive "SCurrent cell attribute to get: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2530 (let ((value (kcell-view:get-attr attribute pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2531 (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2532 (message "Attribute \"%s\" = `%s' in cell <%s>."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2533 attribute value (kcell-view:label pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2534 value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2535
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2536 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2537 ;;; Private functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2538 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2539
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2540 (defun kotl-mode:add-indent-to-region (&optional indent start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2541 "Add current cell's indent to current region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2542 Optionally, INDENT and region START and END may be given."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2543 (or (integerp indent) (setq indent (kcell-view:indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2544 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2545 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2546 (narrow-to-region (or start (point)) (or end (hypb:mark t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2547 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2548 (replace-regexp "\n" (concat "\n" (make-string indent ?\ ))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2549
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2550 (defun kotl-mode:delete-line (&optional pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2551 "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
2552 Does not delete newline at end of line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2553 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2554 (if pos (goto-char pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2555 (if (kview:valid-position-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2556 (let ((bol (kotl-mode:start-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2557 (eol (kotl-mode:finish-of-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2558 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2559 (buffer-substring bol eol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2560 (delete-region bol eol)))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 36
diff changeset
2561 (error "(kotl-mode:delete-line): Invalid position, '%d'" (point)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2562
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2563 (defun kotl-mode:indent-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2564 ;; Disallow the indent-line command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2565 (error "(kotl-mode:indent-line): Insert spaces to indent each line."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2566
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2567 (defun kotl-mode:indent-region (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2568 ;; User might try to indent across cells. This would be bad, so disallow
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2569 ;; the indent-region command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2570 (error "(kotl-mode:indent-region): Insert spaces to indent each line."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2571
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2572 (defun kotl-mode:is-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2573 "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
2574 (if (kview:is-p kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2575 t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2576 (hypb:error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2577 "(kotl-mode:is-p): Command requires a current Hyperbole outline.")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2578
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2579 (defun kotl-mode:tree-end (&optional omit-end-newlines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2580 "Return end point of current cell's tree within this view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2581 If optional OMIT-END-NEWLINES is non-nil, point returned precedes any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2582 newlines at end of tree."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2583 (let* ((label-sep-len (kview:label-separator-length kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2584 (start-indent (kcell-view:indent nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2585 (next))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2586 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2587 (while (and (setq next (kcell-view:next nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2588 (< start-indent (kcell-view:indent nil label-sep-len))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2589 (cond (next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2590 (goto-char (progn (kcell-view:previous nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2591 (kcell-view:end))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2592 ;; Avoid skipping too far at end of file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2593 ((re-search-forward "[\n\r][\n\r]" nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2594 (t (goto-char (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2595 (if omit-end-newlines (skip-chars-backward "\n\r"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2596 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2597
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2598 (defun kotl-mode:tree-start ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2599 "Return beginning of line position preceding current cell's start point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2600 (save-excursion (goto-char (kcell-view:start)) (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2601 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2602
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2603 (defun kotl-mode:line-move (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2604 "Move point ARG visible lines forward within an outline."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2605 (if (not (integerp selective-display))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2606 (forward-line arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2607 ;; Move by arg lines, but ignore invisible ones.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2608 (while (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2609 (vertical-motion 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2610 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2611 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2612 (setq arg (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2613 (while (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2614 (vertical-motion -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2615 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2616 (setq arg (1+ arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2617 (move-to-column (or goal-column temporary-goal-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2618 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2619
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2620 (defun kotl-mode:print-attributes (kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2621 "Print to the `standard-output' stream the attributes of the current visible kcell.
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 36
diff changeset
2622 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
2623 KVIEW is bound correctly) but always operates upon the current view."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2624 ;; Move to start of visible cell to avoid printing attributes for an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2625 ;; invisible kcell which point may be over.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2626 ;; Print first line of cell for reference.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2627 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2628 (princ
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2629 (buffer-substring (progn (beginning-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2630 (progn (kview:end-of-actual-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2631 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2632 (terpri)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2633 (hattr:report (kcell:plist (kcell-view:cell)))
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2636 (defun kotl-mode:set-temp-goal-column ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2637 (if (not (or (eq last-command 'next-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2638 (eq last-command 'previous-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2639 (setq temporary-goal-column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2640 (if (and track-eol (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2641 ;; Don't count beg of empty line as end of line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2642 ;; unless we just did explicit end-of-line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2643 (or (not (bolp)) (eq last-command 'end-of-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2644 9999
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2645 (current-column)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2646
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2647 (defun kotl-mode:to-valid-position (&optional backward-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2648 "Move point to the nearest non-read-only position within current koutline view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2649 With optional BACKWARD-P, move backward if possible to get to valid position."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2650 (if (kview:valid-position-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2651 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2652 (let ((label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2653 (cond ((kotl-mode:bobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2654 (goto-char (kcell-view:start nil label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2655 ((kotl-mode:eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2656 (skip-chars-backward "\n\r"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2657 (t (let ((indent (kcell-view:indent nil label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2658 (if (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2659 (if backward-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2660 (skip-chars-backward "\n\r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2661 (skip-chars-forward "\n\r")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2662 (setq indent (kcell-view:indent nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2663 (if (< (current-column) indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2664 (move-to-column indent))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2665
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2666 (defun kotl-mode:transpose-lines-internal (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2667 "Transpose lines at START and END markers within an outline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2668 Leave point at end of line now residing at START."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2669 (if (and start end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2670 (kview:valid-position-p start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2671 (kview:valid-position-p end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2672 (let* ((pline (kotl-mode:delete-line start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2673 mline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2674 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2675 (setq mline (kotl-mode:delete-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2676 (insert pline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2677 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2678 (insert mline))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2679 ;; Set non-point and non-mark markers to point nowhere before signalling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2680 ;; an error.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2681 (or (eq start (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2682 (eq start (hypb:mark-marker t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2683 (set-marker start nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2684 (or (eq end (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2685 (eq end (hypb:mark-marker t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2686 (set-marker start nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2687 (error "(kotl-mode:transpose-lines): Point or mark is at an invalid position")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2688
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2689 (defun kotl-mode:update-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2690 "Update current view buffer in preparation for saving."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2691 (if (kview:is-p kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2692 (let ((mod-p (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2693 (start (window-start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2694 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2695 (kfile:update)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2696 (set-buffer-modified-p mod-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2697 (set-window-start nil (max (point-min) start) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2698 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2699
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2700 ;;; ------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2701
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2702 (defvar kotl-mode-map nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2703 "Keymap containing koutliner editing and viewing commands.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2704 (if kotl-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2705 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2706 (setq kotl-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2707 (if (string-match "XEmacs\\|Lucid" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2708 (make-keymap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2709 (copy-keymap indented-text-mode-map)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2710 ;; Overload edit keys to deal with structure and labels.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2711 (let (local-cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2712 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2713 (if (string-match "XEmacs\\|Lucid" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2714 ;; XEmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2715 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2716 (lambda (cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2717 (setq local-cmd (intern-soft
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2718 (concat "kotl-mode:" (symbol-name cmd))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2719 ;; Only bind key locally if kotl-mode local-cmd has already
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2720 ;; been defined and cmd is a valid function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2721 (if (and local-cmd (fboundp cmd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2722 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2723 ;; Make local-cmd have the same property list as cmd,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2724 ;; e.g. so pending-delete property is the same.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2725 (setplist local-cmd (symbol-plist cmd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2726 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2727 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2728 (lambda (key) (define-key kotl-mode-map key local-cmd)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2729 (where-is-internal cmd))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2730 ;; GNU Emacs 19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2731 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2732 (lambda (cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2733 (setq local-cmd (intern-soft
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2734 (concat "kotl-mode:" (symbol-name cmd))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2735 ;; Only bind key locally if kotl-mode local-cmd has already
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2736 ;; been defined and cmd is a valid function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2737 (if (and local-cmd (fboundp cmd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2738 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2739 ;; Make local-cmd have the same property list as cmd,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2740 ;; e.g. so pending-delete property is the same.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2741 (setplist local-cmd (symbol-plist cmd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2742 (substitute-key-definition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2743 cmd local-cmd kotl-mode-map global-map))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2744 '(
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2745 back-to-indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2746 backward-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2747 backward-delete-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2748 backward-delete-char-untabify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2749 backward-kill-word
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2750 backward-para
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2751 backward-paragraph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2752 backward-sentence
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2753 backward-word
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2754 beginning-of-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2755 beginning-of-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2756 copy-region-as-kill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2757 copy-to-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2758 delete-blank-lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2759 delete-backward-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2760 delete-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2761 delete-horizontal-space
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2762 delete-indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2763 end-of-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2764 end-of-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2765 fill-paragraph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2766 fill-paragraph-or-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2767 ;; cursor keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2768 fkey-backward-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2769 fkey-forward-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2770 fkey-next-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2771 fkey-previous-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2772 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2773 forward-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2774 forward-word
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2775 forward-para
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2776 forward-paragraph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2777 forward-sentence
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2778 insert-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2779 insert-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2780 insert-register
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2781 just-one-space
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2782 kill-word
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2783 kill-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2784 kill-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2785 kill-ring-save
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2786 kill-sentence
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2787 mark-paragraph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2788 mark-whole-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2789 newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2790 newline-and-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2791 next-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2792 open-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2793 previous-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2794 scroll-down
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2795 scroll-up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2796 set-fill-prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2797 transpose-chars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2798 transpose-lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2799 transpose-paragraphs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2800 transpose-sentences
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2801 transpose-words
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2802 yank
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2803 yank-pop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2804 zap-to-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2805 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2806
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2807
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2808 ;; kotl-mode keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2809 (define-key kotl-mode-map "\C-c@" 'kotl-mode:mail-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2810 (define-key kotl-mode-map "\C-c+" 'kotl-mode:append-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2811 (define-key kotl-mode-map "\C-c," 'kotl-mode:beginning-of-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2812 (define-key kotl-mode-map "\C-c." 'kotl-mode:end-of-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2813 (define-key kotl-mode-map "\C-c<" 'kotl-mode:first-sibling)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2814 (define-key kotl-mode-map "\C-c>" 'kotl-mode:last-sibling)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2815 (define-key kotl-mode-map "\C-c^" 'kotl-mode:beginning-of-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2816 (define-key kotl-mode-map "\C-c$" 'kotl-mode:end-of-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2817 (define-key kotl-mode-map "\C-ca" 'kotl-mode:add-child)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2818 (define-key kotl-mode-map "\C-c\C-a" 'kotl-mode:show-all)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2819 (define-key kotl-mode-map "\C-cb" 'kvspec:toggle-blank-lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2820 (define-key kotl-mode-map "\C-c\C-b" 'kotl-mode:backward-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2821 (define-key kotl-mode-map "\C-cc" 'kotl-mode:copy-after)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2822 (define-key kotl-mode-map "\C-c\C-c" 'kotl-mode:copy-before)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2823 (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
2824 (define-key kotl-mode-map "\C-cd" 'kotl-mode:down-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2825 (define-key kotl-mode-map "\C-c\C-d" 'kotl-mode:down-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2826 (define-key kotl-mode-map "\C-ce" 'kotl-mode:exchange-cells)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2827 (define-key kotl-mode-map "\C-c\C-f" 'kotl-mode:forward-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2828 (define-key kotl-mode-map "\C-cg" 'kotl-mode:goto-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2829 (define-key kotl-mode-map "\C-ch" 'kotl-mode:cell-help)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2830 (define-key kotl-mode-map "\C-c\C-h" 'kotl-mode:hide-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2831 (define-key kotl-mode-map "\M-\C-h" 'kotl-mode:hide-subtree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2832 ;; Override this global binding for set-selective-display with a similar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2833 ;; function appropriate for kotl-mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2834 (define-key kotl-mode-map "\C-x$" 'kotl-mode:hide-sublevels)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2835 (define-key kotl-mode-map "\C-i" 'kotl-mode:demote-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2836 (define-key kotl-mode-map "\M-\C-i" 'kotl-mode:promote-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2837 (define-key kotl-mode-map "\C-j" 'kotl-mode:add-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2838 (define-key kotl-mode-map "\M-j" 'kotl-mode:fill-paragraph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2839 (define-key kotl-mode-map "\C-c\M-j" 'kotl-mode:fill-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2840 (define-key kotl-mode-map "\M-\C-j" 'kotl-mode:fill-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2841 (define-key kotl-mode-map "\C-c\C-k" 'kotl-mode:kill-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2842 (define-key kotl-mode-map "\C-ck" 'kotl-mode:kill-contents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2843 (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
2844 (define-key kotl-mode-map "\C-cl" 'klink:create)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2845 (define-key kotl-mode-map "\C-c\C-l" 'kview:set-label-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2846 (define-key kotl-mode-map "\C-c\M-l" 'kview:set-label-separator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2847 (define-key kotl-mode-map "\C-m" 'kotl-mode:newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2848 (define-key kotl-mode-map "\C-cm" 'kotl-mode:move-after)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2849 (define-key kotl-mode-map "\C-c\C-m" 'kotl-mode:move-before)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2850 (define-key kotl-mode-map "\C-c\C-n" 'kotl-mode:next-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2851 (define-key kotl-mode-map "\C-c\C-o" 'kotl-mode:overview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2852 (define-key kotl-mode-map "\C-c\C-p" 'kotl-mode:previous-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2853 (define-key kotl-mode-map "\C-cp" 'kotl-mode:add-parent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2854 (if (memq (global-key-binding "\M-q") '(fill-paragraph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2855 fill-paragraph-or-region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2856 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2857 (define-key kotl-mode-map "\C-c\M-q" 'kotl-mode:fill-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2858 (define-key kotl-mode-map "\M-\C-q" 'kotl-mode:fill-tree)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2859 (define-key kotl-mode-map "\C-cs" 'kotl-mode:split-cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2860 (define-key kotl-mode-map "\C-c\C-s" 'kotl-mode:show-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2861 (define-key kotl-mode-map "\C-c\C-\\" 'kotl-mode:show-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2862 (define-key kotl-mode-map "\M-s" 'kotl-mode:center-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2863 (define-key kotl-mode-map "\M-S" 'kotl-mode:center-paragraph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2864 (define-key kotl-mode-map "\C-ct" 'kotl-mode:transpose-cells)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2865 (define-key kotl-mode-map "\C-c\C-t" 'kotl-mode:top-cells)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2866 (define-key kotl-mode-map "\C-cu" 'kotl-mode:up-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2867 (define-key kotl-mode-map "\C-c\C-u" 'kotl-mode:up-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2868 (define-key kotl-mode-map "\C-c\C-v" 'kvspec:activate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2869 (define-key kotl-mode-map "\C-x\C-w" 'kfile:write))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2870
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2871 (provide 'kotl-mode)