comparison lispref/streams.texi @ 21007:66d807bdc5b4

*** empty log message ***
author Richard M. Stallman <rms@gnu.org>
date Sat, 28 Feb 1998 01:53:53 +0000
parents 18c0e05d1bff
children 90da2489c498
comparison
equal deleted inserted replaced
21006:00022857f529 21007:66d807bdc5b4
1 @c -*-texinfo-*- 1 @c -*-texinfo-*-
2 @c This is part of the GNU Emacs Lisp Reference Manual. 2 @c This is part of the GNU Emacs Lisp Reference Manual.
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc. 3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1998 Free Software Foundation, Inc.
4 @c See the file elisp.texi for copying conditions. 4 @c See the file elisp.texi for copying conditions.
5 @setfilename ../info/streams 5 @setfilename ../info/streams
6 @node Read and Print, Minibuffers, Debugging, Top 6 @node Read and Print, Minibuffers, Debugging, Top
7 @comment node-name, next, previous, up 7 @comment node-name, next, previous, up
8 @chapter Reading and Printing Lisp Objects 8 @chapter Reading and Printing Lisp Objects
36 @dfn{read syntax} of the object. For example, the text @samp{(a .@: 5)} 36 @dfn{read syntax} of the object. For example, the text @samp{(a .@: 5)}
37 is the read syntax for a cons cell whose @sc{car} is @code{a} and whose 37 is the read syntax for a cons cell whose @sc{car} is @code{a} and whose
38 @sc{cdr} is the number 5. 38 @sc{cdr} is the number 5.
39 39
40 @dfn{Printing} a Lisp object means producing text that represents that 40 @dfn{Printing} a Lisp object means producing text that represents that
41 object---converting the object to its printed representation. Printing 41 object---converting the object to its @dfn{printed representation}
42 the cons cell described above produces the text @samp{(a .@: 5)}. 42 (@pxref{Printed Representation}). Printing the cons cell described
43 above produces the text @samp{(a .@: 5)}.
43 44
44 Reading and printing are more or less inverse operations: printing the 45 Reading and printing are more or less inverse operations: printing the
45 object that results from reading a given piece of text often produces 46 object that results from reading a given piece of text often produces
46 the same text, and reading the text that results from printing an object 47 the same text, and reading the text that results from printing an object
47 usually produces a similar-looking object. For example, printing the 48 usually produces a similar-looking object. For example, printing the
55 three kinds of exceptions: 56 three kinds of exceptions:
56 57
57 @itemize @bullet 58 @itemize @bullet
58 @item 59 @item
59 Printing can produce text that cannot be read. For example, buffers, 60 Printing can produce text that cannot be read. For example, buffers,
60 windows, frames, subprocesses and markers print into text that starts 61 windows, frames, subprocesses and markers print as text that starts
61 with @samp{#}; if you try to read this text, you get an error. There is 62 with @samp{#}; if you try to read this text, you get an error. There is
62 no way to read those data types. 63 no way to read those data types.
63 64
64 @item 65 @item
65 One object can have multiple textual representations. For example, 66 One object can have multiple textual representations. For example,
110 Occasionally @var{function} is called with one argument (always a 111 Occasionally @var{function} is called with one argument (always a
111 character). When that happens, @var{function} should save the argument 112 character). When that happens, @var{function} should save the argument
112 and arrange to return it on the next call. This is called 113 and arrange to return it on the next call. This is called
113 @dfn{unreading} the character; it happens when the Lisp reader reads one 114 @dfn{unreading} the character; it happens when the Lisp reader reads one
114 character too many and wants to ``put it back where it came from''. 115 character too many and wants to ``put it back where it came from''.
116 In this case, it makes no difference what value @var{function} returns.
115 117
116 @item @code{t} 118 @item @code{t}
117 @cindex @code{t} input stream 119 @cindex @code{t} input stream
118 @code{t} used as a stream means that the input is read from the 120 @code{t} used as a stream means that the input is read from the
119 minibuffer. In fact, the minibuffer is invoked once and the text 121 minibuffer. In fact, the minibuffer is invoked once and the text
161 Note that the first read skips a space. Reading skips any amount of 163 Note that the first read skips a space. Reading skips any amount of
162 whitespace preceding the significant text. 164 whitespace preceding the significant text.
163 165
164 In Emacs 18, reading a symbol discarded the delimiter terminating the 166 In Emacs 18, reading a symbol discarded the delimiter terminating the
165 symbol. Thus, point would end up at the beginning of @samp{contents} 167 symbol. Thus, point would end up at the beginning of @samp{contents}
166 rather than after @samp{the}. The Emacs 19 behavior is superior because 168 rather than after @samp{the}. The current behavior is superior because
167 it correctly handles input such as @samp{bar(foo)}, where the 169 it correctly handles input such as @samp{bar(foo)}, where the
168 open-parenthesis that ends one object is needed as the beginning of 170 open-parenthesis that ends one object is needed as the beginning of
169 another object. 171 another object.
170 172
171 Here is an example of reading from a stream that is a marker, 173 Here is an example of reading from a stream that is a marker,
513 contents more clearly. 515 contents more clearly.
514 516
515 @node Output Functions 517 @node Output Functions
516 @section Output Functions 518 @section Output Functions
517 519
518 This section describes the Lisp functions for printing Lisp objects. 520 This section describes the Lisp functions for printing Lisp
521 objects---converting objects into their printed representation.
519 522
520 @cindex @samp{"} in printing 523 @cindex @samp{"} in printing
521 @cindex @samp{\} in printing 524 @cindex @samp{\} in printing
522 @cindex quoting characters in printing 525 @cindex quoting characters in printing
523 @cindex escape characters in printing 526 @cindex escape characters in printing
659 662
660 See @code{format}, in @ref{String Conversion}, for other ways to obtain 663 See @code{format}, in @ref{String Conversion}, for other ways to obtain
661 the printed representation of a Lisp object as a string. 664 the printed representation of a Lisp object as a string.
662 @end defun 665 @end defun
663 666
667 @tindex with-output-to-string
668 @defmac with-output-to-string body...
669 This macro executes the @var{body} forms with standard-output set up so
670 that all output feeds into a string. Then it returns that string.
671
672 For example, if the current buffer name is @samp{foo},
673
674 @example
675 (with-output-to-string
676 (princ "The buffer is ")
677 (princ (buffer-name)))
678 @end example
679
680 @noindent
681 returns @code{"The buffer is foo"}.
682 @end defmac
683
664 @node Output Variables 684 @node Output Variables
665 @section Variables Affecting Output 685 @section Variables Affecting Output
666 686
667 @defvar standard-output 687 @defvar standard-output
668 The value of this variable is the default output stream---the stream 688 The value of this variable is the default output stream---the stream
704 @code{prin1}, but not during the printing of the result. 724 @code{prin1}, but not during the printing of the result.
705 @end defvar 725 @end defvar
706 726
707 @defvar print-length 727 @defvar print-length
708 @cindex printing limits 728 @cindex printing limits
709 The value of this variable is the maximum number of elements of a list, 729 The value of this variable is the maximum number of elements to print in
710 vector or bitvector that will be printed. If an object being printed has 730 any list, vector or bool-vector. If an object being printed has more
711 more than this many elements, it is abbreviated with an ellipsis. 731 than this many elements, it is abbreviated with an ellipsis.
712 732
713 If the value is @code{nil} (the default), then there is no limit. 733 If the value is @code{nil} (the default), then there is no limit.
714 734
715 @example 735 @example
716 @group 736 @group
728 @defvar print-level 748 @defvar print-level
729 The value of this variable is the maximum depth of nesting of 749 The value of this variable is the maximum depth of nesting of
730 parentheses and brackets when printed. Any list or vector at a depth 750 parentheses and brackets when printed. Any list or vector at a depth
731 exceeding this limit is abbreviated with an ellipsis. A value of 751 exceeding this limit is abbreviated with an ellipsis. A value of
732 @code{nil} (which is the default) means no limit. 752 @code{nil} (which is the default) means no limit.
733
734 This variable exists in version 19 and later versions.
735 @end defvar 753 @end defvar