aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeo Liu2014-10-09 06:05:48 +0800
committerLeo Liu2014-10-09 06:05:48 +0800
commit2dbd7a37a809e2dcef6c8e7323ac15c98b051cd9 (patch)
tree3325d872642948f831a9acb971a2c06ce7d10b4d
parent289a43910e29999f125d76a48602b63cea7ed9b9 (diff)
downloademacs-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)
-rw-r--r--doc/lispref/ChangeLog5
-rw-r--r--doc/lispref/streams.texi9
-rw-r--r--doc/misc/ChangeLog4
-rw-r--r--doc/misc/cl.texi5
-rw-r--r--lisp/ChangeLog4
-rw-r--r--lisp/emacs-lisp/cl-extra.el7
-rw-r--r--src/ChangeLog11
-rw-r--r--src/keyboard.c2
-rw-r--r--src/keymap.c2
-rw-r--r--src/print.c28
-rw-r--r--test/ChangeLog5
-rw-r--r--test/automated/print-tests.el56
12 files changed, 125 insertions, 13 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index 510f9e983c3..4d4d0b529cc 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,3 +1,8 @@
12014-10-08 Leo Liu <sdl.web@gmail.com>
2
3 * streams.texi (Output Functions): Document new argument ENSURE to
4 terpri. (Bug#18652)
5
12014-10-04 Martin Rudalics <rudalics@gmx.at> 62014-10-04 Martin Rudalics <rudalics@gmx.at>
2 7
3 * display.texi (Scroll Bars): Add description of horizontal scroll 8 * display.texi (Scroll Bars): Add description of horizontal scroll
diff --git a/doc/lispref/streams.texi b/doc/lispref/streams.texi
index 1d549ae8916..c287b617713 100644
--- a/doc/lispref/streams.texi
+++ b/doc/lispref/streams.texi
@@ -615,10 +615,13 @@ spacing between calls.
615@end example 615@end example
616@end defun 616@end defun
617 617
618@defun terpri &optional stream 618@defun terpri &optional stream ensure
619@cindex newline in print 619@cindex newline in print
620This function outputs a newline to @var{stream}. The name stands 620This function outputs a newline to @var{stream}. The name stands for
621for ``terminate print''. 621``terminate print''. If @var{ensure} is non-nil no newline is printed
622if @var{stream} is already at the beginning of a line. Note in this
623case @var{stream} can not be a function and an error is signalled if
624it is. This function returns @code{t} if a newline is printed.
622@end defun 625@end defun
623 626
624@defun write-char character &optional stream 627@defun write-char character &optional stream
diff --git a/doc/misc/ChangeLog b/doc/misc/ChangeLog
index 050c3339c8b..70207de3b3b 100644
--- a/doc/misc/ChangeLog
+++ b/doc/misc/ChangeLog
@@ -1,3 +1,7 @@
12014-10-08 Leo Liu <sdl.web@gmail.com>
2
3 * cl.texi (Porting Common Lisp): Remove parse-integer.
4
12014-10-06 Ulf Jasper <ulf.jasper@web.de> 52014-10-06 Ulf Jasper <ulf.jasper@web.de>
2 6
3 * newsticker.texi (Supported Formats): Fix order of subheading and 7 * newsticker.texi (Supported Formats): Fix order of subheading and
diff --git a/doc/misc/cl.texi b/doc/misc/cl.texi
index 04a0e5725e8..c15918afc4e 100644
--- a/doc/misc/cl.texi
+++ b/doc/misc/cl.texi
@@ -4707,9 +4707,8 @@ exactly the same thing, so this package has not bothered to
4707implement a Common Lisp-style @code{make-list}. 4707implement a Common Lisp-style @code{make-list}.
4708 4708
4709@item 4709@item
4710A few more notable Common Lisp features not included in this 4710A few more notable Common Lisp features not included in this package:
4711package: @code{compiler-let}, @code{tagbody}, @code{prog}, 4711@code{compiler-let}, @code{prog}, @code{ldb/dpb}, @code{cerror}.
4712@code{ldb/dpb}, @code{parse-integer}, @code{cerror}.
4713 4712
4714@item 4713@item
4715Recursion. While recursion works in Emacs Lisp just like it 4714Recursion. While recursion works in Emacs Lisp just like it
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index ef1bdfba0d6..87852d64a46 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,7 @@
12014-10-08 Leo Liu <sdl.web@gmail.com>
2
3 * emacs-lisp/cl-extra.el (cl-fresh-line): New function.
4
12014-10-08 Glenn Morris <rgm@gnu.org> 52014-10-08 Glenn Morris <rgm@gnu.org>
2 6
3 * calendar/cal-x.el (calendar-dedicate-diary): 7 * calendar/cal-x.el (calendar-dedicate-diary):
diff --git a/lisp/emacs-lisp/cl-extra.el b/lisp/emacs-lisp/cl-extra.el
index e10844069ef..a7970261608 100644
--- a/lisp/emacs-lisp/cl-extra.el
+++ b/lisp/emacs-lisp/cl-extra.el
@@ -647,6 +647,13 @@ PROPLIST is a list of the sort returned by `symbol-plist'.
647 (progn (setplist sym (cdr (cdr plist))) t) 647 (progn (setplist sym (cdr (cdr plist))) t)
648 (cl--do-remf plist tag)))) 648 (cl--do-remf plist tag))))
649 649
650;;; Streams.
651
652;;;###autoload
653(defun cl-fresh-line (&optional stream)
654 "Output a newline unless already at the beginning of a line."
655 (terpri stream 'ensure))
656
650;;; Some debugging aids. 657;;; Some debugging aids.
651 658
652(defun cl-prettyprint (form) 659(defun cl-prettyprint (form)
diff --git a/src/ChangeLog b/src/ChangeLog
index 07e4a148ba2..e01c70f3dce 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,14 @@
12014-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
12014-10-08 Eli Zaretskii <eliz@gnu.org> 122014-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
3370DEFUN ("describe-vector", Fdescribe_vector, Sdescribe_vector, 1, 2, 0, 3370DEFUN ("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
59static Lisp_Object being_printed[PRINT_CIRCLE]; 59static Lisp_Object being_printed[PRINT_CIRCLE];
60 60
61/* Last char printed to stdout by printchar. */
62static 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. */
63static char *print_buffer; 66static 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);
515static void print_preprocess_string (INTERVAL, Lisp_Object); 519static void print_preprocess_string (INTERVAL, Lisp_Object);
516static void print_object (Lisp_Object, Lisp_Object, bool); 520static void print_object (Lisp_Object, Lisp_Object, bool);
517 521
518DEFUN ("terpri", Fterpri, Sterpri, 0, 1, 0, 522DEFUN ("terpri", Fterpri, Sterpri, 0, 2, 0,
519 doc: /* Output a newline to stream PRINTCHARFUN. 523 doc: /* Output a newline to stream PRINTCHARFUN.
524If ENSURE is non-nil only output a newline if not already at the
525beginning of a line. Value is non-nil if a newline is printed.
520If PRINTCHARFUN is omitted or nil, the value of `standard-output' is used. */) 526If 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
533DEFUN ("prin1", Fprin1, Sprin1, 1, 2, 0, 551DEFUN ("prin1", Fprin1, Sprin1, 1, 2, 0,
diff --git a/test/ChangeLog b/test/ChangeLog
index 3d930be56c1..5c2032e7e85 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,8 @@
12014-10-08 Leo Liu <sdl.web@gmail.com>
2
3 * automated/print-tests.el: New file.
4 (terpri): Tests for terpri. (Bug#18652)
5
12014-10-06 Glenn Morris <rgm@gnu.org> 62014-10-06 Glenn Morris <rgm@gnu.org>
2 7
3 * automated/icalendar-tests.el (icalendar--calendar-style): 8 * automated/icalendar-tests.el (icalendar--calendar-style):
diff --git a/test/automated/print-tests.el b/test/automated/print-tests.el
new file mode 100644
index 00000000000..1974cc452a6
--- /dev/null
+++ b/test/automated/print-tests.el
@@ -0,0 +1,56 @@
1;;; print-tests.el --- tests for src/print.c -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2014 Free Software Foundation, Inc.
4
5;; This file is part of GNU Emacs.
6
7;; This program is free software; you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
11
12;; This program is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20;;; Code:
21
22(require 'ert)
23
24(ert-deftest terpri ()
25 (should (string= (with-output-to-string
26 (princ 'abc)
27 (should (terpri nil t)))
28 "abc\n"))
29 (should (string= (with-output-to-string
30 (should-not (terpri nil t))
31 (princ 'xyz))
32 "xyz"))
33 (message nil)
34 (if noninteractive
35 (progn (should (terpri nil t))
36 (should-not (terpri nil t))
37 (princ 'abc)
38 (should (terpri nil t))
39 (should-not (terpri nil t)))
40 (should (string= (progn (should-not (terpri nil t))
41 (princ 'abc)
42 (should (terpri nil t))
43 (current-message))
44 "abc\n")))
45 (let ((standard-output
46 (with-current-buffer (get-buffer-create "*terpri-test*")
47 (insert "--------")
48 (point-max-marker))))
49 (should (terpri nil t))
50 (should-not (terpri nil t))
51 (should (string= (with-current-buffer (marker-buffer standard-output)
52 (buffer-string))
53 "--------\n"))))
54
55(provide 'print-tests)
56;;; print-tests.el ends here