annotate lisp/hyperbole/kotl/kview.el @ 147:e186c2b7192d xemacs-20-2

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