auto upstream
[emacs.git] / lisp / emacs-lisp / eieio-opt.el
blob8867d88cc3a07388276bfbcc448d9b0dba96ea4f
1 ;;; eieio-opt.el -- eieio optional functions (debug, printing, speedbar)
3 ;; Copyright (C) 1996, 1998-2003, 2005, 2008-2013 Free Software
4 ;; Foundation, Inc.
6 ;; Author: Eric M. Ludlam <zappo@gnu.org>
7 ;; Keywords: OO, lisp
8 ;; Package: eieio
10 ;; This file is part of GNU Emacs.
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.
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.
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/>.
25 ;;; Commentary:
27 ;; This contains support functions to eieio. These functions contain
28 ;; some small class browser and class printing functions.
31 (require 'eieio)
32 (require 'find-func)
33 (require 'speedbar)
34 (require 'help-mode)
36 ;;; Code:
37 ;;;###autoload
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)
50 (with-current-buffer (get-buffer "*EIEIO OBJECT BROWSE*")
51 (erase-buffer)
52 (goto-char 0)
53 (eieio-browse-tree root-class "" "")
56 (defun eieio-browse-tree (this-root prefix ch-prefix)
57 "Recursively draw the children of the given class on the screen.
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))
75 ;;; CLASS COMPLETION / DOCUMENTATION
77 ;;;###autoload(defalias 'describe-class 'eieio-describe-class)
79 ;;;###autoload
80 (defun eieio-describe-class (class &optional headerfcn)
81 "Describe a CLASS defined by a string or symbol.
82 If CLASS is actually an object, then also display current values of that object.
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)
87 (called-interactively-p 'interactive))
89 (when headerfcn (funcall headerfcn))
90 (prin1 class)
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 "'"))
100 (terpri)
101 ;; Inheritance tree information
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))))))
173 (with-current-buffer (help-buffer)
174 (buffer-string)))
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))
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)
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)))))
250 ;;;###autoload
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.
261 (prin1 fcn)
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 "'"))
268 (terpri)
269 (princ "Creates an object of class ")
270 (prin1 fcn)
271 (princ ".")
272 (terpri)
273 (terpri)
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)))
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)))
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))))
298 (while sublst
299 (setq buildlist (eieio-build-class-alist
300 (car sublst) instantiable-only buildlist))
301 (setq sublst (cdr sublst)))
302 buildlist))
304 (defvar eieio-read-class nil
305 "History of the function `eieio-read-class' prompt.")
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))))
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))))
327 ;;; METHOD COMPLETION / DOC
329 (defalias 'describe-method 'eieio-describe-generic)
330 ;;;###autoload(defalias 'describe-generic 'eieio-describe-generic)
331 (defalias 'eieio-describe-method 'eieio-describe-generic)
333 ;;;###autoload
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*"
341 (help-setup-xref (list #'eieio-describe-generic generic)
342 (called-interactively-p 'interactive))
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"))
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)
368 (let ((i 4)
369 (prefix [ ":STATIC" ":BEFORE" ":PRIMARY" ":AFTER" ] ))
370 ;; Loop over fanciful generics
371 (while (< i 7)
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
383 (while (< i 4)
384 (let ((gm (reverse (aref (get generic 'eieio-method-tree) i)))
385 location)
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"))
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"))
409 (setq gm (cdr gm))
410 (terpri)
411 (terpri)))
412 (setq i (1+ i)))))
413 (with-current-buffer (help-buffer)
414 (buffer-string)))
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))))
423 (defun eieio-all-generic-functions (&optional class)
424 "Return a list of all generic functions.
425 Optional CLASS argument returns only those functions that contain
426 methods for CLASS."
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)))))))
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)
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)))
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))))))
473 (defvar eieio-read-generic nil
474 "History of the `eieio-read-generic' prompt.")
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))
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))))
488 ;;; METHOD STATS
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)
519 (switch-to-buffer-other-window buff)
520 (erase-buffer)
521 (dolist (S slotn)
522 (princ S)
523 (princ "\t")
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)))
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 "* ")
552 (prin1 M)
553 (terpri)
554 (setq methidx (1+ methidx))
557 (princ "--------------------------------------------------------------------")
558 (terpri)
559 (dolist (S slots)
560 (prin1 (aref idxarray (symbol-value S)))
561 (princ "\t")
563 (prin1 methidx)
564 (princ " Total symbols")
565 (terpri)
566 (dolist (S slotn)
567 (princ S)
568 (princ "\t")
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)
586 ;;; HELP AUGMENTATION
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"))
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"))
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))))
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))))
647 (defun eieio-help-mode-augmentation-maybee (&rest unused)
648 "For buffers thrown into help mode, augment for EIEIO.
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))
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)))))
709 ))))
711 ;;; SPEEDBAR SUPPORT
714 (defvar eieio-class-speedbar-key-map nil
715 "Keymap used when working with a project in speedbar.")
717 (defun eieio-class-speedbar-make-map ()
718 "Make a keymap for EIEIO under speedbar."
719 (setq eieio-class-speedbar-key-map (speedbar-make-specialized-keymap))
721 ;; General viewing stuff
722 (define-key eieio-class-speedbar-key-map "\C-m" 'speedbar-edit-line)
723 (define-key eieio-class-speedbar-key-map "+" 'speedbar-expand-line)
724 (define-key eieio-class-speedbar-key-map "-" 'speedbar-contract-line)
727 (if eieio-class-speedbar-key-map
729 (if (not (featurep 'speedbar))
730 (add-hook 'speedbar-load-hook (lambda ()
731 (eieio-class-speedbar-make-map)
732 (speedbar-add-expansion-list
733 '("EIEIO"
734 eieio-class-speedbar-menu
735 eieio-class-speedbar-key-map
736 eieio-class-speedbar))))
737 (eieio-class-speedbar-make-map)
738 (speedbar-add-expansion-list '("EIEIO"
739 eieio-class-speedbar-menu
740 eieio-class-speedbar-key-map
741 eieio-class-speedbar))))
743 (defvar eieio-class-speedbar-menu
745 "Menu part in easymenu format used in speedbar while in `eieio' mode.")
747 (defun eieio-class-speedbar (dir-or-object depth)
748 "Create buttons in speedbar that represents the current project.
749 DIR-OR-OBJECT is the object to expand, or nil, and DEPTH is the
750 current expansion depth."
751 (when (eq (point-min) (point-max))
752 ;; This function is only called once, to start the whole deal.
753 ;; Ceate, and expand the default object.
754 (eieio-class-button eieio-default-superclass 0)
755 (forward-line -1)
756 (speedbar-expand-line)))
758 (defun eieio-class-button (class depth)
759 "Draw a speedbar button at the current point for CLASS at DEPTH."
760 (if (not (class-p class))
761 (signal 'wrong-type-argument (list 'class-p class)))
762 (let ((subclasses (aref (class-v class) class-children)))
763 (if subclasses
764 (speedbar-make-tag-line 'angle ?+
765 'eieio-sb-expand
766 class
767 (symbol-name class)
768 'eieio-describe-class-sb
769 class
770 'speedbar-directory-face
771 depth)
772 (speedbar-make-tag-line 'angle ? nil nil
773 (symbol-name class)
774 'eieio-describe-class-sb
775 class
776 'speedbar-directory-face
777 depth))))
779 (defun eieio-sb-expand (text class indent)
780 "For button TEXT, expand CLASS at the current location.
781 Argument INDENT is the depth of indentation."
782 (cond ((string-match "+" text) ;we have to expand this file
783 (speedbar-change-expand-button-char ?-)
784 (speedbar-with-writable
785 (save-excursion
786 (end-of-line) (forward-char 1)
787 (let ((subclasses (aref (class-v class) class-children)))
788 (while subclasses
789 (eieio-class-button (car subclasses) (1+ indent))
790 (setq subclasses (cdr subclasses)))))))
791 ((string-match "-" text) ;we have to contract this node
792 (speedbar-change-expand-button-char ?+)
793 (speedbar-delete-subblock indent))
794 (t (error "Ooops... not sure what to do")))
795 (speedbar-center-buffer-smartly))
797 (defun eieio-describe-class-sb (text token indent)
798 "Describe the class TEXT in TOKEN.
799 INDENT is the current indentation level."
800 (speedbar-with-attached-buffer
801 (eieio-describe-class token))
802 (speedbar-maybee-jump-to-attached-frame))
804 (provide 'eieio-opt)
806 ;;; eieio-opt.el ends here