]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/emacs-lisp/cl-print.el (cl-print-compiled): New variable
authorStefan Monnier <monnier@iro.umontreal.ca>
Mon, 13 Mar 2017 02:09:02 +0000 (22:09 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Mon, 13 Mar 2017 02:09:02 +0000 (22:09 -0400)
(cl-print-object) <compiled-function>: Print the docstring and
interactive form.  Obey cl-print-compiled.

lisp/emacs-lisp/cl-print.el

index b4a7be805a3da126fe51b81a21c5cfa608198993..8a8d4a4c1afe98fab595207cd886d18703142de5 100644 (file)
@@ -74,11 +74,45 @@ call other entry points instead, such as `cl-prin1'."
     (cl-print-object (aref object i) stream))
   (princ "]" stream))
 
+(defvar cl-print-compiled nil
+  "Control how to print byte-compiled functions.  Can be:
+- `static' to print the vector of constants.
+- `disassemble' to print the disassembly of the code.
+- nil to skip printing any details about the code.")
+
 (cl-defmethod cl-print-object ((object compiled-function) stream)
   ;; We use "#f(...)" rather than "#<...>" so that pp.el gives better results.
   (princ "#f(compiled-function " stream)
-  (prin1 (help-function-arglist object 'preserve-names) stream)
-  (princ " #<bytecode>)" stream))
+  (let ((args (help-function-arglist object 'preserve-names)))
+    (if args
+        (prin1 args stream)
+      (princ "()" stream)))
+  (let ((doc (documentation object 'raw)))
+    (when doc
+      (princ " " stream)
+      (prin1 doc stream)))
+  (let ((inter (interactive-form object)))
+    (when inter
+      (princ " " stream)
+      (cl-print-object
+       (if (eq 'byte-code (car-safe (cadr inter)))
+           `(interactive ,(make-byte-code nil (nth 1 (cadr inter))
+                                          (nth 2 (cadr inter))
+                                          (nth 3 (cadr inter))))
+         inter)
+       stream)))
+  (if (eq cl-print-compiled 'disassemble)
+      (princ
+       (with-temp-buffer
+         (insert "\n")
+         (disassemble-1 object 0)
+         (buffer-string))
+       stream)
+    (princ " #<bytecode>" stream)
+    (when (eq cl-print-compiled 'static)
+      (princ " " stream)
+      (cl-print-object (aref object 2) stream)))
+  (princ ")" stream))
 
 ;; This belongs in nadvice.el, of course, but some load-ordering issues make it
 ;; complicated: cl-generic uses macros from cl-macs and cl-macs uses advice-add