diff options
| author | Leo Liu | 2014-10-09 06:05:48 +0800 |
|---|---|---|
| committer | Leo Liu | 2014-10-09 06:05:48 +0800 |
| commit | 2dbd7a37a809e2dcef6c8e7323ac15c98b051cd9 (patch) | |
| tree | 3325d872642948f831a9acb971a2c06ce7d10b4d /src/print.c | |
| parent | 289a43910e29999f125d76a48602b63cea7ed9b9 (diff) | |
| download | emacs-2dbd7a37a809e2dcef6c8e7323ac15c98b051cd9.tar.gz emacs-2dbd7a37a809e2dcef6c8e7323ac15c98b051cd9.zip | |
Enhance terpri to allow conditionally output a newline
* doc/lispref/streams.texi (Output Functions): Document new argument ENSURE to
terpri.
* doc/misc/cl.texi (Porting Common Lisp): Remove parse-integer.
* lisp/emacs-lisp/cl-extra.el (cl-fresh-line): New function.
* src/keymap.c (describe_vector_princ):
* src/keyboard.c (Fcommand_error_default_function): Adapt to change to
Fterpri.
* src/print.c (printchar_stdout_last): Declare.
(printchar): Record the last char written to stdout.
(Fterpri): Add optional argument ENSURE.
* test/automated/print-tests.el: New file.
(terpri): Tests for terpri. (Bug#18652)
Diffstat (limited to 'src/print.c')
| -rw-r--r-- | src/print.c | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/print.c b/src/print.c index 7381db61211..49331ef0984 100644 --- a/src/print.c +++ b/src/print.c | |||
| @@ -58,6 +58,9 @@ static ptrdiff_t new_backquote_output; | |||
| 58 | #define PRINT_CIRCLE 200 | 58 | #define PRINT_CIRCLE 200 |
| 59 | static Lisp_Object being_printed[PRINT_CIRCLE]; | 59 | static Lisp_Object being_printed[PRINT_CIRCLE]; |
| 60 | 60 | ||
| 61 | /* Last char printed to stdout by printchar. */ | ||
| 62 | static unsigned int printchar_stdout_last; | ||
| 63 | |||
| 61 | /* When printing into a buffer, first we put the text in this | 64 | /* When printing into a buffer, first we put the text in this |
| 62 | block, then insert it all at once. */ | 65 | block, then insert it all at once. */ |
| 63 | static char *print_buffer; | 66 | static char *print_buffer; |
| @@ -238,6 +241,7 @@ printchar (unsigned int ch, Lisp_Object fun) | |||
| 238 | } | 241 | } |
| 239 | else if (noninteractive) | 242 | else if (noninteractive) |
| 240 | { | 243 | { |
| 244 | printchar_stdout_last = ch; | ||
| 241 | fwrite (str, 1, len, stdout); | 245 | fwrite (str, 1, len, stdout); |
| 242 | noninteractive_need_newline = 1; | 246 | noninteractive_need_newline = 1; |
| 243 | } | 247 | } |
| @@ -515,19 +519,33 @@ static void print_preprocess (Lisp_Object); | |||
| 515 | static void print_preprocess_string (INTERVAL, Lisp_Object); | 519 | static void print_preprocess_string (INTERVAL, Lisp_Object); |
| 516 | static void print_object (Lisp_Object, Lisp_Object, bool); | 520 | static void print_object (Lisp_Object, Lisp_Object, bool); |
| 517 | 521 | ||
| 518 | DEFUN ("terpri", Fterpri, Sterpri, 0, 1, 0, | 522 | DEFUN ("terpri", Fterpri, Sterpri, 0, 2, 0, |
| 519 | doc: /* Output a newline to stream PRINTCHARFUN. | 523 | doc: /* Output a newline to stream PRINTCHARFUN. |
| 524 | If ENSURE is non-nil only output a newline if not already at the | ||
| 525 | beginning of a line. Value is non-nil if a newline is printed. | ||
| 520 | If PRINTCHARFUN is omitted or nil, the value of `standard-output' is used. */) | 526 | If PRINTCHARFUN is omitted or nil, the value of `standard-output' is used. */) |
| 521 | (Lisp_Object printcharfun) | 527 | (Lisp_Object printcharfun, Lisp_Object ensure) |
| 522 | { | 528 | { |
| 523 | PRINTDECLARE; | 529 | Lisp_Object val = Qnil; |
| 524 | 530 | ||
| 531 | PRINTDECLARE; | ||
| 525 | if (NILP (printcharfun)) | 532 | if (NILP (printcharfun)) |
| 526 | printcharfun = Vstandard_output; | 533 | printcharfun = Vstandard_output; |
| 527 | PRINTPREPARE; | 534 | PRINTPREPARE; |
| 528 | PRINTCHAR ('\n'); | 535 | |
| 536 | if (NILP (ensure)) | ||
| 537 | val = Qt; | ||
| 538 | /* Difficult to check if at line beginning so abort. */ | ||
| 539 | else if (FUNCTIONP (printcharfun)) | ||
| 540 | signal_error ("Unsupported function argument", printcharfun); | ||
| 541 | else if (noninteractive && !NILP (printcharfun)) | ||
| 542 | val = printchar_stdout_last == 10 ? Qnil : Qt; | ||
| 543 | else if (NILP (Fbolp ())) | ||
| 544 | val = Qt; | ||
| 545 | |||
| 546 | if (!NILP (val)) PRINTCHAR ('\n'); | ||
| 529 | PRINTFINISH; | 547 | PRINTFINISH; |
| 530 | return Qt; | 548 | return val; |
| 531 | } | 549 | } |
| 532 | 550 | ||
| 533 | DEFUN ("prin1", Fprin1, Sprin1, 1, 2, 0, | 551 | DEFUN ("prin1", Fprin1, Sprin1, 1, 2, 0, |