comparison lisp/oobr/br-clos-ft.el @ 70:131b0175ea99 r20-0b30

Import from CVS: tag r20-0b30
author cvs
date Mon, 13 Aug 2007 09:02:59 +0200
parents 4103f0995bd7
children 4be1180a9e89
comparison
equal deleted inserted replaced
69:804d1389bcd6 70:131b0175ea99
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: InfoDock Associates 9 ;; ORG: Motorola Inc.
10 ;; 10 ;;
11 ;; ORIG-DATE: 03-Oct-90 11 ;; ORIG-DATE: 03-Oct-90
12 ;; LAST-MOD: 31-Oct-96 at 17:04:54 by Bob Weiner 12 ;; LAST-MOD: 6-Aug-95 at 01:52:28 by Bob Weiner
13 ;; 13 ;;
14 ;; Copyright (C) 1990-1996 Free Software Foundation, Inc. 14 ;; Copyright (C) 1990-1995 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-tag-fields-regexp 40 (defconst clos-feature-tag-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
127 (defun clos-feature-name-to-regexp (name) 109 (defun clos-feature-name-to-regexp (name)
128 "Converts feature NAME into a regular expression matching the feature's name tag." 110 "Converts feature NAME into a regular expression matching the feature's name tag."
129 (if (string-match (concat "^" br-feature-type-regexp " ") name) 111 (if (string-match (concat "^" br-feature-type-regexp " ") name)
130 (setq name (substring name (match-end 0)))) 112 (setq name (substring name (match-end 0))))
131 (format "%s%s\(\\(%s\\) %s[ \n]" 113 (format "%s%s\(\\(%s\\) %s[ \n]"
154 (substring signature (match-beginning 1) (match-end 1)) 136 (substring signature (match-beginning 1) (match-end 1))
155 (substring signature (match-beginning 2) (match-end 2)) 137 (substring signature (match-beginning 2) (match-end 2))
156 (if (= ?\( (elt signature (match-end 0))) 138 (if (= ?\( (elt signature (match-end 0)))
157 (substring signature (match-beginning 3))))))) 139 (substring signature (match-beginning 3)))))))
158 140
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
165 (defun clos-feature-tree-command-p (class-or-signature) 141 (defun clos-feature-tree-command-p (class-or-signature)
166 "Display definition of CLASS-OR-SIGNATURE if a signature and return t, else return nil." 142 "Display definition of CLASS-OR-SIGNATURE if a signature and return t, else return nil."
167 (if (br-in-browser) (br-to-view-window)) 143 (if (br-in-browser) (br-to-view-window))
168 (br-feature-found-p (br-feature-file class-or-signature) 144 (br-feature-found-p (br-feature-file class-or-signature)
169 class-or-signature)) 145 class-or-signature))
170 146
171 (defun clos-list-features (class &optional indent) 147 (defun clos-list-features (class &optional indent)
172 "Return sorted list of Clos feature tags lexically defined in CLASS. 148 "Return sorted list of clos feature names lexically defined in CLASS."
173 Optional INDENT is unused but is required for multi-language OO-Browser conformance." 149 (let ((obuf (current-buffer))
174 ;; Use nreverse here so that stable sort ends up leaving same named 150 (class-tag (concat "\n" class clos-type-tag-separator))
175 ;; features in the order they were defined in the source file. 151 (features))
176 (clos-sort-features 152 (set-buffer (funcall br-find-file-noselect-function br-feature-tags-file))
177 (nreverse (clos-feature-map-class-tags 'br-feature-current class)))) 153 (goto-char 1)
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))))
178 160
179 (defun clos-scan-features () 161 (defun clos-scan-features ()
180 "Return reverse ordered list of clos feature definitions in current buffer. 162 "Return reverse ordered list of clos feature definitions in current buffer.
181 Assume point is at the beginning of a widened buffer." 163 Assume point is at the beginning of a widened buffer."
182 (save-excursion 164 (save-excursion
272 254
273 (defun clos-feature-partial-name (signature &optional with-class) 255 (defun clos-feature-partial-name (signature &optional with-class)
274 "Extract the feature name without its class name from feature SIGNATURE. 256 "Extract the feature name without its class name from feature SIGNATURE.
275 If optional WITH-CLASS is non-nil, class name and 'clos-type-tag-separator' 257 If optional WITH-CLASS is non-nil, class name and 'clos-type-tag-separator'
276 are prepended to the name returned." 258 are prepended to the name returned."
277 (if (string-match clos-tag-fields-regexp signature) 259 (if (string-match clos-feature-tag-regexp signature)
278 (let ((class (substring signature 260 (let ((class (substring signature
279 (match-beginning 1) (match-end 1))) 261 (match-beginning 1) (match-end 1)))
280 (name (substring signature (match-beginning 2) 262 (name (substring signature (match-beginning 2)
281 (match-end 2)))) 263 (match-end 2))))
282 (setq name (br-delete-space name)) 264 (setq name (br-delete-space name))
289 271
290 (defun clos-feature-lessp (routine1 routine2) 272 (defun clos-feature-lessp (routine1 routine2)
291 (string-lessp (clos-feature-partial-name routine1) 273 (string-lessp (clos-feature-partial-name routine1)
292 (clos-feature-partial-name routine2))) 274 (clos-feature-partial-name routine2)))
293 275
294 (defun clos-feature-map-tags (function regexp) 276 (defun clos-feature-matches (regexp)
295 "Apply FUNCTION to all current feature tags that match REGEXP and return a list of the results. 277 "Return an unsorted list of feature tags whose names match in part or whole to REGEXP."
296 Feature tags come from the file named by br-feature-tags-file." 278 ;; Ensure match to feature names only; also handle "^" and "$" meta-chars
297 (let ((identifier-chars (concat "[" clos-identifier-chars "]*")) 279 (setq regexp
298 (results)) 280 (concat "^\\(" clos-type-identifier "\\)"
299 ;; Ensure match to feature names only; also handle "^" and "$" meta-chars 281 clos-type-tag-separator
300 (setq regexp 282 clos-def-form-match "['\(]?"
301 (concat "^\\(" clos-type-identifier "\\)" 283 (if (equal (substring regexp 0 1) "^")
302 clos-type-tag-separator 284 (progn (setq regexp (substring regexp 1)) nil)
303 clos-def-form-match "['\(]?" 285 (concat "[" clos-identifier-chars "]*"))
304 (if (equal (substring regexp 0 1) "^") 286 (if (equal (substring regexp -1) "$")
305 (progn (setq regexp (substring regexp 1)) nil) 287 (substring regexp 0 -1)
306 identifier-chars) 288 (concat regexp "[" clos-identifier-chars "]*"))
307 (if (equal (substring regexp -1) "$") 289 "[ \t\n\r]"))
308 (substring regexp 0 -1) 290 (save-excursion
309 (concat regexp identifier-chars)) 291 (set-buffer (funcall br-find-file-noselect-function br-feature-tags-file))
310 "[ \t\n\r\f]")) 292 (goto-char 1)
311 (save-excursion 293 (let ((features))
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) 294 (while (re-search-forward regexp nil t)
315 (setq results (cons (funcall function) results)))) 295 (backward-char) ;; Might have moved past newline.
316 results)) 296 (setq features (cons (br-feature-current) features)))
317 297 features)))
318 (defun clos-feature-matches (regexp)
319 "Return an unsorted list of feature tags whose names match in part or whole to REGEXP.
320 ^ and $ characters may be used to match to the beginning and end of a feature name,
321 respectively."
322 (clos-feature-map-tags
323 ;; Backward-char is necessary in this next function since point might have
324 ;; moved past a newline.
325 (function (lambda () (backward-char) (br-feature-current)))
326 regexp))
327
328 298
329 (defun clos-feature-normalize (routine) 299 (defun clos-feature-normalize (routine)
330 (let* ((len (length routine)) 300 (let* ((len (length routine))
331 (normal-feature (make-string len ?\ )) 301 (normal-feature (make-string len ?\ ))
332 (n 0) (i 0) 302 (n 0) (i 0)