diff options
author | Lars Ingebrigtsen <larsi@gnus.org> | 2022-05-01 23:05:06 +0200 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2022-05-01 23:05:06 +0200 |
commit | 51186ed69c361abd73d20a96e929b127cd7f15f9 (patch) | |
tree | 9eec28cb285349c0324fe54ce219ebd614ef4026 /lisp | |
parent | 4f395efa06d88832c376c2b1d4607677436228c0 (diff) | |
download | emacs-51186ed69c361abd73d20a96e929b127cd7f15f9.tar.gz |
Fix string-lines return for ""
* lisp/subr.el (string-lines): Return the correct result on ""
(bug#55213).
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/subr.el | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index d6ea3092074..aded02c4f79 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -6747,29 +6747,31 @@ is inserted before adjusting the number of empty lines." If OMIT-NULLS, empty lines will be removed from the results. If KEEP-NEWLINES, don't strip trailing newlines from the result lines." - (let ((lines nil) - (start 0)) - (while (< start (length string)) - (let ((newline (string-search "\n" string start))) - (if newline - (progn - (when (or (not omit-nulls) - (not (= start newline))) - (let ((line (substring string start - (if keep-newlines - (1+ newline) - newline)))) - (when (not (and keep-newlines omit-nulls - (equal line "\n"))) - (push line 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. - (push string lines) - (push (substring string start) lines)) - (setq start (length string))))) - (nreverse lines))) + (if (equal string "") + (list "") + (let ((lines nil) + (start 0)) + (while (< start (length string)) + (let ((newline (string-search "\n" string start))) + (if newline + (progn + (when (or (not omit-nulls) + (not (= start newline))) + (let ((line (substring string start + (if keep-newlines + (1+ newline) + newline)))) + (when (not (and keep-newlines omit-nulls + (equal line "\n"))) + (push line 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. + (push string lines) + (push (substring string start) lines)) + (setq start (length string))))) + (nreverse lines)))) (defun buffer-match-p (condition buffer-or-name &optional arg) "Return non-nil if BUFFER-OR-NAME matches CONDITION. |