annotate lisp/hyperbole/kotl/klabel.el @ 27:0a3286277d9b

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