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

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

[nongnu] elpa/subed 0e6ba37 180/389: Add option to ignore subtitle spaci


From: ELPA Syncer
Subject: [nongnu] elpa/subed 0e6ba37 180/389: Add option to ignore subtitle spacing when adjusting start/stop time
Date: Fri, 3 Dec 2021 11:00:21 -0500 (EST)

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

    Add option to ignore subtitle spacing when adjusting start/stop time
---
 subed/subed-srt.el      | 24 ++++++++++++++----------
 tests/test-subed-srt.el | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 10 deletions(-)

diff --git a/subed/subed-srt.el b/subed/subed-srt.el
index b1052d2..c87772d 100644
--- a/subed/subed-srt.el
+++ b/subed/subed-srt.el
@@ -315,12 +315,13 @@ Return point or nil if there is no previous subtitle."
 
 ;;; Manipulation
 
-(defun subed-srt--adjust-subtitle-start (msecs)
+(defun subed-srt--adjust-subtitle-start (msecs &optional ignore-spacing)
   "Add MSECS milliseconds to start time (use negative value to subtract).
 
 If the adjustment would result in overlapping subtitles, reduce
 MSECS so that there are at least `subed-subtitle-spacing'
-milliseconds between subtitles.
+milliseconds between subtitles.  If IGNORE-SPACING is non-nil
+this limitation is disabled.
 
 Return the number of milliseconds the start time was adjusted or
 nil if nothing was adjusted."
@@ -330,12 +331,12 @@ nil if nothing was adjusted."
          (msecs-prev (save-excursion
                        (when (subed-srt--backward-subtitle-id)
                          (subed-srt--subtitle-msecs-stop))))
-         (msecs-min (if msecs-prev (+ msecs-prev subed-subtitle-spacing) 0))
-         (msecs-max (subed-srt--subtitle-msecs-stop)))
+         (msecs-min (if ignore-spacing nil (if msecs-prev (+ msecs-prev 
subed-subtitle-spacing) 0)))
+         (msecs-max (if ignore-spacing nil (subed-srt--subtitle-msecs-stop))))
     (when msecs-new
       (when (and msecs-min (< msecs-new msecs-min))
         (setq msecs-new msecs-min))
-      (when (> msecs-new msecs-max)
+      (when (and msecs-max (> msecs-new msecs-max))
         (setq msecs-new msecs-max))
       ;; msecs-new must be bigger than the current start time if we are adding
       ;; or smaller if we are subtracting.
@@ -348,12 +349,13 @@ nil if nothing was adjusted."
             (subed--run-subtitle-time-adjusted-hook)
             (- msecs-new msecs-start)))))))
 
-(defun subed-srt--adjust-subtitle-stop (msecs)
+(defun subed-srt--adjust-subtitle-stop (msecs &optional ignore-spacing)
   "Add MSECS milliseconds to stop time (use negative value to subtract).
 
 If the adjustment would result in overlapping subtitles, reduce
 MSECS so that there are at least `subed-subtitle-spacing'
-milliseconds between subtitles.
+milliseconds between subtitles.  If IGNORE-SPACING is non-nil
+this limitation is disabled.
 
 Return the number of milliseconds the stop time was adjusted or
 nil if nothing was adjusted."
@@ -363,10 +365,12 @@ nil if nothing was adjusted."
          (msecs-next (save-excursion
                        (when (subed-srt--forward-subtitle-id)
                          (subed-srt--subtitle-msecs-start))))
-         (msecs-min (subed-srt--subtitle-msecs-start))
-         (msecs-max (when msecs-next (- msecs-next subed-subtitle-spacing))))
+         (msecs-min (if ignore-spacing nil (subed-srt--subtitle-msecs-start)))
+         (msecs-max (if ignore-spacing nil (when msecs-next
+                                             (- msecs-next 
subed-subtitle-spacing)))))
+    (message "min:%S max:%S" msecs-min msecs-max)
     (when msecs-new
-      (when (< msecs-new msecs-min)
+      (when (and msecs-min (< msecs-new msecs-min))
         (setq msecs-new msecs-min))
       (when (and msecs-max (> msecs-new msecs-max))
         (setq msecs-new msecs-max))
diff --git a/tests/test-subed-srt.el b/tests/test-subed-srt.el
index 1d13f02..08106d8 100644
--- a/tests/test-subed-srt.el
+++ b/tests/test-subed-srt.el
@@ -655,6 +655,38 @@ Baz.
                 (expect (save-excursion (subed-srt--jump-to-subtitle-time-stop)
                                         (thing-at-point 'line)) :to-equal 
"00:03:03,550 --> 00:03:15,400\n")))
           (describe "enforces limits"
+                    (describe "unless the second argument is truthy"
+                              (it "when adjusting start time."
+                                  (with-temp-buffer
+                                    (insert (concat "1\n"
+                                                    "00:00:01,000 --> 
00:00:02,000\n"
+                                                    "Foo.\n\n"
+                                                    "2\n"
+                                                    "00:00:02,100 --> 
00:00:03,000\n"
+                                                    "Bar.\n"))
+                                    (subed-srt--jump-to-subtitle-id 2)
+                                    (expect (subed-srt--adjust-subtitle-start 
-100 :ignore-spacing) :to-be -100)
+                                    (expect (subed-srt--subtitle-msecs-start 
2) :to-be 2000)
+                                    (expect (subed-srt--subtitle-msecs-stop 1) 
:to-be 2000)
+                                    (expect (subed-srt--adjust-subtitle-start 
-200 :ignore-spacing) :to-be -200)
+                                    (expect (subed-srt--subtitle-msecs-start 
2) :to-be 1800)
+                                    (expect (subed-srt--subtitle-msecs-stop 1) 
:to-be 2000)))
+                              (it "when adjusting stop time."
+                                  (with-temp-buffer
+                                    (insert (concat "1\n"
+                                                    "00:00:01,000 --> 
00:00:02,000\n"
+                                                    "Foo.\n\n"
+                                                    "2\n"
+                                                    "00:00:02,100 --> 
00:00:03,000\n"
+                                                    "Bar.\n"))
+                                    (subed-srt--jump-to-subtitle-id 1)
+                                    (expect (subed-srt--adjust-subtitle-stop 
100 :ignore-spacing) :to-be 100)
+                                    (expect (subed-srt--subtitle-msecs-stop 1) 
:to-be 2100)
+                                    (expect (subed-srt--subtitle-msecs-start 
2) :to-be 2100)
+                                    (expect (subed-srt--adjust-subtitle-stop 
200 :ignore-spacing) :to-be 200)
+                                    (expect (subed-srt--subtitle-msecs-stop 1) 
:to-be 2300)
+                                    (expect (subed-srt--subtitle-msecs-start 
2) :to-be 2100)))
+                              )
                     (describe "when decreasing start time"
                               (it "of the first subtitle."
                                   (with-temp-buffer



reply via email to

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