[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/subed b1c5b88 354/389: Some adjustments to subed-split-sub
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/subed b1c5b88 354/389: Some adjustments to subed-split-subtitle |
Date: |
Fri, 3 Dec 2021 11:00:56 -0500 (EST) |
branch: elpa/subed
commit b1c5b88fc96be8afd1d5a9594c13d055ac5afbfd
Author: Random User <rndusr@posteo.de>
Commit: Random User <rndusr@posteo.de>
Some adjustments to subed-split-subtitle
1. Move point to subtitle text if it isn't already somewhere on the text.
2. If we can't get the splitting position from subed-mpv-playback-position,
use
the middle between the current subtitle's start and end.
3. Use subed-subtitle-spacing to add a gap between before the new subtitle.
4. Return point of the newly inserted subtitle.
---
subed/subed-common.el | 52 ++++++++++++++++++++++++++++++++++-----------------
1 file changed, 35 insertions(+), 17 deletions(-)
diff --git a/subed/subed-common.el b/subed/subed-common.el
index d16f5e0..a4e7d55 100644
--- a/subed/subed-common.el
+++ b/subed/subed-common.el
@@ -632,24 +632,42 @@ Update the end timestamp accordingly."
(error "No previous subtitle to merge into")))
(defun subed-split-subtitle ()
- "Split current subtitle at point using timestamp from MPV."
+ "Split current subtitle at point.
+
+The subtitle text after point is moved to a new subtitle that is
+inserted after the current subtitle.
+
+If a video is playing, `subed-mpv-playback-position' is used as
+the new stop time of the current subtitle. Otherwise, the
+timestamp between the start and stop timestamp of the current
+subtitle is used.
+
+The newly inserted subtitle starts `subed-subtitle-spacing'
+milliseconds after the current subtitle's new end timestamp.
+
+Return point of the new subtitle.
+"
(interactive)
- (let* ((end-timestamp (subed-subtitle-msecs-stop))
- (orig (point))
- (text-beg (save-excursion (subed-jump-to-subtitle-text)))
- (text-end (save-excursion (or (subed-jump-to-subtitle-end) (point))))
- (text (buffer-substring orig text-end)))
- (unless subed-mpv-playback-position
- (error "Not playing back in MPV"))
- (unless (and text-beg text-end (>= orig text-beg) (<= orig text-end))
- (error "Not in the middle of subtitle text"))
- (when (or (> subed-mpv-playback-position end-timestamp)
- (< subed-mpv-playback-position (subed-subtitle-msecs-start)))
- (error "Not in the currently playing subtitle segment"))
- (subed-set-subtitle-time-stop subed-mpv-playback-position)
- (delete-region (point) text-end)
- (subed-append-subtitle nil subed-mpv-playback-position end-timestamp
(string-trim text))
- (subed-regenerate-ids-soon)))
+ (let ((text-beg (save-excursion (subed-jump-to-subtitle-text)))
+ (text-end (save-excursion (or (subed-jump-to-subtitle-end) (point)))))
+ ;; Ensure point is on subtitle text
+ (unless (and text-beg text-end (>= (point) text-beg) (<= (point) text-end))
+ (subed-jump-to-subtitle-text))
+ (let* ((split-timestamp (if subed-mpv-playback-position
+ (+ subed-mpv-playback-position
subed-subtitle-spacing)
+ (let ((sub-len (- (subed-subtitle-msecs-stop)
(subed-subtitle-msecs-start))))
+ (+ (subed-subtitle-msecs-start) (/ sub-len
2)))))
+ (new-text (string-trim (buffer-substring (point) text-end)))
+ (new-start-timestamp (+ split-timestamp subed-subtitle-spacing))
+ (new-stop-timestamp (subed-subtitle-msecs-stop)))
+ (when (or (> split-timestamp new-stop-timestamp)
+ (< split-timestamp (subed-subtitle-msecs-start)))
+ (error "Playback position is not at the subtitle on point."))
+ (subed-set-subtitle-time-stop split-timestamp)
+ (delete-region (point) text-end)
+ (subed-append-subtitle nil new-start-timestamp new-stop-timestamp
new-text))
+ (subed-regenerate-ids-soon)
+ (point)))
;;; Replay time-adjusted subtitle
- [nongnu] elpa/subed d71655f 276/389: Fix parens, (continued)
- [nongnu] elpa/subed d71655f 276/389: Fix parens, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed b740511 277/389: Use mark-active instead of use-region-p, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed e8612e7 279/389: Unify optional argument name, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed d1b308e 280/389: Make subed-subtitle-time-adjusted-hook buffer-local, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 0302aa9 278/389: Move screenshow below introduction, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed c8cf4b7 281/389: Don't insert too many mock subtitles, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 3245922 282/389: Focus correct subtitle, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed d076bac 285/389: Make enforced subtitle boundaries optional, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed b5667c4 286/389: Add tests for subed-enforce-time-boundaries, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed dde5dfd 287/389: Simplify subed-mpv--client-buffer, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed b1c5b88 354/389: Some adjustments to subed-split-subtitle,
ELPA Syncer <=
- [nongnu] elpa/subed 5f1ad41 355/389: "mpv" instead of "MPV" (see `man mpv`, https://mpv.io etc), ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed a83ee74 357/389: Remove trailing space, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed da4dac9 358/389: Two spaces after sentence to make `make test` pass, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 49ddccc 359/389: Move subed--init-alist to subed.el, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 8263b33 360/389: subed-split-subtitle: Use offset or text fraction, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 1c52f1b 361/389: Add tests for splitting subtitles and handle more cases, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed e065632 362/389: Fix previous commit for subed-set-subtitle-text, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed ec7b222 368/389: Enable CPS showing by default and improve CPS toggling functions, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed f28ad22 379/389: Make subed-mpv-jump-to-current-subtitle interactive, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed c76ba50 387/389: Prompt for playback speed factor, ELPA Syncer, 2021/12/03