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 | |
| 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')
| -rw-r--r-- | src/ChangeLog | 11 | ||||
| -rw-r--r-- | src/keyboard.c | 2 | ||||
| -rw-r--r-- | src/keymap.c | 2 | ||||
| -rw-r--r-- | src/print.c | 28 |
4 files changed, 36 insertions, 7 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 07e4a148ba2..e01c70f3dce 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,14 @@ | |||
| 1 | 2014-10-08 Leo Liu <sdl.web@gmail.com> | ||
| 2 | |||
| 3 | Enhance terpri to allow conditionally output a newline. (Bug#18652) | ||
| 4 | * keymap.c (describe_vector_princ): | ||
| 5 | * keyboard.c (Fcommand_error_default_function): Adapt to change to | ||
| 6 | Fterpri. | ||
| 7 | |||
| 8 | * print.c (printchar_stdout_last): Declare. | ||
| 9 | (printchar): Record the last char written to stdout. | ||
| 10 | (Fterpri): Add optional argument ENSURE. | ||
| 11 | |||
| 1 | 2014-10-08 Eli Zaretskii <eliz@gnu.org> | 12 | 2014-10-08 Eli Zaretskii <eliz@gnu.org> |
| 2 | 13 | ||
| 3 | * w32inevt.c (maybe_generate_resize_event): Pass non-zero as the | 14 | * w32inevt.c (maybe_generate_resize_event): Pass non-zero as the |
diff --git a/src/keyboard.c b/src/keyboard.c index 0d042132d8e..6730536dc1d 100644 --- a/src/keyboard.c +++ b/src/keyboard.c | |||
| @@ -1126,7 +1126,7 @@ Default value of `command-error-function'. */) | |||
| 1126 | { | 1126 | { |
| 1127 | print_error_message (data, Qexternal_debugging_output, | 1127 | print_error_message (data, Qexternal_debugging_output, |
| 1128 | SSDATA (context), signal); | 1128 | SSDATA (context), signal); |
| 1129 | Fterpri (Qexternal_debugging_output); | 1129 | Fterpri (Qexternal_debugging_output, Qnil); |
| 1130 | Fkill_emacs (make_number (-1)); | 1130 | Fkill_emacs (make_number (-1)); |
| 1131 | } | 1131 | } |
| 1132 | else | 1132 | else |
diff --git a/src/keymap.c b/src/keymap.c index fa2d4e942b8..d633bdcaae7 100644 --- a/src/keymap.c +++ b/src/keymap.c | |||
| @@ -3364,7 +3364,7 @@ describe_vector_princ (Lisp_Object elt, Lisp_Object fun) | |||
| 3364 | { | 3364 | { |
| 3365 | Findent_to (make_number (16), make_number (1)); | 3365 | Findent_to (make_number (16), make_number (1)); |
| 3366 | call1 (fun, elt); | 3366 | call1 (fun, elt); |
| 3367 | Fterpri (Qnil); | 3367 | Fterpri (Qnil, Qnil); |
| 3368 | } | 3368 | } |
| 3369 | 3369 | ||
| 3370 | DEFUN ("describe-vector", Fdescribe_vector, Sdescribe_vector, 1, 2, 0, | 3370 | DEFUN ("describe-vector", Fdescribe_vector, Sdescribe_vector, 1, 2, 0, |
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, |