aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNoam Postavsky2017-06-11 09:49:44 -0400
committerNoam Postavsky2017-06-12 22:52:37 -0400
commit9b0f52a86e8e3767d7fcf3ef2adf7aa1f58e0e93 (patch)
tree7554a53d823bb3e0f94c989b7955a070d9db85e0
parent52c846d45dc52365349fc71e15d305a20788ce00 (diff)
downloademacs-9b0f52a86e8e3767d7fcf3ef2adf7aa1f58e0e93.tar.gz
emacs-9b0f52a86e8e3767d7fcf3ef2adf7aa1f58e0e93.zip
Buttonize #<bytecode> part of printed functions (Bug#25226)
* lisp/emacs-lisp/cl-print.el: Autoload `disassemble-1'. (cl-print-compiled-button): New variable. (help-byte-code): New button type, calls `disassemble' in its action. (cl-print-object): Use it if `cl-print-compiled-button' is non-nil.
-rw-r--r--lisp/emacs-lisp/cl-print.el33
1 files changed, 29 insertions, 4 deletions
diff --git a/lisp/emacs-lisp/cl-print.el b/lisp/emacs-lisp/cl-print.el
index 70ccaac17b3..89a71d1b6c5 100644
--- a/lisp/emacs-lisp/cl-print.el
+++ b/lisp/emacs-lisp/cl-print.el
@@ -33,6 +33,8 @@
33 33
34;;; Code: 34;;; Code:
35 35
36(require 'button)
37
36(defvar cl-print-readably nil 38(defvar cl-print-readably nil
37 "If non-nil, try and make sure the result can be `read'.") 39 "If non-nil, try and make sure the result can be `read'.")
38 40
@@ -76,13 +78,27 @@ call other entry points instead, such as `cl-prin1'."
76 (cl-print-object (aref object i) stream)) 78 (cl-print-object (aref object i) stream))
77 (princ "]" stream)) 79 (princ "]" stream))
78 80
81(define-button-type 'help-byte-code
82 'follow-link t
83 'action (lambda (button)
84 (disassemble (button-get button 'byte-code-function)))
85 'help-echo (purecopy "mouse-2, RET: disassemble this function"))
86
79(defvar cl-print-compiled nil 87(defvar cl-print-compiled nil
80 "Control how to print byte-compiled functions. Can be: 88 "Control how to print byte-compiled functions. Can be:
81- `static' to print the vector of constants. 89- `static' to print the vector of constants.
82- `disassemble' to print the disassembly of the code. 90- `disassemble' to print the disassembly of the code.
83- nil to skip printing any details about the code.") 91- nil to skip printing any details about the code.")
84 92
93(defvar cl-print-compiled-button nil
94 "Control how to print byte-compiled functions into buffers.
95When the stream is a buffer, make the bytecode part of the output
96into a button whose action shows the function's disassembly.")
97
98(autoload 'disassemble-1 "disass")
99
85(cl-defmethod cl-print-object ((object compiled-function) stream) 100(cl-defmethod cl-print-object ((object compiled-function) stream)
101 (unless stream (setq stream standard-output))
86 ;; We use "#f(...)" rather than "#<...>" so that pp.el gives better results. 102 ;; We use "#f(...)" rather than "#<...>" so that pp.el gives better results.
87 (princ "#f(compiled-function " stream) 103 (princ "#f(compiled-function " stream)
88 (let ((args (help-function-arglist object 'preserve-names))) 104 (let ((args (help-function-arglist object 'preserve-names)))
@@ -110,10 +126,19 @@ call other entry points instead, such as `cl-prin1'."
110 (disassemble-1 object 0) 126 (disassemble-1 object 0)
111 (buffer-string)) 127 (buffer-string))
112 stream) 128 stream)
113 (princ " #<bytecode>" stream) 129 (princ " " stream)
114 (when (eq cl-print-compiled 'static) 130 (let ((button-start (and cl-print-compiled-button
115 (princ " " stream) 131 (bufferp stream)
116 (cl-print-object (aref object 2) stream))) 132 (with-current-buffer stream (point)))))
133 (princ "#<bytecode>" stream)
134 (when (eq cl-print-compiled 'static)
135 (princ " " stream)
136 (cl-print-object (aref object 2) stream))
137 (when button-start
138 (with-current-buffer stream
139 (make-text-button button-start (point)
140 :type 'help-byte-code
141 'byte-code-function object)))))
117 (princ ")" stream)) 142 (princ ")" stream))
118 143
119;; This belongs in nadvice.el, of course, but some load-ordering issues make it 144;; This belongs in nadvice.el, of course, but some load-ordering issues make it