📄 print.c
字号:
PRINTFINISH; return obj;}/* a buffer which is used to hold output being built by prin1-to-string */Lisp_Object Vprin1_to_string_buffer;DEFUN ("prin1-to-string", Fprin1_to_string, Sprin1_to_string, 1, 1, 0, "Return a string containing the printed representation of OBJECT,\n\any Lisp object. Quoting characters are used when needed to make output\n\that `read' can handle, whenever this is possible.") (obj) Lisp_Object obj;{ struct buffer *old = current_buffer; int old_point = -1; int start_point; Lisp_Object original, printcharfun; struct gcpro gcpro1; printcharfun = Vprin1_to_string_buffer; PRINTPREPARE; print_depth = 0; print (obj, printcharfun, 1); /* Make Vprin1_to_string_buffer be the default buffer after PRINTFINSH */ PRINTFINISH; set_buffer_internal (XBUFFER (Vprin1_to_string_buffer)); obj = Fbuffer_string (); GCPRO1 (obj); Ferase_buffer (); set_buffer_internal (old); UNGCPRO; return obj;}DEFUN ("princ", Fprinc, Sprinc, 1, 2, 0, "Output the printed representation of OBJECT, any Lisp object.\n\No quoting characters are used; no delimiters are printed around\n\the contents of strings.\n\Output stream is STREAM, or value of standard-output (which see).") (obj, printcharfun) Lisp_Object obj, printcharfun;{ struct buffer *old = current_buffer; int old_point = -1; int start_point; Lisp_Object original; if (NULL (printcharfun)) printcharfun = Vstandard_output; PRINTPREPARE; print_depth = 0; print (obj, printcharfun, 0); PRINTFINISH; return obj;}DEFUN ("print", Fprint, Sprint, 1, 2, 0, "Output the printed representation of OBJECT, with newlines around it.\n\Quoting characters are printed when needed to make output that `read'\n\can handle, whenever this is possible.\n\Output stream is STREAM, or value of `standard-output' (which see).") (obj, printcharfun) Lisp_Object obj, printcharfun;{ struct buffer *old = current_buffer; int old_point = -1; int start_point; Lisp_Object original; struct gcpro gcpro1;#ifdef MAX_PRINT_CHARS print_chars = 0; max_print = MAX_PRINT_CHARS;#endif /* MAX_PRINT_CHARS */ if (NULL (printcharfun)) printcharfun = Vstandard_output; GCPRO1 (obj); PRINTPREPARE; print_depth = 0; PRINTCHAR ('\n'); print (obj, printcharfun, 1); PRINTCHAR ('\n'); PRINTFINISH;#ifdef MAX_PRINT_CHARS max_print = 0; print_chars = 0;#endif /* MAX_PRINT_CHARS */ UNGCPRO; return obj;}static voidprint (obj, printcharfun, escapeflag)#ifndef RTPC_REGISTER_BUG register Lisp_Object obj;#else Lisp_Object obj;#endif register Lisp_Object printcharfun; int escapeflag;{ char buf[30]; QUIT; print_depth++; if (print_depth > 200) error ("Apparently circular structure being printed");#ifdef MAX_PRINT_CHARS if (max_print && print_chars > max_print) { PRINTCHAR ('\n'); print_chars = 0; }#endif /* MAX_PRINT_CHARS */#ifdef SWITCH_ENUM_BUG switch ((int) XTYPE (obj))#else switch (XTYPE (obj))#endif { default: /* We're in trouble if this happens! Probably should just abort () */ strout ("#<EMACS BUG: INVALID DATATYPE ", -1, printcharfun); sprintf (buf, "(#o%3o)", (int) XTYPE (obj)); strout (buf, -1, printcharfun); strout (" Save your buffers immediately and please report this bug>", -1, printcharfun); break; case Lisp_Int: sprintf (buf, "%d", XINT (obj)); strout (buf, -1, printcharfun); break; case Lisp_String: if (!escapeflag) strout (XSTRING (obj)->data, XSTRING (obj)->size, printcharfun); else { register int i; register unsigned char *p = XSTRING (obj)->data; register unsigned char c; PRINTCHAR ('\"'); for (i = XSTRING (obj)->size; i > 0; i--) { QUIT; c = *p++; if (c == '\n' && print_escape_newlines) { PRINTCHAR ('\\'); PRINTCHAR ('n'); } else { if (c == '\"' || c == '\\') PRINTCHAR ('\\'); PRINTCHAR (c); } } PRINTCHAR ('\"'); } break; case Lisp_Symbol: { register int confusing; register unsigned char *p = XSYMBOL (obj)->name->data; register unsigned char *end = p + XSYMBOL (obj)->name->size; register unsigned char c; if (p != end && (*p == '-' || *p == '+')) p++; if (p == end) confusing = 0; else { while (p != end && *p >= '0' && *p <= '9') p++; confusing = (end == p); } p = XSYMBOL (obj)->name->data; while (p != end) { QUIT; c = *p++; if (escapeflag) { if (c == '\"' || c == '\\' || c == '\'' || c == ';' || c == '#' || c == '(' || c == ')' || c == ',' || c =='.' || c == '`' || c == '[' || c == ']' || c == '?' || c <= 040 || confusing) PRINTCHAR ('\\'), confusing = 0; } PRINTCHAR (c); } } break; case Lisp_Cons: PRINTCHAR ('('); { register int i = 0; register int max = 0; if (XTYPE (Vprint_length) == Lisp_Int) max = XINT (Vprint_length); while (CONSP (obj)) { if (i++) PRINTCHAR (' '); if (max && i > max) { strout ("...", 3, printcharfun); break; } print (Fcar (obj), printcharfun, escapeflag); obj = Fcdr (obj); } } if (!NULL (obj) && !CONSP (obj)) { strout (" . ", 3, printcharfun); print (obj, printcharfun, escapeflag); } PRINTCHAR (')'); break; case Lisp_Vector: PRINTCHAR ('['); { register int i; register Lisp_Object tem; for (i = 0; i < XVECTOR (obj)->size; i++) { if (i) PRINTCHAR (' '); tem = XVECTOR (obj)->contents[i]; print (tem, printcharfun, escapeflag); } } PRINTCHAR (']'); break;#ifndef standalone case Lisp_Buffer: if (NULL (XBUFFER (obj)->name)) strout ("#<killed buffer>", -1, printcharfun); else if (escapeflag) { strout ("#<buffer ", -1, printcharfun); strout (XSTRING (XBUFFER (obj)->name)->data, -1, printcharfun); PRINTCHAR ('>'); } else strout (XSTRING (XBUFFER (obj)->name)->data, -1, printcharfun); break; case Lisp_Process: if (escapeflag) { strout ("#<process ", -1, printcharfun); strout (XSTRING (XPROCESS (obj)->name)->data, -1, printcharfun); PRINTCHAR ('>'); } else strout (XSTRING (XPROCESS (obj)->name)->data, -1, printcharfun); break; case Lisp_Window: strout ("#<window ", -1, printcharfun); sprintf (buf, "%d", XFASTINT (XWINDOW (obj)->sequence_number)); strout (buf, -1, printcharfun); if (!NULL (XWINDOW (obj)->buffer)) { unsigned char *p = XSTRING (XBUFFER (XWINDOW (obj)->buffer)->name)->data; strout (" on ", -1, printcharfun); strout (p, -1, printcharfun); } PRINTCHAR ('>'); break; case Lisp_Window_Configuration: strout ("#<window-configuration>", -1, printcharfun); break; case Lisp_Marker: strout ("#<marker ", -1, printcharfun); if (!(XMARKER (obj)->buffer)) strout ("in no buffer", -1, printcharfun); else { sprintf (buf, "at %d", marker_position (obj)); strout (buf, -1, printcharfun); strout (" in ", -1, printcharfun); strout (XSTRING (XMARKER (obj)->buffer->name)->data, -1, printcharfun); } PRINTCHAR ('>'); break;#endif /* standalone */ case Lisp_Subr: strout ("#<subr ", -1, printcharfun); strout (XSUBR (obj)->symbol_name, -1, printcharfun); PRINTCHAR ('>'); break; } print_depth--;}voidsyms_of_print (){ DEFVAR_LISP ("standard-output", &Vstandard_output, "Function print uses by default for outputting a character.\n\This may be any function of one argument.\n\It may also be a buffer (output is inserted before point)\n\or a marker (output is inserted and the marker is advanced)\n\or the symbol t (output appears in the minibuffer line)."); Vstandard_output = Qt; Qstandard_output = intern ("standard-output"); staticpro (&Qstandard_output); DEFVAR_LISP ("print-length", &Vprint_length, "Maximum length of list to print before abbreviating.\`nil' means no limit."); Vprint_length = Qnil; DEFVAR_BOOL ("print-escape-newlines", &print_escape_newlines, "Non-nil means print newlines in strings as backslash-n."); print_escape_newlines = 0; /* prin1_to_string_buffer initialized in init_buffer_once in buffer.c */ staticpro (&Vprin1_to_string_buffer); defsubr (&Sprin1); defsubr (&Sprin1_to_string); defsubr (&Sprinc); defsubr (&Sprint); defsubr (&Sterpri); defsubr (&Swrite_char);#ifndef standalone defsubr (&Swith_output_to_temp_buffer);#endif /* not standalone */}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -