emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/subed 89df304 304/389: subed-srt--sanitize: Don't insert n


From: ELPA Syncer
Subject: [nongnu] elpa/subed 89df304 304/389: subed-srt--sanitize: Don't insert newline in empty buffer
Date: Fri, 3 Dec 2021 11:00:46 -0500 (EST)

branch: elpa/subed
commit 89df304c94a7170da12929c83a5f09f302e747b0
Author: Random User <rndusr@posteo.de>
Commit: Random User <rndusr@posteo.de>

    subed-srt--sanitize: Don't insert newline in empty buffer
---
 subed/subed-srt.el      | 17 ++++++++++-------
 tests/test-subed-srt.el |  5 +++++
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/subed/subed-srt.el b/subed/subed-srt.el
index c9ddb9b..06e5d29 100644
--- a/subed/subed-srt.el
+++ b/subed/subed-srt.el
@@ -481,13 +481,16 @@ scheduled call is canceled and another call is scheduled 
in
              (delete-region prev-sub-end (point))
              (insert "\n\n"))))
 
-       ;; Two trailing newline if last subtitle text is empty,
-       ;; one trailing newline otherwise
-       (goto-char (point-max))
-       (subed-srt--jump-to-subtitle-end)
-       (unless (looking-at "\n\\'")
-         (delete-region (point) (point-max))
-         (insert "\n"))
+       ;; Two trailing newline if last subtitle text is empty, one trailing
+       ;; newline otherwise; do nothing in empty buffer (no graphical
+       ;; characters)
+       (goto-char (point-min))
+       (when (re-search-forward "[[:graph:]]" nil t)
+         (goto-char (point-max))
+         (subed-srt--jump-to-subtitle-end)
+         (unless (looking-at "\n\\'")
+           (delete-region (point) (point-max))
+           (insert "\n")))
 
        ;; One space before and after " --> "
        (goto-char (point-min))
diff --git a/tests/test-subed-srt.el b/tests/test-subed-srt.el
index a4af646..3a13f88 100644
--- a/tests/test-subed-srt.el
+++ b/tests/test-subed-srt.el
@@ -1385,6 +1385,11 @@ Baz.
       (expect (buffer-string) :not :to-equal mock-srt-data)
       (subed-srt--sanitize)
       (expect (buffer-string) :to-equal mock-srt-data)))
+  (it "does not insert newline in empty buffer."
+    (with-temp-srt-buffer
+      (expect (buffer-string) :to-equal "")
+      (subed-srt--sanitize)
+      (expect (buffer-string) :to-equal "")))
   )
 
 (describe "Renumbering"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]