diff options
| author | Stefan Monnier | 2017-03-12 22:09:02 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2017-03-12 22:09:02 -0400 |
| commit | 94b59f7dd1e8611495ff0f4596dc6dec20e268af (patch) | |
| tree | 3f138455053dc5d80709ba227ecae0a0e96952a7 | |
| parent | cf670b49a7704d63575863f832426d32bf6a8c3c (diff) | |
| download | emacs-94b59f7dd1e8611495ff0f4596dc6dec20e268af.tar.gz emacs-94b59f7dd1e8611495ff0f4596dc6dec20e268af.zip | |
* lisp/emacs-lisp/cl-print.el (cl-print-compiled): New variable
(cl-print-object) <compiled-function>: Print the docstring and
interactive form. Obey cl-print-compiled.
| -rw-r--r-- | lisp/emacs-lisp/cl-print.el | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/lisp/emacs-lisp/cl-print.el b/lisp/emacs-lisp/cl-print.el index b4a7be805a3..8a8d4a4c1af 100644 --- a/lisp/emacs-lisp/cl-print.el +++ b/lisp/emacs-lisp/cl-print.el | |||
| @@ -74,11 +74,45 @@ call other entry points instead, such as `cl-prin1'." | |||
| 74 | (cl-print-object (aref object i) stream)) | 74 | (cl-print-object (aref object i) stream)) |
| 75 | (princ "]" stream)) | 75 | (princ "]" stream)) |
| 76 | 76 | ||
| 77 | (defvar cl-print-compiled nil | ||
| 78 | "Control how to print byte-compiled functions. Can be: | ||
| 79 | - `static' to print the vector of constants. | ||
| 80 | - `disassemble' to print the disassembly of the code. | ||
| 81 | - nil to skip printing any details about the code.") | ||
| 82 | |||
| 77 | (cl-defmethod cl-print-object ((object compiled-function) stream) | 83 | (cl-defmethod cl-print-object ((object compiled-function) stream) |
| 78 | ;; We use "#f(...)" rather than "#<...>" so that pp.el gives better results. | 84 | ;; We use "#f(...)" rather than "#<...>" so that pp.el gives better results. |
| 79 | (princ "#f(compiled-function " stream) | 85 | (princ "#f(compiled-function " stream) |
| 80 | (prin1 (help-function-arglist object 'preserve-names) stream) | 86 | (let ((args (help-function-arglist object 'preserve-names))) |
| 81 | (princ " #<bytecode>)" stream)) | 87 | (if args |
| 88 | (prin1 args stream) | ||
| 89 | (princ "()" stream))) | ||
| 90 | (let ((doc (documentation object 'raw))) | ||
| 91 | (when doc | ||
| 92 | (princ " " stream) | ||
| 93 | (prin1 doc stream))) | ||
| 94 | (let ((inter (interactive-form object))) | ||
| 95 | (when inter | ||
| 96 | (princ " " stream) | ||
| 97 | (cl-print-object | ||
| 98 | (if (eq 'byte-code (car-safe (cadr inter))) | ||
| 99 | `(interactive ,(make-byte-code nil (nth 1 (cadr inter)) | ||
| 100 | (nth 2 (cadr inter)) | ||
| 101 | (nth 3 (cadr inter)))) | ||
| 102 | inter) | ||
| 103 | stream))) | ||
| 104 | (if (eq cl-print-compiled 'disassemble) | ||
| 105 | (princ | ||
| 106 | (with-temp-buffer | ||
| 107 | (insert "\n") | ||
| 108 | (disassemble-1 object 0) | ||
| 109 | (buffer-string)) | ||
| 110 | stream) | ||
| 111 | (princ " #<bytecode>" stream) | ||
| 112 | (when (eq cl-print-compiled 'static) | ||
| 113 | (princ " " stream) | ||
| 114 | (cl-print-object (aref object 2) stream))) | ||
| 115 | (princ ")" stream)) | ||
| 82 | 116 | ||
| 83 | ;; This belongs in nadvice.el, of course, but some load-ordering issues make it | 117 | ;; This belongs in nadvice.el, of course, but some load-ordering issues make it |
| 84 | ;; complicated: cl-generic uses macros from cl-macs and cl-macs uses advice-add | 118 | ;; complicated: cl-generic uses macros from cl-macs and cl-macs uses advice-add |