Mercurial > hg > xemacs-beta
comparison lisp/oobr/br-clos-ft.el @ 100:4be1180a9e89 r20-1b2
Import from CVS: tag r20-1b2
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:15:11 +0200 |
parents | 131b0175ea99 |
children | 929b76928fce |
comparison
equal
deleted
inserted
replaced
99:2d83cbd90d8d | 100:4be1180a9e89 |
---|---|
4 ;; SUMMARY: CLOS OO-Browser class and element functions. | 4 ;; SUMMARY: CLOS OO-Browser class and element functions. |
5 ;; USAGE: GNU Emacs Lisp Library | 5 ;; USAGE: GNU Emacs Lisp Library |
6 ;; KEYWORDS: lisp, oop, tools | 6 ;; KEYWORDS: lisp, oop, tools |
7 ;; | 7 ;; |
8 ;; AUTHOR: Bob Weiner | 8 ;; AUTHOR: Bob Weiner |
9 ;; ORG: Motorola Inc. | 9 ;; ORG: InfoDock Associates |
10 ;; | 10 ;; |
11 ;; ORIG-DATE: 03-Oct-90 | 11 ;; ORIG-DATE: 03-Oct-90 |
12 ;; LAST-MOD: 6-Aug-95 at 01:52:28 by Bob Weiner | 12 ;; LAST-MOD: 31-Oct-96 at 17:04:54 by Bob Weiner |
13 ;; | 13 ;; |
14 ;; Copyright (C) 1990-1995 Free Software Foundation, Inc. | 14 ;; Copyright (C) 1990-1996 Free Software Foundation, Inc. |
15 ;; See the file BR-COPY for license information. | 15 ;; See the file BR-COPY for license information. |
16 ;; | 16 ;; |
17 ;; This file is part of the OO-Browser. | 17 ;; This file is part of the OO-Browser. |
18 ;; | 18 ;; |
19 ;; DESCRIPTION: | 19 ;; DESCRIPTION: |
35 (defconst clos-type-tag-separator "," | 35 (defconst clos-type-tag-separator "," |
36 "String that separates a tags type from its normalized definition form.") | 36 "String that separates a tags type from its normalized definition form.") |
37 | 37 |
38 (defconst clos-def-form-match "\([^ \t\n\r]+[ \t\n\r]+") | 38 (defconst clos-def-form-match "\([^ \t\n\r]+[ \t\n\r]+") |
39 | 39 |
40 (defconst clos-feature-tag-regexp | 40 (defconst clos-tag-fields-regexp |
41 (concat "\\(" clos-type-identifier "\\)" | 41 (concat "\\`\\(" clos-type-identifier "\\)" |
42 clos-type-tag-separator | 42 clos-type-tag-separator |
43 clos-def-form-match "['\(]?" | 43 clos-def-form-match "['\(]?" |
44 "\\((setf[^\)]+)\\|[^\(;,]+\\)\\( *(.*)\\)?") | 44 "\\((setf[^\)]+)\\|[^\(;,]+\\)\\( *(.*)\\)?") |
45 "Regexp matching a fully qualified, normalized clos feature tag. | 45 "Regexp matching a fully qualified, normalized clos feature tag. |
46 Class name is grouping 1. Feature name is grouping 2. Optional | 46 Class name is grouping 1. Feature name is grouping 2. Optional |
104 (clos-to-comments-begin) | 104 (clos-to-comments-begin) |
105 (recenter 0) | 105 (recenter 0) |
106 (goto-char start) | 106 (goto-char start) |
107 t))) | 107 t))) |
108 | 108 |
109 (defun clos-feature-map-class-tags (function class) | |
110 "Apply FUNCTION to all feature tags from CLASS and return a list of the results. | |
111 Feature tags come from the file named by br-feature-tags-file." | |
112 (let ((obuf (current-buffer)) | |
113 (class-tag (concat "\n" class clos-type-tag-separator)) | |
114 (results)) | |
115 (set-buffer (funcall br-find-file-noselect-function br-feature-tags-file)) | |
116 (goto-char 1) | |
117 ;; Feature defs (methods) for a single class could occur in any file, | |
118 ;; according to Common Lisp rules. | |
119 (while (search-forward class-tag nil t) | |
120 (setq results (cons (funcall function) results)) | |
121 ;; Might have deleted current tag and would miss next tag unless point | |
122 ;; is moved backwards. | |
123 (backward-char)) | |
124 (set-buffer obuf) | |
125 results)) | |
126 | |
109 (defun clos-feature-name-to-regexp (name) | 127 (defun clos-feature-name-to-regexp (name) |
110 "Converts feature NAME into a regular expression matching the feature's name tag." | 128 "Converts feature NAME into a regular expression matching the feature's name tag." |
111 (if (string-match (concat "^" br-feature-type-regexp " ") name) | 129 (if (string-match (concat "^" br-feature-type-regexp " ") name) |
112 (setq name (substring name (match-end 0)))) | 130 (setq name (substring name (match-end 0)))) |
113 (format "%s%s\(\\(%s\\) %s[ \n]" | 131 (format "%s%s\(\\(%s\\) %s[ \n]" |
136 (substring signature (match-beginning 1) (match-end 1)) | 154 (substring signature (match-beginning 1) (match-end 1)) |
137 (substring signature (match-beginning 2) (match-end 2)) | 155 (substring signature (match-beginning 2) (match-end 2)) |
138 (if (= ?\( (elt signature (match-end 0))) | 156 (if (= ?\( (elt signature (match-end 0))) |
139 (substring signature (match-beginning 3))))))) | 157 (substring signature (match-beginning 3))))))) |
140 | 158 |
159 (defun clos-feature-tag-regexp (class feature-name) | |
160 "Return a regexp that matches to the feature tag entry for CLASS' FEATURE-NAME." | |
161 (concat "^" (regexp-quote class) clos-type-tag-separator | |
162 clos-def-form-match "['\(]?" | |
163 (regexp-quote feature-name) "\\( *(.*)\\)?")) | |
164 | |
141 (defun clos-feature-tree-command-p (class-or-signature) | 165 (defun clos-feature-tree-command-p (class-or-signature) |
142 "Display definition of CLASS-OR-SIGNATURE if a signature and return t, else return nil." | 166 "Display definition of CLASS-OR-SIGNATURE if a signature and return t, else return nil." |
143 (if (br-in-browser) (br-to-view-window)) | 167 (if (br-in-browser) (br-to-view-window)) |
144 (br-feature-found-p (br-feature-file class-or-signature) | 168 (br-feature-found-p (br-feature-file class-or-signature) |
145 class-or-signature)) | 169 class-or-signature)) |
146 | 170 |
147 (defun clos-list-features (class &optional indent) | 171 (defun clos-list-features (class &optional indent) |
148 "Return sorted list of clos feature names lexically defined in CLASS." | 172 "Return sorted list of Clos feature tags lexically defined in CLASS. |
149 (let ((obuf (current-buffer)) | 173 Optional INDENT is unused but is required for multi-language OO-Browser conformance." |
150 (class-tag (concat "\n" class clos-type-tag-separator)) | 174 ;; Use nreverse here so that stable sort ends up leaving same named |
151 (features)) | 175 ;; features in the order they were defined in the source file. |
152 (set-buffer (funcall br-find-file-noselect-function br-feature-tags-file)) | 176 (clos-sort-features |
153 (goto-char 1) | 177 (nreverse (clos-feature-map-class-tags 'br-feature-current class)))) |
154 ;; Feature defs (methods) for a single class could occur in any file, | |
155 ;; according to Common Lisp rules. | |
156 (while (search-forward class-tag nil t) | |
157 (setq features (cons (br-feature-current) features))) | |
158 (set-buffer obuf) | |
159 (clos-sort-features (nreverse features)))) | |
160 | 178 |
161 (defun clos-scan-features () | 179 (defun clos-scan-features () |
162 "Return reverse ordered list of clos feature definitions in current buffer. | 180 "Return reverse ordered list of clos feature definitions in current buffer. |
163 Assume point is at the beginning of a widened buffer." | 181 Assume point is at the beginning of a widened buffer." |
164 (save-excursion | 182 (save-excursion |
254 | 272 |
255 (defun clos-feature-partial-name (signature &optional with-class) | 273 (defun clos-feature-partial-name (signature &optional with-class) |
256 "Extract the feature name without its class name from feature SIGNATURE. | 274 "Extract the feature name without its class name from feature SIGNATURE. |
257 If optional WITH-CLASS is non-nil, class name and 'clos-type-tag-separator' | 275 If optional WITH-CLASS is non-nil, class name and 'clos-type-tag-separator' |
258 are prepended to the name returned." | 276 are prepended to the name returned." |
259 (if (string-match clos-feature-tag-regexp signature) | 277 (if (string-match clos-tag-fields-regexp signature) |
260 (let ((class (substring signature | 278 (let ((class (substring signature |
261 (match-beginning 1) (match-end 1))) | 279 (match-beginning 1) (match-end 1))) |
262 (name (substring signature (match-beginning 2) | 280 (name (substring signature (match-beginning 2) |
263 (match-end 2)))) | 281 (match-end 2)))) |
264 (setq name (br-delete-space name)) | 282 (setq name (br-delete-space name)) |
271 | 289 |
272 (defun clos-feature-lessp (routine1 routine2) | 290 (defun clos-feature-lessp (routine1 routine2) |
273 (string-lessp (clos-feature-partial-name routine1) | 291 (string-lessp (clos-feature-partial-name routine1) |
274 (clos-feature-partial-name routine2))) | 292 (clos-feature-partial-name routine2))) |
275 | 293 |
294 (defun clos-feature-map-tags (function regexp) | |
295 "Apply FUNCTION to all current feature tags that match REGEXP and return a list of the results. | |
296 Feature tags come from the file named by br-feature-tags-file." | |
297 (let ((identifier-chars (concat "[" clos-identifier-chars "]*")) | |
298 (results)) | |
299 ;; Ensure match to feature names only; also handle "^" and "$" meta-chars | |
300 (setq regexp | |
301 (concat "^\\(" clos-type-identifier "\\)" | |
302 clos-type-tag-separator | |
303 clos-def-form-match "['\(]?" | |
304 (if (equal (substring regexp 0 1) "^") | |
305 (progn (setq regexp (substring regexp 1)) nil) | |
306 identifier-chars) | |
307 (if (equal (substring regexp -1) "$") | |
308 (substring regexp 0 -1) | |
309 (concat regexp identifier-chars)) | |
310 "[ \t\n\r\f]")) | |
311 (save-excursion | |
312 (set-buffer (funcall br-find-file-noselect-function br-feature-tags-file)) | |
313 (goto-char 1) | |
314 (while (re-search-forward regexp nil t) | |
315 (setq results (cons (funcall function) results)))) | |
316 results)) | |
317 | |
276 (defun clos-feature-matches (regexp) | 318 (defun clos-feature-matches (regexp) |
277 "Return an unsorted list of feature tags whose names match in part or whole to REGEXP." | 319 "Return an unsorted list of feature tags whose names match in part or whole to REGEXP. |
278 ;; Ensure match to feature names only; also handle "^" and "$" meta-chars | 320 ^ and $ characters may be used to match to the beginning and end of a feature name, |
279 (setq regexp | 321 respectively." |
280 (concat "^\\(" clos-type-identifier "\\)" | 322 (clos-feature-map-tags |
281 clos-type-tag-separator | 323 ;; Backward-char is necessary in this next function since point might have |
282 clos-def-form-match "['\(]?" | 324 ;; moved past a newline. |
283 (if (equal (substring regexp 0 1) "^") | 325 (function (lambda () (backward-char) (br-feature-current))) |
284 (progn (setq regexp (substring regexp 1)) nil) | 326 regexp)) |
285 (concat "[" clos-identifier-chars "]*")) | 327 |
286 (if (equal (substring regexp -1) "$") | |
287 (substring regexp 0 -1) | |
288 (concat regexp "[" clos-identifier-chars "]*")) | |
289 "[ \t\n\r]")) | |
290 (save-excursion | |
291 (set-buffer (funcall br-find-file-noselect-function br-feature-tags-file)) | |
292 (goto-char 1) | |
293 (let ((features)) | |
294 (while (re-search-forward regexp nil t) | |
295 (backward-char) ;; Might have moved past newline. | |
296 (setq features (cons (br-feature-current) features))) | |
297 features))) | |
298 | 328 |
299 (defun clos-feature-normalize (routine) | 329 (defun clos-feature-normalize (routine) |
300 (let* ((len (length routine)) | 330 (let* ((len (length routine)) |
301 (normal-feature (make-string len ?\ )) | 331 (normal-feature (make-string len ?\ )) |
302 (n 0) (i 0) | 332 (n 0) (i 0) |