Commit | Line | Data |
---|---|---|
e608e7be CY |
1 | ;;; eieio-datadebug.el --- EIEIO extensions to the data debugger. |
2 | ||
ba318903 | 3 | ;; Copyright (C) 2007-2014 Free Software Foundation, Inc. |
e608e7be | 4 | |
9ffe3f52 | 5 | ;; Author: Eric M. Ludlam <zappo@gnu.org> |
e608e7be | 6 | ;; Keywords: OO, lisp |
bd78fa1d | 7 | ;; Package: eieio |
e608e7be CY |
8 | |
9 | ;; This file is part of GNU Emacs. | |
10 | ||
11 | ;; GNU Emacs is free software: you can redistribute it and/or modify | |
12 | ;; it under the terms of the GNU General Public License as published by | |
13 | ;; the Free Software Foundation, either version 3 of the License, or | |
14 | ;; (at your option) any later version. | |
15 | ||
16 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | ;; GNU General Public License for more details. | |
20 | ||
21 | ;; You should have received a copy of the GNU General Public License | |
22 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |
23 | ||
24 | ;;; Commentary: | |
25 | ;; | |
26 | ;; Extensions to data-debug for EIEIO objects. | |
27 | ;; | |
28 | ||
29 | (require 'eieio) | |
30 | (require 'data-debug) | |
31 | ||
32 | ;;; Code: | |
33 | ||
34 | (defun data-debug-insert-object-slots (object prefix) | |
35 | "Insert all the slots of OBJECT. | |
36 | PREFIX specifies what to insert at the start of each line." | |
37 | (let ((attrprefix (concat (make-string (length prefix) ? ) "] "))) | |
38 | (data-debug/eieio-insert-slots object attrprefix))) | |
39 | ||
40 | (defun data-debug-insert-object-slots-from-point (point) | |
41 | "Insert the object slots found at the object button at POINT." | |
42 | (let ((object (get-text-property point 'ddebug)) | |
43 | (indent (get-text-property point 'ddebug-indent)) | |
44 | start) | |
45 | (end-of-line) | |
46 | (setq start (point)) | |
47 | (forward-char 1) | |
48 | (data-debug-insert-object-slots object | |
49 | (concat (make-string indent ? ) | |
50 | "~ ")) | |
51 | (goto-char start))) | |
52 | ||
53 | (defun data-debug-insert-object-button (object prefix prebuttontext) | |
54 | "Insert a button representing OBJECT. | |
9ffe3f52 | 55 | PREFIX is the text that precedes the button. |
e608e7be CY |
56 | PREBUTTONTEXT is some text between PREFIX and the object button." |
57 | (let ((start (point)) | |
58 | (end nil) | |
59 | (str (object-print object)) | |
60 | (tip (format "Object %s\nClass: %S\nParent(s): %S\n%d slots" | |
8ca4f1e0 SM |
61 | (eieio-object-name-string object) |
62 | (eieio-object-class object) | |
63 | (eieio-class-parents (eieio-object-class object)) | |
e608e7be CY |
64 | (length (object-slots object)) |
65 | )) | |
66 | ) | |
67 | (insert prefix prebuttontext str) | |
68 | (setq end (point)) | |
69 | (put-text-property (- end (length str)) end 'face 'font-lock-keyword-face) | |
70 | (put-text-property start end 'ddebug object) | |
71 | (put-text-property start end 'ddebug-indent(length prefix)) | |
72 | (put-text-property start end 'ddebug-prefix prefix) | |
73 | (put-text-property start end 'help-echo tip) | |
74 | (put-text-property start end 'ddebug-function | |
75 | 'data-debug-insert-object-slots-from-point) | |
76 | (insert "\n"))) | |
77 | ||
78 | ;;; METHODS | |
79 | ;; | |
80 | ;; Each object should have an opportunity to show stuff about itself. | |
81 | ||
82 | (defmethod data-debug/eieio-insert-slots ((obj eieio-default-superclass) | |
e8cc7880 | 83 | prefix) |
e608e7be | 84 | "Insert the slots of OBJ into the current DDEBUG buffer." |
e8cc7880 DE |
85 | (let ((inhibit-read-only t)) |
86 | (data-debug-insert-thing (eieio-object-name-string obj) | |
87 | prefix | |
88 | "Name: ") | |
89 | (let* ((cl (eieio-object-class obj)) | |
90 | (cv (class-v cl))) | |
91 | (data-debug-insert-thing (class-constructor cl) | |
92 | prefix | |
93 | "Class: ") | |
94 | ;; Loop over all the public slots | |
95 | (let ((publa (eieio--class-public-a cv)) | |
96 | ) | |
97 | (while publa | |
98 | (if (slot-boundp obj (car publa)) | |
99 | (let* ((i (class-slot-initarg cl (car publa))) | |
100 | (v (eieio-oref obj (car publa)))) | |
101 | (data-debug-insert-thing | |
102 | v prefix (concat | |
103 | (if i (symbol-name i) | |
104 | (symbol-name (car publa))) | |
105 | " "))) | |
106 | ;; Unbound case | |
107 | (let ((i (class-slot-initarg cl (car publa)))) | |
108 | (data-debug-insert-custom | |
109 | "#unbound" prefix | |
110 | (concat (if i (symbol-name i) | |
111 | (symbol-name (car publa))) | |
112 | " ") | |
113 | 'font-lock-keyword-face)) | |
114 | ) | |
115 | (setq publa (cdr publa))))))) | |
e608e7be CY |
116 | |
117 | ;;; Augment the Data debug thing display list. | |
118 | (data-debug-add-specialized-thing (lambda (thing) (object-p thing)) | |
119 | #'data-debug-insert-object-button) | |
120 | ||
121 | ;;; DEBUG METHODS | |
122 | ;; | |
123 | ;; A generic function to run DDEBUG on an object and popup a new buffer. | |
124 | ;; | |
125 | (defmethod data-debug-show ((obj eieio-default-superclass)) | |
a8f316ca | 126 | "Run ddebug against any EIEIO object OBJ." |
8ca4f1e0 | 127 | (data-debug-new-buffer (format "*%s DDEBUG*" (eieio-object-name obj))) |
e608e7be CY |
128 | (data-debug-insert-object-slots obj "]")) |
129 | ||
130 | ;;; DEBUG FUNCTIONS | |
131 | ;; | |
132 | (defun eieio-debug-methodinvoke (method class) | |
133 | "Show the method invocation order for METHOD with CLASS object." | |
134 | (interactive "aMethod: \nXClass Expression: ") | |
7b1bf173 | 135 | (let* ((eieio-pre-method-execution-functions |
e608e7be CY |
136 | (lambda (l) (throw 'moose l) )) |
137 | (data | |
138 | (catch 'moose (eieio-generic-call | |
139 | method (list class)))) | |
140 | (buf (data-debug-new-buffer "*Method Invocation*")) | |
141 | (data2 (mapcar (lambda (sym) | |
142 | (symbol-function (car sym))) | |
143 | data))) | |
144 | (data-debug-insert-thing data2 ">" ""))) | |
145 | ||
146 | (provide 'eieio-datadebug) | |
147 | ||
148 | ;;; eieio-datadebug.el ends here |