[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 4f395efa06: Change string-lines semantics slightly
From: |
Lars Ingebrigtsen |
Subject: |
master 4f395efa06: Change string-lines semantics slightly |
Date: |
Sun, 1 May 2022 14:54:26 -0400 (EDT) |
branch: master
commit 4f395efa06d88832c376c2b1d4607677436228c0
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Change string-lines semantics slightly
* lisp/subr.el (string-lines): Change the semantics slightly --
don't return an empty string for a trailing newline.
---
etc/NEWS | 5 +++++
lisp/subr.el | 7 +------
test/lisp/subr-tests.el | 2 +-
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index 3380c266da..882748d8c7 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -135,6 +135,11 @@ of 'user-emacs-directory'.
* Incompatible changes in Emacs 29.1
+---
+** 'string-lines' handles trailing newlines differently.
+It no longer returns an empty final string if the string ends with a
+newline.
+
---
** 'TAB' and '<backtab>' are now bound in 'button-map'.
This means that if you're standing on a button, 'TAB' will take you to
diff --git a/lisp/subr.el b/lisp/subr.el
index d4f5d0d23b..d6ea309207 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -6762,12 +6762,7 @@ lines."
(when (not (and keep-newlines omit-nulls
(equal line "\n")))
(push line lines))))
- (setq start (1+ newline))
- ;; Include the final newline.
- (when (and (= start (length string))
- (not omit-nulls)
- (not keep-newlines))
- (push "" lines)))
+ (setq start (1+ newline)))
;; No newline in the remaining part.
(if (zerop start)
;; Avoid a string copy if there are no newlines at all.
diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el
index c431930c27..93e4475d6b 100644
--- a/test/lisp/subr-tests.el
+++ b/test/lisp/subr-tests.el
@@ -1030,7 +1030,7 @@ final or penultimate step during initialization."))
(ert-deftest test-string-lines ()
(should (equal (string-lines "foo") '("foo")))
- (should (equal (string-lines "foo\n") '("foo" "")))
+ (should (equal (string-lines "foo\n") '("foo")))
(should (equal (string-lines "foo\nbar") '("foo" "bar")))
(should (equal (string-lines "foo" t) '("foo")))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 4f395efa06: Change string-lines semantics slightly,
Lars Ingebrigtsen <=