aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2023-10-11 13:26:01 +0000
committerAlan Mackenzie2023-10-11 13:26:01 +0000
commitaa45ea8a33132f3a95b1e2c085776919febd5458 (patch)
treec58b28bdb56182e320a0be4f21f803511b3d2156
parent41b83e899392b2b01f4b934d9f34b92a97ecbffd (diff)
downloademacs-aa45ea8a33132f3a95b1e2c085776919febd5458.tar.gz
emacs-aa45ea8a33132f3a95b1e2c085776919febd5458.zip
In cl-prin1, enable raw printing for a byte-compiled function
* lisp/emacs-lisp/cl-print.el (cl-print-compiled): document the new option `raw'. (cl-print-object/compiled-function): when cl-print-compiled is `raw', just print the function using `prin1'. Apply a button to this output which, when activated disassembles the function. * etc/NEWS (cl-print): Add an entry for this new feature.
-rw-r--r--etc/NEWS4
-rw-r--r--lisp/emacs-lisp/cl-print.el83
2 files changed, 52 insertions, 35 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 220568429fd..6637a5c87e2 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -162,6 +162,10 @@ should now work anywhere the data is generated by 'cl-print'.
162 162
163*** Modes can control the expansion via 'cl-print-expand-ellipsis-function'. 163*** Modes can control the expansion via 'cl-print-expand-ellipsis-function'.
164 164
165*** There is a new setting 'raw' for 'cl-print-compiled' which causes
166byte-compiled functions to be printed in full by 'prin1'. A button on
167this output can be activated to disassemble the function.
168
165** Modeline elements can now be right-aligned. 169** Modeline elements can now be right-aligned.
166Anything following the symbol 'mode-line-format-right-align' in 170Anything following the symbol 'mode-line-format-right-align' in
167'mode-line-format' will be right-aligned. Exactly where it is 171'mode-line-format' will be right-aligned. Exactly where it is
diff --git a/lisp/emacs-lisp/cl-print.el b/lisp/emacs-lisp/cl-print.el
index b6d1f13bb2f..56e35078d39 100644
--- a/lisp/emacs-lisp/cl-print.el
+++ b/lisp/emacs-lisp/cl-print.el
@@ -165,6 +165,7 @@ Print the contents hidden by the ellipsis to STREAM."
165(defvar cl-print-compiled nil 165(defvar cl-print-compiled nil
166 "Control how to print byte-compiled functions. 166 "Control how to print byte-compiled functions.
167Acceptable values include: 167Acceptable values include:
168- `raw' to print out the full contents of the function using `prin1'.
168- `static' to print the vector of constants. 169- `static' to print the vector of constants.
169- `disassemble' to print the disassembly of the code. 170- `disassemble' to print the disassembly of the code.
170- nil to skip printing any details about the code.") 171- nil to skip printing any details about the code.")
@@ -187,42 +188,54 @@ into a button whose action shows the function's disassembly.")
187 (if args 188 (if args
188 (prin1 args stream) 189 (prin1 args stream)
189 (princ "()" stream))) 190 (princ "()" stream)))
190 (pcase (help-split-fundoc (documentation object 'raw) object) 191 (if (eq cl-print-compiled 'raw)
191 ;; Drop args which `help-function-arglist' already printed. 192 (let ((button-start
192 (`(,_usage . ,(and doc (guard (stringp doc)))) 193 (and cl-print-compiled-button
193 (princ " " stream) 194 (bufferp stream)
194 (prin1 doc stream))) 195 (with-current-buffer stream (1+ (point))))))
195 (let ((inter (interactive-form object))) 196 (princ " " stream)
196 (when inter 197 (prin1 object stream)
197 (princ " " stream) 198 (when button-start
198 (cl-print-object 199 (with-current-buffer stream
199 (if (eq 'byte-code (car-safe (cadr inter))) 200 (make-text-button button-start (point)
200 `(interactive ,(make-byte-code nil (nth 1 (cadr inter)) 201 :type 'help-byte-code
201 (nth 2 (cadr inter)) 202 'byte-code-function object))))
202 (nth 3 (cadr inter)))) 203 (pcase (help-split-fundoc (documentation object 'raw) object)
203 inter) 204 ;; Drop args which `help-function-arglist' already printed.
204 stream))) 205 (`(,_usage . ,(and doc (guard (stringp doc))))
205 (if (eq cl-print-compiled 'disassemble) 206 (princ " " stream)
206 (princ 207 (prin1 doc stream)))
207 (with-temp-buffer 208 (let ((inter (interactive-form object)))
208 (insert "\n") 209 (when inter
209 (disassemble-1 object 0)
210 (buffer-string))
211 stream)
212 (princ " " stream)
213 (let ((button-start (and cl-print-compiled-button
214 (bufferp stream)
215 (with-current-buffer stream (point)))))
216 (princ (format "#<bytecode %#x>" (sxhash object)) stream)
217 (when (eq cl-print-compiled 'static)
218 (princ " " stream) 210 (princ " " stream)
219 (cl-print-object (aref object 2) stream)) 211 (cl-print-object
220 (when button-start 212 (if (eq 'byte-code (car-safe (cadr inter)))
221 (with-current-buffer stream 213 `(interactive ,(make-byte-code nil (nth 1 (cadr inter))
222 (make-text-button button-start (point) 214 (nth 2 (cadr inter))
223 :type 'help-byte-code 215 (nth 3 (cadr inter))))
224 'byte-code-function object))))) 216 inter)
225 (princ ")" stream)) 217 stream)))
218 (if (eq cl-print-compiled 'disassemble)
219 (princ
220 (with-temp-buffer
221 (insert "\n")
222 (disassemble-1 object 0)
223 (buffer-string))
224 stream)
225 (princ " " stream)
226 (let ((button-start (and cl-print-compiled-button
227 (bufferp stream)
228 (with-current-buffer stream (point)))))
229 (princ (format "#<bytecode %#x>" (sxhash object)) stream)
230 (when (eq cl-print-compiled 'static)
231 (princ " " stream)
232 (cl-print-object (aref object 2) stream))
233 (when button-start
234 (with-current-buffer stream
235 (make-text-button button-start (point)
236 :type 'help-byte-code
237 'byte-code-function object)))))
238 (princ ")" stream)))
226 239
227;; This belongs in oclosure.el, of course, but some load-ordering issues make it 240;; This belongs in oclosure.el, of course, but some load-ordering issues make it
228;; complicated. 241;; complicated.