aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2023-10-11 15:03:43 +0000
committerAlan Mackenzie2023-10-11 15:03:43 +0000
commitcfed3bb395030662059d560f94ea0318f820f00f (patch)
tree611186a3b9014186b1e5a6d544339cec8356c3f3
parentaa45ea8a33132f3a95b1e2c085776919febd5458 (diff)
downloademacs-cfed3bb395030662059d560f94ea0318f820f00f.tar.gz
emacs-cfed3bb395030662059d560f94ea0318f820f00f.zip
Document cl-print.el in cl.texi.
* doc/misc/cl.texi: (Printing): New chapter which documents cl-print.el. * NEWS (cl-print): Add "+++" markings to all the subitems, which have now been documented.
-rw-r--r--doc/misc/cl.texi155
-rw-r--r--etc/NEWS9
2 files changed, 164 insertions, 0 deletions
diff --git a/doc/misc/cl.texi b/doc/misc/cl.texi
index 5de33350f4f..e5a29cbcffb 100644
--- a/doc/misc/cl.texi
+++ b/doc/misc/cl.texi
@@ -55,6 +55,7 @@ modify this GNU manual.''
55 55
56@menu 56@menu
57* Overview:: Basics, usage, organization, naming conventions. 57* Overview:: Basics, usage, organization, naming conventions.
58* Printing:: Human friendly printing with @code{cl-prin1}.
58* Program Structure:: Arglists, @code{cl-eval-when}. 59* Program Structure:: Arglists, @code{cl-eval-when}.
59* Predicates:: Type predicates and equality predicates. 60* Predicates:: Type predicates and equality predicates.
60* Control Structure:: Assignment, conditionals, blocks, looping. 61* Control Structure:: Assignment, conditionals, blocks, looping.
@@ -258,6 +259,160 @@ and @code{:key} is not used.
258@noindent 259@noindent
259[3] Only for one sequence argument or two list arguments. 260[3] Only for one sequence argument or two list arguments.
260 261
262@node Printing
263@chapter Printing
264
265@noindent
266This chapter describes some enhancements to Emacs Lisp's
267@dfn{printing}, the action of representing Lisp objects in text form.
268The functions documented here are intended to produce output more for
269human readers than the standard printing functions such as
270@code{prin1} and @code{princ} (@pxref{Output Functions,,,elisp,GNU
271Emacs Lisp Reference Manual}).
272
273Several of these functions have a parameter @var{stream}; this
274specifies what to do with the characters printing produces. For
275example, it might be a buffer, a marker, @code{nil} (meaning use
276standard output), or @code{t} (use the echo area). @xref{Output
277Streams,,,elisp,GNU Emacs Lisp Reference Manual}, for a full
278description.
279
280@defvar cl-print-readably
281When this variable is non-@code{nil}, @code{cl-prin1} and other
282functions described here try to produce output which can later be read
283by the Lisp reader (@pxref{Input Functions,,,elisp,GNU Emacs Lisp
284Reference Manual}).
285@end defvar
286
287@defvar cl-print-compiled
288This variable controls how to print byte-compiled functions. Valid
289values are:
290@table @code
291@item nil
292The default: Just an internal hex identifier is printed.
293@item static
294The internal hex identifier together with the function's constant
295vector are printed.
296@item disassemble
297The byte code gets disassembled.
298@item raw
299The raw form of the function is printed by @code{prin1}.
300@end table
301
302Sometimes, a button is set on the output to allow you to disassemble
303the function. See @code{cl-print-compile-button}.
304@end defvar
305
306@defvar cl-print-compile-button
307When this variable is non-@code{nil} and a byte-compiled function has
308been printed to a buffer, you can click with the mouse or type
309@key{RET} on that output to disassemble the code. This doesn't apply
310when @code{cl-print-compiled} is set to @code{disassemble}.
311@end defvar
312
313@defvar cl-print-string-length
314The maximum length of a string to print before abbreviating it. A
315value of @code{nil}, the default, means no limit.
316
317When the CL printing functions abbreviate a string, they print the
318first @code{cl-print-string-length} characters of the string, followed
319by ``@enddots{}''. When the printing is to a buffer, you can click
320with the mouse or type @key{RET} on this ellipsis to expand the
321string.
322
323This variable has effect only in the @code{cl-prin*} functions, not in
324primitives such as @code{prin1}.
325@end defvar
326
327@defun cl-prin1 object &option stream
328@code{cl-print1} prints @var{object} on @var{stream} (see above)
329according to its type and the settings described above. The variables
330@code{print-length} and @code{print-level} and the other standard
331Emacs settings also affect the printing (@pxref{Output
332Variables,,,elisp,GNU Emacs Lisp Reference Manual}).
333@end defun
334
335@defun cl-prin1-to-string object
336This function is like @code{cl-prin1}, except the output characters
337are returned as a string from this function rather than being passed
338to a stream.
339@end defun
340
341@defun cl-print-to-string-with-limit print-function value limit
342This function returns a string containing a printed representation of
343@var{value}. It attempts to get the length of the returned string
344under @var{limit} characters with successively more restrictive
345settings of @code{print-level}, @code{print-length}, and
346@code{cl-print-string-length}. It uses @var{print-function} to print,
347a function which should take the arguments @var{value} and a stream
348(see above), and which should respect @code{print-length},
349@code{print-level}, and @code{cl-print-string-length}. @var{limit}
350may be @code{nil} or zero, in which case @var{print-function} will be
351called with these settings bound to @code{nil}; it can also be
352@code{t}, in which case @var{print-function} will be called with their
353current values.
354
355Use this function with @code{cl-prin1} to print an object, possibly
356abbreviating it with one or more ellipses to fit within the size
357limit.
358@end defun
359
360@defun cl-print-object object stream
361This function prints @var{object} on @var{stream} (see above). It is
362actually a @code{cl-defgeneric} (@pxref{Generic Functions,,,elisp,GNU
363Emacs Lisp Reference Manual}), which is defined for several types of
364@var{object}. Normally, you just call @code{cl-prin1} to print an
365@var{object} rather than calling this function directly.
366
367You can write @code{cl-print-object} @code{cl-defmethod}s for other
368types of @var{object}, thus extending @code{cl-prin1}. If such a
369method uses ellipses, you should also write a
370@code{cl-print-object-contents} method for the same type. For
371examples of these methods, see @file{emacs-lisp/cl-print.el} in the
372Emacs source directory.
373@end defun
374
375@defun cl-print-object-contents object start stream
376This function replaces an ellipsis in @var{stream} beginning at
377@var{start} with the text from the partially printed @var{object} it
378represents. It is also a @code{cl-defgeneric} defined for several
379types of @var{object}. @var{stream} is a buffer containing the text
380with the ellipsis. @var{start} specifies the starting position of the
381ellipsis in a manner dependent on the type; it will have been obtained
382from a text property on the ellipsis, having been put there by
383@code{cl-print-insert-ellipsis}.
384@end defun
385
386@defun cl-print-insert-ellipsis object start stream
387This function prints an ellipsis (``@dots{}'') to @var{stream} (see
388above). When @var{stream} is a buffer, the ellipsis will be given the
389@code{cl-print-ellipsis} text property. The value of the text
390property will contain state (including @var{start}) in order to print
391the elided part of @var{object} later. @var{start} should be nil if
392the whole @var{object} is being elided, otherwise it should be an
393index or other pointer into the internals of @var{object} which can be
394passed to `cl-print-object-contents' at a later time.
395@end defun
396
397@defvar cl-print-expand-ellipsis-function
398This variable holds a function which expands an ellipsis in the
399current buffer. The function takes four arguments: @var{begin} and
400@var{end}, which are the bounds of the ellipsis; @var{value}, which is
401the value of the @code{cl-print-ellipsis} text property on the
402ellipsis (typically set earlier by @code{cl-prin1}); and
403@var{line-length}, the desired maximum length of the output. Its
404return value is the buffer position after the expanded text.
405@end defvar
406
407@deffn Command cl-print-expand-ellipsis &optional button
408This command expands the ellipsis at point. Non-interactively, if
409@var{button} is non-@code{nil}, it should be either a buffer position
410or a button made by @code{cl-print-insert-ellipsis}
411(@pxref{Buttons,,,elisp,GNU Emacs Lisp Reference Manual}), which
412indicates the position of the ellipsis. The return value is the
413buffer position after the expanded text.
414@end deffn
415
261@node Program Structure 416@node Program Structure
262@chapter Program Structure 417@chapter Program Structure
263 418
diff --git a/etc/NEWS b/etc/NEWS
index 6637a5c87e2..8b2bcaaf01d 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -150,22 +150,31 @@ executable, if it exists. This should remove the need to change its
150value when installing GNU coreutils using something like ports or 150value when installing GNU coreutils using something like ports or
151Homebrew. 151Homebrew.
152 152
153+++
153** cl-print 154** cl-print
154 155
156+++
155*** You can expand the "..." truncation everywhere. 157*** You can expand the "..." truncation everywhere.
156The code that allowed "..." to be expanded in the "*Backtrace*" buffer 158The code that allowed "..." to be expanded in the "*Backtrace*" buffer
157should now work anywhere the data is generated by 'cl-print'. 159should now work anywhere the data is generated by 'cl-print'.
158 160
161+++
159*** The 'backtrace-ellipsis' button is replaced by 'cl-print-ellipsis'. 162*** The 'backtrace-ellipsis' button is replaced by 'cl-print-ellipsis'.
160 163
164+++
161*** hash-tables' contents can be expanded via the ellipsis. 165*** hash-tables' contents can be expanded via the ellipsis.
162 166
167+++
163*** Modes can control the expansion via 'cl-print-expand-ellipsis-function'. 168*** Modes can control the expansion via 'cl-print-expand-ellipsis-function'.
164 169
170+++
165*** There is a new setting 'raw' for 'cl-print-compiled' which causes 171*** 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 172byte-compiled functions to be printed in full by 'prin1'. A button on
167this output can be activated to disassemble the function. 173this output can be activated to disassemble the function.
168 174
175+++
176*** There is a new chapter in the CL manual documenting cl-print.el.
177
169** Modeline elements can now be right-aligned. 178** Modeline elements can now be right-aligned.
170Anything following the symbol 'mode-line-format-right-align' in 179Anything following the symbol 'mode-line-format-right-align' in
171'mode-line-format' will be right-aligned. Exactly where it is 180'mode-line-format' will be right-aligned. Exactly where it is