1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Change string-lines semantics slightly

* lisp/subr.el (string-lines): Change the semantics slightly --
don't return an empty string for a trailing newline.
This commit is contained in:
Lars Ingebrigtsen 2022-05-01 20:54:11 +02:00
parent 32ab756d82
commit 4f395efa06
3 changed files with 7 additions and 7 deletions

View file

@ -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

View file

@ -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.

View file

@ -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")))