[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/subed c022c57517 4/7: VTT comments: append subtitle before
|
From: |
ELPA Syncer |
|
Subject: |
[nongnu] elpa/subed c022c57517 4/7: VTT comments: append subtitle before comment, add newlines |
|
Date: |
Sun, 5 Nov 2023 10:00:47 -0500 (EST) |
branch: elpa/subed
commit c022c5751716f183ae8f0566ecaaebacdc8efbf5
Author: Sacha Chua <sacha@sachachua.com>
Commit: Sacha Chua <sacha@sachachua.com>
VTT comments: append subtitle before comment, add newlines
* subed/subed-vtt.el (subed-vtt--format-comment): Add newlines after
comment.
(subed--append-subtitle): Append subtitles before any comments.
* tests/test-subed-vtt.el: Add test.
---
subed/subed-vtt.el | 29 ++++++++++++++++++-----------
tests/test-subed-vtt.el | 18 ++++++++++++++++++
2 files changed, 36 insertions(+), 11 deletions(-)
diff --git a/subed/subed-vtt.el b/subed/subed-vtt.el
index fd6159891b..3509db6c74 100644
--- a/subed/subed-vtt.el
+++ b/subed/subed-vtt.el
@@ -238,7 +238,7 @@ Make sure COMMENT ends with a blank line."
"" "\n\n")))
comment)
((string-match "\n" comment) (concat "NOTE\n" comment "\n\n"))
- (t (concat "NOTE " comment))))
+ (t (concat "NOTE " comment "\n\n"))))
(cl-defmethod subed--make-subtitle (&context (major-mode subed-vtt-mode)
&optional _ start stop text
comment)
@@ -284,16 +284,23 @@ TEXT defaults to an empty string.
Move point to the text of the inserted subtitle. Return new
point. Use the format-specific function for MAJOR-MODE."
- (unless (subed-forward-subtitle-id)
- ;; Point is on last subtitle or buffer is empty
- (subed-jump-to-subtitle-end)
- (when (looking-at "[[:space:]]+")
- (replace-match ""))
- ;; Moved point to end of last subtitle; ensure separator exists
- (while (not (looking-at "\\(\\`\\|[[:blank:]]*\n[[:blank:]]*\n\\)"))
- (save-excursion (insert ?\n)))
- ;; Move to end of separator
- (goto-char (match-end 0)))
+ (let ((pos (point)))
+ (if (subed-forward-subtitle-id)
+ ;; Insert before any comments
+ (progn
+ (subed-backward-subtitle-end)
+ (cond
+ ((eobp) (insert "\n\n"))
+ ((looking-at " *\n\n") (goto-char (match-end 0)))))
+ ;; Point is on last subtitle or buffer is empty
+ (subed-jump-to-subtitle-end)
+ (when (looking-at "[[:space:]]+")
+ (replace-match ""))
+ ;; Moved point to end of last subtitle; ensure separator exists
+ (while (not (looking-at "\\(\\`\\|[[:blank:]]*\n[[:blank:]]*\n\\)"))
+ (save-excursion (insert ?\n)))
+ ;; Move to end of separator
+ (goto-char (match-end 0))))
(insert (subed-make-subtitle id start stop text comment))
(unless (eolp)
;; Complete separator with another newline unless we inserted at the end
diff --git a/tests/test-subed-vtt.el b/tests/test-subed-vtt.el
index a5d1e71740..ec1aa0b627 100644
--- a/tests/test-subed-vtt.el
+++ b/tests/test-subed-vtt.el
@@ -899,6 +899,24 @@ Baz.
(expect (point) :to-equal 67)))
)
)
+ (describe "before a comment"
+ (it "inserts before the comment."
+ (with-temp-vtt-buffer
+ (insert (concat "00:00:01.000 --> 00:00:02.000\n"
+ "Foo.\n\n"
+ "NOTE comment\n\n00:00:05.000 --> 00:00:06.000\n"
+ "Bar.\n"))
+ (subed-jump-to-subtitle-time-start "00:00:01.000")
+ (expect (subed-append-subtitle nil 2500 4000 "Baz.") :to-equal 67)
+ (expect (buffer-string) :to-equal (concat "00:00:01.000 -->
00:00:02.000\n"
+ "Foo.\n\n"
+ "00:00:02.500 -->
00:00:04.000\n"
+ "Baz.\n\n"
+ "NOTE
comment\n\n00:00:05.000 --> 00:00:06.000\n"
+ "Bar.\n"))
+ (expect (point) :to-equal 67))
+ )
+ )
(it "when point is on empty text."
(with-temp-vtt-buffer
(insert (concat "00:00:01.000 --> 00:00:02.000\n"
- [nongnu] elpa/subed updated (de7ee92961 -> 2598656c5d), ELPA Syncer, 2023/11/05
- [nongnu] elpa/subed 1c3fbbaa9f 2/7: Update loop after adjusting time, ELPA Syncer, 2023/11/05
- [nongnu] elpa/subed bbebabde9f 3/7: New command subed-mpv-jump-to-current-subtitle-near-end (M-J), ELPA Syncer, 2023/11/05
- [nongnu] elpa/subed 09e9d0232c 1/7: Add subed-append-subtitle-list for easier bulk-adding, ELPA Syncer, 2023/11/05
- [nongnu] elpa/subed c022c57517 4/7: VTT comments: append subtitle before comment, add newlines,
ELPA Syncer <=
- [nongnu] elpa/subed 750ae1f058 6/7: Test improvements, ELPA Syncer, 2023/11/05
- [nongnu] elpa/subed 5c75ea07ff 5/7: subed-waveform: Add mouse bindings for setting start/end and copying, ELPA Syncer, 2023/11/05
- [nongnu] elpa/subed 2598656c5d 7/7: version 1.2.6, ELPA Syncer, 2023/11/05