eieio-opt.el 21 KB

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