Commit | Line | Data |
---|---|---|
6dd12ef2 CY |
1 | ;;; eieio-opt.el -- eieio optional functions (debug, printing, speedbar) |
2 | ||
acaf905b | 3 | ;; Copyright (C) 1996, 1998-2003, 2005, 2008-2012 |
95df8112 | 4 | ;; Free Software Foundation, Inc. |
6dd12ef2 | 5 | |
9ffe3f52 | 6 | ;; Author: Eric M. Ludlam <zappo@gnu.org> |
6dd12ef2 | 7 | ;; Keywords: OO, lisp |
bd78fa1d | 8 | ;; Package: eieio |
6dd12ef2 CY |
9 | |
10 | ;; This file is part of GNU Emacs. | |
11 | ||
12 | ;; GNU Emacs is free software: you can redistribute it and/or modify | |
13 | ;; it under the terms of the GNU General Public License as published by | |
14 | ;; the Free Software Foundation, either version 3 of the License, or | |
15 | ;; (at your option) any later version. | |
16 | ||
17 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | ;; GNU General Public License for more details. | |
21 | ||
22 | ;; You should have received a copy of the GNU General Public License | |
23 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |
24 | ||
25 | ;;; Commentary: | |
26 | ;; | |
27 | ;; This contains support functions to eieio. These functions contain | |
28 | ;; some small class browser and class printing functions. | |
29 | ;; | |
30 | ||
31 | (require 'eieio) | |
62a81506 CY |
32 | (require 'button) |
33 | (require 'help-mode) | |
34 | (require 'find-func) | |
6dd12ef2 CY |
35 | |
36 | ;;; Code: | |
002b46b7 | 37 | ;;;###autoload |
6dd12ef2 CY |
38 | (defun eieio-browse (&optional root-class) |
39 | "Create an object browser window to show all objects. | |
40 | If optional ROOT-CLASS, then start with that, otherwise start with | |
41 | variable `eieio-default-superclass'." | |
42 | (interactive (if current-prefix-arg | |
43 | (list (read (completing-read "Class: " | |
44 | (eieio-build-class-alist) | |
45 | nil t))) | |
46 | nil)) | |
47 | (if (not root-class) (setq root-class 'eieio-default-superclass)) | |
48 | (if (not (class-p root-class)) (signal 'wrong-type-argument (list 'class-p root-class))) | |
49 | (display-buffer (get-buffer-create "*EIEIO OBJECT BROWSE*") t) | |
9a529312 | 50 | (with-current-buffer (get-buffer "*EIEIO OBJECT BROWSE*") |
6dd12ef2 CY |
51 | (erase-buffer) |
52 | (goto-char 0) | |
53 | (eieio-browse-tree root-class "" "") | |
54 | )) | |
55 | ||
56 | (defun eieio-browse-tree (this-root prefix ch-prefix) | |
a8f316ca | 57 | "Recursively draw the children of the given class on the screen. |
6dd12ef2 CY |
58 | Argument THIS-ROOT is the local root of the tree. |
59 | Argument PREFIX is the character prefix to use. | |
60 | Argument CH-PREFIX is another character prefix to display." | |
61 | (if (not (class-p (eval this-root))) (signal 'wrong-type-argument (list 'class-p this-root))) | |
62 | (let ((myname (symbol-name this-root)) | |
63 | (chl (aref (class-v this-root) class-children)) | |
64 | (fprefix (concat ch-prefix " +--")) | |
65 | (mprefix (concat ch-prefix " | ")) | |
66 | (lprefix (concat ch-prefix " "))) | |
67 | (insert prefix myname "\n") | |
68 | (while (cdr chl) | |
69 | (eieio-browse-tree (car chl) fprefix mprefix) | |
70 | (setq chl (cdr chl))) | |
71 | (if chl | |
72 | (eieio-browse-tree (car chl) fprefix lprefix)) | |
73 | )) | |
74 | ||
75 | ;;; CLASS COMPLETION / DOCUMENTATION | |
76 | ||
099e7202 | 77 | ;;;###autoload(defalias 'describe-class 'eieio-describe-class) |
6dd12ef2 | 78 | |
002b46b7 | 79 | ;;;###autoload |
6dd12ef2 CY |
80 | (defun eieio-describe-class (class &optional headerfcn) |
81 | "Describe a CLASS defined by a string or symbol. | |
9ffe3f52 | 82 | If CLASS is actually an object, then also display current values of that object. |
6dd12ef2 CY |
83 | Optional HEADERFCN should be called to insert a few bits of info first." |
84 | (interactive (list (eieio-read-class "Class: "))) | |
85 | (with-output-to-temp-buffer (help-buffer) ;"*Help*" | |
86 | (help-setup-xref (list #'eieio-describe-class class headerfcn) | |
32226619 | 87 | (called-interactively-p 'interactive)) |
6dd12ef2 CY |
88 | |
89 | (when headerfcn (funcall headerfcn)) | |
6dd12ef2 | 90 | (prin1 class) |
62a81506 CY |
91 | (princ " is a") |
92 | (if (class-option class :abstract) | |
93 | (princ "n abstract")) | |
94 | (princ " class") | |
95 | ;; Print file location | |
96 | (when (get class 'class-location) | |
97 | (princ " in `") | |
98 | (princ (file-name-nondirectory (get class 'class-location))) | |
99 | (princ "'")) | |
6dd12ef2 | 100 | (terpri) |
f6b1b0a8 | 101 | ;; Inheritance tree information |
6dd12ef2 CY |
102 | (let ((pl (class-parents class))) |
103 | (when pl | |
104 | (princ " Inherits from ") | |
105 | (while pl | |
106 | (princ "`") (prin1 (car pl)) (princ "'") | |
107 | (setq pl (cdr pl)) | |
108 | (if pl (princ ", "))) | |
109 | (terpri))) | |
110 | (let ((ch (class-children class))) | |
111 | (when ch | |
112 | (princ " Children ") | |
113 | (while ch | |
114 | (princ "`") (prin1 (car ch)) (princ "'") | |
115 | (setq ch (cdr ch)) | |
116 | (if ch (princ ", "))) | |
117 | (terpri))) | |
118 | (terpri) | |
119 | ;; System documentation | |
120 | (let ((doc (documentation-property class 'variable-documentation))) | |
121 | (when doc | |
122 | (princ "Documentation:") | |
123 | (terpri) | |
124 | (princ doc) | |
125 | (terpri) | |
126 | (terpri))) | |
127 | ;; Describe all the slots in this class | |
128 | (eieio-describe-class-slots class) | |
129 | ;; Describe all the methods specific to this class. | |
130 | (let ((methods (eieio-all-generic-functions class)) | |
131 | (doc nil)) | |
132 | (if (not methods) nil | |
133 | (princ "Specialized Methods:") | |
134 | (terpri) | |
135 | (terpri) | |
136 | (while methods | |
137 | (setq doc (eieio-method-documentation (car methods) class)) | |
138 | (princ "`") | |
139 | (prin1 (car methods)) | |
140 | (princ "'") | |
141 | (if (not doc) | |
142 | (princ " Undocumented") | |
143 | (if (car doc) | |
144 | (progn | |
145 | (princ " :STATIC ") | |
146 | (prin1 (car (car doc))) | |
147 | (terpri) | |
148 | (princ (cdr (car doc))))) | |
149 | (setq doc (cdr doc)) | |
150 | (if (car doc) | |
151 | (progn | |
152 | (princ " :BEFORE ") | |
153 | (prin1 (car (car doc))) | |
154 | (terpri) | |
155 | (princ (cdr (car doc))))) | |
156 | (setq doc (cdr doc)) | |
157 | (if (car doc) | |
158 | (progn | |
159 | (princ " :PRIMARY ") | |
160 | (prin1 (car (car doc))) | |
161 | (terpri) | |
162 | (princ (cdr (car doc))))) | |
163 | (setq doc (cdr doc)) | |
164 | (if (car doc) | |
165 | (progn | |
166 | (princ " :AFTER ") | |
167 | (prin1 (car (car doc))) | |
168 | (terpri) | |
169 | (princ (cdr (car doc))))) | |
170 | (terpri) | |
171 | (terpri)) | |
172 | (setq methods (cdr methods)))))) | |
9a529312 | 173 | (with-current-buffer (help-buffer) |
6dd12ef2 CY |
174 | (buffer-string))) |
175 | ||
176 | (defun eieio-describe-class-slots (class) | |
177 | "Describe the slots in CLASS. | |
178 | Outputs to the standard output." | |
179 | (let* ((cv (class-v class)) | |
180 | (docs (aref cv class-public-doc)) | |
181 | (names (aref cv class-public-a)) | |
182 | (deflt (aref cv class-public-d)) | |
183 | (types (aref cv class-public-type)) | |
184 | (publp (aref cv class-public-printer)) | |
185 | (i 0) | |
186 | (prot (aref cv class-protection)) | |
187 | ) | |
188 | (princ "Instance Allocated Slots:") | |
189 | (terpri) | |
190 | (terpri) | |
191 | (while names | |
192 | (if (car prot) (princ "Private ")) | |
193 | (princ "Slot: ") | |
194 | (prin1 (car names)) | |
195 | (when (not (eq (aref types i) t)) | |
196 | (princ " type = ") | |
197 | (prin1 (aref types i))) | |
198 | (unless (eq (car deflt) eieio-unbound) | |
199 | (princ " default = ") | |
200 | (prin1 (car deflt))) | |
201 | (when (car publp) | |
202 | (princ " printer = ") | |
203 | (prin1 (car publp))) | |
204 | (when (car docs) | |
205 | (terpri) | |
206 | (princ " ") | |
207 | (princ (car docs)) | |
208 | (terpri)) | |
209 | (terpri) | |
210 | (setq names (cdr names) | |
211 | docs (cdr docs) | |
212 | deflt (cdr deflt) | |
213 | publp (cdr publp) | |
214 | prot (cdr prot) | |
215 | i (1+ i))) | |
216 | (setq docs (aref cv class-class-allocation-doc) | |
217 | names (aref cv class-class-allocation-a) | |
218 | types (aref cv class-class-allocation-type) | |
219 | i 0 | |
220 | prot (aref cv class-class-allocation-protection)) | |
221 | (when names | |
222 | (terpri) | |
223 | (princ "Class Allocated Slots:")) | |
224 | (terpri) | |
225 | (terpri) | |
226 | (while names | |
227 | (when (car prot) | |
228 | (princ "Private ")) | |
229 | (princ "Slot: ") | |
230 | (prin1 (car names)) | |
231 | (unless (eq (aref types i) t) | |
232 | (princ " type = ") | |
233 | (prin1 (aref types i))) | |
234 | (condition-case nil | |
235 | (let ((value (eieio-oref class (car names)))) | |
236 | (princ " value = ") | |
237 | (prin1 value)) | |
238 | (error nil)) | |
239 | (when (car docs) | |
240 | (terpri) | |
241 | (princ " ") | |
242 | (princ (car docs)) | |
243 | (terpri)) | |
244 | (terpri) | |
245 | (setq names (cdr names) | |
246 | docs (cdr docs) | |
247 | prot (cdr prot) | |
248 | i (1+ i))))) | |
249 | ||
002b46b7 | 250 | ;;;###autoload |
6dd12ef2 CY |
251 | (defun eieio-describe-constructor (fcn) |
252 | "Describe the constructor function FCN. | |
253 | Uses `eieio-describe-class' to describe the class being constructed." | |
254 | (interactive | |
255 | ;; Use eieio-read-class since all constructors have the same name as | |
256 | ;; the class they create. | |
257 | (list (eieio-read-class "Class: "))) | |
258 | (eieio-describe-class | |
259 | fcn (lambda () | |
260 | ;; Describe the constructor part. | |
6dd12ef2 | 261 | (prin1 fcn) |
62a81506 CY |
262 | (princ " is an object constructor function") |
263 | ;; Print file location | |
264 | (when (get fcn 'class-location) | |
265 | (princ " in `") | |
266 | (princ (file-name-nondirectory (get fcn 'class-location))) | |
267 | (princ "'")) | |
6dd12ef2 CY |
268 | (terpri) |
269 | (princ "Creates an object of class ") | |
270 | (prin1 fcn) | |
271 | (princ ".") | |
272 | (terpri) | |
273 | (terpri) | |
274 | )) | |
275 | ) | |
276 | ||
62a81506 CY |
277 | (defun eieio-build-class-list (class) |
278 | "Return a list of all classes that inherit from CLASS." | |
279 | (if (class-p class) | |
280 | (apply #'append | |
281 | (mapcar | |
282 | (lambda (c) | |
283 | (append (list c) (eieio-build-class-list c))) | |
284 | (class-children-fast class))) | |
285 | (list class))) | |
286 | ||
6dd12ef2 CY |
287 | (defun eieio-build-class-alist (&optional class instantiable-only buildlist) |
288 | "Return an alist of all currently active classes for completion purposes. | |
289 | Optional argument CLASS is the class to start with. | |
290 | If INSTANTIABLE-ONLY is non nil, only allow names of classes which | |
291 | are not abstract, otherwise allow all classes. | |
292 | Optional argument BUILDLIST is more list to attach and is used internally." | |
293 | (let* ((cc (or class eieio-default-superclass)) | |
294 | (sublst (aref (class-v cc) class-children))) | |
62a81506 CY |
295 | (unless (assoc (symbol-name cc) buildlist) |
296 | (when (or (not instantiable-only) (not (class-abstract-p cc))) | |
297 | (setq buildlist (cons (cons (symbol-name cc) 1) buildlist)))) | |
6dd12ef2 CY |
298 | (while sublst |
299 | (setq buildlist (eieio-build-class-alist | |
300 | (car sublst) instantiable-only buildlist)) | |
301 | (setq sublst (cdr sublst))) | |
302 | buildlist)) | |
303 | ||
304 | (defvar eieio-read-class nil | |
305 | "History of the function `eieio-read-class' prompt.") | |
306 | ||
307 | (defun eieio-read-class (prompt &optional histvar instantiable-only) | |
308 | "Return a class chosen by the user using PROMPT. | |
309 | Optional argument HISTVAR is a variable to use as history. | |
310 | If INSTANTIABLE-ONLY is non nil, only allow names of classes which | |
311 | are not abstract." | |
312 | (intern (completing-read prompt (eieio-build-class-alist nil instantiable-only) | |
313 | nil t nil | |
314 | (or histvar 'eieio-read-class)))) | |
315 | ||
316 | (defun eieio-read-subclass (prompt class &optional histvar instantiable-only) | |
317 | "Return a class chosen by the user using PROMPT. | |
318 | CLASS is the base class, and completion occurs across all subclasses. | |
319 | Optional argument HISTVAR is a variable to use as history. | |
320 | If INSTANTIABLE-ONLY is non nil, only allow names of classes which | |
321 | are not abstract." | |
322 | (intern (completing-read prompt | |
323 | (eieio-build-class-alist class instantiable-only) | |
324 | nil t nil | |
325 | (or histvar 'eieio-read-class)))) | |
326 | ||
327 | ;;; METHOD COMPLETION / DOC | |
328 | ||
329 | (defalias 'describe-method 'eieio-describe-generic) | |
099e7202 | 330 | ;;;###autoload(defalias 'describe-generic 'eieio-describe-generic) |
6dd12ef2 CY |
331 | (defalias 'eieio-describe-method 'eieio-describe-generic) |
332 | ||
002b46b7 | 333 | ;;;###autoload |
6dd12ef2 CY |
334 | (defun eieio-describe-generic (generic) |
335 | "Describe the generic function GENERIC. | |
336 | Also extracts information about all methods specific to this generic." | |
337 | (interactive (list (eieio-read-generic "Generic Method: "))) | |
338 | (if (not (generic-p generic)) | |
339 | (signal 'wrong-type-argument '(generic-p generic))) | |
340 | (with-output-to-temp-buffer (help-buffer) ; "*Help*" | |
32226619 JB |
341 | (help-setup-xref (list #'eieio-describe-generic generic) |
342 | (called-interactively-p 'interactive)) | |
6dd12ef2 CY |
343 | |
344 | (prin1 generic) | |
345 | (princ " is a generic function") | |
346 | (when (generic-primary-only-p generic) | |
347 | (princ " with only ") | |
348 | (when (generic-primary-only-one-p generic) | |
349 | (princ "one ")) | |
350 | (princ "primary method") | |
351 | (when (not (generic-primary-only-one-p generic)) | |
352 | (princ "s")) | |
353 | ) | |
354 | (princ ".") | |
355 | (terpri) | |
356 | (terpri) | |
357 | (let ((d (documentation generic))) | |
358 | (if (not d) | |
359 | (princ "The generic is not documented.\n") | |
360 | (princ "Documentation:") | |
361 | (terpri) | |
362 | (princ d) | |
363 | (terpri) | |
364 | (terpri))) | |
365 | (princ "Implementations:") | |
366 | (terpri) | |
367 | (terpri) | |
62a81506 | 368 | (let ((i 4) |
6dd12ef2 CY |
369 | (prefix [ ":STATIC" ":BEFORE" ":PRIMARY" ":AFTER" ] )) |
370 | ;; Loop over fanciful generics | |
62a81506 | 371 | (while (< i 7) |
6dd12ef2 CY |
372 | (let ((gm (aref (get generic 'eieio-method-tree) i))) |
373 | (when gm | |
374 | (princ "Generic ") | |
375 | (princ (aref prefix (- i 3))) | |
376 | (terpri) | |
377 | (princ (or (nth 2 gm) "Undocumented")) | |
378 | (terpri) | |
379 | (terpri))) | |
380 | (setq i (1+ i))) | |
381 | (setq i 0) | |
382 | ;; Loop over defined class-specific methods | |
62a81506 CY |
383 | (while (< i 4) |
384 | (let ((gm (reverse (aref (get generic 'eieio-method-tree) i))) | |
385 | location) | |
6dd12ef2 CY |
386 | (while gm |
387 | (princ "`") | |
388 | (prin1 (car (car gm))) | |
389 | (princ "'") | |
390 | ;; prefix type | |
391 | (princ " ") | |
392 | (princ (aref prefix i)) | |
393 | (princ " ") | |
394 | ;; argument list | |
395 | (let* ((func (cdr (car gm))) | |
396 | (arglst (eieio-lambda-arglist func))) | |
397 | (prin1 arglst)) | |
398 | (terpri) | |
399 | ;; 3 because of cdr | |
400 | (princ (or (documentation (cdr (car gm))) | |
401 | "Undocumented")) | |
62a81506 CY |
402 | ;; Print file location if available |
403 | (when (and (setq location (get generic 'method-locations)) | |
404 | (setq location (assoc (caar gm) location))) | |
405 | (setq location (cadr location)) | |
406 | (princ "\n\nDefined in `") | |
407 | (princ (file-name-nondirectory location)) | |
408 | (princ "'\n")) | |
6dd12ef2 CY |
409 | (setq gm (cdr gm)) |
410 | (terpri) | |
411 | (terpri))) | |
412 | (setq i (1+ i))))) | |
9a529312 | 413 | (with-current-buffer (help-buffer) |
6dd12ef2 CY |
414 | (buffer-string))) |
415 | ||
416 | (defun eieio-lambda-arglist (func) | |
417 | "Return the argument list of FUNC, a function body." | |
418 | (if (symbolp func) (setq func (symbol-function func))) | |
419 | (if (byte-code-function-p func) | |
420 | (eieio-compiled-function-arglist func) | |
421 | (car (cdr func)))) | |
422 | ||
423 | (defun eieio-all-generic-functions (&optional class) | |
424 | "Return a list of all generic functions. | |
a8f316ca JB |
425 | Optional CLASS argument returns only those functions that contain |
426 | methods for CLASS." | |
6dd12ef2 CY |
427 | (let ((l nil) tree (cn (if class (symbol-name class) nil))) |
428 | (mapatoms | |
429 | (lambda (symbol) | |
430 | (setq tree (get symbol 'eieio-method-obarray)) | |
431 | (if tree | |
432 | (progn | |
433 | ;; A symbol might be interned for that class in one of | |
434 | ;; these three slots in the method-obarray. | |
435 | (if (or (not class) | |
436 | (fboundp (intern-soft cn (aref tree 0))) | |
437 | (fboundp (intern-soft cn (aref tree 1))) | |
438 | (fboundp (intern-soft cn (aref tree 2)))) | |
439 | (setq l (cons symbol l))))))) | |
440 | l)) | |
441 | ||
442 | (defun eieio-method-documentation (generic class) | |
443 | "Return a list of the specific documentation of GENERIC for CLASS. | |
444 | If there is not an explicit method for CLASS in GENERIC, or if that | |
445 | function has no documentation, then return nil." | |
446 | (let ((tree (get generic 'eieio-method-obarray)) | |
447 | (cn (symbol-name class)) | |
448 | before primary after) | |
449 | (if (not tree) | |
450 | nil | |
451 | ;; A symbol might be interned for that class in one of | |
452 | ;; these three slots in the method-obarray. | |
453 | (setq before (intern-soft cn (aref tree 0)) | |
454 | primary (intern-soft cn (aref tree 1)) | |
455 | after (intern-soft cn (aref tree 2))) | |
456 | (if (not (or (fboundp before) | |
457 | (fboundp primary) | |
458 | (fboundp after))) | |
459 | nil | |
460 | (list (if (fboundp before) | |
461 | (cons (eieio-lambda-arglist before) | |
462 | (documentation before)) | |
463 | nil) | |
464 | (if (fboundp primary) | |
465 | (cons (eieio-lambda-arglist primary) | |
466 | (documentation primary)) | |
467 | nil) | |
468 | (if (fboundp after) | |
469 | (cons (eieio-lambda-arglist after) | |
470 | (documentation after)) | |
471 | nil)))))) | |
472 | ||
473 | (defvar eieio-read-generic nil | |
474 | "History of the `eieio-read-generic' prompt.") | |
475 | ||
476 | (defun eieio-read-generic-p (fn) | |
477 | "Function used in function `eieio-read-generic'. | |
478 | This is because `generic-p' is a macro. | |
479 | Argument FN is the function to test." | |
480 | (generic-p fn)) | |
481 | ||
482 | (defun eieio-read-generic (prompt &optional historyvar) | |
483 | "Read a generic function from the minibuffer with PROMPT. | |
484 | Optional argument HISTORYVAR is the variable to use as history." | |
485 | (intern (completing-read prompt obarray 'eieio-read-generic-p | |
486 | t nil (or historyvar 'eieio-read-generic)))) | |
487 | ||
488 | ;;; METHOD STATS | |
489 | ;; | |
490 | ;; Dump out statistics about all the active methods in a session. | |
491 | (defun eieio-display-method-list () | |
492 | "Display a list of all the methods and what features are used." | |
493 | (interactive) | |
494 | (let* ((meth1 (eieio-all-generic-functions)) | |
495 | (meth (sort meth1 (lambda (a b) | |
496 | (string< (symbol-name a) | |
497 | (symbol-name b))))) | |
498 | (buff (get-buffer-create "*EIEIO Method List*")) | |
499 | (methidx 0) | |
500 | (standard-output buff) | |
501 | (slots '(method-static | |
502 | method-before | |
503 | method-primary | |
504 | method-after | |
505 | method-generic-before | |
506 | method-generic-primary | |
507 | method-generic-after)) | |
508 | (slotn '("static" | |
509 | "before" | |
510 | "primary" | |
511 | "after" | |
512 | "G bef" | |
513 | "G prim" | |
514 | "G aft")) | |
515 | (idxarray (make-vector (length slots) 0)) | |
516 | (primaryonly 0) | |
517 | (oneprimary 0) | |
518 | ) | |
519 | (switch-to-buffer-other-window buff) | |
520 | (erase-buffer) | |
521 | (dolist (S slotn) | |
522 | (princ S) | |
523 | (princ "\t") | |
524 | ) | |
525 | (princ "Method Name") | |
526 | (terpri) | |
527 | (princ "--------------------------------------------------------------------") | |
528 | (terpri) | |
529 | (dolist (M meth) | |
530 | (let ((mtree (get M 'eieio-method-tree)) | |
531 | (P nil) (numP) | |
532 | (!P nil)) | |
533 | (dolist (S slots) | |
534 | (let ((num (length (aref mtree (symbol-value S))))) | |
535 | (aset idxarray (symbol-value S) | |
536 | (+ num (aref idxarray (symbol-value S)))) | |
537 | (prin1 num) | |
538 | (princ "\t") | |
539 | (when (< 0 num) | |
540 | (if (eq S 'method-primary) | |
541 | (setq P t numP num) | |
542 | (setq !P t))) | |
543 | )) | |
544 | ;; Is this a primary-only impl method? | |
545 | (when (and P (not !P)) | |
546 | (setq primaryonly (1+ primaryonly)) | |
547 | (when (= numP 1) | |
548 | (setq oneprimary (1+ oneprimary)) | |
549 | (princ "*")) | |
550 | (princ "* ") | |
551 | ) | |
552 | (prin1 M) | |
553 | (terpri) | |
554 | (setq methidx (1+ methidx)) | |
555 | ) | |
556 | ) | |
557 | (princ "--------------------------------------------------------------------") | |
558 | (terpri) | |
559 | (dolist (S slots) | |
560 | (prin1 (aref idxarray (symbol-value S))) | |
561 | (princ "\t") | |
562 | ) | |
563 | (prin1 methidx) | |
564 | (princ " Total symbols") | |
565 | (terpri) | |
566 | (dolist (S slotn) | |
567 | (princ S) | |
568 | (princ "\t") | |
569 | ) | |
570 | (terpri) | |
571 | (terpri) | |
572 | (princ "Methods Primary Only: ") | |
573 | (prin1 primaryonly) | |
574 | (princ "\t") | |
575 | (princ (format "%d" (* (/ (float primaryonly) (float methidx)) 100))) | |
576 | (princ "% of total methods") | |
577 | (terpri) | |
578 | (princ "Only One Primary Impl: ") | |
579 | (prin1 oneprimary) | |
580 | (princ "\t") | |
581 | (princ (format "%d" (* (/ (float oneprimary) (float primaryonly)) 100))) | |
582 | (princ "% of total primary methods") | |
583 | (terpri) | |
584 | )) | |
585 | ||
586 | ;;; HELP AUGMENTATION | |
587 | ;; | |
62a81506 CY |
588 | (define-button-type 'eieio-method-def |
589 | :supertype 'help-xref | |
590 | 'help-function (lambda (class method file) | |
591 | (eieio-help-find-method-definition class method file)) | |
592 | 'help-echo (purecopy "mouse-2, RET: find method's definition")) | |
593 | ||
594 | (define-button-type 'eieio-class-def | |
595 | :supertype 'help-xref | |
596 | 'help-function (lambda (class file) | |
597 | (eieio-help-find-class-definition class file)) | |
598 | 'help-echo (purecopy "mouse-2, RET: find class definition")) | |
599 | ||
600 | (defun eieio-help-find-method-definition (class method file) | |
601 | (let ((filename (find-library-name file)) | |
602 | location buf) | |
603 | (when (null filename) | |
604 | (error "Cannot find library %s" file)) | |
605 | (setq buf (find-file-noselect filename)) | |
606 | (with-current-buffer buf | |
607 | (goto-char (point-min)) | |
608 | (when | |
609 | (re-search-forward | |
610 | ;; Regexp for searching methods. | |
611 | (concat "(defmethod[ \t\r\n]+" method | |
612 | "\\([ \t\r\n]+:[a-zA-Z]+\\)?" | |
613 | "[ \t\r\n]+(\\s-*(\\(\\sw\\|\\s_\\)+\\s-+" | |
614 | class | |
615 | "\\s-*)") | |
616 | nil t) | |
617 | (setq location (match-beginning 0)))) | |
618 | (if (null location) | |
619 | (message "Unable to find location in file") | |
620 | (pop-to-buffer buf) | |
621 | (goto-char location) | |
622 | (recenter) | |
623 | (beginning-of-line)))) | |
624 | ||
625 | (defun eieio-help-find-class-definition (class file) | |
626 | (let ((filename (find-library-name file)) | |
627 | location buf) | |
628 | (when (null filename) | |
629 | (error "Cannot find library %s" file)) | |
630 | (setq buf (find-file-noselect filename)) | |
631 | (with-current-buffer buf | |
632 | (goto-char (point-min)) | |
633 | (when | |
634 | (re-search-forward | |
635 | ;; Regexp for searching a class. | |
636 | (concat "(defclass[ \t\r\n]+" class "[ \t\r\n]+") | |
637 | nil t) | |
638 | (setq location (match-beginning 0)))) | |
639 | (if (null location) | |
640 | (message "Unable to find location in file") | |
641 | (pop-to-buffer buf) | |
642 | (goto-char location) | |
643 | (recenter) | |
644 | (beginning-of-line)))) | |
645 | ||
646 | ||
6dd12ef2 | 647 | (defun eieio-help-mode-augmentation-maybee (&rest unused) |
a8f316ca | 648 | "For buffers thrown into help mode, augment for EIEIO. |
6dd12ef2 CY |
649 | Arguments UNUSED are not used." |
650 | ;; Scan created buttons so far if we are in help mode. | |
651 | (when (eq major-mode 'help-mode) | |
652 | (save-excursion | |
653 | (goto-char (point-min)) | |
654 | (let ((pos t) (inhibit-read-only t)) | |
655 | (while pos | |
656 | (if (get-text-property (point) 'help-xref) ; move off reference | |
657 | (goto-char | |
658 | (or (next-single-property-change (point) 'help-xref) | |
659 | (point)))) | |
660 | (setq pos (next-single-property-change (point) 'help-xref)) | |
661 | (when pos | |
662 | (goto-char pos) | |
663 | (let* ((help-data (get-text-property (point) 'help-xref)) | |
664 | ;(method (car help-data)) | |
665 | (args (cdr help-data))) | |
666 | (when (symbolp (car args)) | |
667 | (cond ((class-p (car args)) | |
668 | (setcar help-data 'eieio-describe-class)) | |
669 | ((generic-p (car args)) | |
670 | (setcar help-data 'eieio-describe-generic)) | |
671 | (t nil)) | |
672 | )))) | |
673 | ;; start back at the beginning, and highlight some sections | |
674 | (goto-char (point-min)) | |
675 | (while (re-search-forward "^\\(Documentation\\|Implementations\\):$" nil t) | |
676 | (put-text-property (match-beginning 0) (match-end 0) 'face 'bold)) | |
677 | (goto-char (point-min)) | |
678 | (if (re-search-forward "^Specialized Methods:$" nil t) | |
679 | (put-text-property (match-beginning 0) (match-end 0) 'face 'bold)) | |
680 | (goto-char (point-min)) | |
681 | (while (re-search-forward "^\\(Instance\\|Class\\) Allocated Slots:$" nil t) | |
682 | (put-text-property (match-beginning 0) (match-end 0) 'face 'bold)) | |
683 | (goto-char (point-min)) | |
684 | (while (re-search-forward ":\\(STATIC\\|BEFORE\\|AFTER\\|PRIMARY\\)" nil t) | |
685 | (put-text-property (match-beginning 0) (match-end 0) 'face 'bold)) | |
686 | (goto-char (point-min)) | |
687 | (while (re-search-forward "^\\(Private \\)?Slot:" nil t) | |
688 | (put-text-property (match-beginning 0) (match-end 0) 'face 'bold)) | |
62a81506 CY |
689 | (goto-char (point-min)) |
690 | (cond | |
691 | ((looking-at "\\(.+\\) is a generic function") | |
692 | (let ((mname (match-string 1)) | |
693 | cname) | |
694 | (while (re-search-forward "^`\\(.+\\)'[^\0]+?Defined in `\\(.+\\)'" nil t) | |
695 | (setq cname (match-string-no-properties 1)) | |
696 | (help-xref-button 2 'eieio-method-def cname | |
697 | mname | |
698 | (cadr (assoc (intern cname) | |
699 | (get (intern mname) | |
700 | 'method-locations))))))) | |
701 | ((looking-at "\\(.+\\) is an object constructor function in `\\(.+\\)'") | |
702 | (let ((cname (match-string-no-properties 1))) | |
703 | (help-xref-button 2 'eieio-class-def cname | |
704 | (get (intern cname) 'class-location)))) | |
705 | ((looking-at "\\(.+\\) is a\\(n abstract\\)? class in `\\(.+\\)'") | |
706 | (let ((cname (match-string-no-properties 1))) | |
707 | (help-xref-button 3 'eieio-class-def cname | |
708 | (get (intern cname) 'class-location))))) | |
6dd12ef2 CY |
709 | )))) |
710 | ||
711 | ;;; SPEEDBAR SUPPORT | |
712 | ;; | |
713 | (eval-when-compile | |
714 | (condition-case nil | |
715 | (require 'speedbar) | |
a8f316ca | 716 | (error (message "Error loading speedbar... ignored")))) |
6dd12ef2 CY |
717 | |
718 | (defvar eieio-class-speedbar-key-map nil | |
719 | "Keymap used when working with a project in speedbar.") | |
720 | ||
721 | (defun eieio-class-speedbar-make-map () | |
a8f316ca | 722 | "Make a keymap for EIEIO under speedbar." |
6dd12ef2 CY |
723 | (setq eieio-class-speedbar-key-map (speedbar-make-specialized-keymap)) |
724 | ||
725 | ;; General viewing stuff | |
726 | (define-key eieio-class-speedbar-key-map "\C-m" 'speedbar-edit-line) | |
727 | (define-key eieio-class-speedbar-key-map "+" 'speedbar-expand-line) | |
728 | (define-key eieio-class-speedbar-key-map "-" 'speedbar-contract-line) | |
729 | ) | |
730 | ||
731 | (if eieio-class-speedbar-key-map | |
732 | nil | |
733 | (if (not (featurep 'speedbar)) | |
734 | (add-hook 'speedbar-load-hook (lambda () | |
735 | (eieio-class-speedbar-make-map) | |
736 | (speedbar-add-expansion-list | |
737 | '("EIEIO" | |
738 | eieio-class-speedbar-menu | |
739 | eieio-class-speedbar-key-map | |
740 | eieio-class-speedbar)))) | |
741 | (eieio-class-speedbar-make-map) | |
742 | (speedbar-add-expansion-list '("EIEIO" | |
743 | eieio-class-speedbar-menu | |
744 | eieio-class-speedbar-key-map | |
745 | eieio-class-speedbar)))) | |
746 | ||
747 | (defvar eieio-class-speedbar-menu | |
748 | () | |
749 | "Menu part in easymenu format used in speedbar while in `eieio' mode.") | |
750 | ||
751 | (defun eieio-class-speedbar (dir-or-object depth) | |
752 | "Create buttons in speedbar that represents the current project. | |
a8f316ca JB |
753 | DIR-OR-OBJECT is the object to expand, or nil, and DEPTH is the |
754 | current expansion depth." | |
6dd12ef2 CY |
755 | (when (eq (point-min) (point-max)) |
756 | ;; This function is only called once, to start the whole deal. | |
757 | ;; Ceate, and expand the default object. | |
758 | (eieio-class-button eieio-default-superclass 0) | |
759 | (forward-line -1) | |
760 | (speedbar-expand-line))) | |
761 | ||
762 | (defun eieio-class-button (class depth) | |
763 | "Draw a speedbar button at the current point for CLASS at DEPTH." | |
764 | (if (not (class-p class)) | |
765 | (signal 'wrong-type-argument (list 'class-p class))) | |
766 | (let ((subclasses (aref (class-v class) class-children))) | |
767 | (if subclasses | |
768 | (speedbar-make-tag-line 'angle ?+ | |
769 | 'eieio-sb-expand | |
770 | class | |
771 | (symbol-name class) | |
772 | 'eieio-describe-class-sb | |
773 | class | |
774 | 'speedbar-directory-face | |
775 | depth) | |
776 | (speedbar-make-tag-line 'angle ? nil nil | |
777 | (symbol-name class) | |
778 | 'eieio-describe-class-sb | |
779 | class | |
780 | 'speedbar-directory-face | |
781 | depth)))) | |
782 | ||
783 | (defun eieio-sb-expand (text class indent) | |
784 | "For button TEXT, expand CLASS at the current location. | |
785 | Argument INDENT is the depth of indentation." | |
786 | (cond ((string-match "+" text) ;we have to expand this file | |
787 | (speedbar-change-expand-button-char ?-) | |
788 | (speedbar-with-writable | |
789 | (save-excursion | |
790 | (end-of-line) (forward-char 1) | |
791 | (let ((subclasses (aref (class-v class) class-children))) | |
792 | (while subclasses | |
793 | (eieio-class-button (car subclasses) (1+ indent)) | |
794 | (setq subclasses (cdr subclasses))))))) | |
795 | ((string-match "-" text) ;we have to contract this node | |
796 | (speedbar-change-expand-button-char ?+) | |
797 | (speedbar-delete-subblock indent)) | |
798 | (t (error "Ooops... not sure what to do"))) | |
799 | (speedbar-center-buffer-smartly)) | |
800 | ||
801 | (defun eieio-describe-class-sb (text token indent) | |
802 | "Describe the class TEXT in TOKEN. | |
803 | INDENT is the current indentation level." | |
804 | (speedbar-with-attached-buffer | |
805 | (eieio-describe-class token)) | |
806 | (speedbar-maybee-jump-to-attached-frame)) | |
807 | ||
808 | (provide 'eieio-opt) | |
809 | ||
810 | ;;; eieio-opt.el ends here |