diff options
| author | Alan Mackenzie | 2023-10-11 15:03:43 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2023-10-11 15:03:43 +0000 |
| commit | cfed3bb395030662059d560f94ea0318f820f00f (patch) | |
| tree | 611186a3b9014186b1e5a6d544339cec8356c3f3 /doc | |
| parent | aa45ea8a33132f3a95b1e2c085776919febd5458 (diff) | |
| download | emacs-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.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/misc/cl.texi | 155 |
1 files changed, 155 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 | ||
| 266 | This chapter describes some enhancements to Emacs Lisp's | ||
| 267 | @dfn{printing}, the action of representing Lisp objects in text form. | ||
| 268 | The functions documented here are intended to produce output more for | ||
| 269 | human readers than the standard printing functions such as | ||
| 270 | @code{prin1} and @code{princ} (@pxref{Output Functions,,,elisp,GNU | ||
| 271 | Emacs Lisp Reference Manual}). | ||
| 272 | |||
| 273 | Several of these functions have a parameter @var{stream}; this | ||
| 274 | specifies what to do with the characters printing produces. For | ||
| 275 | example, it might be a buffer, a marker, @code{nil} (meaning use | ||
| 276 | standard output), or @code{t} (use the echo area). @xref{Output | ||
| 277 | Streams,,,elisp,GNU Emacs Lisp Reference Manual}, for a full | ||
| 278 | description. | ||
| 279 | |||
| 280 | @defvar cl-print-readably | ||
| 281 | When this variable is non-@code{nil}, @code{cl-prin1} and other | ||
| 282 | functions described here try to produce output which can later be read | ||
| 283 | by the Lisp reader (@pxref{Input Functions,,,elisp,GNU Emacs Lisp | ||
| 284 | Reference Manual}). | ||
| 285 | @end defvar | ||
| 286 | |||
| 287 | @defvar cl-print-compiled | ||
| 288 | This variable controls how to print byte-compiled functions. Valid | ||
| 289 | values are: | ||
| 290 | @table @code | ||
| 291 | @item nil | ||
| 292 | The default: Just an internal hex identifier is printed. | ||
| 293 | @item static | ||
| 294 | The internal hex identifier together with the function's constant | ||
| 295 | vector are printed. | ||
| 296 | @item disassemble | ||
| 297 | The byte code gets disassembled. | ||
| 298 | @item raw | ||
| 299 | The raw form of the function is printed by @code{prin1}. | ||
| 300 | @end table | ||
| 301 | |||
| 302 | Sometimes, a button is set on the output to allow you to disassemble | ||
| 303 | the function. See @code{cl-print-compile-button}. | ||
| 304 | @end defvar | ||
| 305 | |||
| 306 | @defvar cl-print-compile-button | ||
| 307 | When this variable is non-@code{nil} and a byte-compiled function has | ||
| 308 | been 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 | ||
| 310 | when @code{cl-print-compiled} is set to @code{disassemble}. | ||
| 311 | @end defvar | ||
| 312 | |||
| 313 | @defvar cl-print-string-length | ||
| 314 | The maximum length of a string to print before abbreviating it. A | ||
| 315 | value of @code{nil}, the default, means no limit. | ||
| 316 | |||
| 317 | When the CL printing functions abbreviate a string, they print the | ||
| 318 | first @code{cl-print-string-length} characters of the string, followed | ||
| 319 | by ``@enddots{}''. When the printing is to a buffer, you can click | ||
| 320 | with the mouse or type @key{RET} on this ellipsis to expand the | ||
| 321 | string. | ||
| 322 | |||
| 323 | This variable has effect only in the @code{cl-prin*} functions, not in | ||
| 324 | primitives 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) | ||
| 329 | according to its type and the settings described above. The variables | ||
| 330 | @code{print-length} and @code{print-level} and the other standard | ||
| 331 | Emacs settings also affect the printing (@pxref{Output | ||
| 332 | Variables,,,elisp,GNU Emacs Lisp Reference Manual}). | ||
| 333 | @end defun | ||
| 334 | |||
| 335 | @defun cl-prin1-to-string object | ||
| 336 | This function is like @code{cl-prin1}, except the output characters | ||
| 337 | are returned as a string from this function rather than being passed | ||
| 338 | to a stream. | ||
| 339 | @end defun | ||
| 340 | |||
| 341 | @defun cl-print-to-string-with-limit print-function value limit | ||
| 342 | This function returns a string containing a printed representation of | ||
| 343 | @var{value}. It attempts to get the length of the returned string | ||
| 344 | under @var{limit} characters with successively more restrictive | ||
| 345 | settings of @code{print-level}, @code{print-length}, and | ||
| 346 | @code{cl-print-string-length}. It uses @var{print-function} to print, | ||
| 347 | a 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} | ||
| 350 | may be @code{nil} or zero, in which case @var{print-function} will be | ||
| 351 | called 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 | ||
| 353 | current values. | ||
| 354 | |||
| 355 | Use this function with @code{cl-prin1} to print an object, possibly | ||
| 356 | abbreviating it with one or more ellipses to fit within the size | ||
| 357 | limit. | ||
| 358 | @end defun | ||
| 359 | |||
| 360 | @defun cl-print-object object stream | ||
| 361 | This function prints @var{object} on @var{stream} (see above). It is | ||
| 362 | actually a @code{cl-defgeneric} (@pxref{Generic Functions,,,elisp,GNU | ||
| 363 | Emacs 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 | |||
| 367 | You can write @code{cl-print-object} @code{cl-defmethod}s for other | ||
| 368 | types of @var{object}, thus extending @code{cl-prin1}. If such a | ||
| 369 | method uses ellipses, you should also write a | ||
| 370 | @code{cl-print-object-contents} method for the same type. For | ||
| 371 | examples of these methods, see @file{emacs-lisp/cl-print.el} in the | ||
| 372 | Emacs source directory. | ||
| 373 | @end defun | ||
| 374 | |||
| 375 | @defun cl-print-object-contents object start stream | ||
| 376 | This function replaces an ellipsis in @var{stream} beginning at | ||
| 377 | @var{start} with the text from the partially printed @var{object} it | ||
| 378 | represents. It is also a @code{cl-defgeneric} defined for several | ||
| 379 | types of @var{object}. @var{stream} is a buffer containing the text | ||
| 380 | with the ellipsis. @var{start} specifies the starting position of the | ||
| 381 | ellipsis in a manner dependent on the type; it will have been obtained | ||
| 382 | from 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 | ||
| 387 | This function prints an ellipsis (``@dots{}'') to @var{stream} (see | ||
| 388 | above). When @var{stream} is a buffer, the ellipsis will be given the | ||
| 389 | @code{cl-print-ellipsis} text property. The value of the text | ||
| 390 | property will contain state (including @var{start}) in order to print | ||
| 391 | the elided part of @var{object} later. @var{start} should be nil if | ||
| 392 | the whole @var{object} is being elided, otherwise it should be an | ||
| 393 | index or other pointer into the internals of @var{object} which can be | ||
| 394 | passed to `cl-print-object-contents' at a later time. | ||
| 395 | @end defun | ||
| 396 | |||
| 397 | @defvar cl-print-expand-ellipsis-function | ||
| 398 | This variable holds a function which expands an ellipsis in the | ||
| 399 | current buffer. The function takes four arguments: @var{begin} and | ||
| 400 | @var{end}, which are the bounds of the ellipsis; @var{value}, which is | ||
| 401 | the value of the @code{cl-print-ellipsis} text property on the | ||
| 402 | ellipsis (typically set earlier by @code{cl-prin1}); and | ||
| 403 | @var{line-length}, the desired maximum length of the output. Its | ||
| 404 | return value is the buffer position after the expanded text. | ||
| 405 | @end defvar | ||
| 406 | |||
| 407 | @deffn Command cl-print-expand-ellipsis &optional button | ||
| 408 | This command expands the ellipsis at point. Non-interactively, if | ||
| 409 | @var{button} is non-@code{nil}, it should be either a buffer position | ||
| 410 | or a button made by @code{cl-print-insert-ellipsis} | ||
| 411 | (@pxref{Buttons,,,elisp,GNU Emacs Lisp Reference Manual}), which | ||
| 412 | indicates the position of the ellipsis. The return value is the | ||
| 413 | buffer 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 | ||