annotate lisp/hyperbole/kotl/klabel.el @ 36:c53a95d3c46d r19-15b101

Import from CVS: tag r19-15b101
author cvs
date Mon, 13 Aug 2007 08:53:38 +0200
parents 376386a54a3c
children 131b0175ea99
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: klabel.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; SUMMARY: Display label handling for 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: 17-Apr-94
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 0
diff changeset
11 ;; LAST-MOD: 6-Mar-97 at 01:19:02 by Bob Weiner
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 0
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 ;;; Public variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 (defvar klabel-type:changing-flag nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 "Non-nil only while the label type in the current view is being changed.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;; Public functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; klabel - koutline display labels
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 (defun klabel:child (label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 "Return LABEL's child cell label."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 (funcall (kview:get-attr kview 'label-child) label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 (defun klabel:increment (label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 "Return LABEL's sibling label."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (funcall (kview:get-attr kview 'label-increment) label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (defun klabel:level (label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 "Return outline level of LABEL using current kview label type."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (let ((label-type (kview:label-type kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (cond ((memq label-type '(alpha legal))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (funcall (intern-soft (concat "klabel:level-"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (symbol-name label-type)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ((eq label-type 'no) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ((eq label-type 'star) (length label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ((eq label-type 'id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 "(klabel:level): Can't compute the level of an idstamp label"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ((eq label-type 'partial-alpha)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 "(klabel:level): Can't compute the level of a partial-alpha label"))
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 0
diff changeset
51 (t (error "(klabel:level): Invalid label type setting: `%s'"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 label-type)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (defun klabel:parent (label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 "Return LABEL's parent label."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (funcall (kview:get-attr kview 'label-parent) label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (defun klabel-type:child (label-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 "Return function which computes child cell label of LABEL-TYPE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (cond ((memq label-type '(alpha legal partial-alpha))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (intern-soft (concat "klabel:child-"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (symbol-name label-type))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ((eq label-type 'no)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (function (lambda (label) "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ((eq label-type 'star)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (function (lambda (label) (concat label "*"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ((eq label-type 'id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (lambda (label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 "(klabel:child-id): Can't compute child of idstamp label"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (t (error
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 0
diff changeset
73 "(klabel-type:child): Invalid label type setting: `%s'"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 label-type))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (defun klabel-type:increment (label-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 "Return function which computes sibling cell label of LABEL-TYPE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (cond ((memq label-type '(alpha legal partial-alpha))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (intern-soft (concat "klabel:increment-"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (symbol-name label-type))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ((eq label-type 'no)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (lambda (label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (if (equal label "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (error "(klabel:increment-no): 0 cell cannot have a sibling")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ((eq label-type 'star)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (lambda (label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (if (string-equal label "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (error "(klabel:increment-star): 0 cell cannot have a sibling")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 label))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ((eq label-type 'id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (lambda (label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (if (string-equal label "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (error "(klabel:increment-no): 0 cell cannot have a sibling")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (error "(klabel:increment-id): Can't compute sibling of idstamp label")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (t (error
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 0
diff changeset
100 "(klabel:increment): Invalid label type setting: `%s'"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 label-type))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (defun klabel-type:parent (label-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 "Return function which computes parent cell label of LABEL-TYPE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (cond ((memq label-type '(alpha legal partial-alpha))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (intern-soft (concat "klabel:parent-"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (symbol-name label-type))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ((eq label-type 'no)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (lambda (label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (if (equal label "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (error "(klabel:parent-no): 0 cell cannot have a parent")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ((eq label-type 'star)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (lambda (label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (if (string-equal label "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (error "(klabel:parent-star): 0 cell cannot have a parent")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (substring label 0 (1- (length label)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 ((eq label-type 'partial-alpha)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (lambda (label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 "(klabel:parent-partial-alpha): Can't compute parent of partial alpha label"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 ((eq label-type 'id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (lambda (label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 "(klabel:parent-id): Can't compute parent of idstamp label"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (t (error
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 0
diff changeset
131 "(klabel-type:parent): Invalid label type setting: `%s'"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 label-type))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ;;; alpha klabels
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (defun klabel:child-alpha (label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 "Return label for first child of alpha LABEL."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (if (or (string-equal label "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (string-equal label ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 "1"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (concat label (if (< (aref label (1- (length label))) ?a)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 "a" "1"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (defun klabel:increment-alpha (alpha-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 "Increment full ALPHA-LABEL by one and return."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (if (string-equal alpha-label "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (error "(klabel:increment-alpha): 0 cell cannot have a sibling")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (let ((kotl-label (klabel:to-kotl-label alpha-label)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (concat (substring alpha-label 0 (- (length kotl-label)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (kotl-label:increment kotl-label 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (defun klabel:level-alpha (label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 "Return outline level as an integer of alpha-style (Augment-style) LABEL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 First visible outline cell is level 1."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (if (string-equal label "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (let ((i 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (level 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (len (length label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (digit-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 chr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (while (< i len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (if (and (>= (setq chr (aref label i)) ?0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (<= chr ?9))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (or digit-p (setq level (1+ level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 digit-p t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 ;; assume chr is alpha
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (if digit-p (setq level (1+ level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 digit-p nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (setq i (1+ i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 level)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (defun klabel:parent-alpha (label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 "Return parent label of full alpha LABEL."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (cond ((or (string-equal label "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (string-equal label ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (error "(klabel:parent-alpha): 0 cell cannot have a parent"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ((kotl-label:integer-p label) ;; level 1 label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (t (substring label 0 (- (length (klabel:to-kotl-label label)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 ;;; partial-alpha klabels
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (fset 'klabel:child-partial-alpha 'kotl-label:child)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (defun klabel:increment-partial-alpha (label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 "Increment partial alpha LABEL by one and return."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (if (string-equal label "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (error "(klabel:increment-partial-alpha): 0 cell cannot have a sibling")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (kotl-label:increment label 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 ;;; legal klabels
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (defun klabel:child-legal (label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 "Return label for first child of legal LABEL."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (if (or (string-equal label "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (string-equal label ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 "1"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (concat label ".1")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (defun klabel:increment-legal (label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 "Increment full legal LABEL by one and return."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (cond ((string-equal label "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (error "(klabel:increment-legal): 0 cell cannot have a sibling"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 ((string-match "[0-9]+$" label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (concat (substring label 0 (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (int-to-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (1+ (string-to-int (substring label (match-beginning 0)))))))
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 0
diff changeset
215 (t (error "(klabel:increment-legal): Invalid label, `%s'" label))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (defun klabel:level-legal (label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 "Return outline level as an integer of legal-style LABEL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 First visible outline cell is level 1."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (if (string-equal label "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (let ((i 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (level 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (len (length label)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (while (< i len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (if (= (aref label i) ?.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (setq level (1+ level)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (setq i (1+ i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 level)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (defun klabel:parent-legal (label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 "Return parent label of full legal LABEL."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (cond ((or (string-equal label "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (string-equal label ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (error "(klabel:parent-legal): 0 cell cannot have a parent"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 ((kotl-label:integer-p label) ;; level 1 label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (t (substring label 0 (string-match "\\.[0-9]+$" label)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 ;;; klabel-type - Sets display label format and converts among formats
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 ;; Default label-type to use for new views.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 ;; It must be one of the following symbols:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 ;; no for no labels,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 ;; id for permanent idstamp labels, e.g. 001, 002, etc.
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 0
diff changeset
247 ;; alpha for `1a2' full alphanumeric labels
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 0
diff changeset
248 ;; legal for `1.1.2' labels
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 0
diff changeset
249 ;; partial-alpha for partial alphanumeric labels, e.g. `2' for node `1a2'
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 0
diff changeset
250 ;; star for multi-star labeling, e.g. `***'.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 ;; Functions to compute sibling and child labels for particular label types.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (defun klabel-type:function (&optional label-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 "Return function which will return display label for current cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 Label format is optional LABEL-TYPE or the default label type for the current view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 Function signature is: (func prev-label &optional child-p), where prev-label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 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
261 non-nil if cell is to be the child of the preceding cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (or label-type (setq label-type (kview:label-type kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (cond ((eq label-type 'no)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (function (lambda (prev-label &optional child-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 ((eq label-type 'partial-alpha)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (function (lambda (prev-label &optional child-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (if child-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (if (kotl-label:integer-p prev-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 "a" "1")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (kotl-label:increment prev-label 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 ((eq label-type 'id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (function (lambda (prev-label &optional child-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (format "0%d" (kcell-view:idstamp)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (t (intern-soft (concat "klabel-type:"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (symbol-name label-type) "-label")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (defun klabel-type:alpha-label (prev-label &optional child-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 "Return full alphanumeric label, e.g. 1a2, for cell following PREV-LABEL's cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 With optional CHILD-P, return label for first child cell of PREV-LABEL cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (if child-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (klabel:child prev-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (klabel:increment prev-label)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (defun klabel-type:legal-label (prev-label &optional child-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 "Return full legal label, e.g. 1.1.2, for cell following PREV-LABEL's cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 With optional CHILD-P, return label for first child cell of PREV-LABEL cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (if child-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (if (string-equal prev-label "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 "1"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (concat prev-label ".1"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (let* ((last-part (string-match "[0-9]+$" prev-label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (partial-legal (substring prev-label last-part))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (next (kotl-label:create (1+ (string-to-int partial-legal)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (if (equal last-part prev-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (concat (substring prev-label 0 last-part) next)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (defun klabel-type:to-label-end (&optional label-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 "Return function which will search backward to a the end of a cell's label.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 Label format is optional LABEL-TYPE or the default label type for the current view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 Function signature is: (). It takes no arguments and begins the search from point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (or label-type (setq label-type (kview:label-type kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (or (cdr (assq label-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 'alpha
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (if (re-search-backward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 "\\(\\`\\|[\n\r][\n\r]\\)[ \t]*[1-9][0-9a-zA-Z]*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (goto-char (match-end 0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 'legal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (if (re-search-backward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 "\\(\\`\\|[\n\r][\n\r]\\)[ \t]*[0-9]+\\(\\.[0-9]+\\)*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (goto-char (match-end 0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 'star
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (if (re-search-backward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 "\\(\\`\\|[\n\r][\n\r]\\)[ \t]*\\*+" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (goto-char (match-end 0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 'no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (goto-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (if (and (not hyperb:lemacs-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (string-lessp emacs-version "19.22"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (kproperty:previous-single-change (point) 'kcell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 ;; (GNU Emacs V19.22 / Lucid Emacs V19.9) or greater
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (- (kproperty:previous-single-change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (point) 'kcell) 1))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 'partial-alpha
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (if (re-search-backward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 "\\(\\`\\|[\n\r][\n\r]\\)[ \t]*[0-9]+\\|[a-zA-Z]+"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (goto-char (match-end 0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 'id
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (if (re-search-backward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 "\\(\\`\\|[\n\r][\n\r]\\)[ \t]*0[0-9]+" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (goto-char (match-end 0)))))))))
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 0
diff changeset
356 (error "(kview:to-label-end): Invalid label type: `%s'" label-type)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (defun klabel-type:star-label (prev-label &optional child-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 "Return full star label, e.g. ***, for cell following PREV-LABEL's cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 With optional CHILD-P, return label for first child cell of PREV-LABEL cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (if child-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (concat prev-label "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 prev-label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 ;; Functions to compute labels for cells following point and for all cells in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 ;; a view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (defun klabel-type:set-labels (label-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 "Replace labels of all cells in current view with those of LABEL-TYPE (a symbol)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (let (first-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (goto-char (kcell-view:start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (setq first-label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (cond ((memq label-type '(alpha legal partial-alpha))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 "1")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 ((eq label-type 'id) (kcell-view:idstamp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 ((eq label-type 'no) "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 ((eq label-type 'star) "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (t (error
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 0
diff changeset
383 "(klabel-type:set-labels): Invalid label type: `%s'"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 label-type))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (let ((klabel-type:changing-flag t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (klabel-type:update-labels-from-point label-type first-label)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (defun klabel-type:set-alpha (current-cell-label label-sep-len current-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 per-level-indent &optional current-tree-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 "Set the labels of current cell, its following siblings and their subtrees.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 CURRENT-CELL-LABEL is the label to display for the current cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 LABEL-SEP-LEN is the length of the separation between a cell's label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 and the start of its contents."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (let (label-prefix label-suffix suffix-val suffix-function opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (if current-cell-label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (setq label-suffix (klabel:to-kotl-label current-cell-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 label-prefix (substring current-cell-label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 0 (- (length label-suffix)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 suffix-function (if (kotl-label:integer-p label-suffix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (progn (setq suffix-val
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (string-to-int label-suffix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 'int-to-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (setq suffix-val
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (kotl-label:alpha-to-int label-suffix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 'kotl-label:int-to-alpha)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (while current-cell-label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 ;; Set current cell's label.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (klabel:set current-cell-label label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 ;; Process any subtrees of current cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (if (kcell-view:child nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 ;; Recurse over subtree.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (klabel-type:set-alpha
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (klabel:child-alpha current-cell-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 label-sep-len
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (+ current-indent per-level-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 per-level-indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 ;; Process next sibling of current cell if any.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (setq opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (if (and (not current-tree-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (kcell-view:next nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (= current-indent (kcell-view:indent nil label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (setq suffix-val (1+ suffix-val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 label-suffix (funcall suffix-function suffix-val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 current-cell-label (concat label-prefix label-suffix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (setq current-cell-label nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (defun klabel-type:set-id (current-cell-label label-sep-len &rest ignore)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 "Set the labels of current cell, its following siblings and their subtrees.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 CURRENT-CELL-LABEL is the label to display for the current cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 ;; Only need to do this when switching from one label type to another,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 ;; i.e. when every cell label will be updated. So if not starting with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 ;; first cell, do nothing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (if (kotl-mode:first-cell-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (while (and (klabel:set (kcell-view:idstamp) label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (kcell-view:next nil label-sep-len)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (defun klabel-type:set-legal (current-cell-label label-sep-len current-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 per-level-indent &optional current-tree-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 "Set the labels of current cell, its following siblings and their subtrees.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 CURRENT-CELL-LABEL is the label to display for the current cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 LABEL-SEP-LEN is the length of the separation between a cell's label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 and the start of its contents."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (let (label-prefix label-suffix suffix-val opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (if current-cell-label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (setq label-suffix (klabel:to-kotl-label current-cell-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 label-prefix (substring current-cell-label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 0 (- (length label-suffix)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 suffix-val (string-to-int label-suffix)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (while current-cell-label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 ;; Set current cell's label.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (klabel:set current-cell-label label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 ;; Process any subtrees of current cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (if (kcell-view:child nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 ;; Recurse over subtree.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (klabel-type:set-legal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (klabel:child-legal current-cell-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 label-sep-len
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (+ current-indent per-level-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 per-level-indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 ;; Process next sibling of current cell if any.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (setq opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (if (and (not current-tree-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (kcell-view:next nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (= current-indent (kcell-view:indent nil label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (setq suffix-val (1+ suffix-val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 label-suffix (int-to-string suffix-val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 current-cell-label (concat label-prefix label-suffix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (setq current-cell-label nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (defun klabel-type:set-no (current-cell-label label-sep-len &rest ignore)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 "Set the labels of current cell, its following siblings and their subtrees.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 CURRENT-CELL-LABEL is the label to display for the current cell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 ;; Only need to do this when switching from one label type to another,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 ;; i.e. when every cell label will be updated. So if not starting with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 ;; first cell, do nothing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (if (kotl-mode:first-cell-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (while (and (klabel:set "" label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (kcell-view:next nil label-sep-len)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (defun klabel-type:set-partial-alpha (current-cell-label label-sep-len
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 current-indent per-level-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 &optional current-tree-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 "Set the labels of current cell, its following siblings and their subtrees.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 CURRENT-CELL-LABEL is the label to display for the current cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 LABEL-SEP-LEN is the length of the separation between a cell's label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 and the start of its contents."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (let (label-suffix suffix-val suffix-function opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (if current-cell-label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (setq label-suffix current-cell-label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 suffix-function (if (kotl-label:integer-p label-suffix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (progn (setq suffix-val
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (string-to-int label-suffix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 'int-to-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (setq suffix-val
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (kotl-label:alpha-to-int label-suffix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 'kotl-label:int-to-alpha)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (while current-cell-label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 ;; Set current cell's label.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (klabel:set current-cell-label label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 ;; Process any subtrees of current cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (if (kcell-view:child nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 ;; Recurse over subtree.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (klabel-type:set-partial-alpha
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (klabel:child-partial-alpha current-cell-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 label-sep-len
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (+ current-indent per-level-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 per-level-indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 ;; Process next sibling of current cell if any.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (setq opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (if (and (not current-tree-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (kcell-view:next nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (= current-indent (kcell-view:indent nil label-sep-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (setq suffix-val (1+ suffix-val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 label-suffix (funcall suffix-function suffix-val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 current-cell-label label-suffix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (setq current-cell-label nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (defun klabel-type:set-star (current-cell-label label-sep-len &rest ignore)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 "Set the labels of current cell, its following siblings and their subtrees.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 CURRENT-CELL-LABEL is the label to display for the current cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 LABEL-SEP-LEN is the length of the separation between a cell's label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 and the start of its contents."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 ;; Only need to do this when switching from one label type to another,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 ;; i.e. when every cell label will be updated. So if not starting with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 ;; first cell, do nothing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (if (kotl-mode:first-cell-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (while (and (klabel:set (make-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (kcell-view:level nil label-sep-len) ?*)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (kcell-view:next nil label-sep-len)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (defun klabel-type:update-labels (current-cell-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 "Update the labels of current cell, its following siblings and their subtrees.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 CURRENT-CELL-LABEL is the label to display for the current cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 If, however, it is \"0\", then all cell labels are updated."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (let ((label-type (kview:label-type kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (if (string-equal current-cell-label "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 ;; Update all cells in view.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (klabel-type:set-labels label-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 ;; Update current tree and its siblings only.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (klabel-type:update-labels-from-point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 label-type current-cell-label))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (defun klabel-type:update-tree-labels (current-cell-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 "Update the labels of current cell and its subtree.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 CURRENT-CELL-LABEL is the label to display for the current cell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 Use '(klabel-type:update-labels "0")' to update all cells in an outline."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (let ((label-type (kview:label-type kview))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (funcall (intern-soft (concat "klabel-type:set-"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (symbol-name label-type)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 first-label label-sep-len
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (kcell-view:indent nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (kview:level-indent kview)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 ;; Update current tree only.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 ;;; kotl-label--the part of a full label which represents a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 ;;; kcell's relative position in the koutline hierarchy,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 ;;; e.g. the full label "1a2" has kotl-label "2".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (defun kotl-label:alpha-to-int (alpha-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 "Return integer value of ALPHA-LABEL, e.g. `b' returns 2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 Assumes ALPHA-LABEL is alphabetic."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (let ((power (length alpha-label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (digit 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (min (1- ?a)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (apply '+ (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (function (lambda (chr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (setq digit (- chr min)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 power (1- power))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (* (apply '* (make-list power 26)) digit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 alpha-label))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 (defun kotl-label:alpha-p (label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 "Return LABEL if LABEL is composed of all alphabetic characters, else return nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (if (string-match "\\`[a-zA-Z]+\\'" label) label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (defun kotl-label:child (label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 "Return child label of partial alpha LABEL."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (cond ((or (string-equal label "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (string-equal label ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 "1")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 ((kotl-label:integer-p label) "a")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 (t "1")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 (defun kotl-label:create (int-or-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 "Return new kcell label from INT-OR-STRING."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (cond ((integerp int-or-string) (int-to-string int-or-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 ((equal int-or-string "") "0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (t int-or-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 (defun kotl-label:increment (label n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 "Return LABEL incremented by N.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 For example, if N were 1, 2 would become 3, z would become aa, and aa would
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 become bb. If N were -2, 4 would become 2, etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 LABEL must be >= 1 or >= a. If LABEL is decremented below 1 or a, an error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 is signaled."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (if (not (kotl-label:is-p label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (error
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 0
diff changeset
607 "(kotl-label:increment): First arg, `%s', must be a kotl-label."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (let ((int-p) (val 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (if (or (setq int-p (kotl-label:integer-p label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 (kotl-label:alpha-p label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 ;; Test if trying to decrement below 1 or a.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 (if int-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (progn (setq int-p (string-to-int label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (if (> (setq val (+ int-p n)) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (kotl-label:create val)
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 0
diff changeset
617 (error "(kotl-label:increment): Decrement of `%s' by `%d' is less than 1." label n)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 ;; alpha-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 (if (<= 0 (setq val (+ n (kotl-label:alpha-to-int label))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (kotl-label:create
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 (kotl-label:int-to-alpha val))
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 0
diff changeset
622 (error "(kotl-label:increment): Decrement of `%s' by `%d' is illegal." label n)))
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 0
diff changeset
623 (error "(kotl-label:increment): label, `%s', must be all digits or alpha characters" label))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (defun kotl-label:increment-alpha (label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 "Return alphabetic LABEL incremented by 1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 For example, z would become aa, and aa would become bb. LABEL must be >= a."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (kotl-label:int-to-alpha
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (1+ (kotl-label:alpha-to-int label))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 (defun kotl-label:increment-int (int-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 "Return INT-STRING label incremented by 1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 For example, \"14\" would become \"15\"."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (int-to-string (1+ (string-to-int int-string))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 (defun kotl-label:integer-p (label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 "Return LABEL iff LABEL is composed of all digits, else return nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (if (string-match "\\`[0-9]+\\'" label) label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 ;; This handles partial alphabetic labels with a maximum single level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 ;; sequence of 17575 items, which = (1- (expt 26 3)), after which it gives
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 ;; invalid results. This should be large enough for any practical cases.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (defun kotl-label:int-to-alpha (n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 "Return alphabetic representation of N as a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 N may be an integer or a string containing an integer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (if (stringp n) (setq n (string-to-int n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (let ((lbl "") pow26 exp26 quotient remainder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (if (= n 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (setq pow26 (floor (kotl-label:log26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (if (= (mod (1- n) 26) 0) n (1- n)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 (while (>= pow26 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 (setq exp26 (expt 26 pow26)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 quotient (floor (/ n exp26))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 remainder (mod n exp26))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (if (= remainder 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 (setq quotient (- quotient (1+ pow26))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 n 26)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 (setq n remainder
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 quotient (max 0 (1- quotient))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (setq lbl (concat lbl (char-to-string (+ quotient ?a)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 pow26 (1- pow26)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 lbl)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (defun kotl-label:is-p (object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 "Return non-nil if OBJECT is a KOTL-LABEL."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 (stringp object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 ;;; Private functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (defun klabel:set (new-label &optional label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 "Replace label displayed in cell at point with NEW-LABEL, which may be a different label type.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 Return NEW-LABEL string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 (let ((modified (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 (thru-label (- (kcell-view:indent nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 (or label-sep-len
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (kview:label-separator-length kview)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (kcell-view:to-label-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 ;; delete backwards thru label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 (delete-backward-char thru-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 ;; replace with new label, right justified
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 (insert (format (format "%%%ds" thru-label) new-label)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 (set-buffer-modified-p modified)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 new-label))
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 klabel:to-kotl-label (label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 "Given full alpha or legal LABEL, return rightmost part, called a kotl-label.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 For example, the full label \"1a2\" has kotl-label \"2\", as does \"1.1.2\"."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (if (string-match "[0-9]+$\\|[a-zA-Z]+$" label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 (substring label (match-beginning 0))
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 0
diff changeset
698 (error "(klabel:to-kotl-label): Invalid label, `%s'" label)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 (defun klabel-type:update-labels-from-point (label-type first-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 (let ((label-sep-len (kview:label-separator-length kview)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 (funcall (intern-soft (concat "klabel-type:set-"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 (symbol-name label-type)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 first-label label-sep-len
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 (kcell-view:indent nil label-sep-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 (kview:level-indent kview)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (defun kotl-label:log26 (n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 "Return log base 26 of integer N."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 (/ (log10 n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 ;; Next line = (log10 26.514147167125703)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 1.423477662509912))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 (provide 'klabel)