annotate lisp/hyperbole/kotl/kview.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children c53a95d3c46d
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: kview.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; SUMMARY: Display handling of koutlines.
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: 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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; LAST-MOD: 2-Nov-95 at 00:52:52 by Bob Weiner
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;; Other required Lisp Libraries
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 (mapcar 'require '(klabel kfill hypb))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;;; Public variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 (set-default 'kview nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 (defvar kview:default-blank-lines t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 "*Default setting of whether to show blank lines between koutline cells.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 T means show them, nil means don't show them.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 (defvar kview:default-levels-to-show 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 "*Default number of cell levels to show. 0 means all levels.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 (defvar kview:default-lines-to-show 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 "*Default number of lines per cell to show. 0 means all lines.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (defvar kview:default-label-min-width 4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 "*Minimum width to which to pad labels in a kotl view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 Labels are padded with spaces on the left.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (defvar kview:default-label-separator " "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 "*Default string of characters to insert between label and contents of a koutline cell.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (defvar kview:default-label-type 'alpha
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 "*Default label-type to use for new koutlines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 It must be one of the following symbols:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 no for no labels
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 id for permanent idstamp labels, e.g. 001, 002, etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 alpha for '1a2' full alphanumeric labels
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 legal for '1.1.2' labels
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 partial-alpha for partial alphanumeric labels, e.g. '2' for node '1a2'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 star for multi-star labeling, e.g. '***'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (defvar kview:default-level-indent 3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 "*Default number of spaces to indent each succeeding level in koutlines.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;;; Public functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;;; kcell-view
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (defun kcell-view:backward (&optional visible-p label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 "Move to start of the prior cell at the same level as the current cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 With optional VISIBLE-P, consider only visible cells.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 Return t unless no such cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (or label-sep-len (setq label-sep-len
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (let ((opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (found) (done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (curr-indent 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (start-indent (kcell-view:indent nil label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (while (and (not (or found done))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (kcell-view:previous visible-p label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (if (bobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (progn (setq done t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (goto-char opoint))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (setq curr-indent (kcell-view:indent nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (cond ((= curr-indent start-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (goto-char (kcell-view:start nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (setq found t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ((< curr-indent start-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;; Went past start of this tree without a match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (setq done t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (goto-char opoint))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;; else go to prior node
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (defun kview:beginning-of-actual-line ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 "Go to the beginning of the current line whether collapsed or not."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (if (re-search-backward "[\n\r]" nil 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (forward-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (defun kcell-view:cell (&optional pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 "Return kcell at optional POS or point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (kproperty:get (kcell-view:plist-point pos) 'kcell))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (defun kcell-view:child (&optional visible-p label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 "Move to start of current cell's child.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 With optional VISIBLE-P, consider only visible children.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 Return t unless cell has no matching child.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 Optional LABEL-SEP-LEN is the length of the separation between
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 a cell's label and the start of its contents."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (let* ((opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (prev-indent (kcell-view:indent nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (next (kcell-view:next visible-p label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (or label-sep-len (setq label-sep-len
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 ;; Since kcell-view:next leaves point at the start of a cell, the cell's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 ;; indent is just the current-column of point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (if (and next (> (current-column) prev-indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ;; Move back to previous point and return nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (defun kcell-view:child-p (&optional pos visible-p label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 "Return t if cell at optional POS or point has a child.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 With optional VISIBLE-P, consider only visible children.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 Optional LABEL-SEP-LEN is the length of the separation between
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 a cell's label and the start of its contents."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (if pos (goto-char pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (kcell-view:child visible-p label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (defun kcell-view:collapse (&optional pos label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 "Collapse cell at optional POS or point within the current view."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (goto-char (kcell-view:start pos label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (subst-char-in-region (point) (kcell-view:end-contents) ?\n ?\r t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (defun kcell-view:collapsed-p (&optional pos label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 "Return t if cell at optional POS or point is collapsed within the current view."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (goto-char (kcell-view:start pos label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (if (search-forward "\r" (kcell-view:end-contents) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (defun kcell-view:contents (&optional pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 "Return contents of cell at optional POS or point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (if pos (goto-char pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (let ((indent (kcell-view:indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (start (kcell-view:start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (end (kcell-view:end-contents)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 ;; Remove indentation from all but first line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (hypb:replace-match-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (concat "\\([\n\r]\\)" (make-string indent ?\ ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (buffer-substring start end) "\\1"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (defun kcell-view:create (kview cell level klabel &optional no-fill)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 "Insert into KVIEW at point, CELL at LEVEL (1 = first level) with KLABEL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 Optional NO-FILL non-nil suppresses filling of cell's contents upon insertion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 or movement."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (if (= (kcell:idstamp cell) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (or no-fill (setq no-fill (kcell:get-attr cell 'no-fill)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (let* ((label-min-width (kview:label-min-width kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (label-fmt (format "%%%ds" label-min-width))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (label (if (string= klabel "") "" (format label-fmt klabel)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (label-separator (if (string= klabel "") " "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (kview:label-separator kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (mult-line-indent (* (1- level) (kview:level-indent kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (thru-label (+ mult-line-indent label-min-width
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (length label-separator)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (old-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (fill-prefix (make-string thru-label ?\ ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 contents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 new-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (if no-fill (kcell:set-attr cell 'no-fill t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (insert fill-prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (setq contents (kview:insert-contents cell nil no-fill fill-prefix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 ;; Insert lines to separate cell from next.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (insert (if (or no-fill (equal contents ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 "\n\n" "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (if (kview:get-attr kview 'blank-lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 ;; Make blank lines invisible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (kproperty:put (1- (point)) (min (point) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 '(invisible t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (kfile:narrow-to-kcells)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (setq new-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (goto-char old-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 ;; Delete leading spaces used to get fill right in first cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 ;; line. Replace it with label.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (delete-char thru-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (insert (format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (format "%%%ds" (- thru-label (length label-separator)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (setq old-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (insert label-separator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (goto-char old-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 ;; Add cell's attributes to the text property list at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (kproperty:set 'kcell cell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (goto-char new-point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (defun kcell-view:end (&optional pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 "Return end position of cell from optional POS or point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 Includes blank lines following cell contents."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (or pos (setq pos (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (or (re-search-forward "[\n\r][\n\r]" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (defun kcell-view:end-contents (&optional pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 "Return end position of cell contents from optional POS or point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 Excludes blank lines following cell contents."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (if pos (goto-char pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (goto-char (kcell-view:end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (skip-chars-backward "\n\r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (defun kcell-view:expand (&optional pos label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 "Expand cell at optional POS or point within the current view."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (goto-char (kcell-view:start pos label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (subst-char-in-region (point) (kcell-view:end-contents) ?\r ?\n t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (defun kcell-view:forward (&optional visible-p label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 "Move to start of the following cell at the same level as the current cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 With optional VISIBLE-P, consider only visible cells.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 Return t unless no such cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (or label-sep-len (setq label-sep-len
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (let ((opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (found) (done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (curr-indent 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (start-indent (kcell-view:indent nil label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (while (and (not (or found done))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (kcell-view:next visible-p label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (setq curr-indent (kcell-view:indent nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (cond ((= curr-indent start-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (goto-char (kcell-view:start nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (setq found t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 ((< curr-indent start-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 ;; Went past end of this tree without a match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (setq done t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (goto-char opoint))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 ;; else go to following node
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 ;; If didn't find a match, return to original point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (or found (goto-char opoint))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (defun kcell-view:get-attr (attribute &optional pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 "Return ATTRIBUTE's value for current cell or cell at optional POS."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (if pos (goto-char pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (kcell:get-attr (kcell-view:cell) attribute)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (defun kcell-view:idstamp (&optional pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 "Return idstamp string of cell at optional POS or point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (if pos (goto-char pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (format "0%d" (kcell:idstamp (kcell-view:cell)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (defun kcell-view:indent (&optional pos label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 "Return indentation of cell at optional POS or point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 Optional LABEL-SEP-LEN is the view-specific length of the separator between a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 cell's label and the start of its contents."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (+ (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (kcell-view:to-label-end pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (or label-sep-len (kview:label-separator-length kview))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (defun kcell-view:label (&optional pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 "Return displayed label string of cell at optional POS or point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 If labels are off, return cell's idstamp as a string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (if pos (goto-char pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (let ((label-type (kview:label-type kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (if (eq label-type 'no)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (kcell-view:idstamp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (kcell-view:to-label-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (buffer-substring (point) (progn (skip-chars-backward "^ \t\n\r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (point)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (defun kcell-view:level (&optional pos label-sep-len indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 "Return cell level relative to top cell of the outline for current cell or one at optional POS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 0 = top cell level, 1 = 1st level in outline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 Optional LABEL-SEP-LEN is length of spaces between a cell label and its the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 start of its body in the current view. Optional INDENT is the indentation in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 characters of the cell whose level is desired."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (or label-sep-len (setq label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (if pos (goto-char pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (/ (- (or indent (kcell-view:indent nil label-sep-len)) label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (kview:level-indent kview))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (defun kcell-view:line (&optional pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 "Return contents of cell line at point or optional POS as a string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (if pos (goto-char pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (if (kview:valid-position-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (buffer-substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (kotl-mode:beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (kotl-mode:end-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (error "(kcell-view:line): Invalid position, '%d'" (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (defun kcell-view:next (&optional visible-p label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 "Move to start of next cell within current view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 With optional VISIBLE-P, consider only visible cells.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 Return t unless no next cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (let ((opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 ;; If a subtree is collapsed, be sure we end up at the start of a visible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 ;; cell rather than within an invisible one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (if visible-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (progn (goto-char (kcell-view:end-contents)) (end-of-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (setq pos (kproperty:next-single-change (point) 'kcell))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (if (or (null pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (if (goto-char pos) (kotl-mode:eobp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (progn (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (goto-char (kcell-view:start nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (not (eq opoint (point))))))
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 kcell-view:operate (function &optional start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 "Invoke FUNCTION with view restricted to current cell contents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 Optional START and END are start and endpoints of cell to use."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (narrow-to-region (or start (kcell-view:start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (or end (kcell-view:end-contents)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (funcall function)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (defun kcell-view:parent (&optional visible-p label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 "Move to start of current cell's parent within current view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 If parent is top cell, move to first cell within view and return 0.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 Otherwise, return t unless optional VISIBLE-P is non-nil and the parent cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 is not part of the current view."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (or label-sep-len (setq label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (let ((opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (parent-level (1- (kcell-view:level nil label-sep-len))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (if (= parent-level 0) ;; top cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (progn (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (goto-char (kcell-view:start nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 ;; Skip from point back past any siblings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (while (kcell-view:backward visible-p label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 ;; Move back to parent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (if (kcell-view:previous visible-p label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 ;; Move back to previous point and return nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (defun kcell-view:previous (&optional visible-p label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 "Move to start of previous cell within current view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 With optional VISIBLE-P, consider only visible cells.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 Return t unless no previous cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (let ((opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (pos (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (goto-char (kcell-view:start nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 ;; If a subtree is collapsed, be sure we end up at the start of a visible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 ;; cell rather than within an invisible one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (if visible-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (if (setq pos (kproperty:previous-single-change (point) 'kcell))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (goto-char pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (if (and pos (not (kotl-mode:bobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (setq pos (kproperty:previous-single-change (point) 'kcell)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (progn (goto-char pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (skip-chars-backward "\n\r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (if visible-p (beginning-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (goto-char (kcell-view:start nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (not (eq opoint (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 ;; No previous cell exists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (defun kcell-view:plist (&optional pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 "Return attributes associated with cell at optional POS or point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (kcell:plist (kcell-view:cell pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (defun kcell-view:plist-point (&optional pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 "Return buffer position of attributes associated with cell at optional POS or point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (save-excursion (1+ (kcell-view:to-label-end pos))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (defun kcell-view:to-label-end (&optional pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 "Move point after end of current cell's label and return point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (if pos (goto-char pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (kview:end-of-actual-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (cond ((null kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (error "(kcell-view:to-label-end): Invalid kview; try {M-x kotl-mode RET} to fix it."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (klabel-type:changing-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 ;; When changing from one label type to another, e.g. alpha to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 ;; legal, we can't depend on the label being of the type given by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 ;; the kview, so use kcell properties to find label end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (if (kproperty:get (1- (point)) 'kcell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 ;; If not at beginning of cell contents, move there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (goto-char (kproperty:previous-single-change (point) 'kcell)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 ;; Then move to end of label via embedded kcell property.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (goto-char (kproperty:previous-single-change (point) 'kcell)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 ((funcall (kview:get-attr kview 'to-label-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (t (error "(kcell-view:to-label-end): Can't find end of current cell's label"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (defun kcell-view:reference (&optional pos relative-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 "Return a reference to the kcell at optional POS or point for use in a link.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 The reference is a string of the form, \"<kcell-file, cell-ref>\" where
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 cell-ref is as described in the documentation for 'kcell:ref-to-id'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 Kcell-file is made relative to optional RELATIVE-DIR before it is returned."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (format "<%s, %s=%s>" (hpath:relative-to buffer-file-name relative-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (kcell-view:label pos) (kcell-view:idstamp pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (defun kcell-view:remove-attr (attribute &optional pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 "Remove ATTRIBUTE, if any, for current cell or cell at optional POS."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (interactive "*SAttribute to remove: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (if pos (goto-char pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (let ((kcell (kcell:remove-attr (kcell-view:cell) attribute)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (message "Cell <%s> now has no %s attribute."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (kcell-view:label) attribute))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 kcell)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (defun kcell-view:set-attr (attribute value &optional pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 "Set ATTRIBUTE's VALUE for current cell or cell at optional POS and return the cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (if pos (goto-char pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 ;; Returns kcell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (kcell:set-attr (kcell-view:cell) attribute value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (defun kcell-view:set-cell (kcell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 "Attach KCELL property to cell at point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (kcell-view:to-label-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (kproperty:set 'kcell kcell)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (defun kcell-view:sibling-p (&optional pos visible-p label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 "Return t if cell at optional POS or point has a successor.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 With optional VISIBLE-P, consider only visible siblings."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (if pos (goto-char pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (kcell-view:forward visible-p label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (defun kcell-view:start (&optional pos label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 "Return start position of cell contents from optional POS or point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (+ (kcell-view:to-label-end pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (or label-sep-len (kview:label-separator-length kview)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 ;;; kview - one view per buffer, multiple views per kotl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (defun kview:add-cell (klabel level &optional contents prop-list no-fill)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 "Create a new cell with full KLABEL and add it at point at LEVEL within outline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 1 = first level. Optional cell CONTENTS and PROP-LIST may also be given, as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 well as NO-FILL which skips filling of any CONTENTS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 Return new cell. This function does not renumber any other cells."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (let ((new-cell (kcell:create contents (kview:id-increment kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 prop-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (kcell-view:create kview new-cell level klabel no-fill)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 new-cell))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (defun kview:buffer (kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 "Return kview's buffer or nil if argument is not a kview."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (if (kview:is-p kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (get-buffer (kview:get-attr kview 'view-buffer-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (defun kview:create (buffer-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 &optional id-counter label-type level-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 label-separator label-min-width blank-lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 levels-to-show lines-to-show)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 "Return a new kview for BUFFER-NAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 Optional ID-COUNTER is the maximum permanent id previously given out in this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 outline. Optional LABEL-TYPE, LEVEL-INDENT, LABEL-SEPARATOR, LABEL-MIN-WIDTH,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 BLANK-LINES, LEVELS-TO-SHOW, and LINES-TO-SHOW may also be given, otherwise default values are used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 See documentation of:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 'kview:default-label-type' for LABEL-TYPE,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 'kview:default-level-indent' for LEVEL-INDENT,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 'kview:default-label-separator' for LABEL-SEPARATOR,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 'kview:default-label-min-width' for LABEL-MIN-WIDTH,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 'kview:default-blank-lines' for BLANK-LINES,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 'kview:default-levels-to-show' for LEVELS-TO-SHOW,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 'kview:default-lines-to-show' for LINES-TO-SHOW."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (let ((buf (get-buffer buffer-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (cond ((null buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (error "(kview:create): No such buffer, '%s'." buffer-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 ((or (null id-counter) (= id-counter 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (setq id-counter 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 ((not (integerp id-counter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (error "(kview:create): 2nd arg, '%s', must be an integer." id-counter)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (if (and (boundp 'kview) (eq (kview:buffer kview) buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 ;; Don't recreate view if it exists.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (make-local-variable 'kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (setq kview
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (list 'kview 'plist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (list 'view-buffer-name buffer-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 'top-cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (kcell:create-top buffer-file-name id-counter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 'label-type (or label-type kview:default-label-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 'label-min-width (or label-min-width
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 kview:default-label-min-width)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 'label-separator (or label-separator
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 kview:default-label-separator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 'label-separator-length
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (length (or label-separator
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 kview:default-label-separator))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 'level-indent (or level-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 kview:default-level-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 'blank-lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (or blank-lines kview:default-blank-lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 'levels-to-show
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (or levels-to-show kview:default-levels-to-show)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 'lines-to-show
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (or lines-to-show kview:default-lines-to-show)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (kview:set-functions (or label-type kview:default-label-type)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 ;;; Using this stimulates an GNU Emacs V19.19 bug in text-property handling,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 ;; visible when one deletes a sibling cell and then deletes the prior cell,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 ;; the following cell is left with a different idstamp and its label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 ;; displays as "0". Using delete-char here would solve the problem but we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 ;; suggest you upgrade to a newer version of GNU Emacs in which the bug is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 ;; fixed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (defun kview:delete-region (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 "Delete cells between START and END points from current view."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (delete-region start end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (defun kview:end-of-actual-line ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 "Go to the end of the current line whether collapsed or not."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (if (re-search-forward "[\n\r]" nil 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (backward-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (defun kview:fill-region (start end &optional kcell justify)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 "Fill region between START and END within current view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 With optional KCELL, assume START and END delimit that cell's contents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 With optional JUSTIFY, justify region as well.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 Fill-prefix must be a string of spaces the length of this cell's indent, when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 this function is called."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (let ((opoint (set-marker (make-marker) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (label-sep-len (kview:label-separator-length kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (continue t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 prev-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (while continue
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (if (kcell:get-attr (or kcell (kcell-view:cell)) 'no-fill)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 (setq continue (kcell-view:next nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (fill-paragraph justify t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (setq prev-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (forward-paragraph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 (re-search-forward "[^ \t\n\r]" nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (setq continue (and continue
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (/= (point) prev-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (< (point) (min end (point-max))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 ;; Return to original point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (set-marker opoint nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (cond ((and hyperb:xemacs-p (or (>= emacs-minor-version 12)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 (> emacs-major-version 19)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 (defun kview:goto-cell-id (id-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 "Move point to start of cell with idstamp ID-STRING and return t, else nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (let ((cell-id (string-to-int id-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 label-end kcell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (setq label-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 (map-extents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 (function (lambda (extent unused)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (setq kcell (extent-property extent 'kcell))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (if (= (kcell:idstamp kcell) cell-id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (extent-end-position extent))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 nil nil nil nil nil 'kcell))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (if (null label-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 (goto-char label-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 (hyperb:lemacs-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (defun kview:goto-cell-id (id-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 "Move point to start of cell with idstamp ID-STRING and return t, else nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 (let ((cell-id (string-to-int id-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 label-end kcell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (setq label-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (map-extents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (function (lambda (extent unused)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 (setq kcell (extent-property extent 'kcell))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (and kcell (= (kcell:idstamp kcell) cell-id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (extent-end-position extent))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (if (null label-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 (goto-char label-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 ;; Emacs 19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 (t (defun kview:goto-cell-id (id-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 "Move point to start of cell with idstamp ID-STRING and return t, else nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 (let ((cell-id (string-to-int id-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 pos kcell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (while (and (setq pos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 (kproperty:next-single-change (point) 'kcell))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (goto-char pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (or (null (setq kcell (kproperty:get pos 'kcell)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (/= (kcell:idstamp kcell) cell-id))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (if pos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 (forward-char (kview:label-separator-length kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 (defun kview:id-increment (kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 "Return next idstamp (an integer) for KVIEW."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (let* ((top-cell (kview:get-attr kview 'top-cell))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (counter (1+ (kcell:get-attr top-cell 'id-counter))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (kcell:set-attr top-cell 'id-counter counter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 counter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (defun kview:idstamp-to-label (permanent-id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 "Return relative label for cell with PERMANENT-ID within current kview."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (if (kotl-mode:goto-cell permanent-id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (kcell-view:label))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 (defun kview:insert-contents (kcell contents no-fill fill-prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 "Insert KCELL's CONTENTS into view at point and fill resulting paragraphs, unless NO-FILL is non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 FILL-PREFIX is the indentation string for the current cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 If CONTENTS is nil, get contents from KCELL. Return contents inserted (this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 value may differ from the value passed in.)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 (let ((start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 (setq contents (or contents (kcell:contents kcell) ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (insert contents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 ;; Delete any extra newlines at end of cell contents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (setq end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (skip-chars-backward "\n\r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (delete-region (point) end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (setq end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (if no-fill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 ;; Insert proper indent in all but the first line which has
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 ;; already been indented.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (narrow-to-region start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (while (re-search-forward "[\n\r]" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (insert fill-prefix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (goto-char (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 ;; Filling cell will insert proper indent on all lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 (if (equal contents "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 (narrow-to-region (point) end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 ;; Add fill-prefix to all but paragraph separator lines, so
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 ;; filling is done properly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (while (re-search-forward "[\n\r][^\n\r]" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (forward-char -1) (insert fill-prefix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (kview:fill-region start end kcell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 ;; Now add fill-prefix to paragraph separator lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (while (re-search-forward "[\n\r][\n\r]" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (forward-char -1) (insert fill-prefix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 (goto-char (point-max))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 contents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (defun kview:is-p (object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 "Is OBJECT a kview?"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 (if (listp object) (eq (car object) 'kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (defun kview:kotl (kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 "Return kview's kotl object or nil if argument is not a kview."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (if (kview:is-p kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 (kview:get-attr kview 'kotl)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 (defun kview:label (klabel-function prev-label child-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 "Return label string to display for current cell computed from KLABEL-FUNCTION, PREV-LABEL and CHILD-P."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (funcall klabel-function prev-label child-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (defun kview:label-function (kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 "Return function which will return display label for current cell in KVIEW.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 Function signature is: (func prev-label &optional child-p), where prev-label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 is the display label of the cell preceding the current one and child-p is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 non-nil if cell is to be the child of the preceding cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 (kview:get-attr kview 'label-function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 (defun kview:label-min-width (kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 "Return kview's label-min-width setting or nil if argument is not a kview.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 See documentation for kview:default-label-min-width."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 (if (kview:is-p kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (kview:get-attr kview 'label-min-width)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 (defun kview:label-separator (kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 "Return kview's label-separator setting or nil if argument is not a kview.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 See documentation for kview:default-label-separator."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 (if (kview:is-p kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 (kview:get-attr kview 'label-separator)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 (defun kview:label-separator-length (kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 "Return kview's label-separator length or nil if argument is not a kview.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 See documentation for kview:default-label-separator."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 (kview:get-attr kview 'label-separator-length))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (defun kview:label-type (kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 "Return kview's label-type setting or nil if argument is not a kview.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 See documentation for kview:default-label-type."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 (if (kview:is-p kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 (kview:get-attr kview 'label-type)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 (defun kview:level-indent (kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 "Return kview's level-indent setting or nil if argument is not a kview.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 See documentation for kview:default-level-indent."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (if (kview:is-p kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 (kview:get-attr kview 'level-indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 (defun kview:map-branch (func kview &optional first-p visible-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 "Applies FUNC to the sibling trees from point forward within KVIEW and returns results as a list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 With optional FIRST-P non-nil, begins with first sibling in current branch.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 With optional VISIBLE-P, considers only those sibling cells that are visible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 in the view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 FUNC should take one argument, the kview local variable of the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 buffer or some other kview, and should operate upon the cell at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 `Cell-indent' contains the indentation value of the first cell mapped when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 FUNC is called so that it may test against this value. `Label-sep-len'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 contains the label separator length.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 See also 'kview:map-siblings' and 'kview:map-tree'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 (set-buffer (kview:buffer kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 (let ((results)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 (label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 (if first-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 ;; Move back to first predecessor at same level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 (while (kcell-view:backward t label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (let ((cell-indent (kcell-view:indent nil label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 ;; Terminate when no further cells or when reach a cell at an equal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 ;; or higher level in the kotl than the first cell that we processed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 (while (and (progn (setq results (cons (funcall func kview) results))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 (kcell-view:next visible-p label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 (> (kcell-view:indent nil label-sep-len) cell-indent))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 (nreverse results))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (defun kview:map-siblings (func kview &optional first-p visible-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 "Applies FUNC to the sibling cells from point forward within KVIEW and returns results as a list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 With optional FIRST-P non-nil, begins with first sibling in current branch.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 With optional VISIBLE-P, considers only those sibling cells that are visible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 in the view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 FUNC should take one argument, the kview local variable of the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 buffer or some other kview, and should operate upon the cell at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 `Cell-indent' contains the indentation value of the first cell mapped when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 FUNC is called so that it may test against this value. `Label-sep-len'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 contains the label separator length.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 See also 'kview:map-branch' and 'kview:map-tree'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (set-buffer (kview:buffer kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 (let ((results)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 (label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 (if first-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 ;; Move back to first predecessor at same level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (while (kcell-view:backward t label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 (let ((cell-indent (kcell-view:indent nil label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 ;; Terminate when no further cells at same level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 (while (progn (setq results (cons (funcall func kview) results))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 (kcell-view:forward visible-p label-sep-len))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 (nreverse results))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (defun kview:map-tree (func kview &optional top-p visible-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 "Applies FUNC to the tree starting at point within KVIEW and returns results as a list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 With optional TOP-P non-nil, maps over all of kview's cells.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 With optional VISIBLE-P, considers only those cells that are visible in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 FUNC should take one argument, the kview local variable of the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 buffer or some other kview, and should operate upon the cell at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 `Cell-indent' contains the indentation value of the first cell mapped when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 FUNC is called so that it may test against this value. `Label-sep-len'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 contains the label separator length.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 See also 'kview:map-branch' and 'kview:map-siblings'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 (let ((results)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 (label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 (set-buffer (kview:buffer kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 (if top-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 (progn (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 (kview:end-of-actual-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 ;; Terminate when no further cells to process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 (while (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 (setq results (cons (funcall func kview) results))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 (kcell-view:next visible-p label-sep-len))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 (let ((cell-indent (kcell-view:indent nil label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 ;; Terminate when no further cells or when reach a cell at an equal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 ;; or higher level in the kotl than the first cell that we processed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 (while (and (progn (setq results (cons (funcall func kview) results))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 (kcell-view:next visible-p label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 (> (kcell-view:indent nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 cell-indent))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 (nreverse results)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 (defun kview:move (from-start from-end to-start from-indent to-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 &optional copy-p fill-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 "Move tree between FROM-START and FROM-END to TO-START, changing FROM-INDENT to TO-INDENT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 Copy tree if optional COPY-P is non-nil. Refill cells if optional
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 FILL-P is non-nil. Leave point at TO-START."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 (let ((region (buffer-substring from-start from-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 (new-start (set-marker (make-marker) to-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 collapsed-cells expr new-end space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 ;; Move or copy tree region to new location.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 (or copy-p (delete-region from-start from-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 (goto-char new-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 (insert region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 (setq new-end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 ;; Change indentation of tree cells.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 (if (/= from-indent to-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 (narrow-to-region new-start new-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 ;; Store list of which cells are presently collapsed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 (setq collapsed-cells
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 (kview:map-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 (function (lambda (view)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 ;; Use free variable label-sep-len bound in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 ;; kview:map-tree for speed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 (kcell-view:collapsed-p nil label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 kview t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 ;; Expand all cells.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 (subst-char-in-region new-start new-end ?\r ?\n t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 (if (< from-indent to-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 ;; Add indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 (setq expr (make-string (1+ (- to-indent from-indent)) ?\ ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 (while (re-search-forward "^ " nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 (replace-match expr t t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 (forward-line 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 ;; Reduce indent in all but first cell lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 (setq expr (concat "^" (make-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 (- from-indent to-indent) ?\ )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 (while (re-search-forward expr nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 (replace-match "" t t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 ;; Reduce indent in first cell lines which may have an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 ;; autonumber or other cell delimiter.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 (setq space (- from-indent to-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 (kview:label-separator-length kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 (if (zerop space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 (setq expr (concat "^" (make-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 (- from-indent to-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 (kview:label-separator-length kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 ?\ )))
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 (lambda (view)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 (if (looking-at expr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 (replace-match "" t t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 kview t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 (if fill-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 ;; Refill cells without no-fill attribute.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 (kview:map-tree (function (lambda (view)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 (kotl-mode:fill-cell nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 kview t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 ;; Collapse temporarily expanded cells.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 (if (delq nil collapsed-cells)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 (kview:map-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 (lambda (view)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 (if (car collapsed-cells)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 ;; Use free variable label-sep-len bound in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 ;; kview:map-tree for speed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 (kcell-view:collapse nil label-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 (setq collapsed-cells (cdr collapsed-cells))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 kview t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 (goto-char new-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 ;; Delete temporary markers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 (set-marker new-start nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 (defun kview:set-buffer-name (kview new-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 "Set kview's buffer name to NEW-NAME."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 (if (kview:is-p kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 (let ((buf (kview:buffer kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 (if buf (set-buffer buf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 (kview:set-attr kview 'view-buffer-name new-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 (error "(kview:set-buffer-name): Invalid kview argument")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 (defun kview:set-label-type (kview new-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 "Change kview's label display type to NEW-TYPE, updating all displayed labels.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 See documentation for variable, kview:default-label-type, for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 valid values of NEW-TYPE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 (interactive (list kview
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 (let ((completion-ignore-case)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 (label-type (kview:label-type kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 new-type-str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 (if (string=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 (setq new-type-str
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 (completing-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 (format "View label type (current = %s): "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 label-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 '(("alpha") ("legal") ("id") ("no")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 ("partial-alpha") ("star"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 label-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 (intern new-type-str)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 (if (not (memq new-type '(alpha legal id no partial-alpha star)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 (error "(kview:set-label-type): Invalid label type, '%s'." new-type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 ;; Disable use of partial-alpha for now since it is broken.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 (if (eq new-type 'partial-alpha)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 (error "(kview:set-label-type): Partial-alpha labels don't work, choose another type"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 (let ((old-label-type (kview:label-type kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 (if (eq old-label-type new-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 (klabel-type:set-labels new-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 (kview:set-attr kview 'label-type new-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 (kview:set-functions new-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 (kvspec:update t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 (defun kview:top-cell (kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 "Return kview's invisible top cell with idstamp 0 or nil if argument is not a kview."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 (if (kview:is-p kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 (kview:get-attr kview 'top-cell)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 (defun kview:valid-position-p (&optional pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 "Return non-nil iff point or optional POS is at a position where editing may occur.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 The read-only positions between cells and within cell indentations are invalid."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 (cond ((null pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 (>= (current-column) (kcell-view:indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 ((not (integer-or-marker-p pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 (error "(kview:valid-position-p): Argument POS not an integer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 or marker, '%s'" pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 ((or (< pos (point-min)) (> pos (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 (error "(kview:valid-position-p): Invalid POS argument, '%d'"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 (t (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 (goto-char pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 (>= (current-column) (kcell-view:indent))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 ;;; Private functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 (defun kview:get-attr (obj attribute)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 "Return the value of OBJECT's ATTRIBUTE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 (car (cdr (memq attribute (car (cdr (memq 'plist obj)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 (defun kview:set-attr (obj attribute value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 "Set OBJECT's ATTRIBUTE to VALUE and return VALUE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 (let* ((plist-ptr (cdr (memq 'plist obj)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 (plist (car plist-ptr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 (attr (memq attribute plist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 (if attr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 (setcar (cdr attr) value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 (setcar plist-ptr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 (nconc (list attribute value) plist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 (defun kview:set-functions (label-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 "Setup functions which handle labels of LABEL-TYPE for current view."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 (kview:set-attr kview 'label-function (klabel-type:function label-type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 (kview:set-attr kview 'label-child (klabel-type:child label-type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 (kview:set-attr kview 'label-increment (klabel-type:increment label-type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 (kview:set-attr kview 'label-parent (klabel-type:parent label-type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 (kview:set-attr kview 'to-label-end (klabel-type:to-label-end label-type)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 (defun kview:set-label-separator (label-separator &optional set-default-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 "Set the LABEL-SEPARATOR (a string) between labels and cell contents for the current kview.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 With optional prefix arg SET-DEFAULT-P, the default separator value used for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 new outlines is also set to this new value."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 (progn (barf-if-buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 (list (if (kview:is-p kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 (read-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 (format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 "Change current%s label separator from \"%s\" to: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 (if current-prefix-arg " and default" "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 (kview:label-separator kview))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 current-prefix-arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 (barf-if-buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 (cond ((not (kview:is-p kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 (error "(kview:set-label-separator): This is not a koutline"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 ((not (stringp label-separator))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 (error "(kview:set-label-separator): Invalid separator, \"%s\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 label-separator))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 ((< (length label-separator) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 (error "(kview:set-label-separator): Separator must be two or more characters, \"%s\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 label-separator)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 (let* ((old-sep-len (kview:label-separator-length kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 (sep-len (length label-separator))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 (sep-len-increase (- sep-len old-sep-len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 (indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 (reindent-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 (cond ((zerop sep-len-increase)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 (function (lambda ())))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 ((> sep-len-increase 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 ;; Increase indent in each cell line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 (function (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 (setq indent (make-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 sep-len-increase ?\ ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 (while (re-search-forward "[^\n\r][\n\r] " nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 (insert indent)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 ;; Decrease indent in each cell line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 (function (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 (setq indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 (concat "[^\n\r][\n\r]"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 (make-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 (- sep-len-increase) ?\ )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 (while (re-search-forward indent nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 (delete-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 (+ (match-beginning 0) 2) (match-end 0))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 (kproperty:replace-separator pos label-separator old-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 ;; Reindent all lines in cells except the first line which has already
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 ;; been done.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 (funcall reindent-function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 (kview:set-attr kview 'label-separator label-separator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 (kview:set-attr kview 'label-separator-length sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 (if set-default-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 (setq kview:default-label-separator label-separator))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 (provide 'kview)