[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/subed 5ed05ad398 02/22: Implement mode-specific functions
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/subed 5ed05ad398 02/22: Implement mode-specific functions with cl-defmethod |
Date: |
Tue, 1 Feb 2022 14:05:27 -0500 (EST) |
branch: elpa/subed
commit 5ed05ad3983fc65b6b0cbc963c031edcba518318
Author: Sacha Chua <sacha@sachachua.com>
Commit: Sacha Chua <sacha@sachachua.com>
Implement mode-specific functions with cl-defmethod
* subed/subed-common.el: Define generic functions for
timestamp-to-msecs, msecs-to-timestamp, subtitle-id, subtitle-id-max,
subtitle-id-at-msecs, jump-to-subtitle-id,
jump-to-subtitle-time-start, jump-to-subtitle-time-stop,
jump-to-subtitle-text, jump-to-subtitle-end,
jump-to-subtitle-id-at-msecs, forward-subtitle-id,
backward-subtitle-id, forward-subtitle-text, backward-subtitle-text,
forward-subtitle-end, backward-subtitle-end,
forward-subtitle-time-start, backward-subtitle-time-start,
forward-subtitle-time-stop, backward-subtitle-time-stop,
subtitle-msecs-start, subtitle-msecs-stop, subtitle-text,
subtitle-relative-point, set-subtitle-time-start,
set-subtitle-time-stop, make-subtitle, prepend-subtitle,
append-subtitle, kill-subtitle, sanitize, validate, sort,
insert-subtitle, insert-subtitle-adjacent, split-subtitle.
(subed--regexp-separator): New buffer-local variable.
(subed--regexp-timestamp): New buffer-local variable.
(subed-sanitize-functions): Add subed-sort.
(subed-validate-functions): Add subed-validate.
* subed/subed-ass.el, subed/subed-srt.el, subed/subed-vtt.el: Use
cl-defmethod to implement timestamp-to-msecs, msecs-to-timestamp,
subtitle-id, subtitle-id-at-msecs, jump-to-subtitle-id,
jump-to-subtitle-time-start, jump-to-subtitle-time-stop,
jump-to-subtitle-text, jump-to-subtitle-end, forward-subtitle-id,
backward-subtitle-id, make-subtitle, prepend-subtitle,
append-subtitle, merge-with-next.
* tests/tests-subed-common.el, tests/test-subed-vtt.el,
tests/test-subed-srt.el, tests/test-subed-ass.el: Use generic
functions.
---
Makefile | 8 +
subed/subed-ass.el | 315 ++++++--------------------
subed/subed-common.el | 344 +++++++++++++++++++++++++---
subed/subed-srt.el | 396 ++++++++++----------------------
subed/subed-vtt.el | 371 ++++++++----------------------
subed/subed.el | 99 +-------
tests/test-subed-ass.el | 210 ++++++++---------
tests/test-subed-common.el | 386 +++++++++++++++----------------
tests/test-subed-srt.el | 552 ++++++++++++++++++++++-----------------------
tests/test-subed-vtt.el | 464 ++++++++++++++++++-------------------
10 files changed, 1419 insertions(+), 1726 deletions(-)
diff --git a/Makefile b/Makefile
index dfafbb4e48..91871cd8cc 100644
--- a/Makefile
+++ b/Makefile
@@ -16,6 +16,10 @@ test:
emacs --quick --batch --eval "(checkdoc-file \"subed/subed-mpv.el\")"
emacs --quick --batch --eval "(checkdoc-file \"subed/subed-srt.el\")"
+autoloads:
+ emacs --quick --batch --eval "(progn (setq generated-autoload-file
(expand-file-name \"subed-autoloads.el\" \"subed\") backup-inhibited t) \
+ (update-directory-autoloads \"./subed\"))"
+
test-compile:
emacs --quick --batch --eval "(progn (add-to-list 'load-path
(expand-file-name \"subed\" default-directory)) \
(byte-compile-file
\"subed/subed.el\"))"
@@ -27,6 +31,10 @@ test-compile:
(byte-compile-file
\"subed/subed-mpv.el\"))"
emacs --quick --batch --eval "(progn (add-to-list 'load-path
(expand-file-name \"subed\" default-directory)) \
(byte-compile-file
\"subed/subed-srt.el\"))"
+ emacs --quick --batch --eval "(progn (add-to-list 'load-path
(expand-file-name \"subed\" default-directory)) \
+ (byte-compile-file
\"subed/subed-vtt.el\"))"
+ emacs --quick --batch --eval "(progn (add-to-list 'load-path
(expand-file-name \"subed\" default-directory)) \
+ (byte-compile-file
\"subed/subed-ass.el\"))"
emacs --quick --batch --eval "(progn (add-to-list 'load-path
(expand-file-name \"subed\" default-directory)) \
(byte-compile-file
\"subed/subed-debug.el\"))"
make clean
diff --git a/subed/subed-ass.el b/subed/subed-ass.el
index faae396a11..3b5e46040d 100644
--- a/subed/subed-ass.el
+++ b/subed/subed-ass.el
@@ -47,11 +47,12 @@
(defconst subed-ass--regexp-start
"\\(?:Dialogue\\|Comment\\|Picture\\|Sound\\|Movie\\|Command\\): [0-9]+,")
(defconst subed-ass--regexp-separator "\n")
-(defun subed-ass--timestamp-to-msecs (time-string)
+(cl-defmethod subed--timestamp-to-msecs (time-string &context (major-mode
subed-ass-mode))
"Find HH:MM:SS.MS pattern in TIME-STRING and convert it to milliseconds.
-Return nil if TIME-STRING doesn't match the pattern."
+Return nil if TIME-STRING doesn't match the pattern.
+Use the format-specific function for MAJOR-MODE."
(save-match-data
- (when (string-match subed-ass--regexp-timestamp time-string)
+ (when (string-match subed--regexp-timestamp time-string)
(let ((hours (string-to-number (or (match-string 2 time-string) "0")))
(mins (string-to-number (match-string 3 time-string)))
(secs (string-to-number (match-string 4 time-string)))
@@ -61,29 +62,23 @@ Return nil if TIME-STRING doesn't match the pattern."
(* (truncate secs) 1000)
(truncate msecs))))))
-(defun subed-ass--msecs-to-timestamp (msecs)
+(cl-defmethod subed--msecs-to-timestamp (msecs &context (major-mode
subed-ass-mode))
"Convert MSECS to string in the format H:MM:SS.CS."
;; We need to wrap format-seconds in save-match-data because it does regexp
;; stuff and we need to preserve our own match-data.
(concat (save-match-data (format-seconds "%h:%02m:%02s" (/ msecs 1000)))
"." (format "%02d" (/ (mod msecs 1000) 10))))
-(defun subed-ass--subtitle-id ()
- "Return the ID of the subtitle at point or nil if there is no ID."
+(cl-defmethod subed--subtitle-id (&context (major-mode subed-ass-mode))
(save-excursion
- (when (subed-ass--jump-to-subtitle-id)
- (when (looking-at subed-ass--regexp-timestamp)
- (match-string 0)))))
+ (when (and (subed--jump-to-subtitle-time-start)
+ (looking-at subed--regexp-timestamp))
+ (match-string 0))))
-(defun subed-ass--subtitle-id-max ()
- "Return the ID of the last subtitle or nil if there are no subtitles."
- (save-excursion
- (goto-char (point-max))
- (subed-ass--subtitle-id)))
-
-(defun subed-ass--subtitle-id-at-msecs (msecs)
+(cl-defmethod subed--subtitle-id-at-msecs (msecs &context (major-mode
subed-ass-mode))
"Return the ID of the subtitle at MSECS milliseconds.
-Return nil if there is no subtitle at MSECS."
+Return nil if there is no subtitle at MSECS.
+Use the format-specific function for BACKEND."
(save-match-data
(save-excursion
(goto-char (point-min))
@@ -91,76 +86,38 @@ Return nil if there is no subtitle at MSECS."
(only-hours (truncate (/ secs 3600)))
(only-mins (truncate (/ (- secs (* only-hours 3600)) 60))))
;; Move to first subtitle in the relevant hour
- (when (re-search-forward (format "\\(%s\\|\\`\\)%02d:"
subed-ass--regexp-separator only-hours) nil t)
+ (when (re-search-forward (format "\\(%s\\|\\`\\)%02d:"
subed--regexp-separator only-hours) nil t)
(beginning-of-line)
;; Move to first subtitle in the relevant hour and minute
(re-search-forward (format "\\(\n\n\\|\\`\\)%02d:%02d" only-hours
only-mins) nil t)))
;; Move to first subtitle that starts at or after MSECS
(catch 'subtitle-id
- (while (<= (or (subed-ass--subtitle-msecs-start) -1) msecs)
+ (while (<= (or (subed-subtitle-msecs-start) -1) msecs)
;; If stop time is >= MSECS, we found a match
- (let ((cur-sub-end (subed-ass--subtitle-msecs-stop)))
+ (let ((cur-sub-end (subed-subtitle-msecs-stop)))
(when (and cur-sub-end (>= cur-sub-end msecs))
- (throw 'subtitle-id (subed-ass--subtitle-id))))
- (unless (subed-ass--forward-subtitle-id)
+ (throw 'subtitle-id (subed-subtitle-id))))
+ (unless (subed--forward-subtitle-id)
(throw 'subtitle-id nil)))))))
-(defun subed-ass--subtitle-msecs-start (&optional sub-id)
- "Subtitle start time in milliseconds or nil if it can't be found.
-If SUB-ID is not given, use subtitle on point."
- (let ((timestamp (save-excursion
- (when (subed-ass--jump-to-subtitle-time-start sub-id)
- (when (looking-at subed-ass--regexp-timestamp)
- (match-string 0))))))
- (when timestamp
- (subed-ass--timestamp-to-msecs timestamp))))
-
-(defun subed-ass--subtitle-msecs-stop (&optional sub-id)
- "Subtitle stop time in milliseconds or nil if it can't be found.
-If SUB-ID is not given, use subtitle on point."
- (let ((timestamp (save-excursion
- (when (subed-ass--jump-to-subtitle-time-stop sub-id)
- (when (looking-at subed-ass--regexp-timestamp)
- (match-string 0))))))
- (when timestamp
- (subed-ass--timestamp-to-msecs timestamp))))
-
-(defun subed-ass--subtitle-text (&optional sub-id)
- "Return subtitle's text or an empty string.
-If SUB-ID is not given, use subtitle on point."
- (or (save-excursion
- (let ((beg (subed-ass--jump-to-subtitle-text sub-id))
- (end (subed-ass--jump-to-subtitle-end sub-id)))
- (when (and beg end)
- (buffer-substring beg end))))
- ""))
-
-(defun subed-ass--subtitle-relative-point ()
- "Point relative to subtitle's ID or nil if ID can't be found."
- (let ((start-point (save-excursion
- (when (subed-ass--jump-to-subtitle-id)
- (point)))))
- (when start-point
- (- (point) start-point))))
-
;;; Traversing
-(defun subed-ass--jump-to-subtitle-id (&optional sub-id)
+(cl-defmethod subed--jump-to-subtitle-id (&context (major-mode subed-ass-mode)
&optional sub-id)
"Move to the ID of a subtitle and return point.
If SUB-ID is not given, focus the current subtitle's ID.
Return point or nil if no subtitle ID could be found.
-ASS doesn't use IDs, so we use the starting timestamp instead."
- (interactive)
+ASS doesn't use IDs, so we use the starting timestamp instead.
+Use the format-specific function for MAJOR-MODE."
(save-match-data
(if (stringp sub-id)
(let* ((orig-point (point))
- (find-ms (subed-ass--timestamp-to-msecs sub-id))
- (regex (concat "^\\(?:" subed-ass--regexp-start "\\)\\("
subed-ass--regexp-timestamp "\\)"))
+ (find-ms (subed--timestamp-to-msecs sub-id))
+ (regex (concat "^\\(?:" subed-ass--regexp-start "\\)\\("
subed--regexp-timestamp "\\)"))
done)
(goto-char (point-min))
(while (not done)
(if (re-search-forward regex nil t)
- (when (= (subed-ass--timestamp-to-msecs (match-string 1))
find-ms)
+ (when (= (subed-timestamp-to-msecs (match-string 1)) find-ms)
(setq done 'found)
(goto-char (match-beginning 1)))
(setq done 'not-found)
@@ -169,78 +126,57 @@ ASS doesn't use IDs, so we use the starting timestamp
instead."
(beginning-of-line)
(point)))
(end-of-line)
- (let* ((regex (concat "^\\(?:" subed-ass--regexp-start "\\)\\("
subed-ass--regexp-timestamp "\\)"))
+ (let* ((regex (concat "^\\(?:" subed-ass--regexp-start "\\)\\("
subed--regexp-timestamp "\\)"))
(match-found (re-search-backward regex nil t)))
- (when (or match-found (re-search-forward regex nil t)) ;;
maybe at the beginning?
+ (when (or match-found (re-search-forward regex nil t)) ;; maybe at the
beginning?
(goto-char (match-beginning 0))
(point))))))
-(defun subed-ass--jump-to-subtitle-id-at-msecs (msecs)
- "Move point to the ID of the subtitle that is playing at MSECS.
-Return point or nil if point is still on the same subtitle.
-See also `subed-ass--subtitle-id-at-msecs'."
- (let ((current-sub-id (subed-ass--subtitle-id))
- (target-sub-id (subed-ass--subtitle-id-at-msecs msecs)))
- (when (and target-sub-id current-sub-id (not (equal target-sub-id
current-sub-id)))
- (subed-ass--jump-to-subtitle-id target-sub-id))))
-
-(defun subed-ass--jump-to-subtitle-text-at-msecs (msecs)
- "Move point to the text of the subtitle that is playing at MSECS.
-Return point or nil if point is still on the same subtitle.
-See also `subed-ass--subtitle-id-at-msecs'."
- (when (subed-ass--jump-to-subtitle-id-at-msecs msecs)
- (subed-ass--jump-to-subtitle-text)))
-
-(defun subed-ass--jump-to-subtitle-time-start (&optional sub-id)
+(cl-defmethod subed--jump-to-subtitle-time-start (&context (major-mode
subed-ass-mode) &optional sub-id)
"Move point to subtitle's start time.
If SUB-ID is not given, use subtitle on point.
Return point or nil if no start time could be found."
- (interactive)
(save-match-data
- (when (subed-ass--jump-to-subtitle-id sub-id)
- (when (re-search-forward subed-ass--regexp-timestamp (line-end-position)
t)
+ (when (subed-jump-to-subtitle-id sub-id)
+ (when (re-search-forward subed--regexp-timestamp (line-end-position) t)
(goto-char (match-beginning 0))
(point)))))
-(defun subed-ass--jump-to-subtitle-time-stop (&optional sub-id)
+(cl-defmethod subed--jump-to-subtitle-time-stop (&context (major-mode
subed-ass-mode) &optional sub-id)
"Move point to subtitle's stop time.
If SUB-ID is not given, use subtitle on point.
Return point or nil if no stop time could be found."
- (interactive)
(save-match-data
- (when (subed-ass--jump-to-subtitle-id sub-id)
- (re-search-forward (concat "\\(?:" subed-ass--regexp-timestamp "\\),")
(point-at-eol) t)
- (when (looking-at subed-ass--regexp-timestamp)
+ (when (subed-jump-to-subtitle-id sub-id)
+ (re-search-forward (concat "\\(?:" subed--regexp-timestamp "\\),")
(point-at-eol) t)
+ (when (looking-at subed--regexp-timestamp)
(point)))))
-(defun subed-ass--jump-to-subtitle-text (&optional sub-id)
+(cl-defmethod subed--jump-to-subtitle-text (&context (major-mode
subed-ass-mode) &optional sub-id)
"Move point on the first character of subtitle's text.
If SUB-ID is not given, use subtitle on point.
Return point or nil if a the subtitle's text can't be found."
- (interactive)
- (when (subed-ass--jump-to-subtitle-id sub-id)
+ (when (subed-jump-to-subtitle-id sub-id)
(beginning-of-line)
(when (looking-at ".*?,.*?,.*?,.*?,.*?,.*?,.*?,.*?,.*?,")
(goto-char (match-end 0)))
(point)))
-(defun subed-ass--jump-to-subtitle-end (&optional sub-id)
+(cl-defmethod subed--jump-to-subtitle-end (&context (major-mode
subed-ass-mode) &optional sub-id)
"Move point after the last character of the subtitle's text.
If SUB-ID is not given, use subtitle on point.
Return point or nil if point did not change or if no subtitle end
can be found."
- (interactive)
(save-match-data
(let ((orig-point (point)))
- (when (subed-ass--jump-to-subtitle-text sub-id)
+ (when (subed-jump-to-subtitle-text sub-id)
(end-of-line)
(unless (= orig-point (point))
(point))))))
-(defun subed-ass--forward-subtitle-id ()
+(cl-defmethod subed--forward-subtitle-id (&context (major-mode subed-ass-mode))
"Move point to next subtitle's ID.
Return point or nil if there is no next subtitle."
- (interactive)
(save-match-data
(let ((pos (point)))
(forward-line 1)
@@ -252,12 +188,11 @@ Return point or nil if there is no next subtitle."
(goto-char pos)
nil))))
-(defun subed-ass--backward-subtitle-id ()
+(cl-defmethod subed--backward-subtitle-id (&context (major-mode
subed-ass-mode))
"Move point to previous subtitle's ID.
Return point or nil if there is no previous subtitle."
- (interactive)
(let ((orig-point (point)))
- (when (subed-ass--jump-to-subtitle-id)
+ (when (subed-jump-to-subtitle-id)
(forward-line -1)
(while (not (or (bobp) (looking-at subed-ass--regexp-start)))
(forward-line -1))
@@ -266,87 +201,9 @@ Return point or nil if there is no previous subtitle."
(goto-char orig-point)
nil))))
-(defun subed-ass--forward-subtitle-text ()
- "Move point to next subtitle's text.
-Return point or nil if there is no next subtitle."
- (interactive)
- (when (subed-ass--forward-subtitle-id)
- (subed-ass--jump-to-subtitle-text)))
-
-(defun subed-ass--backward-subtitle-text ()
- "Move point to previous subtitle's text.
-Return point or nil if there is no previous subtitle."
- (interactive)
- (when (subed-ass--backward-subtitle-id)
- (subed-ass--jump-to-subtitle-text)))
-
-(defun subed-ass--forward-subtitle-end ()
- "Move point to end of next subtitle.
-Return point or nil if there is no next subtitle."
- (interactive)
- (when (subed-ass--forward-subtitle-id)
- (subed-ass--jump-to-subtitle-end)))
-
-(defun subed-ass--backward-subtitle-end ()
- "Move point to end of previous subtitle.
-Return point or nil if there is no previous subtitle."
- (interactive)
- (when (subed-ass--backward-subtitle-id)
- (subed-ass--jump-to-subtitle-end)))
-
-(defun subed-ass--forward-subtitle-time-start ()
- "Move point to next subtitle's start time."
- (interactive)
- (when (subed-ass--forward-subtitle-id)
- (subed-ass--jump-to-subtitle-time-start)))
-
-(defun subed-ass--backward-subtitle-time-start ()
- "Move point to previous subtitle's start time."
- (interactive)
- (when (subed-ass--backward-subtitle-id)
- (subed-ass--jump-to-subtitle-time-start)))
-
-(defun subed-ass--forward-subtitle-time-stop ()
- "Move point to next subtitle's stop time."
- (interactive)
- (when (subed-ass--forward-subtitle-id)
- (subed-ass--jump-to-subtitle-time-stop)))
-
-(defun subed-ass--backward-subtitle-time-stop ()
- "Move point to previous subtitle's stop time."
- (interactive)
- (when (subed-ass--backward-subtitle-id)
- (subed-ass--jump-to-subtitle-time-stop)))
-
;;; Manipulation
-(defun subed-ass--set-subtitle-time-start (msecs &optional sub-id)
- "Set subtitle start time to MSECS milliseconds.
-
-If SUB-ID is not given, set the start of the current subtitle.
-
-Return the new subtitle start time in milliseconds."
- (save-excursion
- (when (or (not sub-id)
- (and sub-id (subed-ass--jump-to-subtitle-id sub-id)))
- (subed-ass--jump-to-subtitle-time-start)
- (when (looking-at subed-ass--regexp-timestamp)
- (replace-match (subed-ass--msecs-to-timestamp msecs))))))
-
-(defun subed-ass--set-subtitle-time-stop (msecs &optional sub-id)
- "Set subtitle stop time to MSECS milliseconds.
-
-If SUB-ID is not given, set the stop of the current subtitle.
-
-Return the new subtitle stop time in milliseconds."
- (save-excursion
- (when (or (not sub-id)
- (and sub-id (subed-ass--jump-to-subtitle-id sub-id)))
- (subed-ass--jump-to-subtitle-time-stop)
- (when (looking-at subed-ass--regexp-timestamp)
- (replace-match (subed-ass--msecs-to-timestamp msecs))))))
-
-(defun subed-ass--make-subtitle (&optional id start stop text)
+(cl-defmethod subed--make-subtitle (&context (major-mode subed-ass-mode)
&optional id start stop text)
"Generate new subtitle string.
ID, START default to 0.
@@ -355,14 +212,13 @@ TEXT defaults to an empty string.
A newline is appended to TEXT, meaning you'll get two trailing
newlines if TEXT is nil or empty."
- (interactive "P")
(format "Dialogue: 0,%s,%s,Default,,0,0,0,,%s\n"
- (subed-ass--msecs-to-timestamp (or start 0))
- (subed-ass--msecs-to-timestamp (or stop (+ (or start 0)
+ (subed-msecs-to-timestamp (or start 0))
+ (subed-msecs-to-timestamp (or stop (+ (or start 0)
subed-default-subtitle-length)))
(replace-regexp-in-string "\n" "\\n" (or text ""))))
-(defun subed-ass--prepend-subtitle (&optional id start stop text)
+(cl-defmethod subed--prepend-subtitle (&context (major-mode subed-ass-mode)
&optional id start stop text)
"Insert new subtitle before the subtitle at point.
ID and START default to 0.
@@ -371,13 +227,12 @@ TEXT defaults to an empty string.
Move point to the text of the inserted subtitle.
Return new point."
- (interactive "P")
- (subed-ass--jump-to-subtitle-id)
- (insert (subed-ass--make-subtitle id start stop text))
+ (subed-jump-to-subtitle-id)
+ (insert (subed-make-subtitle id start stop text))
(forward-line -1)
- (subed-ass--jump-to-subtitle-text))
+ (subed-jump-to-subtitle-text))
-(defun subed-ass--append-subtitle (&optional id start stop text)
+(cl-defmethod subed--append-subtitle (&context (major-mode subed-ass-mode)
&optional id start stop text)
"Insert new subtitle after the subtitle at point.
ID, START default to 0.
@@ -386,82 +241,38 @@ TEXT defaults to an empty string.
Move point to the text of the inserted subtitle.
Return new point."
- (interactive "P")
- (unless (subed-ass--forward-subtitle-id)
+ (unless (subed-forward-subtitle-id)
;; Point is on last subtitle or buffer is empty
- (subed-ass--jump-to-subtitle-end)
+ (subed-jump-to-subtitle-end)
(unless (bolp) (insert "\n")))
- (insert (subed-ass--make-subtitle id start stop text))
+ (insert (subed-make-subtitle id start stop text))
(forward-line -1)
- (subed-ass--jump-to-subtitle-text))
-
-(defun subed-ass--kill-subtitle ()
- "Remove subtitle at point."
- (interactive)
- (let ((beg (save-excursion (subed-ass--jump-to-subtitle-id)
- (point)))
- (end (save-excursion (subed-ass--jump-to-subtitle-id)
- (when (subed-ass--forward-subtitle-id)
- (point)))))
- (if (not end)
- ;; Removing the last subtitle because forward-subtitle-id returned nil
- (setq beg (save-excursion (goto-char beg)
- (subed-ass--backward-subtitle-end)
- (1+ (point)))
- end (save-excursion (goto-char (point-max)))))
- (delete-region beg end)))
-
-(defun subed-ass--merge-with-next ()
+ (subed-jump-to-subtitle-text))
+
+(cl-defmethod subed--merge-with-next (&context (major-mode subed-ass-mode))
"Merge the current subtitle with the next subtitle.
Update the end timestamp accordingly."
- (interactive)
(save-excursion
- (subed-ass--jump-to-subtitle-end)
+ (subed-jump-to-subtitle-end)
(let ((pos (point)) new-end)
- (if (subed-ass--forward-subtitle-time-stop)
+ (if (subed-forward-subtitle-time-stop)
(progn
- (when (looking-at subed-ass--regexp-timestamp)
- (setq new-end (subed-ass--timestamp-to-msecs (match-string 0))))
- (subed-ass--jump-to-subtitle-text)
+ (when (looking-at subed--regexp-timestamp)
+ (setq new-end (subed-timestamp-to-msecs (match-string 0))))
+ (subed-jump-to-subtitle-text)
(delete-region pos (point))
(insert " ")
- (subed-ass--set-subtitle-time-stop new-end))
+ (subed-set-subtitle-time-stop new-end))
(error "No subtitle to merge into")))))
-;;; Maintenance
-
-(defun subed-ass--regenerate-ids ()
- "Not applicable to ASS."
- (interactive))
-
-(defvar-local subed-ass--regenerate-ids-soon-timer nil)
-(defun subed-ass--regenerate-ids-soon ()
- "Not applicable to ASS."
- (interactive))
-
-(defun subed-ass--sanitize ()
- "Not yet implemented."
- (interactive))
-
-(defun subed-ass--validate ()
- "Not yet implemented."
- (interactive))
-
-(defun subed-ass--sort ()
- "Not yet implemented."
- (interactive))
-
-(defun subed-ass--init ()
- "This function is called when subed-mode is entered for a ASS file."
- (setq-local subed--subtitle-format "ass")
- (setq-local font-lock-defaults '(subed-ass-font-lock-keywords)))
-
;;;###autoload
(define-derived-mode subed-ass-mode subed-mode "Subed-ASS"
"Major mode for editing Advanced SubStation Alpha subtitle files."
- (subed--init "ass")
- (subed-ass--init))
+ (setq-local subed--subtitle-format "ass")
+ (setq-local subed--regexp-timestamp subed-ass--regexp-timestamp)
+ (setq-local subed--regexp-separator subed-ass--regexp-separator)
+ (setq-local font-lock-defaults '(subed-ass-font-lock-keywords)))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.ass\\'" . subed-ass-mode))
diff --git a/subed/subed-common.el b/subed/subed-common.el
index f6d1891342..af3e8337b6 100644
--- a/subed/subed-common.el
+++ b/subed/subed-common.el
@@ -33,14 +33,295 @@
(require 'subed-mpv)
-;;; Utilities
+;;; Generic functions
+
+
+(defvar-local subed--regexp-separator nil "Regexp separating subtitles.")
+(defvar-local subed--regexp-timestamp nil "Regexp matching timestamps.")
+
+(defmacro subed-define-generic-function (name args doc &rest body)
+ "Declare an object method and provide the old way of calling it."
+ (declare (indent 2))
+ `(progn
+ (cl-defgeneric ,(intern (concat "subed--" (symbol-name name)))
+ ,args
+ ,doc
+ ,@(if (eq (caar body) 'interactive)
+ (cdr body)
+ body))
+ (defun ,(intern (concat "subed-" (symbol-name name))) ,args
+ ,doc
+ ,(if (eq (caar body) 'interactive)
+ (car body))
+ (,(intern (concat "subed--" (symbol-name name)))
+ ,@(delq nil (mapcar (lambda (a)
+ (unless (string-match "^&" (symbol-name a))
+ a))
+ args))))))
+
+(subed-define-generic-function timestamp-to-msecs (time-string)
+ "Find timestamp pattern in TIME-STRING and convert it to milliseconds.
+Return nil if TIME-STRING doesn't match the pattern.")
+
+(subed-define-generic-function msecs-to-timestamp (msecs)
+ "Convert MSECS to string in the subtitle's timestamp format.")
+
+(subed-define-generic-function subtitle-id ()
+ "Return the ID of the subtitle at point or nil if there is no ID.")
+
+(subed-define-generic-function subtitle-id-max ()
+ "Return the ID of the last subtitle or nil if there are no subtitles."
+ (save-excursion
+ (goto-char (point-max))
+ (subed-subtitle-id)))
+
+(subed-define-generic-function subtitle-id-at-msecs (msecs)
+ "Return the ID of the subtitle at MSECS milliseconds.
+Return nil if there is no subtitle at MSECS.")
+
+(subed-define-generic-function jump-to-subtitle-id (&optional sub-id)
+ "Move to the ID of a subtitle and return point.
+If SUB-ID is not given, focus the current subtitle's ID.
+Return point or nil if no subtitle ID could be found."
+ (interactive))
+
+(subed-define-generic-function jump-to-subtitle-time-start (&optional sub-id)
+ "Move point to subtitle's start time.
+If SUB-ID is not given, use subtitle on point.
+Return point or nil if no start time could be found."
+ (interactive))
+
+(subed-define-generic-function jump-to-subtitle-time-stop (&optional sub-id)
+ "Move point to subtitle's stop time.
+If SUB-ID is not given, use subtitle on point.
+Return point or nil if no stop time could be found."
+ (interactive))
+
+(subed-define-generic-function jump-to-subtitle-text (&optional sub-id)
+ "Move point on the first character of subtitle's text.
+If SUB-ID is not given, use subtitle on point.
+Return point or nil if a the subtitle's text can't be found."
+ (interactive))
+
+(subed-define-generic-function jump-to-subtitle-end (&optional sub-id)
+ "Move point after the last character of the subtitle's text.
+If SUB-ID is not given, use subtitle on point.
+Return point or nil if point did not change or if no subtitle end
+can be found."
+ (interactive))
+
+(subed-define-generic-function jump-to-subtitle-id-at-msecs (msecs)
+ "Move point to the ID of the subtitle that is playing at MSECS.
+Return point or nil if point is still on the same subtitle.
+See also `subed-subtitle-id-at-msecs'."
+ (let ((current-sub-id (subed-subtitle-id))
+ (target-sub-id (subed-subtitle-id-at-msecs msecs)))
+ (when (and target-sub-id current-sub-id (not (= target-sub-id
current-sub-id)))
+ (subed-jump-to-subtitle-id target-sub-id))))
+
+(subed-define-generic-function jump-to-subtitle-id-at-msecs (msecs)
+ "Move point to the ID of the subtitle that is playing at MSECS.
+Return point or nil if point is still on the same subtitle.
+See also `subed-subtitle-id-at-msecs'."
+ (let ((current-sub-id (subed-subtitle-id))
+ (target-sub-id (subed-subtitle-id-at-msecs msecs)))
+ (when (and target-sub-id current-sub-id (not (equal target-sub-id
current-sub-id)))
+ (subed-jump-to-subtitle-id target-sub-id))))
+
+(subed-define-generic-function forward-subtitle-id ()
+ "Move point to next subtitle's ID.
+Return point or nil if there is no next subtitle."
+ (interactive))
+
+(subed-define-generic-function backward-subtitle-id ()
+ "Move point to previous subtitle's ID.
+Return point or nil if there is no previous subtitle."
+ (interactive))
+
+(subed-define-generic-function forward-subtitle-text ()
+ "Move point to next subtitle's text.
+Return point or nil if there is no next subtitle."
+ (interactive)
+ (when (subed-forward-subtitle-id)
+ (subed-jump-to-subtitle-text)))
+
+(subed-define-generic-function backward-subtitle-text ()
+ "Move point to previous subtitle's text.
+Return point or nil if there is no previous subtitle."
+ (interactive)
+ (when (subed-backward-subtitle-id)
+ (subed-jump-to-subtitle-text)))
+
+(subed-define-generic-function forward-subtitle-end ()
+ "Move point to end of next subtitle.
+Return point or nil if there is no next subtitle."
+ (interactive)
+ (when (subed-forward-subtitle-id)
+ (subed-jump-to-subtitle-end)))
-(defun subed-msecs-to-timestamp (msecs)
- "Convert MSECS to human-readable string."
- ;; We need to wrap format-seconds in save-match-data because it does regexp
- ;; stuff and we need to preserve our own match-data.
- (concat (save-match-data (format-seconds "%02h:%02m:%02s" (/ msecs 1000)))
- "," (format "%03d" (mod msecs 1000))))
+(subed-define-generic-function backward-subtitle-end ()
+ "Move point to end of previous subtitle.
+Return point or nil if there is no previous subtitle."
+ (interactive)
+ (when (subed-backward-subtitle-id)
+ (subed-jump-to-subtitle-end)))
+
+(subed-define-generic-function forward-subtitle-time-start ()
+ "Move point to next subtitle's start time."
+ (interactive)
+ (when (subed-forward-subtitle-id)
+ (subed-jump-to-subtitle-time-start)))
+
+(subed-define-generic-function backward-subtitle-time-start ()
+ "Move point to previous subtitle's start time."
+ (interactive)
+ (when (subed-backward-subtitle-id)
+ (subed-jump-to-subtitle-time-start)))
+
+(subed-define-generic-function forward-subtitle-time-stop ()
+ "Move point to next subtitle's stop time."
+ (interactive)
+ (when (subed-forward-subtitle-id)
+ (subed-jump-to-subtitle-time-stop)))
+
+(subed-define-generic-function backward-subtitle-time-stop ()
+ "Move point to previous subtitle's stop time."
+ (interactive)
+ (when (subed-backward-subtitle-id)
+ (subed-jump-to-subtitle-time-stop)))
+
+(subed-define-generic-function subtitle-msecs-start (&optional sub-id)
+ "Subtitle start time in milliseconds or nil if it can't be found.
+If SUB-ID is not given, use subtitle on point."
+ (let ((timestamp (save-excursion
+ (when (subed-jump-to-subtitle-time-start sub-id)
+ (when (looking-at subed--regexp-timestamp)
+ (match-string 0))))))
+ (when timestamp
+ (subed-timestamp-to-msecs timestamp))))
+
+(subed-define-generic-function subtitle-msecs-stop (&optional sub-id)
+ "Subtitle stop time in milliseconds or nil if it can't be found.
+If SUB-ID is not given, use subtitle on point."
+ (let ((timestamp (save-excursion
+ (when (subed-jump-to-subtitle-time-stop sub-id)
+ (when (looking-at subed--regexp-timestamp)
+ (match-string 0))))))
+ (when timestamp
+ (subed-timestamp-to-msecs timestamp))))
+
+(subed-define-generic-function subtitle-text (&optional sub-id)
+ "Return subtitle's text or an empty string.
+If SUB-ID is not given, use subtitle on point."
+ (or (save-excursion
+ (let ((beg (subed-jump-to-subtitle-text sub-id))
+ (end (subed-jump-to-subtitle-end sub-id)))
+ (when (and beg end)
+ (buffer-substring beg end)))) ""))
+
+(subed-define-generic-function subtitle-relative-point ()
+ "Point relative to subtitle's ID or nil if ID can't be found."
+ (let ((start-point (save-excursion
+ (when (subed-jump-to-subtitle-id)
+ (point)))))
+ (when start-point
+ (- (point) start-point))))
+
+(subed-define-generic-function set-subtitle-time-start (msecs &optional sub-id)
+ "Set subtitle start time to MSECS milliseconds.
+
+If SUB-ID is not given, set the start of the current subtitle.
+
+Return the new subtitle start time in milliseconds."
+ (save-excursion
+ (when (or (not sub-id)
+ (and sub-id (subed-jump-to-subtitle-id sub-id)))
+ (when (and (subed-jump-to-subtitle-time-start sub-id)
+ (looking-at subed--regexp-timestamp))
+ (replace-match (subed-msecs-to-timestamp msecs))))))
+
+(subed-define-generic-function set-subtitle-time-stop (msecs &optional sub-id)
+ "Set subtitle stop time to MSECS milliseconds.
+
+If SUB-ID is not given, set the stop of the current subtitle.
+
+Return the new subtitle stop time in milliseconds."
+ (save-excursion
+ (when (and (subed-jump-to-subtitle-time-stop sub-id)
+ (looking-at subed--regexp-timestamp))
+ (replace-match (subed-msecs-to-timestamp msecs)))))
+
+(subed-define-generic-function make-subtitle (&optional id start stop text)
+ "Generate new subtitle string.
+
+ID, START default to 0.
+STOP defaults to (+ START `subed-subtitle-spacing')
+TEXT defaults to an empty string."
+ (interactive "P"))
+
+(subed-define-generic-function prepend-subtitle (&optional id start stop text)
+ "Insert new subtitle before the subtitle at point.
+
+ID and START default to 0.
+STOP defaults to (+ START `subed-subtitle-spacing')
+TEXT defaults to an empty string.
+
+Move point to the text of the inserted subtitle.
+Return new point."
+ (interactive "P"))
+
+(subed-define-generic-function append-subtitle (&optional id start stop text)
+ "Insert new subtitle after the subtitle at point.
+
+ID, START default to 0.
+STOP defaults to (+ START `subed-subtitle-spacing')
+TEXT defaults to an empty string.
+
+Move point to the text of the inserted subtitle.
+Return new point."
+ (interactive "P"))
+
+(subed-define-generic-function kill-subtitle ()
+ "Remove subtitle at point."
+ (interactive)
+ (let ((beg (save-excursion (subed-jump-to-subtitle-id)
+ (point)))
+ (end (save-excursion (subed-jump-to-subtitle-id)
+ (when (subed-forward-subtitle-id)
+ (point)))))
+ (if (not end)
+ ;; Removing the last subtitle because forward-subtitle-id returned nil
+ (setq beg (save-excursion (goto-char beg)
+ (subed-backward-subtitle-end)
+ (1+ (point)))
+ end (save-excursion (goto-char (point-max)))))
+ (delete-region beg end)))
+
+(subed-define-generic-function sanitize ()
+ "Remove surplus newlines and whitespace.")
+
+(subed-define-generic-function validate ()
+ "Move point to the first invalid subtitle and report an error.")
+
+(subed-define-generic-function sort ()
+ "Sanitize, then sort subtitles by start time and re-number them."
+ (interactive)
+ (atomic-change-group
+ (subed-sanitize)
+ (subed-validate)
+ (subed-save-excursion
+ (goto-char (point-min))
+ (sort-subr nil
+ ;; nextrecfun (move to next record/subtitle or to end-of-buffer
+ ;; if there are no more records)
+ (lambda () (unless (subed-forward-subtitle-id)
+ (goto-char (point-max))))
+ ;; endrecfun (move to end of current record/subtitle)
+ #'subed-jump-to-subtitle-end
+ ;; startkeyfun (return sort value of current record/subtitle)
+ #'subed-subtitle-msecs-start))))
+
+;;; Utilities
(defmacro subed-save-excursion (&rest body)
"Restore relative point within current subtitle after executing BODY.
@@ -663,7 +944,7 @@ Return a list of values in the following order:
msecs-min msecs-max msecs-avail msecs-per-sub msecs-between
insert-subtitle-func)))
-(defun subed-insert-subtitle (&optional arg)
+(subed-define-generic-function insert-subtitle (&optional arg)
"Insert subtitle(s) evenly spaced.
The inserted subtitles are `subed-default-subtitle-length'
@@ -717,11 +998,10 @@ following manner:
(funcall insert-subtitle-func nil msecs-start msecs-stop nil)))
(unless insert-before-current
(dotimes (_ (1- number-of-subs))
- (subed-backward-subtitle-text))))
- (subed-regenerate-ids-soon))
+ (subed-backward-subtitle-text)))))
(point))
-(defun subed-insert-subtitle-adjacent (&optional arg)
+(subed-define-generic-function insert-subtitle-adjacent (&optional arg)
"Insert subtitle(s) close to each other.
The inserted subtitles are `subed-default-subtitle-length'
@@ -768,11 +1048,10 @@ following manner:
(funcall insert-subtitle-func nil msecs-start msecs-stop nil)))
(unless insert-before-current
(dotimes (_ (1- number-of-subs))
- (subed-backward-subtitle-text))))
- (subed-regenerate-ids-soon))
+ (subed-backward-subtitle-text)))))
(point))
-(defun subed-split-subtitle (&optional offset)
+(subed-define-generic-function split-subtitle (&optional offset)
"Split current subtitle at point.
The subtitle text after point is moved to a new subtitle that is
@@ -830,7 +1109,6 @@ position of the point."
(delete-region (point) (progn (subed-jump-to-subtitle-end)
(skip-chars-forward " \t") (point)))
(when (looking-at "[ \t]+") (replace-match ""))
(subed-append-subtitle nil new-start-timestamp orig-end (string-trim
new-text)))
- (subed-regenerate-ids-soon)
(point)))
;;; Merging
@@ -1421,12 +1699,12 @@ the stop time isn't smaller than the start time."
;;; Sorting and sanitizing
(defvar-local subed-sanitize-functions
- '(subed-trim-overlap-maybe-sanitize)
+ '(subed-sort subed-trim-overlap-maybe-sanitize)
"Functions to sanitize this buffer.
Functions can clean up whitespace, rearrange subtitles, etc.")
(defvar-local subed-validate-functions
- '(subed-trim-overlap-maybe-check)
+ '(subed-validate subed-trim-overlap-maybe-check)
"Functions to validate this buffer.
Validation functions should throw an error or prompt the user for
action.")
@@ -1438,19 +1716,27 @@ action.")
(run-hooks 'subed-sanitize-functions)
(run-hooks 'subed-validate-functions)))
-(defun subed-sort ()
+(subed-define-generic-function sort ()
"Sort subtitles."
- (subed-save-excursion
- (goto-char (point-min))
- (sort-subr nil
- ;; nextrecfun (move to next record/subtitle or to end-of-buffer
- ;; if there are no more records)
- (lambda () (unless (subed-forward-subtitle-id)
- (goto-char (point-max))))
- ;; endrecfun (move to end of current record/subtitle)
- #'subed-jump-to-subtitle-end
- ;; startkeyfun (return sort value of current record/subtitle)
- #'subed-subtitle-msecs-start)))
+ (atomic-change-group
+ (subed-sanitize)
+ (subed-validate)
+ (subed-save-excursion
+ (goto-char (point-min))
+ (unless (subed-subtitle-id)
+ (subed-forward-subtitle-id))
+ (sort-subr nil
+ ;; nextrecfun (move to next record/subtitle or to end-of-buffer
+ ;; if there are no more records)
+ (lambda () (unless (subed-forward-subtitle-id)
+ (goto-char (point-max))))
+ ;; endrecfun (move to end of current record/subtitle)
+ #'subed-jump-to-subtitle-end
+ ;; startkeyfun (return sort value of current record/subtitle)
+ #'subed-subtitle-msecs-start))))
+
+;;; Initialization
+
(provide 'subed-common)
;;; subed-common.el ends here
diff --git a/subed/subed-srt.el b/subed/subed-srt.el
index 9c27a10216..ad231ce8f9 100644
--- a/subed/subed-srt.el
+++ b/subed/subed-srt.el
@@ -47,11 +47,12 @@
(defconst subed-srt--regexp-timestamp
"\\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\),\\([0-9]+\\)")
(defconst subed-srt--regexp-separator "\\(?:[[:blank:]]*\n\\)+[[:blank:]]*\n")
-(defun subed-srt--timestamp-to-msecs (time-string)
+(cl-defmethod subed--timestamp-to-msecs (time-string &context (major-mode
subed-srt-mode))
"Find HH:MM:SS,MS pattern in TIME-STRING and convert it to milliseconds.
-Return nil if TIME-STRING doesn't match the pattern."
+Return nil if TIME-STRING doesn't match the pattern.
+Use the format-specific function for MAJOR-MODE."
(save-match-data
- (when (string-match subed-srt--regexp-timestamp time-string)
+ (when (string-match subed--regexp-timestamp time-string)
(let ((hours (string-to-number (match-string 1 time-string)))
(mins (string-to-number (match-string 2 time-string)))
(secs (string-to-number (match-string 3 time-string)))
@@ -61,28 +62,25 @@ Return nil if TIME-STRING doesn't match the pattern."
(* (truncate secs) 1000)
(truncate msecs))))))
-(defun subed-srt--msecs-to-timestamp (msecs)
- "Convert MSECS to string in the format HH:MM:SS,MS."
+(cl-defmethod subed--msecs-to-timestamp (msecs &context (major-mode
subed-srt-mode))
+ "Convert MSECS to string in the format HH:MM:SS,MS.
+Use the format-specific function for MAJOR-MODE."
;; We need to wrap format-seconds in save-match-data because it does regexp
;; stuff and we need to preserve our own match-data.
(concat (save-match-data (format-seconds "%02h:%02m:%02s" (/ msecs 1000)))
"," (format "%03d" (mod msecs 1000))))
-(defun subed-srt--subtitle-id ()
- "Return the ID of the subtitle at point or nil if there is no ID."
+(cl-defmethod subed--subtitle-id (&context (major-mode subed-srt-mode))
+ "Return the ID of the subtitle at point or nil if there is no ID.
+Use the format-specific function for MAJOR-MODE."
(save-excursion
- (when (subed-srt--jump-to-subtitle-id)
+ (when (subed-jump-to-subtitle-id)
(string-to-number (current-word)))))
-(defun subed-srt--subtitle-id-max ()
- "Return the ID of the last subtitle or nil if there are no subtitles."
- (save-excursion
- (goto-char (point-max))
- (subed-srt--subtitle-id)))
-
-(defun subed-srt--subtitle-id-at-msecs (msecs)
+(cl-defmethod subed--subtitle-id-at-msecs (msecs &context (major-mode
subed-srt-mode))
"Return the ID of the subtitle at MSECS milliseconds.
-Return nil if there is no subtitle at MSECS."
+Return nil if there is no subtitle at MSECS.
+Use the format-specific function for MAJOR-MODE."
(save-match-data
(save-excursion
(goto-char (point-min))
@@ -90,71 +88,33 @@ Return nil if there is no subtitle at MSECS."
(only-hours (truncate (/ secs 3600)))
(only-mins (truncate (/ (- secs (* only-hours 3600)) 60))))
;; Move to first subtitle in the relevant hour
- (when (re-search-forward (format "\\(%s\\|\\`\\)[0-9]+\n%02d:"
subed-srt--regexp-separator only-hours) nil t)
+ (when (re-search-forward (format "\\(%s\\|\\`\\)[0-9]+\n%02d:"
subed--regexp-separator only-hours) nil t)
(beginning-of-line)
;; Move to first subtitle in the relevant hour and minute
(re-search-forward (format "\\(\n\n\\|\\`\\)[0-9]+\n%02d:%02d"
only-hours only-mins) nil t)))
;; Move to first subtitle that starts at or after MSECS
(catch 'subtitle-id
- (while (<= (or (subed-srt--subtitle-msecs-start) -1) msecs)
+ (while (<= (or (subed-subtitle-msecs-start) -1) msecs)
;; If stop time is >= MSECS, we found a match
- (let ((cur-sub-end (subed-srt--subtitle-msecs-stop)))
+ (let ((cur-sub-end (subed-subtitle-msecs-stop)))
(when (and cur-sub-end (>= cur-sub-end msecs))
- (throw 'subtitle-id (subed-srt--subtitle-id))))
- (unless (subed-srt--forward-subtitle-id)
+ (throw 'subtitle-id (subed-subtitle-id))))
+ (unless (subed-forward-subtitle-id)
(throw 'subtitle-id nil)))))))
-(defun subed-srt--subtitle-msecs-start (&optional sub-id)
- "Subtitle start time in milliseconds or nil if it can't be found.
-If SUB-ID is not given, use subtitle on point."
- (let ((timestamp (save-excursion
- (when (subed-srt--jump-to-subtitle-time-start sub-id)
- (when (looking-at subed-srt--regexp-timestamp)
- (match-string 0))))))
- (when timestamp
- (subed-srt--timestamp-to-msecs timestamp))))
-
-(defun subed-srt--subtitle-msecs-stop (&optional sub-id)
- "Subtitle stop time in milliseconds or nil if it can't be found.
-If SUB-ID is not given, use subtitle on point."
- (let ((timestamp (save-excursion
- (when (subed-srt--jump-to-subtitle-time-stop sub-id)
- (when (looking-at subed-srt--regexp-timestamp)
- (match-string 0))))))
- (when timestamp
- (subed-srt--timestamp-to-msecs timestamp))))
-
-(defun subed-srt--subtitle-text (&optional sub-id)
- "Return subtitle's text or an empty string.
-If SUB-ID is not given, use subtitle on point."
- (or (save-excursion
- (let ((beg (subed-srt--jump-to-subtitle-text sub-id))
- (end (subed-srt--jump-to-subtitle-end sub-id)))
- (when (and beg end)
- (buffer-substring beg end)))) ""))
-
-(defun subed-srt--subtitle-relative-point ()
- "Point relative to subtitle's ID or nil if ID can't be found."
- (let ((start-point (save-excursion
- (when (subed-srt--jump-to-subtitle-id)
- (point)))))
- (when start-point
- (- (point) start-point))))
-
-
;;; Traversing
-(defun subed-srt--jump-to-subtitle-id (&optional sub-id)
+(cl-defmethod subed--jump-to-subtitle-id (&context (major-mode subed-srt-mode)
&optional sub-id)
"Move to the ID of a subtitle and return point.
If SUB-ID is not given, focus the current subtitle's ID.
-Return point or nil if no subtitle ID could be found."
- (interactive)
+Return point or nil if no subtitle ID could be found.
+Use the format-specific function for MAJOR-MODE."
(save-match-data
(if sub-id
;; Look for a line that contains only the ID, preceded by one or more
;; blank lines or the beginning of the buffer.
(let* ((orig-point (point))
- (regex (format "\\(%s\\|\\`\\)\\(%d\\)$"
subed-srt--regexp-separator sub-id))
+ (regex (format "\\(%s\\|\\`\\)\\(%d\\)$"
subed--regexp-separator sub-id))
(match-found (progn (goto-char (point-min))
(re-search-forward regex nil t))))
(if match-found
@@ -164,7 +124,7 @@ Return point or nil if no subtitle ID could be found."
(re-search-forward "\\([[:blank:]]*\n\\)+" nil t)
;; Find two or more blank lines or the beginning of the buffer, followed
;; by line composed of only digits.
- (let* ((regex (concat "\\(" subed-srt--regexp-separator
"\\|\\`\\)\\([0-9]+\\)$"))
+ (let* ((regex (concat "\\(" subed--regexp-separator
"\\|\\`\\)\\([0-9]+\\)$"))
(match-found (re-search-backward regex nil t)))
(when match-found
(goto-char (match-beginning 2)))))
@@ -172,63 +132,46 @@ Return point or nil if no subtitle ID could be found."
(when (looking-at "^\\([0-9]+\\)$")
(point))))
-(defun subed-srt--jump-to-subtitle-id-at-msecs (msecs)
- "Move point to the ID of the subtitle that is playing at MSECS.
-Return point or nil if point is still on the same subtitle.
-See also `subed-srt--subtitle-id-at-msecs'."
- (let ((current-sub-id (subed-srt--subtitle-id))
- (target-sub-id (subed-srt--subtitle-id-at-msecs msecs)))
- (when (and target-sub-id current-sub-id (not (= target-sub-id
current-sub-id)))
- (subed-srt--jump-to-subtitle-id target-sub-id))))
-
-(defun subed-srt--jump-to-subtitle-text-at-msecs (msecs)
- "Move point to the text of the subtitle that is playing at MSECS.
-Return point or nil if point is still on the same subtitle.
-See also `subed-srt--subtitle-id-at-msecs'."
- (when (subed-srt--jump-to-subtitle-id-at-msecs msecs)
- (subed-srt--jump-to-subtitle-text)))
-
-(defun subed-srt--jump-to-subtitle-time-start (&optional sub-id)
+(cl-defmethod subed--jump-to-subtitle-time-start (&context (major-mode
subed-srt-mode) &optional sub-id)
"Move point to subtitle's start time.
If SUB-ID is not given, use subtitle on point.
-Return point or nil if no start time could be found."
- (interactive)
+Return point or nil if no start time could be found.
+Use the format-specific function for MAJOR-MODE."
(save-match-data
- (when (subed-srt--jump-to-subtitle-id sub-id)
+ (when (subed-jump-to-subtitle-id sub-id)
(forward-line)
- (when (looking-at subed-srt--regexp-timestamp)
+ (when (looking-at subed--regexp-timestamp)
(point)))))
-(defun subed-srt--jump-to-subtitle-time-stop (&optional sub-id)
+(cl-defmethod subed--jump-to-subtitle-time-stop (&context (major-mode
subed-srt-mode) &optional sub-id)
"Move point to subtitle's stop time.
If SUB-ID is not given, use subtitle on point.
-Return point or nil if no stop time could be found."
- (interactive)
+Return point or nil if no stop time could be found.
+Use the format-specific function for MAJOR-MODE."
(save-match-data
- (when (subed-srt--jump-to-subtitle-id sub-id)
+ (when (subed-jump-to-subtitle-id sub-id)
(forward-line 1)
(re-search-forward " *--> *" (point-at-eol) t)
- (when (looking-at subed-srt--regexp-timestamp)
+ (when (looking-at subed--regexp-timestamp)
(point)))))
-(defun subed-srt--jump-to-subtitle-text (&optional sub-id)
+(cl-defmethod subed--jump-to-subtitle-text (&context (major-mode
subed-srt-mode) &optional sub-id)
"Move point on the first character of subtitle's text.
If SUB-ID is not given, use subtitle on point.
-Return point or nil if a the subtitle's text can't be found."
- (interactive)
- (when (subed-srt--jump-to-subtitle-id sub-id)
+Return point or nil if a the subtitle's text can't be found.
+Use the format-specific function for MAJOR-MODE."
+ (when (subed-jump-to-subtitle-id sub-id)
(forward-line 2)
(point)))
-(defun subed-srt--jump-to-subtitle-end (&optional sub-id)
+(cl-defmethod subed--jump-to-subtitle-end (&context (major-mode
subed-srt-mode) &optional sub-id)
"Move point after the last character of the subtitle's text.
If SUB-ID is not given, use subtitle on point.
Return point or nil if point did not change or if no subtitle end
-can be found."
- (interactive)
+can be found. Use the format-specific function for MAJOR-MODE."
(save-match-data
(let ((orig-point (point)))
- (subed-srt--jump-to-subtitle-text sub-id)
+ (subed-jump-to-subtitle-text sub-id)
;; Look for next separator or end of buffer. We can't use
;; `subed-srt--regexp-separator' here because if subtitle text is empty,
;; it may be the only empty line in the separator, i.e. there's only one
@@ -239,109 +182,30 @@ can be found."
(unless (= (point) orig-point)
(point)))))
-(defun subed-srt--forward-subtitle-id ()
+(cl-defmethod subed--forward-subtitle-id (&context (major-mode subed-srt-mode))
"Move point to next subtitle's ID.
-Return point or nil if there is no next subtitle."
- (interactive)
+Return point or nil if there is no next subtitle.
+Use the format-specific function for MAJOR-MODE."
(save-match-data
- (when (re-search-forward (concat subed-srt--regexp-separator "[0-9]+\n")
nil t)
- (subed-srt--jump-to-subtitle-id))))
+ (when (re-search-forward (concat subed--regexp-separator "[0-9]+\n") nil t)
+ (subed-jump-to-subtitle-id))))
-(defun subed-srt--backward-subtitle-id ()
+(cl-defmethod subed--backward-subtitle-id (&context (major-mode
subed-srt-mode))
"Move point to previous subtitle's ID.
-Return point or nil if there is no previous subtitle."
- (interactive)
+Return point or nil if there is no previous subtitle.
+Use the format-specific function for MAJOR-MODE."
(let ((orig-point (point)))
- (when (subed-srt--jump-to-subtitle-id)
- (if (re-search-backward (concat "\\(" subed-srt--regexp-separator
"\\|\\`[[:space:]]*\\)" "\\([0-9]+\\)\n") nil t)
+ (when (subed-jump-to-subtitle-id)
+ (if (re-search-backward (concat "\\(" subed--regexp-separator
"\\|\\`[[:space:]]*\\)" "\\([0-9]+\\)\n") nil t)
(progn
(goto-char (match-beginning 2))
(point))
(goto-char orig-point)
nil))))
-(defun subed-srt--forward-subtitle-text ()
- "Move point to next subtitle's text.
-Return point or nil if there is no next subtitle."
- (interactive)
- (when (subed-srt--forward-subtitle-id)
- (subed-srt--jump-to-subtitle-text)))
-
-(defun subed-srt--backward-subtitle-text ()
- "Move point to previous subtitle's text.
-Return point or nil if there is no previous subtitle."
- (interactive)
- (when (subed-srt--backward-subtitle-id)
- (subed-srt--jump-to-subtitle-text)))
-
-(defun subed-srt--forward-subtitle-end ()
- "Move point to end of next subtitle.
-Return point or nil if there is no next subtitle."
- (interactive)
- (when (subed-srt--forward-subtitle-id)
- (subed-srt--jump-to-subtitle-end)))
-
-(defun subed-srt--backward-subtitle-end ()
- "Move point to end of previous subtitle.
-Return point or nil if there is no previous subtitle."
- (interactive)
- (when (subed-srt--backward-subtitle-id)
- (subed-srt--jump-to-subtitle-end)))
-
-(defun subed-srt--forward-subtitle-time-start ()
- "Move point to next subtitle's start time."
- (interactive)
- (when (subed-srt--forward-subtitle-id)
- (subed-srt--jump-to-subtitle-time-start)))
-
-(defun subed-srt--backward-subtitle-time-start ()
- "Move point to previous subtitle's start time."
- (interactive)
- (when (subed-srt--backward-subtitle-id)
- (subed-srt--jump-to-subtitle-time-start)))
-
-(defun subed-srt--forward-subtitle-time-stop ()
- "Move point to next subtitle's stop time."
- (interactive)
- (when (subed-srt--forward-subtitle-id)
- (subed-srt--jump-to-subtitle-time-stop)))
-
-(defun subed-srt--backward-subtitle-time-stop ()
- "Move point to previous subtitle's stop time."
- (interactive)
- (when (subed-srt--backward-subtitle-id)
- (subed-srt--jump-to-subtitle-time-stop)))
-
-
;;; Manipulation
-(defun subed-srt--set-subtitle-time-start (msecs &optional sub-id)
- "Set subtitle start time to MSECS milliseconds.
-
-If SUB-ID is not given, set the start of the current subtitle.
-
-Return the new subtitle start time in milliseconds."
- (save-excursion
- (when (or (not sub-id)
- (and sub-id (subed-srt--jump-to-subtitle-id sub-id)))
- (subed-srt--jump-to-subtitle-time-start)
- (when (looking-at subed-srt--regexp-timestamp)
- (replace-match (subed-srt--msecs-to-timestamp msecs))))))
-
-(defun subed-srt--set-subtitle-time-stop (msecs &optional sub-id)
- "Set subtitle stop time to MSECS milliseconds.
-
-If SUB-ID is not given, set the stop of the current subtitle.
-
-Return the new subtitle stop time in milliseconds."
- (save-excursion
- (when (or (not sub-id)
- (and sub-id (subed-srt--jump-to-subtitle-id sub-id)))
- (subed-srt--jump-to-subtitle-time-stop)
- (when (looking-at subed-srt--regexp-timestamp)
- (replace-match (subed-srt--msecs-to-timestamp msecs))))))
-
-(defun subed-srt--make-subtitle (&optional id start stop text)
+(cl-defmethod subed--make-subtitle (&context (major-mode subed-srt-mode)
&optional id start stop text)
"Generate new subtitle string.
ID, START default to 0.
@@ -349,16 +213,16 @@ STOP defaults to (+ START `subed-subtitle-spacing')
TEXT defaults to an empty string.
A newline is appended to TEXT, meaning you'll get two trailing
-newlines if TEXT is nil or empty."
- (interactive "P")
+newlines if TEXT is nil or empty. Use the format-specific
+function for MAJOR-MODE."
(format "%s\n%s --> %s\n%s\n"
(or id 0)
- (subed-srt--msecs-to-timestamp (or start 0))
- (subed-srt--msecs-to-timestamp (or stop (+ (or start 0)
-
subed-default-subtitle-length)))
+ (subed-msecs-to-timestamp (or start 0))
+ (subed-msecs-to-timestamp (or stop (+ (or start 0)
+
subed-default-subtitle-length)))
(or text "")))
-(defun subed-srt--prepend-subtitle (&optional id start stop text)
+(cl-defmethod subed--prepend-subtitle (&context (major-mode subed-srt-mode)
&optional id start stop text)
"Insert new subtitle before the subtitle at point.
ID and START default to 0.
@@ -366,17 +230,16 @@ STOP defaults to (+ START `subed-subtitle-spacing')
TEXT defaults to an empty string.
Move point to the text of the inserted subtitle.
-Return new point."
- (interactive "P")
- (subed-srt--jump-to-subtitle-id)
- (insert (subed-srt--make-subtitle id start stop text))
+Return new point. Use the format-specific function for MAJOR-MODE."
+ (subed-jump-to-subtitle-id)
+ (insert (subed-make-subtitle id start stop text))
(save-match-data
(when (looking-at "\\([[:space:]]*\\|^\\)[0-9]+$")
(insert "\n")))
(forward-line -2)
- (subed-srt--jump-to-subtitle-text))
+ (subed-jump-to-subtitle-text))
-(defun subed-srt--append-subtitle (&optional id start stop text)
+(cl-defmethod subed--append-subtitle (&context (major-mode subed-srt-mode)
&optional id start stop text)
"Insert new subtitle after the subtitle at point.
ID, START default to 0.
@@ -384,56 +247,48 @@ STOP defaults to (+ START `subed-subtitle-spacing')
TEXT defaults to an empty string.
Move point to the text of the inserted subtitle.
-Return new point."
- (interactive "P")
- (unless (subed-srt--forward-subtitle-id)
+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-srt--jump-to-subtitle-end)
+ (subed-jump-to-subtitle-end)
;; 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-srt--make-subtitle id start stop text))
+ (insert (subed-make-subtitle id start stop text))
;; Complete separator with another newline unless we inserted at the end
(save-match-data
(when (looking-at "\\([[:space:]]*\\|^\\)[0-9]+$")
(insert ?\n)))
(forward-line -2)
- (subed-srt--jump-to-subtitle-text))
+ (subed-jump-to-subtitle-text))
-(defun subed-srt--kill-subtitle ()
- "Remove subtitle at point."
- (interactive)
- (let ((beg (save-excursion (subed-srt--jump-to-subtitle-id)
- (point)))
- (end (save-excursion (subed-srt--jump-to-subtitle-id)
- (when (subed-srt--forward-subtitle-id)
- (point)))))
- (if (not end)
- ;; Removing the last subtitle because forward-subtitle-id returned nil
- (setq beg (save-excursion (goto-char beg)
- (subed-srt--backward-subtitle-end)
- (1+ (point)))
- end (save-excursion (goto-char (point-max)))))
- (delete-region beg end))
+(cl-defmethod subed--kill-subtitle :after (&context (major-mode
subed-srt-mode))
+ "Remove subtitle at point.
+Use the format-specific function for MAJOR-MODE."
(subed-srt--regenerate-ids-soon))
-(defun subed-srt--merge-with-next ()
+(cl-defmethod subed--split-subtitle :after (&context (major-mode
subed-srt-mode) &optional offset)
+ "Split current subtitle at point.
+Use the format-specific function for MAJOR-MODE."
+ (subed-srt--regenerate-ids-soon))
+
+(cl-defmethod subed--merge-with-next (&context (major-mode subed-srt-mode))
"Merge the current subtitle with the next subtitle.
-Update the end timestamp accordingly."
- (interactive)
+Update the end timestamp accordingly.
+Use the format-specific function for MAJOR-MODE."
(save-excursion
- (subed-srt--jump-to-subtitle-end)
+ (subed-jump-to-subtitle-end)
(let ((pos (point)) new-end)
- (if (subed-srt--forward-subtitle-time-stop)
+ (if (subed-forward-subtitle-time-stop)
(progn
- (when (looking-at subed-srt--regexp-timestamp)
- (setq new-end (subed-srt--timestamp-to-msecs (match-string 0))))
- (subed-srt--jump-to-subtitle-text)
+ (when (looking-at subed--regexp-timestamp)
+ (setq new-end (subed-timestamp-to-msecs (match-string 0))))
+ (subed-jump-to-subtitle-text)
(delete-region pos (point))
(insert "\n")
- (subed-srt--set-subtitle-time-stop new-end)
+ (subed-set-subtitle-time-stop new-end)
(subed-srt--regenerate-ids-soon))
(error "No subtitle to merge into")))))
@@ -446,13 +301,13 @@ Update the end timestamp accordingly."
(save-match-data
(save-excursion
(goto-char (point-min))
- (subed-srt--jump-to-subtitle-id)
+ (subed-jump-to-subtitle-id)
(when (looking-at "^[[:digit:]]+$")
(unless (string= (current-word) "1")
(delete-region (point) (progn (forward-word 1) (point)))
(insert "1")))
(let ((id 2))
- (while (subed-srt--forward-subtitle-id)
+ (while (subed-forward-subtitle-id)
(let ((id-str (number-to-string id)))
(unless (string= (current-word) id-str)
(delete-region (point) (progn (forward-word 1) (point)))
@@ -475,9 +330,9 @@ scheduled call is canceled and another call is scheduled in
(setq subed-srt--regenerate-ids-soon-timer nil)
(subed-srt--regenerate-ids)))))
-(defun subed-srt--sanitize ()
- "Remove surplus newlines and whitespace."
- (interactive)
+(cl-defmethod subed--sanitize (&context (major-mode subed-srt-mode))
+ "Remove surplus newlines and whitespace.
+Use the format-specific function for MAJOR-MODE."
(atomic-change-group
(save-match-data
(subed-save-excursion
@@ -496,8 +351,8 @@ scheduled call is canceled and another call is scheduled in
;; Replace separators between subtitles with double newlines
(goto-char (point-min))
- (while (subed-srt--forward-subtitle-id)
- (let ((prev-sub-end (save-excursion (when
(subed-srt--backward-subtitle-end)
+ (while (subed-forward-subtitle-id)
+ (let ((prev-sub-end (save-excursion (when
(subed-backward-subtitle-end)
(point)))))
(when (and prev-sub-end
(not (string= (buffer-substring prev-sub-end (point))
"\n\n")))
@@ -510,27 +365,28 @@ scheduled call is canceled and another call is scheduled
in
(goto-char (point-min))
(when (re-search-forward "[[:graph:]]" nil t)
(goto-char (point-max))
- (subed-srt--jump-to-subtitle-end)
+ (subed-jump-to-subtitle-end)
(unless (looking-at "\n\\'")
(delete-region (point) (point-max))
(insert "\n")))
;; One space before and after " --> "
(goto-char (point-min))
- (while (re-search-forward (format "^%s" subed-srt--regexp-timestamp)
nil t)
+ (while (re-search-forward (format "^%s" subed--regexp-timestamp) nil t)
(when (looking-at "[[:blank:]]*-->[[:blank:]]*")
(unless (= (length (match-string 0)) 5)
(replace-match " --> "))))))))
-(defun subed-srt--validate ()
- "Move point to the first invalid subtitle and report an error."
- (interactive)
+(cl-defmethod subed--validate (&context (major-mode subed-srt-mode))
+ "Move point to the first invalid subtitle and report an error.
+Use the format-specific function for MAJOR-MODE."
(when (> (buffer-size) 0)
(atomic-change-group
(save-match-data
(let ((orig-point (point)))
(goto-char (point-min))
- (while (and (re-search-forward (format "\\(%s\\|\\`\\)"
subed-srt--regexp-separator) nil t)
+ (while (and (re-search-forward (format "\\(%s\\|\\`\\)"
subed--regexp-separator)
+ nil t)
(looking-at "[[:alnum:]]"))
(unless (looking-at "^[0-9]+$")
(error "Found invalid subtitle ID: %S" (substring (or
(thing-at-point 'line :no-properties) "\n") 0 -1)))
@@ -550,33 +406,31 @@ scheduled call is canceled and another call is scheduled
in
(error "Found invalid stop time: %S" (substring (or
(thing-at-point 'line :no-properties) "\n") 0 -1))))
(goto-char orig-point))))))
-(defun subed-srt--sort ()
- "Sanitize, then sort subtitles by start time and re-number them."
- (interactive)
- (atomic-change-group
- (subed-srt--sanitize)
- (subed-srt--validate)
- (subed-save-excursion
- (goto-char (point-min))
- (sort-subr nil
- ;; nextrecfun (move to next record/subtitle or to end-of-buffer
- ;; if there are no more records)
- (lambda () (unless (subed-srt--forward-subtitle-id)
- (goto-char (point-max))))
- ;; endrecfun (move to end of current record/subtitle)
- #'subed-srt--jump-to-subtitle-end
- ;; startkeyfun (return sort value of current record/subtitle)
- #'subed-srt--subtitle-msecs-start))
- (subed-srt--regenerate-ids)))
-
-(defun subed-srt--init ()
- "This function is called when subed-mode is entered for a SRT file."
+(cl-defmethod subed--sort :after (&context (major-mode subed-srt-mode))
+ "Renumber after sorting. Format-specific for MAJOR-MODE."
+ (subed-srt--regenerate-ids))
+
+(cl-defmethod subed--insert-subtitle :after (&context (major-mode
subed-srt-mode) &optional arg)
+ "Renumber afterwards. Format-specific for MAJOR-MODE."
+ (subed-srt--regenerate-ids-soon)
+ (point))
+
+(cl-defmethod subed--insert-subtitle-adjacent :after (&context (major-mode
subed-srt-mode) &optional arg)
+ "Renumber afterwards. Format-specific for MAJOR-MODE."
+ (subed-srt--regenerate-ids-soon)
+ (point))
+
+;;;###autoload
+(define-derived-mode subed-srt-mode subed-mode "Subed-SRT"
+ "Major mode for editing SubRip subtitle files."
(setq-local subed--subtitle-format "srt")
+ (setq-local subed--regexp-timestamp subed-srt--regexp-timestamp)
+ (setq-local subed--regexp-separator subed-srt--regexp-separator)
(setq-local font-lock-defaults '(subed-srt-font-lock-keywords))
;; Support for fill-paragraph (M-q)
- (let ((timestamps-regexp (concat subed-srt--regexp-timestamp
+ (let ((timestamps-regexp (concat subed--regexp-timestamp
" *--> *"
- subed-srt--regexp-timestamp)))
+ subed--regexp-timestamp)))
(setq-local paragraph-separate (concat "^\\("
(mapconcat 'identity
`("[[:blank:]]*"
"[[:digit:]]+"
@@ -589,15 +443,7 @@ scheduled call is canceled and another call is scheduled in
(mapconcat 'identity '("^-"
"[[:graph:]]*$") "\\|")
"\\)")))
- (add-hook 'subed-sanitize-functions #'subed-srt--sort nil t)
- (add-hook 'subed-sanitize-functions #'subed-srt--regenerate-ids t t)
- (add-hook 'subed-validate-functions #'subed-srt--validate t t))
-
-;;;###autoload
-(define-derived-mode subed-srt-mode subed-mode "Subed-SRT"
- "Major mode for editing SubRip subtitle files."
- (subed--init "srt")
- (subed-srt--init))
+ (add-hook 'subed-sanitize-functions #'subed-srt--regenerate-ids t t))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.srt\\'" . subed-srt-mode))
diff --git a/subed/subed-vtt.el b/subed/subed-vtt.el
index 9da409be48..15cf027b3b 100644
--- a/subed/subed-vtt.el
+++ b/subed/subed-vtt.el
@@ -46,11 +46,11 @@
(defconst subed-vtt--regexp-timestamp
"\\(\\([0-9]+\\):\\)?\\([0-9]+\\):\\([0-9]+\\)\\.\\([0-9]+\\)")
(defconst subed-vtt--regexp-separator "\\(?:[[:blank:]]*\n\\)+\\(?:NOTE[
\n]\\(?:.+?\n\\)+\n\\)*\n")
-(defun subed-vtt--timestamp-to-msecs (time-string)
+(cl-defmethod subed--timestamp-to-msecs (time-string &context (major-mode
subed-vtt-mode))
"Find HH:MM:SS.MS pattern in TIME-STRING and convert it to milliseconds.
Return nil if TIME-STRING doesn't match the pattern."
(save-match-data
- (when (string-match subed-vtt--regexp-timestamp time-string)
+ (when (string-match subed--regexp-timestamp time-string)
(let ((hours (string-to-number (or (match-string 2 time-string) "0")))
(mins (string-to-number (match-string 3 time-string)))
(secs (string-to-number (match-string 4 time-string)))
@@ -60,29 +60,25 @@ Return nil if TIME-STRING doesn't match the pattern."
(* (truncate secs) 1000)
(truncate msecs))))))
-(defun subed-vtt--msecs-to-timestamp (msecs)
- "Convert MSECS to string in the format HH:MM:SS,MS."
+(cl-defmethod subed--msecs-to-timestamp (msecs &context (major-mode
subed-vtt-mode))
+ "Convert MSECS to string in the format HH:MM:SS.MS."
;; We need to wrap format-seconds in save-match-data because it does regexp
;; stuff and we need to preserve our own match-data.
(concat (save-match-data (format-seconds "%02h:%02m:%02s" (/ msecs 1000)))
"." (format "%03d" (mod msecs 1000))))
-(defun subed-vtt--subtitle-id ()
- "Return the ID of the subtitle at point or nil if there is no ID."
+(cl-defmethod subed--subtitle-id (&context (major-mode subed-vtt-mode))
+ "Return the ID of the subtitle at point or nil if there is no ID.
+Use the format-specific function for MAJOR-MODE."
(save-excursion
- (when (subed-vtt--jump-to-subtitle-id)
- (when (looking-at subed-vtt--regexp-timestamp)
- (match-string 0)))))
+ (when (and (subed-jump-to-subtitle-time-start)
+ (looking-at subed--regexp-timestamp))
+ (match-string 0))))
-(defun subed-vtt--subtitle-id-max ()
- "Return the ID of the last subtitle or nil if there are no subtitles."
- (save-excursion
- (goto-char (point-max))
- (subed-vtt--subtitle-id)))
-
-(defun subed-vtt--subtitle-id-at-msecs (msecs)
+(cl-defmethod subed--subtitle-id-at-msecs (msecs &context (major-mode
subed-vtt-mode))
"Return the ID of the subtitle at MSECS milliseconds.
-Return nil if there is no subtitle at MSECS."
+Return nil if there is no subtitle at MSECS. Use the
+format-specific function for MAJOR-MODE."
(save-match-data
(save-excursion
(goto-char (point-min))
@@ -90,72 +86,34 @@ Return nil if there is no subtitle at MSECS."
(only-hours (truncate (/ secs 3600)))
(only-mins (truncate (/ (- secs (* only-hours 3600)) 60))))
;; Move to first subtitle in the relevant hour
- (when (re-search-forward (format "\\(%s\\|\\`\\)%02d:"
subed-vtt--regexp-separator only-hours) nil t)
+ (when (re-search-forward (format "\\(%s\\|\\`\\)%02d:"
subed--regexp-separator only-hours) nil t)
(beginning-of-line)
;; Move to first subtitle in the relevant hour and minute
(re-search-forward (format "\\(\n\n\\|\\`\\)%02d:%02d" only-hours
only-mins) nil t)))
;; Move to first subtitle that starts at or after MSECS
(catch 'subtitle-id
- (while (<= (or (subed-vtt--subtitle-msecs-start) -1) msecs)
+ (while (<= (or (subed-subtitle-msecs-start) -1) msecs)
;; If stop time is >= MSECS, we found a match
- (let ((cur-sub-end (subed-vtt--subtitle-msecs-stop)))
+ (let ((cur-sub-end (subed-subtitle-msecs-stop)))
(when (and cur-sub-end (>= cur-sub-end msecs))
- (throw 'subtitle-id (subed-vtt--subtitle-id))))
- (unless (subed-vtt--forward-subtitle-id)
+ (throw 'subtitle-id (subed-subtitle-id))))
+ (unless (subed-forward-subtitle-id)
(throw 'subtitle-id nil)))))))
-(defun subed-vtt--subtitle-msecs-start (&optional sub-id)
- "Subtitle start time in milliseconds or nil if it can't be found.
-If SUB-ID is not given, use subtitle on point."
- (let ((timestamp (save-excursion
- (when (subed-vtt--jump-to-subtitle-time-start sub-id)
- (when (looking-at subed-vtt--regexp-timestamp)
- (match-string 0))))))
- (when timestamp
- (subed-vtt--timestamp-to-msecs timestamp))))
-
-(defun subed-vtt--subtitle-msecs-stop (&optional sub-id)
- "Subtitle stop time in milliseconds or nil if it can't be found.
-If SUB-ID is not given, use subtitle on point."
- (let ((timestamp (save-excursion
- (when (subed-vtt--jump-to-subtitle-time-stop sub-id)
- (when (looking-at subed-vtt--regexp-timestamp)
- (match-string 0))))))
- (when timestamp
- (subed-vtt--timestamp-to-msecs timestamp))))
-
-(defun subed-vtt--subtitle-text (&optional sub-id)
- "Return subtitle's text or an empty string.
-If SUB-ID is not given, use subtitle on point."
- (or (save-excursion
- (let ((beg (subed-vtt--jump-to-subtitle-text sub-id))
- (end (subed-vtt--jump-to-subtitle-end sub-id)))
- (when (and beg end)
- (buffer-substring beg end))))
- ""))
-
-(defun subed-vtt--subtitle-relative-point ()
- "Point relative to subtitle's ID or nil if ID can't be found."
- (let ((start-point (save-excursion
- (when (subed-vtt--jump-to-subtitle-id)
- (point)))))
- (when start-point
- (- (point) start-point))))
-
;;; Traversing
-(defun subed-vtt--jump-to-subtitle-id (&optional sub-id)
+(cl-defmethod subed--jump-to-subtitle-id (&context (major-mode subed-vtt-mode)
&optional sub-id)
"Move to the ID of a subtitle and return point.
If SUB-ID is not given, focus the current subtitle's ID.
Return point or nil if no subtitle ID could be found.
-WebVTT doesn't use IDs, so we use the starting timestamp instead."
- (interactive)
+WebVTT doesn't use IDs, so we use the starting timestamp instead.
+Use the format-specific function for MAJOR-MODE."
(save-match-data
(if (stringp sub-id)
- ;; Look for a line that contains only the ID, preceded by one or more
+ ;; Look for a line that contains the timestamp, preceded by one or more
;; blank lines or the beginning of the buffer.
(let* ((orig-point (point))
- (regex (concat "\\(" subed-srt--regexp-separator "\\|\\`\\)\\("
(regexp-quote sub-id) "\\)"))
+ (regex (concat "\\(" subed--regexp-separator "\\|\\`\\)\\("
(regexp-quote sub-id) "\\)"))
(match-found (progn (goto-char (point-min))
(re-search-forward regex nil t))))
(if match-found
@@ -165,7 +123,7 @@ WebVTT doesn't use IDs, so we use the starting timestamp
instead."
(re-search-forward "\\([[:blank:]]*\n\\)+" nil t)
;; Find two or more blank lines or the beginning of the buffer, followed
;; by line starting with a timestamp.
- (let* ((regex (concat "\\(" subed-srt--regexp-separator "\\|\\`\\)\\("
subed-vtt--regexp-timestamp "\\)"))
+ (let* ((regex (concat "\\(" subed--regexp-separator "\\|\\`\\)\\("
subed--regexp-timestamp "\\)"))
(match-found (re-search-backward regex nil t)))
(when match-found
(goto-char (match-beginning 2)))))
@@ -173,176 +131,76 @@ WebVTT doesn't use IDs, so we use the starting timestamp
instead."
(when (looking-at "^\\(\\([0-9]+:\\)?[0-9]+:[0-9]+\\.[0-9]+\\)")
(point))))
-(defun subed-vtt--jump-to-subtitle-id-at-msecs (msecs)
- "Move point to the ID of the subtitle that is playing at MSECS.
-Return point or nil if point is still on the same subtitle.
-See also `subed-vtt--subtitle-id-at-msecs'."
- (let ((current-sub-id (subed-vtt--subtitle-id))
- (target-sub-id (subed-vtt--subtitle-id-at-msecs msecs)))
- (when (and target-sub-id current-sub-id (not (equal target-sub-id
current-sub-id)))
- (subed-vtt--jump-to-subtitle-id target-sub-id))))
-
-(defun subed-vtt--jump-to-subtitle-text-at-msecs (msecs)
- "Move point to the text of the subtitle that is playing at MSECS.
-Return point or nil if point is still on the same subtitle.
-See also `subed-vtt--subtitle-id-at-msecs'."
- (when (subed-vtt--jump-to-subtitle-id-at-msecs msecs)
- (subed-vtt--jump-to-subtitle-text)))
-
-(defun subed-vtt--jump-to-subtitle-time-start (&optional sub-id)
+(cl-defmethod subed--jump-to-subtitle-time-start (&context (major-mode
subed-vtt-mode) &optional sub-id)
"Move point to subtitle's start time.
If SUB-ID is not given, use subtitle on point.
-Return point or nil if no start time could be found."
- (interactive)
+Return point or nil if no start time could be found.
+Use the format-specific function for MAJOR-MODE."
(save-match-data
- (when (subed-vtt--jump-to-subtitle-id sub-id)
- (when (looking-at subed-vtt--regexp-timestamp)
+ (when (subed-jump-to-subtitle-id sub-id)
+ (when (looking-at subed--regexp-timestamp)
(point)))))
-(defun subed-vtt--jump-to-subtitle-time-stop (&optional sub-id)
+(cl-defmethod subed--jump-to-subtitle-time-stop (&context (major-mode
subed-vtt-mode) &optional sub-id)
"Move point to subtitle's stop time.
If SUB-ID is not given, use subtitle on point.
Return point or nil if no stop time could be found."
- (interactive)
(save-match-data
- (when (subed-vtt--jump-to-subtitle-id sub-id)
+ (when (subed-jump-to-subtitle-id sub-id)
(re-search-forward " *--> *" (point-at-eol) t)
- (when (looking-at subed-vtt--regexp-timestamp)
+ (when (looking-at subed--regexp-timestamp)
(point)))))
-(defun subed-vtt--jump-to-subtitle-text (&optional sub-id)
+(cl-defmethod subed--jump-to-subtitle-text (&context (major-mode
subed-vtt-mode) &optional sub-id)
"Move point on the first character of subtitle's text.
If SUB-ID is not given, use subtitle on point.
Return point or nil if a the subtitle's text can't be found."
- (interactive)
- (when (subed-vtt--jump-to-subtitle-id sub-id)
+ (when (subed-jump-to-subtitle-id sub-id)
(forward-line 1)
(point)))
-(defun subed-vtt--jump-to-subtitle-end (&optional sub-id)
+(cl-defmethod subed--jump-to-subtitle-end (&context (major-mode
subed-vtt-mode) &optional sub-id)
"Move point after the last character of the subtitle's text.
If SUB-ID is not given, use subtitle on point.
Return point or nil if point did not change or if no subtitle end
can be found."
- (interactive)
(save-match-data
(let ((orig-point (point)))
- (subed-vtt--jump-to-subtitle-text sub-id)
+ (subed-jump-to-subtitle-text sub-id)
;; Look for next separator or end of buffer. We can't use
;; `subed-vtt--regexp-separator' here because if subtitle text is empty,
;; it may be the only empty line in the separator, i.e. there's only one
;; "\n".
(let ((regex (concat "\\([[:blank:]]*\n\\)+"
"\\(?:NOTE[ \n]\\(?:.+?\n\\)+\n\\)*"
- "\\(" subed-vtt--regexp-timestamp
"\\)\\|\\([[:blank:]]*\n*\\)\\'")))
+ "\\(" subed--regexp-timestamp
"\\)\\|\\([[:blank:]]*\n*\\)\\'")))
(when (re-search-forward regex nil t)
(goto-char (match-beginning 0))))
(unless (= (point) orig-point)
(point)))))
-(defun subed-vtt--forward-subtitle-id ()
+(cl-defmethod subed--forward-subtitle-id (&context (major-mode subed-vtt-mode))
"Move point to next subtitle's ID.
Return point or nil if there is no next subtitle."
- (interactive)
(save-match-data
- (when (re-search-forward (concat subed-vtt--regexp-separator
subed-vtt--regexp-timestamp) nil t)
- (subed-vtt--jump-to-subtitle-id))))
+ (when (re-search-forward (concat subed--regexp-separator
subed--regexp-timestamp) nil t)
+ (subed-jump-to-subtitle-id))))
-(defun subed-vtt--backward-subtitle-id ()
+(cl-defmethod subed--backward-subtitle-id (&context (major-mode
subed-vtt-mode))
"Move point to previous subtitle's ID.
Return point or nil if there is no previous subtitle."
- (interactive)
(let ((orig-point (point)))
- (when (subed-vtt--jump-to-subtitle-id)
- (if (re-search-backward (concat "\\(" subed-vtt--regexp-separator
"\\|\\`[[:space:]]*\\)\\(" subed-vtt--regexp-timestamp "\\)") nil t)
+ (when (subed-jump-to-subtitle-id)
+ (if (re-search-backward (concat "\\(" subed--regexp-separator
"\\|\\`[[:space:]]*\\)\\(" subed--regexp-timestamp "\\)") nil t)
(progn
(goto-char (match-beginning 2))
(point))
(goto-char orig-point)
nil))))
-(defun subed-vtt--forward-subtitle-text ()
- "Move point to next subtitle's text.
-Return point or nil if there is no next subtitle."
- (interactive)
- (when (subed-vtt--forward-subtitle-id)
- (subed-vtt--jump-to-subtitle-text)))
-
-(defun subed-vtt--backward-subtitle-text ()
- "Move point to previous subtitle's text.
-Return point or nil if there is no previous subtitle."
- (interactive)
- (when (subed-vtt--backward-subtitle-id)
- (subed-vtt--jump-to-subtitle-text)))
-
-(defun subed-vtt--forward-subtitle-end ()
- "Move point to end of next subtitle.
-Return point or nil if there is no next subtitle."
- (interactive)
- (when (subed-vtt--forward-subtitle-id)
- (subed-vtt--jump-to-subtitle-end)))
-
-(defun subed-vtt--backward-subtitle-end ()
- "Move point to end of previous subtitle.
-Return point or nil if there is no previous subtitle."
- (interactive)
- (when (subed-vtt--backward-subtitle-id)
- (subed-vtt--jump-to-subtitle-end)))
-
-(defun subed-vtt--forward-subtitle-time-start ()
- "Move point to next subtitle's start time."
- (interactive)
- (when (subed-vtt--forward-subtitle-id)
- (subed-vtt--jump-to-subtitle-time-start)))
-
-(defun subed-vtt--backward-subtitle-time-start ()
- "Move point to previous subtitle's start time."
- (interactive)
- (when (subed-vtt--backward-subtitle-id)
- (subed-vtt--jump-to-subtitle-time-start)))
-
-(defun subed-vtt--forward-subtitle-time-stop ()
- "Move point to next subtitle's stop time."
- (interactive)
- (when (subed-vtt--forward-subtitle-id)
- (subed-vtt--jump-to-subtitle-time-stop)))
-
-(defun subed-vtt--backward-subtitle-time-stop ()
- "Move point to previous subtitle's stop time."
- (interactive)
- (when (subed-vtt--backward-subtitle-id)
- (subed-vtt--jump-to-subtitle-time-stop)))
-
-
;;; Manipulation
-(defun subed-vtt--set-subtitle-time-start (msecs &optional sub-id)
- "Set subtitle start time to MSECS milliseconds.
-
-If SUB-ID is not given, set the start of the current subtitle.
-
-Return the new subtitle start time in milliseconds."
- (save-excursion
- (when (or (not sub-id)
- (and sub-id (subed-vtt--jump-to-subtitle-id sub-id)))
- (subed-vtt--jump-to-subtitle-time-start)
- (when (looking-at subed-vtt--regexp-timestamp)
- (replace-match (subed-vtt--msecs-to-timestamp msecs))))))
-
-(defun subed-vtt--set-subtitle-time-stop (msecs &optional sub-id)
- "Set subtitle stop time to MSECS milliseconds.
-
-If SUB-ID is not given, set the stop of the current subtitle.
-
-Return the new subtitle stop time in milliseconds."
- (save-excursion
- (when (or (not sub-id)
- (and sub-id (subed-vtt--jump-to-subtitle-id sub-id)))
- (subed-vtt--jump-to-subtitle-time-stop)
- (when (looking-at subed-vtt--regexp-timestamp)
- (replace-match (subed-vtt--msecs-to-timestamp msecs))))))
-
-(defun subed-vtt--make-subtitle (&optional id start stop text)
+(cl-defmethod subed--make-subtitle (&context (major-mode subed-vtt-mode)
&optional id start stop text)
"Generate new subtitle string.
ID, START default to 0.
@@ -351,14 +209,13 @@ TEXT defaults to an empty string.
A newline is appended to TEXT, meaning you'll get two trailing
newlines if TEXT is nil or empty."
- (interactive "P")
(format "%s --> %s\n%s\n"
- (subed-vtt--msecs-to-timestamp (or start 0))
- (subed-vtt--msecs-to-timestamp (or stop (+ (or start 0)
-
subed-default-subtitle-length)))
+ (subed-msecs-to-timestamp (or start 0))
+ (subed-msecs-to-timestamp (or stop (+ (or start 0)
+
subed-default-subtitle-length)))
(or text "")))
-(defun subed-vtt--prepend-subtitle (&optional id start stop text)
+(cl-defmethod subed--prepend-subtitle (&context (major-mode subed-vtt-mode)
&optional id start stop text)
"Insert new subtitle before the subtitle at point.
ID and START default to 0.
@@ -367,89 +224,61 @@ TEXT defaults to an empty string.
Move point to the text of the inserted subtitle.
Return new point."
- (interactive "P")
- (subed-vtt--jump-to-subtitle-id)
- (insert (subed-vtt--make-subtitle id start stop text))
+ (subed-jump-to-subtitle-id)
+ (insert (subed-make-subtitle id start stop text))
(save-match-data
- (when (looking-at (concat "\\([[:space:]]*\\|^\\)"
subed-vtt--regexp-timestamp))
+ (when (looking-at (concat "\\([[:space:]]*\\|^\\)"
subed--regexp-timestamp))
(insert "\n")))
(forward-line -2)
- (subed-vtt--jump-to-subtitle-text))
+ (subed-jump-to-subtitle-text))
-(defun subed-vtt--append-subtitle (&optional id start stop text)
+(cl-defmethod subed--append-subtitle (&context (major-mode subed-vtt-mode)
&optional id start stop text)
"Insert new subtitle after the subtitle at point.
ID, START default to 0.
STOP defaults to (+ START `subed-subtitle-spacing')
TEXT defaults to an empty string.
-Move point to the text of the inserted subtitle.
-Return new point."
- (interactive "P")
- (unless (subed-vtt--forward-subtitle-id)
+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-vtt--jump-to-subtitle-end)
+ (subed-jump-to-subtitle-end)
;; 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-vtt--make-subtitle id start stop text))
+ (insert (subed-make-subtitle id start stop text))
;; Complete separator with another newline unless we inserted at the end
(save-match-data
- (when (looking-at (concat "\\([[:space:]]*\\|^\\)"
subed-vtt--regexp-timestamp))
+ (when (looking-at (concat "\\([[:space:]]*\\|^\\)"
subed--regexp-timestamp))
(insert ?\n)))
(forward-line -2)
- (subed-vtt--jump-to-subtitle-text))
-
-(defun subed-vtt--kill-subtitle ()
- "Remove subtitle at point."
- (interactive)
- (let ((beg (save-excursion (subed-vtt--jump-to-subtitle-id)
- (point)))
- (end (save-excursion (subed-vtt--jump-to-subtitle-id)
- (when (subed-vtt--forward-subtitle-id)
- (point)))))
- (if (not end)
- ;; Removing the last subtitle because forward-subtitle-id returned nil
- (setq beg (save-excursion (goto-char beg)
- (subed-vtt--backward-subtitle-end)
- (1+ (point)))
- end (save-excursion (goto-char (point-max)))))
- (delete-region beg end)))
-
-(defun subed-vtt--merge-with-next ()
+ (subed-jump-to-subtitle-text))
+
+(cl-defmethod subed--merge-with-next (&context (major-mode subed-vtt-mode))
"Merge the current subtitle with the next subtitle.
-Update the end timestamp accordingly."
- (interactive)
+Update the end timestamp accordingly.
+Use the format-specific function for MAJOR-MODE."
(save-excursion
- (subed-vtt--jump-to-subtitle-end)
+ (subed-jump-to-subtitle-end)
(let ((pos (point)) new-end)
- (if (subed-vtt--forward-subtitle-time-stop)
+ (if (subed-forward-subtitle-time-stop)
(progn
- (when (looking-at subed-vtt--regexp-timestamp)
- (setq new-end (subed-vtt--timestamp-to-msecs (match-string 0))))
- (subed-vtt--jump-to-subtitle-text)
+ (when (looking-at subed--regexp-timestamp)
+ (setq new-end (subed-timestamp-to-msecs (match-string 0))))
+ (subed-jump-to-subtitle-text)
(delete-region pos (point))
(insert "\n")
- (subed-vtt--set-subtitle-time-stop new-end))
+ (subed-set-subtitle-time-stop new-end))
(error "No subtitle to merge into")))))
-
;;; Maintenance
-(defun subed-vtt--regenerate-ids ()
- "Not applicable to WebVTT."
- (interactive))
-(defvar-local subed-vtt--regenerate-ids-soon-timer nil)
-(defun subed-vtt--regenerate-ids-soon ()
- "Not applicable to WebVTT."
- (interactive))
-
-(defun subed-vtt--sanitize ()
+(cl-defmethod subed--sanitize (&context (major-mode subed-vtt-mode))
"Remove surplus newlines and whitespace."
- (interactive)
(atomic-change-group
(save-match-data
(subed-save-excursion
@@ -468,8 +297,8 @@ Update the end timestamp accordingly."
;; Replace separators between subtitles with double newlines
(goto-char (point-min))
- (while (subed-vtt--forward-subtitle-id)
- (let ((prev-sub-end (save-excursion (when
(subed-vtt--backward-subtitle-end)
+ (while (subed-forward-subtitle-id)
+ (let ((prev-sub-end (save-excursion (when
(subed-backward-subtitle-end)
(point)))))
(when (and prev-sub-end
(not (string= (buffer-substring prev-sub-end (point))
"\n\n")))
@@ -482,29 +311,28 @@ Update the end timestamp accordingly."
(goto-char (point-min))
(when (re-search-forward "[[:graph:]]" nil t)
(goto-char (point-max))
- (subed-vtt--jump-to-subtitle-end)
+ (subed-jump-to-subtitle-end)
(unless (looking-at "\n\\'")
(delete-region (point) (point-max))
(insert "\n")))
;; One space before and after " --> "
(goto-char (point-min))
- (while (re-search-forward (format "^%s" subed-vtt--regexp-timestamp)
nil t)
+ (while (re-search-forward (format "^%s" subed--regexp-timestamp) nil t)
(when (looking-at "[[:blank:]]*-->[[:blank:]]*")
(unless (= (length (match-string 0)) 5)
(replace-match " --> "))))))))
-(defun subed-vtt--validate ()
+(cl-defmethod subed--validate (&context (major-mode subed-vtt-mode))
"Move point to the first invalid subtitle and report an error."
- (interactive)
(when (> (buffer-size) 0)
(atomic-change-group
(save-match-data
(let ((orig-point (point)))
(goto-char (point-min))
- (while (and (re-search-forward (format "^\\(%s\\)"
subed-vtt--regexp-timestamp) nil t)
+ (while (and (re-search-forward (format "^\\(%s\\)"
subed--regexp-timestamp) nil t)
(goto-char (match-beginning 1)))
- ;; This regex is stricter than `subed-vtt--regexp-timestamp'
+ ;; This regex is stricter than `subed--regexp-timestamp'
(unless (looking-at
"^[0-9]\\{2\\}:[0-9]\\{2\\}:[0-9]\\{2\\}\\(\\.[0-9]\\{0,3\\}\\)")
(error "Found invalid start time: %S" (substring (or
(thing-at-point 'line :no-properties) "\n") 0 -1)))
(when (re-search-forward "[[:blank:]]" (point-at-eol) t)
@@ -519,33 +347,40 @@ Update the end timestamp accordingly."
(error "Found invalid stop time: %S" (substring (or
(thing-at-point 'line :no-properties) "\n") 0 -1))))
(goto-char orig-point))))))
-(defun subed-vtt--sort ()
- "Sanitize, then sort subtitles by start time and re-number them."
- (interactive)
+(cl-defmethod subed--sort (&context (major-mode subed-vtt-mode))
+ "Sanitize, then sort subtitles by start time."
(atomic-change-group
- (subed-vtt--sanitize)
- (subed-vtt--validate)
+ (subed-sanitize)
+ (subed-validate)
(subed-save-excursion
(goto-char (point-min))
- (subed-vtt--forward-subtitle-id)
+ (subed-forward-subtitle-id)
(sort-subr nil
;; nextrecfun (move to next record/subtitle or to end-of-buffer
;; if there are no more records)
- (lambda () (unless (subed-vtt--forward-subtitle-id)
+ (lambda () (unless (subed-forward-subtitle-id)
(goto-char (point-max))))
;; endrecfun (move to end of current record/subtitle)
- #'subed-vtt--jump-to-subtitle-end
+ #'subed-jump-to-subtitle-end
;; startkeyfun (return sort value of current record/subtitle)
- #'subed-vtt--subtitle-msecs-start))))
+ #'subed-subtitle-msecs-start))))
+
-(defun subed-vtt--init ()
+(cl-defmethod subed--init :after (&context (major-mode subed-vtt-mode))
"This function is called when subed-mode is entered for a SRT file."
+ )
+
+;;;###autoload
+(define-derived-mode subed-vtt-mode subed-mode "Subed-VTT"
+ "Major mode for editing WebVTT subtitle files."
(setq-local subed--subtitle-format "vtt")
- (setq-local font-lock-defaults '(subed-vtt-font-lock-keywords))
+ (setq-local subed--regexp-timestamp subed-vtt--regexp-timestamp)
+ (setq-local subed--regexp-separator subed-vtt--regexp-separator)
+ (setq-local font-lock-defaults '(subed-vtt-font-lock-keywords))
;; Support for fill-paragraph (M-q)
- (let ((timestamps-regexp (concat subed-vtt--regexp-timestamp
+ (let ((timestamps-regexp (concat subed--regexp-timestamp
" *--> *"
- subed-vtt--regexp-timestamp)))
+ subed--regexp-timestamp)))
(setq-local paragraph-separate (concat "^\\("
(mapconcat 'identity
`("[[:blank:]]*"
"[[:digit:]]+"
@@ -557,15 +392,7 @@ Update the end timestamp accordingly."
;; a "-" at the start of the line.
(mapconcat 'identity '("^-"
"[[:graph:]]*$") "\\|")
- "\\)"))
- (add-hook 'subed-sanitize-functions #'subed-vtt--sort nil t)
- (add-hook 'subed-validate-functions #'subed-vtt--validate t t)))
-
-;;;###autoload
-(define-derived-mode subed-vtt-mode subed-mode "Subed-VTT"
- "Major mode for editing WebVTT subtitle files."
- (subed--init "vtt")
- (subed-vtt--init))
+ "\\)"))))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.vtt\\'" . subed-vtt-mode))
diff --git a/subed/subed.el b/subed/subed.el
index 7701180b24..b3c31f0650 100644
--- a/subed/subed.el
+++ b/subed/subed.el
@@ -90,102 +90,15 @@
html-tag-keymap))
subed-mode-map))
-;;;###autoload
-(defvar subed--init-alist '(("srt" . subed-srt--init)
- ("vtt" . subed-vtt--init)
- ("ass" . subed-ass--init))
- "Alist that maps file extensions to format-specific init functions.")
-
-;;; Abstraction hack to support different subtitle formats
-;;
-;; We need subtitle format-specific functions for each individual buffer so it
-;; is possible to open a .srt and a .sub file in the same Emacs session.
-;; Buffer-local functions don't exist in Elisp, but we can store the format in
a
-;; buffer-local variable.
-;;
-;; `subed-mode-enable' runs a format-specific init function based on the file
-;; extension. The init function sets the buffer-local variable
-;; `subed--subtitle-format' which is then used by generic functions to assemble
-;; the names of format-specific functions on the fly (e.g. (concat "subed-"
-;; subed-subtitle-format "--subtitle-id")).
-
-(defvar subed--generic-function-suffixes
- (list "subtitle-id" "subtitle-id-max" "subtitle-id-at-msecs"
- "subtitle-msecs-start" "subtitle-msecs-stop"
- "subtitle-text" "subtitle-relative-point"
- "msecs-to-timestamp" "timestamp-to-msecs"
- "jump-to-subtitle-id" "jump-to-subtitle-id-at-msecs"
- "jump-to-subtitle-time-start" "jump-to-subtitle-time-stop"
- "jump-to-subtitle-text" "jump-to-subtitle-text-at-msecs"
- "jump-to-subtitle-end"
- "forward-subtitle-id" "backward-subtitle-id"
- "forward-subtitle-text" "backward-subtitle-text"
- "forward-subtitle-end" "backward-subtitle-end"
- "forward-subtitle-time-start" "backward-subtitle-time-start"
- "forward-subtitle-time-stop" "backward-subtitle-time-stop"
- "set-subtitle-time-start" "set-subtitle-time-stop"
- "prepend-subtitle" "append-subtitle" "kill-subtitle" "merge-with-next"
- "regenerate-ids" "regenerate-ids-soon"
- "sanitize" "validate" "sort" "make-subtitle"))
-
-(defun subed--get-generic-func (func-suffix)
- "Return the generic/public function for FUNC-SUFFIX."
- (intern (concat "subed-" func-suffix)))
-
-(defun subed--get-specific-func (func-suffix)
- "Return the format-specific function for the current buffer for FUNC-SUFFIX."
- (intern (concat "subed-" subed--subtitle-format "--" func-suffix)))
-
-(defun subed--init (&optional format)
- "Call subtitle format-specific init function and (re-)alias generic
functions.
-If FORMAT is specified, use that. If not, load the format
-specified in `subed--init-alist'."
- ;; Call format-specific init function based on file extension and
- ;; `subed--init-alist'.
- (let* ((file-ext (when (buffer-file-name)
- (file-name-extension (buffer-file-name))))
- (init-func (alist-get (or format file-ext) subed--init-alist nil nil
'equal)))
- (if (functionp init-func)
- (funcall init-func)
- (error "Missing init function: %S" init-func))
- (unless subed--subtitle-format
- (error "%S failed to set buffer-local variable: subed--subtitle-format"
- init-func)))
- ;; Define generic functions like `subed-subtitle-text'.
- (cl-loop for func-suffix in subed--generic-function-suffixes do
- (let ((generic-func (subed--get-generic-func func-suffix))
- (specific-func (subed--get-specific-func func-suffix)))
- (unless (functionp specific-func)
- (error "Missing subtitle format-specific function: %s"
specific-func))
- (if (functionp specific-func)
- (let* ((argspec (help-function-arglist specific-func))
- (argvars (seq-filter (lambda (argvar)
- (let ((first-char (substring
(symbol-name argvar) 0 1)))
- (not (equal first-char "&"))))
- argspec)))
- (defalias generic-func
- `(lambda ,argspec
- ,(interactive-form specific-func) ;; (interactive ...)
or nil
- (let (;; Get the format-specific function for the
current
- ;; buffer. We must do this every time the
generic
- ;; function is called because the result depends
on
- ;; the buffer-local variable
`subed--subtitle-format'.
- (specific-func (subed--get-specific-func
,func-suffix))
- ;; Turn the list of variable names into a list of
- ;; corresponding values.
- (argvals (mapcar 'eval ',argvars)))
- (apply specific-func argvals)))
- (documentation specific-func t)))))))
-
(defun subed-auto-find-video-maybe ()
"Load video associated with this subtitle file."
(let ((video-file (subed-guess-video-file)))
- (when video-file
- (subed-debug "Auto-discovered video file: %s" video-file)
- (condition-case err
- (subed-mpv-find-video video-file)
- (error (message "%s -- Set subed-auto-find-video to nil to avoid
this error."
- (car (cdr err))))))))
+ (when video-file
+ (subed-debug "Auto-discovered video file: %s" video-file)
+ (condition-case err
+ (subed-mpv-find-video video-file)
+ (error (message "%s -- Set subed-auto-find-video to nil to avoid this
error."
+ (car (cdr err))))))))
;; TODO: Make these more configurable.
(defun subed-set-up-defaults ()
diff --git a/tests/test-subed-ass.el b/tests/test-subed-ass.el
index 10532b0539..624881f5fe 100644
--- a/tests/test-subed-ass.el
+++ b/tests/test-subed-ass.el
@@ -23,7 +23,7 @@ Dialogue: 0,0:00:17.00,0:00:19.80,Default,,0,0,0,,I hope it
works.
")
(defmacro with-temp-ass-buffer (&rest body)
- "Call `subed-ass--init' in temporary buffer before running BODY."
+ "Initialize temporary buffer with `subed-ass-mode' and run BODY."
`(with-temp-buffer
(subed-ass-mode)
(progn ,@body)))
@@ -34,63 +34,63 @@ Dialogue: 0,0:00:17.00,0:00:19.80,Default,,0,0,0,,I hope it
works.
(it "returns the time in milliseconds."
(with-temp-ass-buffer
(insert mock-ass-data)
- (subed-ass--jump-to-subtitle-id "0:00:14.00")
- (expect (subed-ass--subtitle-msecs-start) :to-equal (* 14 1000))
- (expect (subed-ass--subtitle-msecs-stop) :to-equal (+ (* 16 1000)
800))))
+ (subed-jump-to-subtitle-id "0:00:14.00")
+ (expect (subed-subtitle-msecs-start) :to-equal (* 14 1000))
+ (expect (subed-subtitle-msecs-stop) :to-equal (+ (* 16 1000) 800))))
(it "returns nil if time can't be found."
(with-temp-ass-buffer
- (expect (subed-ass--subtitle-msecs-start) :to-be nil)
- (expect (subed-ass--subtitle-msecs-stop) :to-be nil)))
+ (expect (subed-subtitle-msecs-start) :to-be nil)
+ (expect (subed-subtitle-msecs-stop) :to-be nil)))
)
(describe "the subtitle text"
(describe "when text is empty"
(it "and at the beginning with a trailing newline."
(with-temp-ass-buffer
(insert mock-ass-data)
- (subed-ass--jump-to-subtitle-text "0:00:11.12")
+ (subed-jump-to-subtitle-text "0:00:11.12")
(kill-line)
- (expect (subed-ass--subtitle-text) :to-equal "")))))
+ (expect (subed-subtitle-text) :to-equal "")))))
(describe "when text is not empty"
(it "and has no linebreaks."
(with-temp-ass-buffer
(insert mock-ass-data)
- (subed-ass--jump-to-subtitle-text "0:00:14.00")
- (expect (subed-ass--subtitle-text) :to-equal "This is a test.")))))
+ (subed-jump-to-subtitle-text "0:00:14.00")
+ (expect (subed-subtitle-text) :to-equal "This is a test.")))))
(describe "Jumping"
(describe "to current subtitle timestamp"
(it "can handle different formats of timestamps."
(with-temp-ass-buffer
(insert mock-ass-data)
- (expect (subed-ass--jump-to-subtitle-id "00:00:11.120") :to-equal 564)
- (expect (subed-ass--subtitle-msecs-start) :to-equal 11120)))
+ (expect (subed-jump-to-subtitle-id "00:00:11.120") :to-equal 564)
+ (expect (subed-subtitle-msecs-start) :to-equal 11120)))
(it "returns timestamp's point when point is already on the timestamp."
(with-temp-ass-buffer
(insert mock-ass-data)
(goto-char (point-min))
- (subed-ass--jump-to-subtitle-id "0:00:11.12")
- (expect (subed-ass--jump-to-subtitle-time-start) :to-equal (point))
- (expect (looking-at subed-ass--regexp-timestamp) :to-be t)
+ (subed-jump-to-subtitle-id "0:00:11.12")
+ (expect (subed-jump-to-subtitle-time-start) :to-equal (point))
+ (expect (looking-at subed--regexp-timestamp) :to-be t)
(expect (match-string 0) :to-equal "0:00:11.12")))
(it "returns timestamp's point when point is on the text."
(with-temp-ass-buffer
(insert mock-ass-data)
(search-backward "test")
(expect (thing-at-point 'word) :to-equal "test")
- (expect (subed-ass--jump-to-subtitle-time-start) :to-equal 640)
- (expect (looking-at subed-ass--regexp-timestamp) :to-be t)
+ (expect (subed-jump-to-subtitle-time-start) :to-equal 640)
+ (expect (looking-at subed--regexp-timestamp) :to-be t)
(expect (match-string 0) :to-equal "0:00:14.00")))
(it "returns nil if buffer is empty."
(with-temp-ass-buffer
(expect (buffer-string) :to-equal "")
- (expect (subed-ass--jump-to-subtitle-time-start) :to-equal nil))))
+ (expect (subed-jump-to-subtitle-time-start) :to-equal nil))))
(describe "to specific subtitle by timestamp"
(it "returns timestamp's point if wanted time exists."
(with-temp-ass-buffer
(insert mock-ass-data)
(goto-char (point-max))
- (expect (subed-ass--jump-to-subtitle-id "0:00:11.12") :to-equal 564)
+ (expect (subed-jump-to-subtitle-id "0:00:11.12") :to-equal 564)
(expect (looking-at (regexp-quote "Dialogue: 0,0:00:11.12")) :to-be t)
- (expect (subed-ass--jump-to-subtitle-id "0:00:17.00") :to-equal 694)
+ (expect (subed-jump-to-subtitle-id "0:00:17.00") :to-equal 694)
(expect (looking-at (regexp-quote "Dialogue: 0,0:00:17.00")) :to-be
t)))
(it "returns nil and does not move if wanted ID does not exists."
(with-temp-ass-buffer
@@ -98,237 +98,237 @@ Dialogue: 0,0:00:17.00,0:00:19.80,Default,,0,0,0,,I hope
it works.
(goto-char (point-min))
(search-forward "test")
(let ((stored-point (point)))
- (expect (subed-ass--jump-to-subtitle-id "0:08:00") :to-equal nil)
+ (expect (subed-jump-to-subtitle-id "0:08:00") :to-equal nil)
(expect stored-point :to-equal (point))))))
(describe "to subtitle start time"
(it "returns start time's point if movement was successful."
(with-temp-ass-buffer
(insert mock-ass-data)
(re-search-backward "world")
- (expect (subed-ass--jump-to-subtitle-time-start) :to-equal 576)
- (expect (looking-at subed-ass--regexp-timestamp) :to-be t)
+ (expect (subed-jump-to-subtitle-time-start) :to-equal 576)
+ (expect (looking-at subed--regexp-timestamp) :to-be t)
(expect (match-string 0) :to-equal "0:00:11.12")))
(it "returns nil if movement failed."
(with-temp-ass-buffer
- (expect (subed-ass--jump-to-subtitle-time-start) :to-equal nil))))
+ (expect (subed-jump-to-subtitle-time-start) :to-equal nil))))
(describe "to subtitle stop time"
(it "returns stop time's point if movement was successful."
(with-temp-ass-buffer
(insert mock-ass-data)
(re-search-backward "test")
- (expect (subed-ass--jump-to-subtitle-time-stop) :to-equal 651)
- (expect (looking-at subed-ass--regexp-timestamp) :to-be t)
+ (expect (subed-jump-to-subtitle-time-stop) :to-equal 651)
+ (expect (looking-at subed--regexp-timestamp) :to-be t)
(expect (match-string 0) :to-equal "0:00:16.80")))
(it "returns nil if movement failed."
(with-temp-ass-buffer
- (expect (subed-ass--jump-to-subtitle-time-stop) :to-equal nil))))
+ (expect (subed-jump-to-subtitle-time-stop) :to-equal nil))))
(describe "to subtitle text"
(it "returns subtitle text's point if movement was successful."
(with-temp-ass-buffer
(insert mock-ass-data)
(goto-char (point-min))
- (expect (subed-ass--jump-to-subtitle-text) :to-equal 614)
+ (expect (subed-jump-to-subtitle-text) :to-equal 614)
(expect (looking-at "Hello, world!") :to-equal t)
(forward-line 1)
- (expect (subed-ass--jump-to-subtitle-text) :to-equal 678)
+ (expect (subed-jump-to-subtitle-text) :to-equal 678)
(expect (looking-at "This is a test.") :to-equal t)))
(it "returns nil if movement failed."
(with-temp-ass-buffer
- (expect (subed-ass--jump-to-subtitle-time-stop) :to-equal nil))))
+ (expect (subed-jump-to-subtitle-time-stop) :to-equal nil))))
(describe "to end of subtitle text"
(it "returns point if subtitle end can be found."
(with-temp-ass-buffer
(insert mock-ass-data)
(goto-char (point-min))
- (expect (subed-ass--jump-to-subtitle-end) :to-be 627)
+ (expect (subed-jump-to-subtitle-end) :to-be 627)
(expect (looking-back "Hello, world!") :to-be t)
(forward-char 2)
- (expect (subed-ass--jump-to-subtitle-end) :to-be 693)
+ (expect (subed-jump-to-subtitle-end) :to-be 693)
(expect (looking-back "This is a test.") :to-be t)
(forward-char 2)
- (expect (subed-ass--jump-to-subtitle-end) :to-be 760)
+ (expect (subed-jump-to-subtitle-end) :to-be 760)
(expect (looking-back "I hope it works.") :to-be t)))
(it "returns nil if subtitle end cannot be found."
(with-temp-ass-buffer
- (expect (subed-ass--jump-to-subtitle-end) :to-be nil)))
+ (expect (subed-jump-to-subtitle-end) :to-be nil)))
(it "returns nil if point did not move."
(with-temp-ass-buffer
(insert mock-ass-data)
- (subed-ass--jump-to-subtitle-text "0:00:11.12")
- (subed-ass--jump-to-subtitle-end)
- (expect (subed-ass--jump-to-subtitle-end) :to-be nil)))
+ (subed-jump-to-subtitle-text "0:00:11.12")
+ (subed-jump-to-subtitle-end)
+ (expect (subed-jump-to-subtitle-end) :to-be nil)))
(it "works if text is empty."
(with-temp-ass-buffer
(insert mock-ass-data)
- (subed-ass--jump-to-subtitle-text "00:00:11.12")
+ (subed-jump-to-subtitle-text "00:00:11.12")
(kill-line)
(backward-char)
- (expect (subed-ass--jump-to-subtitle-end) :to-be 614))))
+ (expect (subed-jump-to-subtitle-end) :to-be 614))))
(describe "to next subtitle ID"
(it "returns point when there is a next subtitle."
(with-temp-ass-buffer
(insert mock-ass-data)
- (subed-ass--jump-to-subtitle-id "00:00:11.12")
- (expect (subed-ass--forward-subtitle-id) :to-be 628)
+ (subed-jump-to-subtitle-id "00:00:11.12")
+ (expect (subed-forward-subtitle-id) :to-be 628)
(expect (looking-at (regexp-quote "Dialogue: 0,0:00:14.00")) :to-be
t)))
(it "returns nil and doesn't move when there is no next subtitle."
(with-temp-ass-buffer
(expect (thing-at-point 'word) :to-equal nil)
- (expect (subed-ass--forward-subtitle-id) :to-be nil))
+ (expect (subed-forward-subtitle-id) :to-be nil))
(with-temp-ass-buffer
(insert mock-ass-data)
- (subed-ass--jump-to-subtitle-text "0:00:17.00")
- (expect (subed-ass--forward-subtitle-id) :to-be nil))))
+ (subed-jump-to-subtitle-text "0:00:17.00")
+ (expect (subed-forward-subtitle-id) :to-be nil))))
(describe "to previous subtitle ID"
(it "returns point when there is a previous subtitle."
(with-temp-ass-buffer
(insert mock-ass-data)
- (subed-ass--jump-to-subtitle-text "00:00:14.00")
- (expect (subed-ass--backward-subtitle-id) :to-be 564)))
+ (subed-jump-to-subtitle-text "00:00:14.00")
+ (expect (subed-backward-subtitle-id) :to-be 564)))
(it "returns nil and doesn't move when there is no previous subtitle."
(with-temp-ass-buffer
- (expect (subed-ass--backward-subtitle-id) :to-be nil))
+ (expect (subed-backward-subtitle-id) :to-be nil))
(with-temp-ass-buffer
(insert mock-ass-data)
- (subed-ass--jump-to-subtitle-id "00:00:11.12")
- (expect (subed-ass--backward-subtitle-id) :to-be nil))))
+ (subed-jump-to-subtitle-id "00:00:11.12")
+ (expect (subed-backward-subtitle-id) :to-be nil))))
(describe "to next subtitle text"
(it "returns point when there is a next subtitle."
(with-temp-ass-buffer
(insert mock-ass-data)
- (subed-ass--jump-to-subtitle-id "00:00:14.00")
- (expect (subed-ass--forward-subtitle-text) :to-be 744)
+ (subed-jump-to-subtitle-id "00:00:14.00")
+ (expect (subed-forward-subtitle-text) :to-be 744)
(expect (thing-at-point 'word) :to-equal "I")))
(it "returns nil and doesn't move when there is no next subtitle."
(with-temp-ass-buffer
(goto-char (point-max))
(insert (concat mock-ass-data "\n\n"))
- (subed-ass--jump-to-subtitle-id "00:00:17.00")
- (expect (subed-ass--forward-subtitle-text) :to-be nil))))
+ (subed-jump-to-subtitle-id "00:00:17.00")
+ (expect (subed-forward-subtitle-text) :to-be nil))))
(describe "to previous subtitle text"
(it "returns point when there is a previous subtitle."
(with-temp-ass-buffer
(insert mock-ass-data)
- (subed-ass--jump-to-subtitle-id "00:00:14.00")
- (expect (subed-ass--backward-subtitle-text) :to-be 614)
+ (subed-jump-to-subtitle-id "00:00:14.00")
+ (expect (subed-backward-subtitle-text) :to-be 614)
(expect (thing-at-point 'word) :to-equal "Hello")))
(it "returns nil and doesn't move when there is no previous subtitle."
(with-temp-ass-buffer
(insert mock-ass-data)
(goto-char (point-min))
- (subed-ass--forward-subtitle-time-start)
+ (subed-forward-subtitle-time-start)
(expect (looking-at (regexp-quote "0:00:11.12")) :to-be t)
- (expect (subed-ass--backward-subtitle-text) :to-be nil)
+ (expect (subed-backward-subtitle-text) :to-be nil)
(expect (looking-at (regexp-quote "0:00:11.12")) :to-be t))))
(describe "to next subtitle end"
(it "returns point when there is a next subtitle."
(with-temp-ass-buffer
(insert mock-ass-data)
- (subed-ass--jump-to-subtitle-text "00:00:14.00")
+ (subed-jump-to-subtitle-text "00:00:14.00")
(expect (thing-at-point 'word) :to-equal "This")
- (expect (subed-ass--forward-subtitle-end) :to-be 760)))
+ (expect (subed-forward-subtitle-end) :to-be 760)))
(it "returns nil and doesn't move when there is no next subtitle."
(with-temp-ass-buffer
(insert (concat mock-ass-data "\n\n"))
- (subed-ass--jump-to-subtitle-text "00:00:17.00")
- (expect (subed-ass--forward-subtitle-end) :to-be nil))))
+ (subed-jump-to-subtitle-text "00:00:17.00")
+ (expect (subed-forward-subtitle-end) :to-be nil))))
(describe "to previous subtitle end"
(it "returns point when there is a previous subtitle."
(with-temp-ass-buffer
(insert mock-ass-data)
- (subed-ass--jump-to-subtitle-id "00:00:14.00")
- (expect (subed-ass--backward-subtitle-end) :to-be 627)))
+ (subed-jump-to-subtitle-id "00:00:14.00")
+ (expect (subed-backward-subtitle-end) :to-be 627)))
(it "returns nil and doesn't move when there is no previous subtitle."
(with-temp-ass-buffer
(insert mock-ass-data)
(goto-char (point-min))
- (subed-ass--forward-subtitle-id)
+ (subed-forward-subtitle-id)
(expect (looking-at (regexp-quote "Dialogue: 0,0:00:11.12")) :to-be t)
- (expect (subed-ass--backward-subtitle-text) :to-be nil)
+ (expect (subed-backward-subtitle-text) :to-be nil)
(expect (looking-at (regexp-quote "Dialogue: 0,0:00:11.12")) :to-be
t))))
(describe "to next subtitle start time"
(it "returns point when there is a next subtitle."
(with-temp-ass-buffer
(insert mock-ass-data)
- (subed-ass--jump-to-subtitle-id "00:00:14.00")
- (expect (subed-ass--forward-subtitle-time-start) :to-be 706)))
+ (subed-jump-to-subtitle-id "00:00:14.00")
+ (expect (subed-forward-subtitle-time-start) :to-be 706)))
(it "returns nil and doesn't move when there is no next subtitle."
(with-temp-ass-buffer
(insert mock-ass-data)
- (subed-ass--jump-to-subtitle-id "00:00:17.00")
+ (subed-jump-to-subtitle-id "00:00:17.00")
(let ((pos (point)))
- (expect (subed-ass--forward-subtitle-time-start) :to-be nil)
+ (expect (subed-forward-subtitle-time-start) :to-be nil)
(expect (point) :to-be pos)))))
(describe "to previous subtitle stop"
(it "returns point when there is a previous subtitle."
(with-temp-ass-buffer
(insert mock-ass-data)
- (subed-ass--jump-to-subtitle-id "00:00:14.00")
- (expect (subed-ass--backward-subtitle-time-stop) :to-be 587)))
+ (subed-jump-to-subtitle-id "00:00:14.00")
+ (expect (subed-backward-subtitle-time-stop) :to-be 587)))
(it "returns nil and doesn't move when there is no previous subtitle."
(with-temp-ass-buffer
(insert mock-ass-data)
(goto-char (point-min))
- (subed-ass--forward-subtitle-id)
- (expect (subed-ass--backward-subtitle-time-stop) :to-be nil)
+ (subed-forward-subtitle-id)
+ (expect (subed-backward-subtitle-time-stop) :to-be nil)
(expect (looking-at (regexp-quote "Dialogue: 0,0:00:11.12")) :to-be
t))))
(describe "to next subtitle stop time"
(it "returns point when there is a next subtitle."
(with-temp-ass-buffer
(insert mock-ass-data)
- (subed-ass--jump-to-subtitle-id "00:00:14.00")
- (expect (subed-ass--forward-subtitle-time-stop) :to-be 717)))
+ (subed-jump-to-subtitle-id "00:00:14.00")
+ (expect (subed-forward-subtitle-time-stop) :to-be 717)))
(it "returns nil and doesn't move when there is no next subtitle."
(with-temp-ass-buffer
(insert mock-ass-data)
- (subed-ass--jump-to-subtitle-id "00:00:17.00")
+ (subed-jump-to-subtitle-id "00:00:17.00")
(let ((pos (point)))
- (expect (subed-ass--forward-subtitle-time-stop) :to-be nil)
+ (expect (subed-forward-subtitle-time-stop) :to-be nil)
(expect (point) :to-be pos))))))
(describe "Setting start/stop time"
(it "of subtitle should set it."
(with-temp-ass-buffer
(insert mock-ass-data)
- (subed-ass--jump-to-subtitle-id "00:00:14.00")
- (subed-ass--set-subtitle-time-start (+ (* 15 1000) 400))
- (expect (subed-ass--subtitle-msecs-start) :to-be (+ (* 15 1000) 400)))))
+ (subed-jump-to-subtitle-id "00:00:14.00")
+ (subed-set-subtitle-time-start (+ (* 15 1000) 400))
+ (expect (subed-subtitle-msecs-start) :to-be (+ (* 15 1000) 400)))))
(describe "Inserting a subtitle"
(describe "in an empty buffer"
(describe "before the current subtitle"
(it "creates an empty subtitle when passed nothing."
(with-temp-ass-buffer
- (subed-ass--prepend-subtitle)
+ (subed-prepend-subtitle)
(expect (buffer-string) :to-equal (concat "Dialogue:
0,0:00:00.00,0:00:01.00,Default,,0,0,0,,\n"))))
(it "creates a subtitle with a start time."
(with-temp-ass-buffer
- (subed-ass--prepend-subtitle nil 12340)
+ (subed-prepend-subtitle nil 12340)
(expect (buffer-string) :to-equal (concat "Dialogue:
0,0:00:12.34,0:00:13.34,Default,,0,0,0,,\n"))))
(it "creates a subtitle with a start time and stop time."
(with-temp-ass-buffer
- (subed-ass--prepend-subtitle nil 60000 65000)
+ (subed-prepend-subtitle nil 60000 65000)
(expect (buffer-string) :to-equal "Dialogue:
0,0:01:00.00,0:01:05.00,Default,,0,0,0,,\n")))
(it "creates a subtitle with start time, stop time and text."
(with-temp-ass-buffer
- (subed-ass--prepend-subtitle nil 60000 65000 "Hello world")
+ (subed-prepend-subtitle nil 60000 65000 "Hello world")
(expect (buffer-string) :to-equal "Dialogue:
0,0:01:00.00,0:01:05.00,Default,,0,0,0,,Hello world\n"))))
(describe "after the current subtitle"
(it "creates an empty subtitle when passed nothing."
(with-temp-ass-buffer
- (subed-ass--append-subtitle)
+ (subed-append-subtitle)
(expect (buffer-string) :to-equal (concat "Dialogue:
0,0:00:00.00,0:00:01.00,Default,,0,0,0,,\n"))))
(it "creates a subtitle with a start time."
(with-temp-ass-buffer
- (subed-ass--append-subtitle nil 12340)
+ (subed-append-subtitle nil 12340)
(expect (buffer-string) :to-equal (concat "Dialogue:
0,0:00:12.34,0:00:13.34,Default,,0,0,0,,\n"))))
(it "creates a subtitle with a start time and stop time."
(with-temp-ass-buffer
- (subed-ass--append-subtitle nil 60000 65000)
+ (subed-append-subtitle nil 60000 65000)
(expect (buffer-string) :to-equal "Dialogue:
0,0:01:00.00,0:01:05.00,Default,,0,0,0,,\n")))
(it "creates a subtitle with start time, stop time and text."
(with-temp-ass-buffer
- (subed-ass--append-subtitle nil 60000 65000 "Hello world")
+ (subed-append-subtitle nil 60000 65000 "Hello world")
(expect (buffer-string) :to-equal "Dialogue:
0,0:01:00.00,0:01:05.00,Default,,0,0,0,,Hello world\n"))))))
(describe "in a non-empty buffer"
(describe "before the current subtitle"
@@ -336,16 +336,16 @@ Dialogue: 0,0:00:17.00,0:00:19.80,Default,,0,0,0,,I hope
it works.
(it "creates the subtitle before the current one."
(with-temp-ass-buffer
(insert mock-ass-data)
- (subed-ass--jump-to-subtitle-time-stop)
- (subed-ass--prepend-subtitle)
+ (subed-jump-to-subtitle-time-stop)
+ (subed-prepend-subtitle)
(expect (buffer-substring (line-beginning-position)
(line-end-position))
:to-equal (concat "Dialogue:
0,0:00:00.00,0:00:01.00,Default,,0,0,0,,")))))
(describe "with point on a middle subtitle"
(it "creates the subtitle before the current one."
(with-temp-ass-buffer
(insert mock-ass-data)
- (subed-ass--jump-to-subtitle-time-stop "0:00:14.00")
- (subed-ass--prepend-subtitle)
+ (subed-jump-to-subtitle-time-stop "0:00:14.00")
+ (subed-prepend-subtitle)
(expect (buffer-substring (line-beginning-position)
(line-end-position))
:to-equal (concat "Dialogue:
0,0:00:00.00,0:00:01.00,Default,,0,0,0,,"))
(forward-line 1)
@@ -357,35 +357,35 @@ Dialogue: 0,0:00:17.00,0:00:19.80,Default,,0,0,0,,I hope
it works.
(it "creates the subtitle after the current one."
(with-temp-ass-buffer
(insert mock-ass-data)
- (subed-ass--jump-to-subtitle-time-stop "0:00:14.00")
- (subed-ass--append-subtitle)
+ (subed-jump-to-subtitle-time-stop "0:00:14.00")
+ (subed-append-subtitle)
(expect (buffer-substring (line-beginning-position)
(line-end-position))
:to-equal (concat "Dialogue:
0,0:00:00.00,0:00:01.00,Default,,0,0,0,,"))
(forward-line -1)
- (expect (subed-ass--subtitle-msecs-start) :to-be 14000))))))
+ (expect (subed-subtitle-msecs-start) :to-be 14000))))))
(describe "Killing a subtitle"
(it "removes the first subtitle."
(with-temp-ass-buffer
(insert mock-ass-data)
- (subed-ass--jump-to-subtitle-text "0:00:11.12")
- (subed-ass--kill-subtitle)
- (expect (subed-ass--subtitle-msecs-start) :to-be 14000)
+ (subed-jump-to-subtitle-text "0:00:11.12")
+ (subed-kill-subtitle)
+ (expect (subed-subtitle-msecs-start) :to-be 14000)
(forward-line -1)
(beginning-of-line)
(expect (looking-at "Format: Layer")))))
(it "removes it in between."
(with-temp-ass-buffer
(insert mock-ass-data)
- (subed-ass--jump-to-subtitle-text "00:00:14.00")
- (subed-ass--kill-subtitle)
- (expect (subed-ass--subtitle-msecs-start) :to-be 17000)))
+ (subed-jump-to-subtitle-text "00:00:14.00")
+ (subed-kill-subtitle)
+ (expect (subed-subtitle-msecs-start) :to-be 17000)))
(it "removes the last subtitle."
(with-temp-ass-buffer
(insert mock-ass-data)
- (subed-ass--jump-to-subtitle-text "00:00:17.00")
- (subed-ass--kill-subtitle)
- (expect (subed-ass--subtitle-msecs-start) :to-be 14000)))
+ (subed-jump-to-subtitle-text "00:00:17.00")
+ (subed-kill-subtitle)
+ (expect (subed-subtitle-msecs-start) :to-be 14000)))
(describe "Converting msecs to timestamp"
(it "uses the right format"
(with-temp-ass-buffer
- (expect (subed-ass--msecs-to-timestamp 1410) :to-equal "0:00:01.41")))))
+ (expect (subed-msecs-to-timestamp 1410) :to-equal "0:00:01.41")))))
diff --git a/tests/test-subed-common.el b/tests/test-subed-common.el
index 2fa62d8688..b11a874311 100644
--- a/tests/test-subed-common.el
+++ b/tests/test-subed-common.el
@@ -24,7 +24,7 @@ Baz.
`(with-temp-buffer
;; subed--init uses file extension to detect format
(setq buffer-file-name "test.srt")
- (subed--init)
+ (subed-srt-mode)
(progn ,@body)))
(describe "Iterating over subtitles"
@@ -971,18 +971,18 @@ Baz.
(it "a single subtile."
(cl-loop for arg in (list nil 1) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(expect (subed-insert-subtitle arg) :to-equal 33)
(expect (buffer-string) :to-equal (concat "0\n"
"00:00:00,000 -->
00:00:01,000\n"
"\n"))
(expect (point) :to-equal 33)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
(it "multiple subtiles."
(cl-loop for arg in (list 2) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(expect (subed-insert-subtitle arg) :to-equal 33)
(expect (buffer-string) :to-equal (concat "0\n"
"00:00:00,000 -->
00:00:01,000\n"
@@ -991,25 +991,25 @@ Baz.
"00:00:01,100 -->
00:00:02,100\n"
"\n"))
(expect (point) :to-equal 33)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
)
(describe "prepending"
(it "a single subtile."
(cl-loop for arg in (list '- -1 (list 4)) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(expect (subed-insert-subtitle arg) :to-equal 33)
(expect (buffer-string) :to-equal (concat "0\n"
"00:00:00,000 -->
00:00:01,000\n"
"\n"))
(expect (point) :to-equal 33)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
(it "multiple subtiles."
(cl-loop for arg in (list -2 (list -16)) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(expect (subed-insert-subtitle arg) :to-equal 33)
(expect (buffer-string) :to-equal (concat "0\n"
"00:00:00,000 -->
00:00:01,000\n"
@@ -1018,8 +1018,8 @@ Baz.
"00:00:01,100 -->
00:00:02,100\n"
"\n"))
(expect (point) :to-equal 33)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
)
)
(describe "in a non-empty buffer"
@@ -1027,7 +1027,7 @@ Baz.
(it "a single subtitle."
(cl-loop for arg in (list '- -1 (list 4)) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:59,000 --> 00:01:00,000\n"
"Foo.\n\n"
@@ -1046,12 +1046,12 @@ Baz.
"00:02:00,000 -->
00:02:01,000\n"
"Bar.\n"))
(expect (point) :to-equal 71)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
(it "multiple subtitles."
(cl-loop for arg in (list -2 (list 16)) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:59,000 --> 00:01:00,000\n"
"Foo.\n\n"
@@ -1073,14 +1073,14 @@ Baz.
"00:02:00,000 -->
00:02:01,000\n"
"Bar.\n"))
(expect (point) :to-equal 71)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
)
(describe "appending between subtitles"
(it "a single subtitle."
(cl-loop for arg in (list nil 1) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:59,000 --> 00:01:00,000\n"
"Foo.\n\n"
@@ -1099,12 +1099,12 @@ Baz.
"00:02:00,000 -->
00:02:01,000\n"
"Bar.\n"))
(expect (point) :to-equal 71)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
(it "multiple subtitles."
(cl-loop for arg in (list 2) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:59,000 --> 00:01:00,000\n"
"Foo.\n\n"
@@ -1126,18 +1126,18 @@ Baz.
"00:02:00,000 -->
00:02:01,000\n"
"Bar.\n"))
(expect (point) :to-equal 71)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
)
(describe "prepending to the first subtitle"
(it "a single subtitle."
(cl-loop for arg in (list '- -1 (list 4)) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:01:00,000 --> 00:01:01,000\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(expect (subed-insert-subtitle arg) :to-equal 33)
(expect (buffer-string) :to-equal (concat "0\n"
"00:00:30,000 -->
00:00:31,000\n"
@@ -1146,16 +1146,16 @@ Baz.
"00:01:00,000 -->
00:01:01,000\n"
"Foo.\n"))
(expect (point) :to-equal 33)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
(it "multiple subtitles."
(cl-loop for arg in (list -2 (list 16)) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:01:00,000 --> 00:01:01,000\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(expect (subed-insert-subtitle arg) :to-equal 33)
(expect (buffer-string) :to-equal (concat "0\n"
"00:00:20,000 -->
00:00:21,000\n"
@@ -1167,18 +1167,18 @@ Baz.
"00:01:00,000 -->
00:01:01,000\n"
"Foo.\n"))
(expect (point) :to-equal 33)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
)
(describe "appending to the last subtitle"
(it "a single subtitle."
(cl-loop for arg in (list nil 1) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:59,000 --> 00:01:00,000\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(expect (subed-insert-subtitle arg) :to-equal 71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:59,000 -->
00:01:00,000\n"
@@ -1187,15 +1187,15 @@ Baz.
"00:01:00,100 -->
00:01:01,100\n"
"\n"))
(expect (point) :to-equal 71)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
(it "multiple subtitles."
(cl-loop for arg in (list 2) do
(with-temp-srt-buffer
(insert (concat "1\n"
"00:00:59,000 --> 00:01:00,000\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-text 3)
+ (subed-jump-to-subtitle-text 3)
(expect (subed-insert-subtitle arg) :to-equal 71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:59,000 -->
00:01:00,000\n"
@@ -1213,14 +1213,14 @@ Baz.
(it "a single subtitle."
(cl-loop for arg in (list nil 1) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:59,000 --> 00:01:00,000\n"
"Foo.\n\n"
"2\n"
"00:01:00,600 --> 00:01:02,000\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(expect (subed-insert-subtitle arg) :to-equal 71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:59,000
--> 00:01:00,000\n"
@@ -1232,19 +1232,19 @@ Baz.
"00:01:00,600
--> 00:01:02,000\n"
"Foo.\n"))
(expect (point) :to-equal 71)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
(it "multiple subtitles."
(cl-loop for arg in (list 2) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:59,000 --> 00:01:00,000\n"
"Foo.\n\n"
"2\n"
"00:01:00,600 --> 00:01:02,000\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(expect (subed-insert-subtitle arg) :to-equal 71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:59,000
--> 00:01:00,000\n"
@@ -1259,22 +1259,22 @@ Baz.
"00:01:00,600
--> 00:01:02,000\n"
"Foo.\n"))
(expect (point) :to-equal 71)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
)
(describe "to prepend"
(describe "between subtitles"
(it "a single subtitle."
(cl-loop for arg in (list '- -1 (list 4)) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:57,000 --> 00:00:59,100\n"
"Foo.\n\n"
"2\n"
"00:01:00,000 --> 00:01:02,000\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-text 2)
+ (subed-jump-to-subtitle-text 2)
(expect (subed-insert-subtitle arg) :to-equal 71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:57,000
--> 00:00:59,100\n"
@@ -1286,19 +1286,19 @@ Baz.
"00:01:00,000
--> 00:01:02,000\n"
"Foo.\n"))
(expect (point) :to-equal 71)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
(it "multiple subtitles."
(cl-loop for arg in (list -2 (list 16)) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:57,000 --> 00:00:59,100\n"
"Foo.\n\n"
"2\n"
"00:01:00,000 --> 00:01:02,000\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-text 2)
+ (subed-jump-to-subtitle-text 2)
(expect (subed-insert-subtitle arg) :to-equal 71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:57,000
--> 00:00:59,100\n"
@@ -1313,18 +1313,18 @@ Baz.
"00:01:00,000
--> 00:01:02,000\n"
"Foo.\n"))
(expect (point) :to-equal 71)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
)
(describe "before the first subtitle"
(it "a single subtitle."
(cl-loop for arg in (list '- -1 (list 4)) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:00,500 --> 00:00:02,000\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(expect (subed-insert-subtitle arg) :to-equal 33)
(expect (buffer-string) :to-equal (concat "0\n"
"00:00:00,100
--> 00:00:00,400\n"
@@ -1333,16 +1333,16 @@ Baz.
"00:00:00,500
--> 00:00:02,000\n"
"Foo.\n"))
(expect (point) :to-equal 33)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
(it "multiple subtitles."
(cl-loop for arg in (list -2 (list 16)) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:00,600 --> 00:00:01,500\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(expect (subed-insert-subtitle arg) :to-equal 33)
(expect (buffer-string) :to-equal (concat "0\n"
"00:00:00,100
--> 00:00:00,250\n"
@@ -1354,8 +1354,8 @@ Baz.
"00:00:00,600
--> 00:00:01,500\n"
"Foo.\n"))
(expect (point) :to-equal 33)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
)
)
)
@@ -1365,14 +1365,14 @@ Baz.
(it "a single subtitle."
(cl-loop for arg in (list '- -1 (list 4)) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:55,000 --> 00:00:59,950\n"
"Foo.\n\n"
"2\n"
"00:01:00,000 --> 00:01:02,000\n"
"Bar.\n"))
- (subed-srt--jump-to-subtitle-text 2)
+ (subed-jump-to-subtitle-text 2)
(expect (subed-insert-subtitle arg) :to-equal 71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:55,000
--> 00:00:59,950\n"
@@ -1384,19 +1384,19 @@ Baz.
"00:01:00,000
--> 00:01:02,000\n"
"Bar.\n"))
(expect (point) :to-equal 71)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
(it "multiple subtitles."
(cl-loop for arg in (list -2 (list 16)) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:57,000 --> 00:00:59,999\n"
"Foo.\n\n"
"2\n"
"00:01:00,000 --> 00:01:02,000\n"
"Bar.\n"))
- (subed-srt--jump-to-subtitle-text 2)
+ (subed-jump-to-subtitle-text 2)
(expect (subed-insert-subtitle arg) :to-equal 71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:57,000
--> 00:00:59,999\n"
@@ -1411,21 +1411,21 @@ Baz.
"00:01:00,000
--> 00:01:02,000\n"
"Bar.\n"))
(expect (point) :to-equal 71)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
)
(describe "when appending"
(it "a single subtitle."
(cl-loop for arg in (list nil 1) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:59,000 --> 00:01:00,000\n"
"Foo.\n\n"
"2\n"
"00:01:00,010 --> 00:01:02,000\n"
"Bar.\n"))
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(expect (subed-insert-subtitle arg) :to-equal 71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:59,000
--> 00:01:00,000\n"
@@ -1437,19 +1437,19 @@ Baz.
"00:01:00,010
--> 00:01:02,000\n"
"Bar.\n"))
(expect (point) :to-equal 71)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
(it "multiple subtitles."
(cl-loop for arg in (list 2) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:59,000 --> 00:01:00,000\n"
"Foo.\n\n"
"2\n"
"00:01:00,100 --> 00:01:02,000\n"
"Bar.\n"))
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(expect (subed-insert-subtitle arg) :to-equal 71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:59,000
--> 00:01:00,000\n"
@@ -1464,19 +1464,19 @@ Baz.
"00:01:00,100
--> 00:01:02,000\n"
"Bar.\n"))
(expect (point) :to-equal 71)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
)
)
(describe "before the first subtitle"
(it "a single subtitle."
(cl-loop for arg in (list '- -1 (list 4)) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:00,050 --> 00:00:02,000\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(expect (subed-insert-subtitle arg) :to-equal 33)
(expect (buffer-string) :to-equal (concat "0\n"
"00:00:00,000
--> 00:00:00,000\n"
@@ -1485,16 +1485,16 @@ Baz.
"00:00:00,050
--> 00:00:02,000\n"
"Foo.\n"))
(expect (point) :to-equal 33)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
(it "multiple subtitles."
(cl-loop for arg in (list -2 (list 16)) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:00,100 --> 00:00:01,500\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(expect (subed-insert-subtitle arg) :to-equal 33)
(expect (buffer-string) :to-equal (concat "0\n"
"00:00:00,000
--> 00:00:00,000\n"
@@ -1506,8 +1506,8 @@ Baz.
"00:00:00,100
--> 00:00:01,500\n"
"Foo.\n"))
(expect (point) :to-equal 33)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
)
)
)
@@ -1519,18 +1519,18 @@ Baz.
(it "a single subtile."
(cl-loop for arg in (list nil 1) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(expect (subed-insert-subtitle-adjacent arg) :to-equal 33)
(expect (buffer-string) :to-equal (concat "0\n"
"00:00:00,000 -->
00:00:01,000\n"
"\n"))
(expect (point) :to-equal 33)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
(it "multiple subtiles."
(cl-loop for arg in (list 2) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(expect (subed-insert-subtitle-adjacent arg) :to-equal 33)
(expect (buffer-string) :to-equal (concat "0\n"
"00:00:00,000 -->
00:00:01,000\n"
@@ -1539,25 +1539,25 @@ Baz.
"00:00:01,100 -->
00:00:02,100\n"
"\n"))
(expect (point) :to-equal 33)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
)
(describe "prepending"
(it "a single subtile."
(cl-loop for arg in (list '- -1 (list 4)) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(expect (subed-insert-subtitle-adjacent arg) :to-equal 33)
(expect (buffer-string) :to-equal (concat "0\n"
"00:00:00,000 -->
00:00:01,000\n"
"\n"))
(expect (point) :to-equal 33)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
(it "multiple subtiles."
(cl-loop for arg in (list -2 (list -16)) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(expect (subed-insert-subtitle-adjacent arg) :to-equal 33)
(expect (buffer-string) :to-equal (concat "0\n"
"00:00:00,000 -->
00:00:01,000\n"
@@ -1566,8 +1566,8 @@ Baz.
"00:00:01,100 -->
00:00:02,100\n"
"\n"))
(expect (point) :to-equal 33)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
)
)
(describe "in a non-empty buffer"
@@ -1575,7 +1575,7 @@ Baz.
(it "a single subtitle."
(cl-loop for arg in (list '- -1 (list 4)) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:59,000 --> 00:01:00,000\n"
"Foo.\n\n"
@@ -1594,12 +1594,12 @@ Baz.
"00:02:00,000 -->
00:02:01,000\n"
"Bar.\n"))
(expect (point) :to-equal 71)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
(it "multiple subtitles."
(cl-loop for arg in (list -2 (list 16)) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:59,000 --> 00:01:00,000\n"
"Foo.\n\n"
@@ -1621,14 +1621,14 @@ Baz.
"00:02:00,000 -->
00:02:01,000\n"
"Bar.\n"))
(expect (point) :to-equal 71)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
)
(describe "appending between subtitles"
(it "a single subtitle."
(cl-loop for arg in (list nil 1) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:59,000 --> 00:01:00,000\n"
"Foo.\n\n"
@@ -1647,12 +1647,12 @@ Baz.
"00:02:00,000 -->
00:02:01,000\n"
"Bar.\n"))
(expect (point) :to-equal 71)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
(it "multiple subtitles."
(cl-loop for arg in (list 2) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:59,000 --> 00:01:00,000\n"
"Foo.\n\n"
@@ -1674,18 +1674,18 @@ Baz.
"00:02:00,000 -->
00:02:01,000\n"
"Bar.\n"))
(expect (point) :to-equal 71)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
)
(describe "prepending to the first subtitle"
(it "a single subtitle."
(cl-loop for arg in (list '- -1 (list 4)) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:01:00,000 --> 00:01:01,000\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(expect (subed-insert-subtitle-adjacent arg) :to-equal 33)
(expect (buffer-string) :to-equal (concat "0\n"
"00:00:58,900 -->
00:00:59,900\n"
@@ -1694,16 +1694,16 @@ Baz.
"00:01:00,000 -->
00:01:01,000\n"
"Foo.\n"))
(expect (point) :to-equal 33)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
(it "multiple subtitles."
(cl-loop for arg in (list -2 (list 16)) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:01:00,000 --> 00:01:01,000\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(expect (subed-insert-subtitle-adjacent arg) :to-equal 33)
(expect (buffer-string) :to-equal (concat "0\n"
"00:00:57,800 -->
00:00:58,800\n"
@@ -1715,18 +1715,18 @@ Baz.
"00:01:00,000 -->
00:01:01,000\n"
"Foo.\n"))
(expect (point) :to-equal 33)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
)
(describe "appending to the last subtitle"
(it "a single subtitle."
(cl-loop for arg in (list nil 1) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:59,000 --> 00:01:00,000\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(expect (subed-insert-subtitle-adjacent arg) :to-equal 71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:59,000 -->
00:01:00,000\n"
@@ -1735,16 +1735,16 @@ Baz.
"00:01:00,100 -->
00:01:01,100\n"
"\n"))
(expect (point) :to-equal 71)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
(it "multiple subtitles."
(cl-loop for arg in (list 2) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:59,000 --> 00:01:00,000\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-text 3)
+ (subed-jump-to-subtitle-text 3)
(expect (subed-insert-subtitle-adjacent arg) :to-equal 71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:59,000 -->
00:01:00,000\n"
@@ -1756,22 +1756,22 @@ Baz.
"00:01:01,200 -->
00:01:02,200\n"
"\n"))
(expect (point) :to-equal 71)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
)
(describe "when there is not enough time for the subtitles"
(describe "to append"
(it "a single subtitle."
(cl-loop for arg in (list nil 1) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:59,000 --> 00:01:00,000\n"
"Foo.\n\n"
"2\n"
"00:01:00,500 --> 00:01:05,000\n"
"Bar.\n"))
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(expect (subed-insert-subtitle-adjacent arg) :to-equal 71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:59,000
--> 00:01:00,000\n"
@@ -1783,19 +1783,19 @@ Baz.
"00:01:00,500
--> 00:01:05,000\n"
"Bar.\n"))
(expect (point) :to-equal 71)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
(it "multiple subtitles."
(cl-loop for arg in (list 2) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:59,000 --> 00:01:00,000\n"
"Foo.\n\n"
"2\n"
"00:01:00,500 --> 00:01:05,000\n"
"Bar.\n"))
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(expect (subed-insert-subtitle-adjacent arg) :to-equal 71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:59,000
--> 00:01:00,000\n"
@@ -1810,22 +1810,22 @@ Baz.
"00:01:00,500
--> 00:01:05,000\n"
"Bar.\n"))
(expect (point) :to-equal 71)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
)
(describe "to prepend"
(describe "between subtitles"
(it "a single subtitle."
(cl-loop for arg in (list '- -1 (list 4)) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:59,000 --> 00:01:00,000\n"
"Foo.\n\n"
"2\n"
"00:01:00,700 --> 00:01:05,000\n"
"Bar.\n"))
- (subed-srt--jump-to-subtitle-text 2)
+ (subed-jump-to-subtitle-text 2)
(expect (subed-insert-subtitle-adjacent arg) :to-equal
71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:59,000
--> 00:01:00,000\n"
@@ -1837,19 +1837,19 @@ Baz.
"00:01:00,700
--> 00:01:05,000\n"
"Bar.\n"))
(expect (point) :to-equal 71)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
(it "multiple subtitles."
(cl-loop for arg in (list -2 (list 16)) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:59,000 --> 00:01:00,000\n"
"Foo.\n\n"
"2\n"
"00:01:00,500 --> 00:01:05,000\n"
"Bar.\n"))
- (subed-srt--jump-to-subtitle-text 2)
+ (subed-jump-to-subtitle-text 2)
(expect (subed-insert-subtitle-adjacent arg) :to-equal
71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:59,000
--> 00:01:00,000\n"
@@ -1864,18 +1864,18 @@ Baz.
"00:01:00,500
--> 00:01:05,000\n"
"Bar.\n"))
(expect (point) :to-equal 71)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
)
(describe "before the first subtitle"
(it "a single subtitle."
(cl-loop for arg in (list '- -1 (list 4)) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:01,000 --> 00:00:02,000\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(expect (subed-insert-subtitle-adjacent arg) :to-equal
33)
(expect (buffer-string) :to-equal (concat "0\n"
"00:00:00,100
--> 00:00:00,900\n"
@@ -1884,16 +1884,16 @@ Baz.
"00:00:01,000
--> 00:00:02,000\n"
"Foo.\n"))
(expect (point) :to-equal 33)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
(it "multiple subtitles."
(cl-loop for arg in (list -2 (list 16)) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:00,800 --> 00:00:03,000\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-text 2)
+ (subed-jump-to-subtitle-text 2)
(expect (subed-insert-subtitle-adjacent arg) :to-equal
33)
(expect (buffer-string) :to-equal (concat "0\n"
"00:00:00,100
--> 00:00:00,350\n"
@@ -1905,8 +1905,8 @@ Baz.
"00:00:00,800
--> 00:00:03,000\n"
"Foo.\n"))
(expect (point) :to-equal 33)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
)
)
)
@@ -1916,14 +1916,14 @@ Baz.
(it "a single subtitle."
(cl-loop for arg in (list '- -1 (list 4)) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:59,000 --> 00:01:00,000\n"
"Foo.\n\n"
"2\n"
"00:01:00,005 --> 00:01:05,000\n"
"Bar.\n"))
- (subed-srt--jump-to-subtitle-text 2)
+ (subed-jump-to-subtitle-text 2)
(expect (subed-insert-subtitle-adjacent arg) :to-equal
71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:59,000
--> 00:01:00,000\n"
@@ -1935,19 +1935,19 @@ Baz.
"00:01:00,005
--> 00:01:05,000\n"
"Bar.\n"))
(expect (point) :to-equal 71)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
(it "multiple subtitles."
(cl-loop for arg in (list -2 (list 16)) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:59,000 --> 00:01:00,000\n"
"Foo.\n\n"
"2\n"
"00:01:00,025 --> 00:01:05,000\n"
"Bar.\n"))
- (subed-srt--jump-to-subtitle-text 2)
+ (subed-jump-to-subtitle-text 2)
(expect (subed-insert-subtitle-adjacent arg) :to-equal
71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:59,000
--> 00:01:00,000\n"
@@ -1962,21 +1962,21 @@ Baz.
"00:01:00,025
--> 00:01:05,000\n"
"Bar.\n"))
(expect (point) :to-equal 71)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
)
(describe "when appending"
(it "a single subtitle."
(cl-loop for arg in (list nil 1) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:59,000 --> 00:01:00,000\n"
"Foo.\n\n"
"2\n"
"00:01:00,099 --> 00:01:05,000\n"
"Bar.\n"))
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(expect (subed-insert-subtitle-adjacent arg) :to-equal
71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:59,000
--> 00:01:00,000\n"
@@ -1988,19 +1988,19 @@ Baz.
"00:01:00,099
--> 00:01:05,000\n"
"Bar.\n"))
(expect (point) :to-equal 71)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
(it "multiple subtitles."
(cl-loop for arg in (list 2) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:59,000 --> 00:01:00,000\n"
"Foo.\n\n"
"2\n"
"00:01:00,075 --> 00:01:05,000\n"
"Bar.\n"))
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(expect (subed-insert-subtitle-adjacent arg) :to-equal
71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:59,000
--> 00:01:00,000\n"
@@ -2015,19 +2015,19 @@ Baz.
"00:01:00,075
--> 00:01:05,000\n"
"Bar.\n"))
(expect (point) :to-equal 71)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
)
)
(describe "before the first subtitle"
(it "a single subtitle."
(cl-loop for arg in (list '- -1 (list 4)) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:00,040 --> 00:00:05,000\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(expect (subed-insert-subtitle-adjacent arg) :to-equal 33)
(expect (buffer-string) :to-equal (concat "0\n"
"00:00:00,040
--> 00:00:00,040\n"
@@ -2036,16 +2036,16 @@ Baz.
"00:00:00,040
--> 00:00:05,000\n"
"Foo.\n"))
(expect (point) :to-equal 33)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
(it "multiple subtitles."
(cl-loop for arg in (list -2 (list 16)) do
(with-temp-srt-buffer
- (spy-on 'subed-regenerate-ids-soon)
+ (spy-on 'subed-srt--regenerate-ids-soon)
(insert (concat "1\n"
"00:00:00,024 --> 00:00:05,000\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(expect (subed-insert-subtitle-adjacent arg) :to-equal 33)
(expect (buffer-string) :to-equal (concat "0\n"
"00:00:00,024
--> 00:00:00,024\n"
@@ -2057,8 +2057,8 @@ Baz.
"00:00:00,024
--> 00:00:05,000\n"
"Foo.\n"))
(expect (point) :to-equal 33)
- (expect 'subed-regenerate-ids-soon
:to-have-been-called-times 1)
- (spy-calls-reset 'subed-regenerate-ids-soon))))
+ (expect 'subed-srt--regenerate-ids-soon
:to-have-been-called-times 1)
+ (spy-calls-reset 'subed-srt--regenerate-ids-soon))))
)
)
)
@@ -2079,15 +2079,17 @@ Baz.
(subed--sync-player-to-point)
(expect 'subed-mpv-jump :not :to-have-been-called))
(it "seeks player if point is on future subtitle."
- (subed-srt--init)
- (setq subed-mpv-playback-position 6501)
- (subed--sync-player-to-point)
- (expect 'subed-mpv-jump :to-have-been-called-with 5000))
+ (with-temp-buffer
+ (subed-srt-mode)
+ (setq subed-mpv-playback-position 6501)
+ (subed--sync-player-to-point)
+ (expect 'subed-mpv-jump :to-have-been-called-with 5000)))
(it "seeks player if point is on past subtitle."
- (subed-srt--init)
- (setq subed-mpv-playback-position 4999)
- (subed--sync-player-to-point)
- (expect 'subed-mpv-jump :to-have-been-called-with 5000))
+ (with-temp-buffer
+ (subed-srt-mode)
+ (setq subed-mpv-playback-position 4999)
+ (subed--sync-player-to-point)
+ (expect 'subed-mpv-jump :to-have-been-called-with 5000)))
)
(describe "Temporarily disabling point-to-player syncing"
@@ -2184,7 +2186,7 @@ that has two lines.
(goto-char (match-end 0))
(subed-split-subtitle 100)
(expect (subed-subtitle-text 1) :to-equal "This is a")
- (subed-regenerate-ids)
+ (subed-srt--regenerate-ids)
(expect (subed-subtitle-text 2) :to-equal "subtitle\nthat has two
lines.")))
(it "properly splits text when called at the end of a line in the middle
of the subtitle"
(with-temp-srt-buffer
@@ -2193,7 +2195,7 @@ that has two lines.
(goto-char (match-end 0))
(subed-split-subtitle 100)
(expect (subed-subtitle-text 1) :to-equal "This is a subtitle")
- (subed-regenerate-ids)
+ (subed-srt--regenerate-ids)
(expect (subed-subtitle-text 2) :to-equal "that has two lines.")))
(it "properly splits text when called at the beginning of a line in the
middle of the subtitle."
(with-temp-srt-buffer
@@ -2209,7 +2211,7 @@ This is a subtitle
00:01:23,200 --> 00:02:34,567
that has two lines.
") (expect (subed-subtitle-text 1) :to-equal "This is a subtitle")
- (subed-regenerate-ids)
+ (subed-srt--regenerate-ids)
(expect (subed-subtitle-text 2) :to-equal "that has two lines.")))
(it "properly splits text when called at the end of the subtitle."
(with-temp-srt-buffer
@@ -2217,7 +2219,7 @@ that has two lines.
(subed-jump-to-subtitle-end 1)
(subed-split-subtitle 100)
(expect (subed-subtitle-text 1) :to-equal "This is a subtitle\nthat
has two lines.")
- (subed-regenerate-ids)
+ (subed-srt--regenerate-ids)
(expect (subed-subtitle-text 2) :to-equal "")))
(it "properly splits text when called before whitespace at the end of
the subtitle."
(with-temp-srt-buffer
@@ -2226,7 +2228,7 @@ that has two lines.
(save-excursion (insert " "))
(subed-split-subtitle 100)
(expect (subed-subtitle-text 1) :to-equal "This is a subtitle\nthat
has two lines.")
- (subed-regenerate-ids)
+ (subed-srt--regenerate-ids)
(expect (subed-subtitle-text 2) :to-equal ""))))
(describe "with another subtitle after it"
:var ((text "1
@@ -2265,7 +2267,7 @@ This is another.
(backward-word 1)
(subed-split-subtitle 100)
(expect (subed-subtitle-text 1) :to-equal "This is a")
- (subed-regenerate-ids)
+ (subed-srt--regenerate-ids)
(expect (subed-subtitle-text 2) :to-equal "subtitle\nthat has two
lines.")))
(it "properly splits text when called at the end of a line in the middle
of the subtitle"
(with-temp-srt-buffer
@@ -2274,7 +2276,7 @@ This is another.
(goto-char (match-end 0))
(subed-split-subtitle 100)
(expect (subed-subtitle-text 1) :to-equal "This is a subtitle")
- (subed-regenerate-ids)
+ (subed-srt--regenerate-ids)
(expect (subed-subtitle-text 2) :to-equal "that has two lines.")))
(it "properly splits text when called at the beginning of a line in the
middle of the subtitle."
(with-temp-srt-buffer
@@ -2294,7 +2296,7 @@ that has two lines.
00:05:00,000 --> 00:06:00,000
This is another.
") (expect (subed-subtitle-text 1) :to-equal "This is a subtitle")
- (subed-regenerate-ids)
+ (subed-srt--regenerate-ids)
(expect (subed-subtitle-text 2) :to-equal "that has two lines.")))
(it "properly splits text when called at the end of the subtitle."
(with-temp-srt-buffer
@@ -2302,7 +2304,7 @@ This is another.
(subed-jump-to-subtitle-end 1)
(subed-split-subtitle 100)
(expect (subed-subtitle-text 1) :to-equal "This is a subtitle\nthat
has two lines.")
- (subed-regenerate-ids)
+ (subed-srt--regenerate-ids)
(expect (subed-subtitle-text 2) :to-equal "")))
(it "properly splits text when called before whitespace at the end of
the subtitle."
(with-temp-srt-buffer
@@ -2311,7 +2313,7 @@ This is another.
(save-excursion (insert " "))
(subed-split-subtitle 100)
(expect (subed-subtitle-text 1) :to-equal "This is a subtitle\nthat
has two lines.")
- (subed-regenerate-ids)
+ (subed-srt--regenerate-ids)
(expect (subed-subtitle-text 2) :to-equal "")))))
(describe "when playing the video in MPV"
(it "splits at point in the middle of the subtitle."
diff --git a/tests/test-subed-srt.el b/tests/test-subed-srt.el
index a272af833d..acf1496a23 100644
--- a/tests/test-subed-srt.el
+++ b/tests/test-subed-srt.el
@@ -18,7 +18,7 @@ Baz.
")
(defmacro with-temp-srt-buffer (&rest body)
- "Call `subed-srt--init' in temporary buffer before running BODY."
+ "Initialize buffer to `subed-srt-mode' and run BODY."
`(with-temp-buffer
(subed-srt-mode)
(progn ,@body)))
@@ -28,172 +28,172 @@ Baz.
(it "returns the subtitle ID if it can be found."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-text 2)
- (expect (subed-srt--subtitle-id) :to-equal 2)))
+ (subed-jump-to-subtitle-text 2)
+ (expect (subed-subtitle-id) :to-equal 2)))
(it "returns nil if no subtitle ID can be found."
(with-temp-srt-buffer
- (expect (subed-srt--subtitle-id) :to-equal nil)))
+ (expect (subed-subtitle-id) :to-equal nil)))
)
(describe "the subtitle ID at playback time"
(it "returns subtitle ID if time is equal to start time."
(with-temp-srt-buffer
(insert mock-srt-data)
(cl-loop for target-id from 1 to 3 do
- (let ((msecs (subed-srt--subtitle-msecs-start target-id)))
+ (let ((msecs (subed-subtitle-msecs-start target-id)))
(cl-loop for outset-id from 1 to 3 do
(progn
- (subed-srt--jump-to-subtitle-id outset-id)
- (expect (subed-srt--subtitle-id-at-msecs msecs)
:to-equal target-id)))))))
+ (subed-jump-to-subtitle-id outset-id)
+ (expect (subed-subtitle-id-at-msecs msecs)
:to-equal target-id)))))))
(it "returns subtitle ID if time is equal to stop time."
(with-temp-srt-buffer
(insert mock-srt-data)
(cl-loop for target-id from 1 to 3 do
- (let ((msecs (subed-srt--subtitle-msecs-stop target-id)))
+ (let ((msecs (subed-subtitle-msecs-stop target-id)))
(cl-loop for outset-id from 1 to 3 do
(progn
- (subed-srt--jump-to-subtitle-id outset-id)
- (expect (subed-srt--subtitle-id-at-msecs msecs)
:to-equal target-id)))))))
+ (subed-jump-to-subtitle-id outset-id)
+ (expect (subed-subtitle-id-at-msecs msecs)
:to-equal target-id)))))))
(it "returns subtitle ID if time is between start and stop time."
(with-temp-srt-buffer
(insert mock-srt-data)
(cl-loop for target-id from 1 to 3 do
- (let ((msecs (+ 1 (subed-srt--subtitle-msecs-start
target-id))))
+ (let ((msecs (+ 1 (subed-subtitle-msecs-start target-id))))
(cl-loop for outset-id from 1 to 3 do
(progn
- (subed-srt--jump-to-subtitle-id outset-id)
- (expect (subed-srt--subtitle-id-at-msecs msecs)
:to-equal target-id)))))))
+ (subed-jump-to-subtitle-id outset-id)
+ (expect (subed-subtitle-id-at-msecs msecs)
:to-equal target-id)))))))
(it "returns nil if time is before the first subtitle's start time."
(with-temp-srt-buffer
(insert mock-srt-data)
(let ((msecs (- (save-excursion
(goto-char (point-min))
- (subed-srt--subtitle-msecs-start)) 1)))
+ (subed-subtitle-msecs-start)) 1)))
(cl-loop for outset-id from 1 to 3 do
(progn
- (subed-srt--jump-to-subtitle-id outset-id)
- (expect (subed-srt--subtitle-id-at-msecs msecs) :to-equal
nil))))))
+ (subed-jump-to-subtitle-id outset-id)
+ (expect (subed-subtitle-id-at-msecs msecs) :to-equal
nil))))))
(it "returns nil if time is after the last subtitle's start time."
(with-temp-srt-buffer
(insert mock-srt-data)
(let ((msecs (+ (save-excursion
(goto-char (point-max))
- (subed-srt--subtitle-msecs-stop)) 1)))
+ (subed-subtitle-msecs-stop)) 1)))
(cl-loop for outset-id from 1 to 3 do
(progn
- (subed-srt--jump-to-subtitle-id outset-id)
- (expect (subed-srt--subtitle-id-at-msecs msecs) :to-equal
nil))))))
+ (subed-jump-to-subtitle-id outset-id)
+ (expect (subed-subtitle-id-at-msecs msecs) :to-equal
nil))))))
(it "returns nil if time is between subtitles."
(with-temp-srt-buffer
(insert mock-srt-data)
(cl-loop for target-id from 1 to 2 do
- (let ((msecs (+ (subed-srt--subtitle-msecs-stop target-id)
1)))
+ (let ((msecs (+ (subed-subtitle-msecs-stop target-id) 1)))
(cl-loop for outset-id from 1 to 3 do
(progn
- (subed-srt--jump-to-subtitle-id outset-id)
- (expect (subed-srt--subtitle-id-at-msecs msecs)
:to-equal nil))))
- (let ((msecs (- (subed-srt--subtitle-msecs-start (+ target-id
1)) 1)))
+ (subed-jump-to-subtitle-id outset-id)
+ (expect (subed-subtitle-id-at-msecs msecs)
:to-equal nil))))
+ (let ((msecs (- (subed-subtitle-msecs-start (+ target-id 1))
1)))
(cl-loop for outset-id from 1 to 3 do
(progn
- (subed-srt--jump-to-subtitle-id outset-id)
- (expect (subed-srt--subtitle-id-at-msecs msecs)
:to-equal nil)))))))
+ (subed-jump-to-subtitle-id outset-id)
+ (expect (subed-subtitle-id-at-msecs msecs)
:to-equal nil)))))))
(it "doesn't fail if start time is invalid."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-id 2)
- (let ((msecs (- (subed-srt--subtitle-msecs-start) 1)))
- (subed-srt--jump-to-subtitle-time-start)
+ (subed-jump-to-subtitle-id 2)
+ (let ((msecs (- (subed-subtitle-msecs-start) 1)))
+ (subed-jump-to-subtitle-time-start)
(forward-char 8) (delete-char 1)
- (expect (subed-srt--subtitle-id-at-msecs msecs) :to-equal 2))))
+ (expect (subed-subtitle-id-at-msecs msecs) :to-equal 2))))
)
(describe "the subtitle start/stop time"
(it "returns the time in milliseconds."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-text 2)
- (expect (subed-srt--subtitle-msecs-start) :to-equal (+ (* 2 60000) (*
2 1000) 234))
- (expect (subed-srt--subtitle-msecs-stop) :to-equal (+ (* 2 60000) (*
10 1000) 345))))
+ (subed-jump-to-subtitle-text 2)
+ (expect (subed-subtitle-msecs-start) :to-equal (+ (* 2 60000) (* 2
1000) 234))
+ (expect (subed-subtitle-msecs-stop) :to-equal (+ (* 2 60000) (* 10
1000) 345))))
(it "handles lack of digits in milliseconds gracefully."
(with-temp-srt-buffer
(insert mock-srt-data)
(subed-jump-to-subtitle-id 3)
(expect (save-excursion (subed-jump-to-subtitle-time-start)
(thing-at-point 'line)) :to-equal "00:03:03,45
--> 00:03:15,5\n")
- (expect (subed-srt--subtitle-msecs-start) :to-equal (+ (* 3 60 1000)
(* 3 1000) 450))
- (expect (subed-srt--subtitle-msecs-stop) :to-equal (+ (* 3 60 1000)
(* 15 1000) 500))))
+ (expect (subed-subtitle-msecs-start) :to-equal (+ (* 3 60 1000) (* 3
1000) 450))
+ (expect (subed-subtitle-msecs-stop) :to-equal (+ (* 3 60 1000) (* 15
1000) 500))))
(it "returns nil if time can't be found."
(with-temp-srt-buffer
- (expect (subed-srt--subtitle-msecs-start) :to-be nil)
- (expect (subed-srt--subtitle-msecs-stop) :to-be nil)))
+ (expect (subed-subtitle-msecs-start) :to-be nil)
+ (expect (subed-subtitle-msecs-stop) :to-be nil)))
)
(describe "the subtitle text"
(describe "when text is empty"
(it "and at the beginning with a trailing newline."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(kill-line)
- (expect (subed-srt--subtitle-text) :to-equal "")))
+ (expect (subed-subtitle-text) :to-equal "")))
(it "and at the beginning without a trailing newline."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(kill-whole-line)
- (expect (subed-srt--subtitle-text) :to-equal "")))
+ (expect (subed-subtitle-text) :to-equal "")))
(it "and in the middle."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-text 2)
+ (subed-jump-to-subtitle-text 2)
(kill-line)
- (expect (subed-srt--subtitle-text) :to-equal "")))
+ (expect (subed-subtitle-text) :to-equal "")))
(it "and at the end with a trailing newline."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-text 3)
+ (subed-jump-to-subtitle-text 3)
(kill-line)
- (expect (subed-srt--subtitle-text) :to-equal "")))
+ (expect (subed-subtitle-text) :to-equal "")))
(it "and at the end without a trailing newline."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-text 3)
+ (subed-jump-to-subtitle-text 3)
(kill-whole-line)
- (expect (subed-srt--subtitle-text) :to-equal "")))
+ (expect (subed-subtitle-text) :to-equal "")))
)
(describe "when text is not empty"
(it "and has no linebreaks."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-text 2)
- (expect (subed-srt--subtitle-text) :to-equal "Bar.")))
+ (subed-jump-to-subtitle-text 2)
+ (expect (subed-subtitle-text) :to-equal "Bar.")))
(it "and has linebreaks."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-text 2)
+ (subed-jump-to-subtitle-text 2)
(insert "Bar.\n")
- (expect (subed-srt--subtitle-text) :to-equal "Bar.\nBar.")))
+ (expect (subed-subtitle-text) :to-equal "Bar.\nBar.")))
)
)
(describe "the point within the subtitle"
(it "returns the relative point if we can find an ID."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-id 2)
- (expect (subed-srt--subtitle-relative-point) :to-equal 0)
+ (subed-jump-to-subtitle-id 2)
+ (expect (subed-subtitle-relative-point) :to-equal 0)
(forward-line)
- (expect (subed-srt--subtitle-relative-point) :to-equal 2)
+ (expect (subed-subtitle-relative-point) :to-equal 2)
(forward-line)
- (expect (subed-srt--subtitle-relative-point) :to-equal 32)
+ (expect (subed-subtitle-relative-point) :to-equal 32)
(forward-char)
- (expect (subed-srt--subtitle-relative-point) :to-equal 33)
+ (expect (subed-subtitle-relative-point) :to-equal 33)
(forward-line)
- (expect (subed-srt--subtitle-relative-point) :to-equal 37)
+ (expect (subed-subtitle-relative-point) :to-equal 37)
(forward-line)
- (expect (subed-srt--subtitle-relative-point) :to-equal 0)))
+ (expect (subed-subtitle-relative-point) :to-equal 0)))
(it "returns nil if we can't find an ID."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-id 1)
+ (subed-jump-to-subtitle-id 1)
(insert "foo")
- (expect (subed-srt--subtitle-relative-point) :to-equal nil)))
+ (expect (subed-subtitle-relative-point) :to-equal nil)))
)
)
@@ -204,21 +204,21 @@ Baz.
(insert mock-srt-data)
(goto-char (point-min))
(expect (thing-at-point 'word) :to-equal "1")
- (expect (subed-srt--jump-to-subtitle-id) :to-equal 1)
+ (expect (subed-jump-to-subtitle-id) :to-equal 1)
(expect (thing-at-point 'word) :to-equal "1")))
(it "returns ID's point when point is on the duration."
(with-temp-srt-buffer
(insert mock-srt-data)
(search-backward ",234")
(expect (thing-at-point 'word) :to-equal "02")
- (expect (subed-srt--jump-to-subtitle-id) :to-equal 39)
+ (expect (subed-jump-to-subtitle-id) :to-equal 39)
(expect (thing-at-point 'word) :to-equal "2")))
(it "returns ID's point when point is on the text."
(with-temp-srt-buffer
(insert mock-srt-data)
(search-backward "Baz.")
(expect (thing-at-point 'word) :to-equal "Baz")
- (expect (subed-srt--jump-to-subtitle-id) :to-equal 77)
+ (expect (subed-jump-to-subtitle-id) :to-equal 77)
(expect (thing-at-point 'word) :to-equal "3")))
(it "returns ID's point when point is between subtitles."
(with-temp-srt-buffer
@@ -226,18 +226,18 @@ Baz.
(goto-char (point-min))
(search-forward "Bar.\n")
(expect (thing-at-point 'line) :to-equal "\n")
- (expect (subed-srt--jump-to-subtitle-id) :to-equal 39)
+ (expect (subed-jump-to-subtitle-id) :to-equal 39)
(expect (thing-at-point 'word) :to-equal "2")))
(it "returns nil if buffer is empty."
(with-temp-srt-buffer
(expect (buffer-string) :to-equal "")
- (expect (subed-srt--jump-to-subtitle-id) :to-equal nil)))
+ (expect (subed-jump-to-subtitle-id) :to-equal nil)))
(it "returns ID's point when buffer starts with blank lines."
(with-temp-srt-buffer
(insert (concat " \n \t \n" mock-srt-data))
(search-backward "Foo.")
(expect (thing-at-point 'line) :to-equal "Foo.\n")
- (expect (subed-srt--jump-to-subtitle-id) :to-equal 7)
+ (expect (subed-jump-to-subtitle-id) :to-equal 7)
(expect (thing-at-point 'word) :to-equal "1")))
(it "returns ID's point when subtitles are separated with blank lines."
(with-temp-srt-buffer
@@ -245,7 +245,7 @@ Baz.
(goto-char (point-min))
(search-forward "Foo.\n")
(insert " \n \t \n")
- (expect (subed-srt--jump-to-subtitle-id) :to-equal 1)
+ (expect (subed-jump-to-subtitle-id) :to-equal 1)
(expect (thing-at-point 'word) :to-equal "1")))
)
(describe "to specific subtitle ID"
@@ -253,11 +253,11 @@ Baz.
(with-temp-srt-buffer
(insert mock-srt-data)
(goto-char (point-max))
- (expect (subed-srt--jump-to-subtitle-id 2) :to-equal 39)
+ (expect (subed-jump-to-subtitle-id 2) :to-equal 39)
(expect (thing-at-point 'word) :to-equal "2")
- (expect (subed-srt--jump-to-subtitle-id 1) :to-equal 1)
+ (expect (subed-jump-to-subtitle-id 1) :to-equal 1)
(expect (thing-at-point 'word) :to-equal "1")
- (expect (subed-srt--jump-to-subtitle-id 3) :to-equal 77)
+ (expect (subed-jump-to-subtitle-id 3) :to-equal 77)
(expect (thing-at-point 'word) :to-equal "3")))
(it "returns nil and does not move if wanted ID does not exists."
(with-temp-srt-buffer
@@ -265,7 +265,7 @@ Baz.
(goto-char (point-min))
(search-forward "Foo")
(let ((stored-point (point)))
- (expect (subed-srt--jump-to-subtitle-id 4) :to-equal nil)
+ (expect (subed-jump-to-subtitle-id 4) :to-equal nil)
(expect stored-point :to-equal (point)))))
)
(describe "to subtitle ID at specific time"
@@ -273,348 +273,348 @@ Baz.
(with-temp-srt-buffer
(insert mock-srt-data)
(goto-char (point-max))
- (spy-on 'subed-srt--subtitle-id-at-msecs :and-return-value (point-min))
- (expect (subed-srt--jump-to-subtitle-id-at-msecs 123450) :to-equal
(point-min))
+ (spy-on 'subed-subtitle-id-at-msecs :and-return-value (point-min))
+ (expect (subed-jump-to-subtitle-id-at-msecs 123450) :to-equal
(point-min))
(expect (point) :to-equal (point-min))
- (expect 'subed-srt--subtitle-id-at-msecs :to-have-been-called-with
123450)
- (expect 'subed-srt--subtitle-id-at-msecs :to-have-been-called-times
1)))
+ (expect 'subed-subtitle-id-at-msecs :to-have-been-called-with 123450)
+ (expect 'subed-subtitle-id-at-msecs :to-have-been-called-times 1)))
(it "returns nil if point didn't change."
(with-temp-srt-buffer
(insert mock-srt-data)
(goto-char 75)
- (spy-on 'subed-srt--subtitle-id-at-msecs :and-return-value 75)
- (expect (subed-srt--jump-to-subtitle-id-at-msecs 123450) :to-equal nil)
+ (spy-on 'subed-subtitle-id-at-msecs :and-return-value 75)
+ (expect (subed-jump-to-subtitle-id-at-msecs 123450) :to-equal nil)
(expect (point) :to-equal 75)
- (expect 'subed-srt--subtitle-id-at-msecs :to-have-been-called-with
123450)
- (expect 'subed-srt--subtitle-id-at-msecs :to-have-been-called-times
1)))
+ (expect 'subed-subtitle-id-at-msecs :to-have-been-called-with 123450)
+ (expect 'subed-subtitle-id-at-msecs :to-have-been-called-times 1)))
)
(describe "to subtitle start time"
(it "returns start time's point if movement was successful."
(with-temp-srt-buffer
(insert mock-srt-data)
(goto-char (point-min))
- (expect (subed-srt--jump-to-subtitle-time-start) :to-equal 3)
- (expect (looking-at subed-srt--regexp-timestamp) :to-be t)
+ (expect (subed-jump-to-subtitle-time-start) :to-equal 3)
+ (expect (looking-at subed--regexp-timestamp) :to-be t)
(expect (match-string 0) :to-equal "00:01:01,000")
(re-search-forward "\n\n")
- (expect (subed-srt--jump-to-subtitle-time-start) :to-equal 41)
- (expect (looking-at subed-srt--regexp-timestamp) :to-be t)
+ (expect (subed-jump-to-subtitle-time-start) :to-equal 41)
+ (expect (looking-at subed--regexp-timestamp) :to-be t)
(expect (match-string 0) :to-equal "00:02:02,234")
(re-search-forward "\n\n")
- (expect (subed-srt--jump-to-subtitle-time-start) :to-equal 79)
- (expect (looking-at subed-srt--regexp-timestamp) :to-be t)
+ (expect (subed-jump-to-subtitle-time-start) :to-equal 79)
+ (expect (looking-at subed--regexp-timestamp) :to-be t)
(expect (match-string 0) :to-equal "00:03:03,45")))
(it "returns nil if movement failed."
(with-temp-srt-buffer
- (expect (subed-srt--jump-to-subtitle-time-start) :to-equal nil)))
+ (expect (subed-jump-to-subtitle-time-start) :to-equal nil)))
)
(describe "to subtitle stop time"
(it "returns stop time's point if movement was successful."
(with-temp-srt-buffer
(insert mock-srt-data)
(goto-char (point-min))
- (expect (subed-srt--jump-to-subtitle-time-stop) :to-equal 20)
- (expect (looking-at subed-srt--regexp-timestamp) :to-be t)
+ (expect (subed-jump-to-subtitle-time-stop) :to-equal 20)
+ (expect (looking-at subed--regexp-timestamp) :to-be t)
(expect (match-string 0) :to-equal "00:01:05,123")
(re-search-forward "\n\n")
- (expect (subed-srt--jump-to-subtitle-time-stop) :to-equal 58)
- (expect (looking-at subed-srt--regexp-timestamp) :to-be t)
+ (expect (subed-jump-to-subtitle-time-stop) :to-equal 58)
+ (expect (looking-at subed--regexp-timestamp) :to-be t)
(expect (match-string 0) :to-equal "00:02:10,345")
(re-search-forward "\n\n")
- (expect (subed-srt--jump-to-subtitle-time-stop) :to-equal 95)
- (expect (looking-at subed-srt--regexp-timestamp) :to-be t)
+ (expect (subed-jump-to-subtitle-time-stop) :to-equal 95)
+ (expect (looking-at subed--regexp-timestamp) :to-be t)
(expect (match-string 0) :to-equal "00:03:15,5")))
(it "returns nil if movement failed."
(with-temp-srt-buffer
- (expect (subed-srt--jump-to-subtitle-time-stop) :to-equal nil)))
+ (expect (subed-jump-to-subtitle-time-stop) :to-equal nil)))
)
(describe "to subtitle text"
(it "returns subtitle text's point if movement was successful."
(with-temp-srt-buffer
(insert mock-srt-data)
(goto-char (point-min))
- (expect (subed-srt--jump-to-subtitle-text) :to-equal 33)
+ (expect (subed-jump-to-subtitle-text) :to-equal 33)
(expect (point) :to-equal (save-excursion (goto-char (point-max))
(search-backward "Foo.")))
(re-search-forward "\n\n")
- (expect (subed-srt--jump-to-subtitle-text) :to-equal 71)
+ (expect (subed-jump-to-subtitle-text) :to-equal 71)
(expect (point) :to-equal (save-excursion (goto-char (point-max))
(search-backward "Bar.")))
(re-search-forward "\n\n")
- (expect (subed-srt--jump-to-subtitle-text) :to-equal 106)
+ (expect (subed-jump-to-subtitle-text) :to-equal 106)
(expect (point) :to-equal (save-excursion (goto-char (point-max))
(search-backward "Baz.")))))
(it "returns nil if movement failed."
(with-temp-srt-buffer
- (expect (subed-srt--jump-to-subtitle-time-stop) :to-equal nil)))
+ (expect (subed-jump-to-subtitle-time-stop) :to-equal nil)))
)
(describe "to end of subtitle text"
(it "returns point if subtitle end can be found."
(with-temp-srt-buffer
(insert mock-srt-data)
(goto-char (point-min))
- (expect (subed-srt--jump-to-subtitle-end) :to-be 37)
+ (expect (subed-jump-to-subtitle-end) :to-be 37)
(expect (looking-back "^Foo.$") :to-be t)
(forward-char 2)
- (expect (subed-srt--jump-to-subtitle-end) :to-be 75)
+ (expect (subed-jump-to-subtitle-end) :to-be 75)
(expect (looking-back "^Bar.$") :to-be t)
(forward-char 2)
- (expect (subed-srt--jump-to-subtitle-end) :to-be 110)
+ (expect (subed-jump-to-subtitle-end) :to-be 110)
(expect (looking-back "^Baz.$") :to-be t)
(goto-char (point-max))
(backward-char 2)
- (expect (subed-srt--jump-to-subtitle-end) :to-be 110)
+ (expect (subed-jump-to-subtitle-end) :to-be 110)
(expect (looking-back "^Baz.$") :to-be t)))
(it "returns nil if subtitle end cannot be found."
(with-temp-srt-buffer
- (expect (subed-srt--jump-to-subtitle-end) :to-be nil)))
+ (expect (subed-jump-to-subtitle-end) :to-be nil)))
(it "returns nil if point did not move."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(kill-line)
- (expect (subed-srt--jump-to-subtitle-end) :to-be nil)))
+ (expect (subed-jump-to-subtitle-end) :to-be nil)))
(it "works if text is empty with trailing newline."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(kill-line)
(backward-char)
- (expect (subed-srt--jump-to-subtitle-end) :to-be 33)
+ (expect (subed-jump-to-subtitle-end) :to-be 33)
(expect (looking-at "^$") :to-be t)
- (subed-srt--jump-to-subtitle-text 2)
+ (subed-jump-to-subtitle-text 2)
(kill-line)
(backward-char)
- (expect (subed-srt--jump-to-subtitle-end) :to-be 67)
+ (expect (subed-jump-to-subtitle-end) :to-be 67)
(expect (looking-at "^$") :to-be t)
- (subed-srt--jump-to-subtitle-text 3)
+ (subed-jump-to-subtitle-text 3)
(kill-line)
(backward-char)
- (expect (subed-srt--jump-to-subtitle-end) :to-be 98)
+ (expect (subed-jump-to-subtitle-end) :to-be 98)
(expect (looking-at "^$") :to-be t)))
(it "works if text is empty without trailing newline."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(kill-whole-line)
- (expect (subed-srt--jump-to-subtitle-end) :to-be nil)
+ (expect (subed-jump-to-subtitle-end) :to-be nil)
(expect (looking-at "^$") :to-be t)
(goto-char (point-min))
- (expect (subed-srt--jump-to-subtitle-end) :to-be 33)
+ (expect (subed-jump-to-subtitle-end) :to-be 33)
(expect (looking-at "^$") :to-be t)
- (subed-srt--jump-to-subtitle-text 2)
+ (subed-jump-to-subtitle-text 2)
(kill-whole-line)
- (expect (subed-srt--jump-to-subtitle-end) :to-be nil)
+ (expect (subed-jump-to-subtitle-end) :to-be nil)
(expect (looking-at "^$") :to-be t)
(backward-char)
- (expect (subed-srt--jump-to-subtitle-end) :to-be 66)
+ (expect (subed-jump-to-subtitle-end) :to-be 66)
(expect (looking-at "^$") :to-be t)
- (subed-srt--jump-to-subtitle-text 3)
+ (subed-jump-to-subtitle-text 3)
(kill-whole-line)
- (expect (subed-srt--jump-to-subtitle-end) :to-be nil)
+ (expect (subed-jump-to-subtitle-end) :to-be nil)
(expect (looking-at "^$") :to-be t)
(backward-char)
- (expect (subed-srt--jump-to-subtitle-end) :to-be 96)
+ (expect (subed-jump-to-subtitle-end) :to-be 96)
(expect (looking-at "^$") :to-be t)))
)
(describe "to next subtitle ID"
(it "returns point when there is a next subtitle."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-id 1)
+ (subed-jump-to-subtitle-id 1)
(expect (thing-at-point 'word) :to-equal "1")
- (expect (subed-srt--forward-subtitle-id) :to-be 39)
+ (expect (subed-forward-subtitle-id) :to-be 39)
(expect (thing-at-point 'word) :to-equal "2")
- (subed-srt--jump-to-subtitle-time-start 2)
+ (subed-jump-to-subtitle-time-start 2)
(expect (thing-at-point 'word) :to-equal "00")
- (expect (subed-srt--forward-subtitle-id) :to-be 77)
+ (expect (subed-forward-subtitle-id) :to-be 77)
(expect (thing-at-point 'word) :to-equal "3")))
(it "returns nil and doesn't move when there is no next subtitle."
(with-temp-srt-buffer
(expect (thing-at-point 'word) :to-equal nil)
- (expect (subed-srt--forward-subtitle-id) :to-be nil))
+ (expect (subed-forward-subtitle-id) :to-be nil))
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(expect (thing-at-point 'word) :to-equal "Foo")
- (expect (subed-srt--forward-subtitle-id) :to-be 39)
+ (expect (subed-forward-subtitle-id) :to-be 39)
(expect (thing-at-point 'word) :to-equal "2")
- (subed-srt--jump-to-subtitle-time-stop 2)
+ (subed-jump-to-subtitle-time-stop 2)
(expect (thing-at-point 'word) :to-equal "00")
- (expect (subed-srt--forward-subtitle-id) :to-be 77)
+ (expect (subed-forward-subtitle-id) :to-be 77)
(expect (thing-at-point 'word) :to-equal "3"))
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-text 3)
+ (subed-jump-to-subtitle-text 3)
(expect (thing-at-point 'word) :to-equal "Baz")
- (expect (subed-srt--forward-subtitle-id) :to-be nil)
+ (expect (subed-forward-subtitle-id) :to-be nil)
(expect (thing-at-point 'word) :to-equal "Baz"))
(with-temp-srt-buffer
(insert (concat mock-srt-data "\n\n"))
- (subed-srt--jump-to-subtitle-time-stop 3)
+ (subed-jump-to-subtitle-time-stop 3)
(expect (thing-at-point 'word) :to-equal "00")
- (expect (subed-srt--forward-subtitle-id) :to-be nil)
+ (expect (subed-forward-subtitle-id) :to-be nil)
(expect (thing-at-point 'word) :to-equal "00")))
)
(describe "to previous subtitle ID"
(it "returns point when there is a previous subtitle."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-text 2)
+ (subed-jump-to-subtitle-text 2)
(expect (thing-at-point 'word) :to-equal "Bar")
- (expect (subed-srt--backward-subtitle-id) :to-be 1)
+ (expect (subed-backward-subtitle-id) :to-be 1)
(expect (thing-at-point 'word) :to-equal "1")
- (subed-srt--jump-to-subtitle-time-stop 3)
+ (subed-jump-to-subtitle-time-stop 3)
(expect (thing-at-point 'word) :to-equal "00")
- (expect (subed-srt--backward-subtitle-id) :to-be 39)
+ (expect (subed-backward-subtitle-id) :to-be 39)
(expect (thing-at-point 'word) :to-equal "2")))
(it "returns nil and doesn't move when there is no previous subtitle."
(with-temp-srt-buffer
- (expect (subed-srt--backward-subtitle-id) :to-be nil))
+ (expect (subed-backward-subtitle-id) :to-be nil))
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-id 1)
+ (subed-jump-to-subtitle-id 1)
(expect (thing-at-point 'word) :to-equal "1")
- (expect (subed-srt--backward-subtitle-id) :to-be nil)
+ (expect (subed-backward-subtitle-id) :to-be nil)
(expect (thing-at-point 'word) :to-equal "1"))
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(expect (thing-at-point 'word) :to-equal "Foo")
- (expect (subed-srt--backward-subtitle-id) :to-be nil)
+ (expect (subed-backward-subtitle-id) :to-be nil)
(expect (thing-at-point 'word) :to-equal "Foo"))
(with-temp-srt-buffer
(insert (concat "\n\n\n" mock-srt-data))
- (subed-srt--jump-to-subtitle-time-stop 1)
+ (subed-jump-to-subtitle-time-stop 1)
(expect (thing-at-point 'word) :to-equal "00")
- (expect (subed-srt--backward-subtitle-id) :to-be nil)
+ (expect (subed-backward-subtitle-id) :to-be nil)
(expect (thing-at-point 'word) :to-equal "00")))
)
(describe "to next subtitle text"
(it "returns point when there is a next subtitle."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-id 1)
+ (subed-jump-to-subtitle-id 1)
(expect (thing-at-point 'word) :to-equal "1")
- (expect (subed-srt--forward-subtitle-text) :to-be 71)
+ (expect (subed-forward-subtitle-text) :to-be 71)
(expect (thing-at-point 'word) :to-equal "Bar")))
(it "returns nil and doesn't move when there is no next subtitle."
(with-temp-srt-buffer
(goto-char (point-max))
(insert (concat mock-srt-data "\n\n"))
- (subed-srt--jump-to-subtitle-id 3)
+ (subed-jump-to-subtitle-id 3)
(expect (thing-at-point 'word) :to-equal "3")
- (expect (subed-srt--forward-subtitle-text) :to-be nil)
+ (expect (subed-forward-subtitle-text) :to-be nil)
(expect (thing-at-point 'word) :to-equal "3")))
)
(describe "to previous subtitle text"
(it "returns point when there is a previous subtitle."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-id 3)
+ (subed-jump-to-subtitle-id 3)
(expect (thing-at-point 'word) :to-equal "3")
- (expect (subed-srt--backward-subtitle-text) :to-be 71)
+ (expect (subed-backward-subtitle-text) :to-be 71)
(expect (thing-at-point 'word) :to-equal "Bar")))
(it "returns nil and doesn't move when there is no previous subtitle."
(with-temp-srt-buffer
(insert mock-srt-data)
(goto-char (point-min))
(expect (thing-at-point 'word) :to-equal "1")
- (expect (subed-srt--backward-subtitle-text) :to-be nil)
+ (expect (subed-backward-subtitle-text) :to-be nil)
(expect (thing-at-point 'word) :to-equal "1")))
)
(describe "to next subtitle end"
(it "returns point when there is a next subtitle."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-text 2)
+ (subed-jump-to-subtitle-text 2)
(expect (thing-at-point 'word) :to-equal "Bar")
- (expect (subed-srt--forward-subtitle-end) :to-be 110)
+ (expect (subed-forward-subtitle-end) :to-be 110)
(expect (thing-at-point 'word) :to-equal nil)))
(it "returns nil and doesn't move when there is no next subtitle."
(with-temp-srt-buffer
(insert (concat mock-srt-data "\n\n"))
- (subed-srt--jump-to-subtitle-text 3)
+ (subed-jump-to-subtitle-text 3)
(end-of-line)
(expect (thing-at-point 'word) :to-equal nil)
- (expect (subed-srt--forward-subtitle-end) :to-be nil)
+ (expect (subed-forward-subtitle-end) :to-be nil)
(expect (thing-at-point 'word) :to-equal nil)))
)
(describe "to previous subtitle end"
(it "returns point when there is a previous subtitle."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-id 3)
+ (subed-jump-to-subtitle-id 3)
(expect (thing-at-point 'word) :to-equal "3")
- (expect (subed-srt--backward-subtitle-text) :to-be 71)
+ (expect (subed-backward-subtitle-text) :to-be 71)
(expect (thing-at-point 'word) :to-equal "Bar")))
(it "returns nil and doesn't move when there is no previous subtitle."
(with-temp-srt-buffer
(insert mock-srt-data)
(goto-char (point-min))
(expect (thing-at-point 'word) :to-equal "1")
- (expect (subed-srt--backward-subtitle-text) :to-be nil)
+ (expect (subed-backward-subtitle-text) :to-be nil)
(expect (thing-at-point 'word) :to-equal "1")))
)
(describe "to next subtitle start time"
(it "returns point when there is a next subtitle."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(expect (thing-at-point 'word) :to-equal "Foo")
- (expect (subed-srt--forward-subtitle-time-start) :to-be 41)
+ (expect (subed-forward-subtitle-time-start) :to-be 41)
(expect (thing-at-point 'word) :to-equal "00")))
(it "returns nil and doesn't move when there is no next subtitle."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-id 3)
+ (subed-jump-to-subtitle-id 3)
(expect (thing-at-point 'word) :to-equal "3")
- (expect (subed-srt--forward-subtitle-time-start) :to-be nil)
+ (expect (subed-forward-subtitle-time-start) :to-be nil)
(expect (thing-at-point 'word) :to-equal "3")))
)
(describe "to previous subtitle start time"
(it "returns point when there is a previous subtitle."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-id 2)
+ (subed-jump-to-subtitle-id 2)
(expect (thing-at-point 'word) :to-equal "2")
- (expect (subed-srt--backward-subtitle-time-start) :to-be 3)
+ (expect (subed-backward-subtitle-time-start) :to-be 3)
(expect (thing-at-point 'word) :to-equal "00")))
(it "returns nil and doesn't move when there is no previous subtitle."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-id 1)
+ (subed-jump-to-subtitle-id 1)
(expect (thing-at-point 'word) :to-equal "1")
- (expect (subed-srt--backward-subtitle-time-start) :to-be nil)
+ (expect (subed-backward-subtitle-time-start) :to-be nil)
(expect (thing-at-point 'word) :to-equal "1")))
)
(describe "to next subtitle stop time"
(it "returns point when there is a next subtitle."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(expect (thing-at-point 'word) :to-equal "Foo")
- (expect (subed-srt--forward-subtitle-time-stop) :to-be 58)
+ (expect (subed-forward-subtitle-time-stop) :to-be 58)
(expect (thing-at-point 'word) :to-equal "00")))
(it "returns nil and doesn't move when there is no next subtitle."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-id 3)
+ (subed-jump-to-subtitle-id 3)
(expect (thing-at-point 'word) :to-equal "3")
- (expect (subed-srt--forward-subtitle-time-stop) :to-be nil)
+ (expect (subed-forward-subtitle-time-stop) :to-be nil)
(expect (thing-at-point 'word) :to-equal "3")))
)
(describe "to previous subtitle stop time"
(it "returns point when there is a previous subtitle."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-id 3)
+ (subed-jump-to-subtitle-id 3)
(expect (thing-at-point 'word) :to-equal "3")
- (expect (subed-srt--backward-subtitle-time-stop) :to-be 58)
+ (expect (subed-backward-subtitle-time-stop) :to-be 58)
(expect (thing-at-point 'word) :to-equal "00")))
(it "returns nil and doesn't move when there is no previous subtitle."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-id 1)
+ (subed-jump-to-subtitle-id 1)
(expect (thing-at-point 'word) :to-equal "1")
- (expect (subed-srt--backward-subtitle-time-stop) :to-be nil)
+ (expect (subed-backward-subtitle-time-stop) :to-be nil)
(expect (thing-at-point 'word) :to-equal "1")))
)
)
@@ -623,8 +623,8 @@ Baz.
(it "of current subtitle."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-end 2)
- (subed-srt--set-subtitle-time-start (+ (* 1 60 60 1000) (* 2 60 1000) (*
3 1000) 400))
+ (subed-jump-to-subtitle-end 2)
+ (subed-set-subtitle-time-start (+ (* 1 60 60 1000) (* 2 60 1000) (* 3
1000) 400))
(expect (buffer-string) :to-equal (concat "1\n"
"00:01:01,000 -->
00:01:05,123\n"
"Foo.\n\n"
@@ -634,7 +634,7 @@ Baz.
"3\n"
"00:03:03,45 --> 00:03:15,5\n"
"Baz.\n"))
- (subed-srt--set-subtitle-time-stop (+ (* 5 60 60 1000) (* 6 60 1000) (*
7 1000) 800))
+ (subed-set-subtitle-time-stop (+ (* 5 60 60 1000) (* 6 60 1000) (* 7
1000) 800))
(expect (buffer-string) :to-equal (concat "1\n"
"00:01:01,000 -->
00:01:05,123\n"
"Foo.\n\n"
@@ -647,8 +647,8 @@ Baz.
(it "of specific subtitle."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-time-stop 3)
- (subed-srt--set-subtitle-time-start (+ (* 2 60 60 1000) (* 4 60 1000) (*
6 1000) 800) 1)
+ (subed-jump-to-subtitle-time-stop 3)
+ (subed-set-subtitle-time-start (+ (* 2 60 60 1000) (* 4 60 1000) (* 6
1000) 800) 1)
(expect (buffer-string) :to-equal (concat "1\n"
"02:04:06,800 -->
00:01:05,123\n"
"Foo.\n\n"
@@ -658,8 +658,8 @@ Baz.
"3\n"
"00:03:03,45 --> 00:03:15,5\n"
"Baz.\n"))
- (subed-srt--jump-to-subtitle-text 1)
- (subed-srt--set-subtitle-time-stop (+ (* 3 60 60 1000) (* 5 60 1000) (*
7 1000) 900) 3)
+ (subed-jump-to-subtitle-text 1)
+ (subed-set-subtitle-time-stop (+ (* 3 60 60 1000) (* 5 60 1000) (* 7
1000) 900) 3)
(expect (buffer-string) :to-equal (concat "1\n"
"02:04:06,800 -->
00:01:05,123\n"
"Foo.\n\n"
@@ -673,10 +673,10 @@ Baz.
(with-temp-srt-buffer
(insert mock-srt-data)
(subed-jump-to-subtitle-id 3)
- (subed-srt--set-subtitle-time-start (+ (* 1 60 60 1000) (* 2 60 1000) (*
3 1000) 4) 3)
+ (subed-set-subtitle-time-start (+ (* 1 60 60 1000) (* 2 60 1000) (* 3
1000) 4) 3)
(expect (save-excursion (subed-jump-to-subtitle-time-start)
(thing-at-point 'line)) :to-equal "01:02:03,004
--> 00:03:15,5\n")
- (subed-srt--set-subtitle-time-stop (+ (* 2 60 60 1000) (* 3 60 1000) (*
4 1000) 60) 3)
+ (subed-set-subtitle-time-stop (+ (* 2 60 60 1000) (* 3 60 1000) (* 4
1000) 60) 3)
(expect (save-excursion (subed-jump-to-subtitle-time-start)
(thing-at-point 'line)) :to-equal "01:02:03,004
--> 02:03:04,060\n")))
)
@@ -686,31 +686,31 @@ Baz.
(describe "before"
(it "passing nothing."
(with-temp-srt-buffer
- (expect (subed-srt--prepend-subtitle) :to-equal 33)
+ (expect (subed-prepend-subtitle) :to-equal 33)
(expect (buffer-string) :to-equal (concat "0\n"
"00:00:00,000 -->
00:00:01,000\n\n"))
(expect (point) :to-equal 33)))
(it "passing ID."
(with-temp-srt-buffer
- (expect (subed-srt--prepend-subtitle 2) :to-equal 33)
+ (expect (subed-prepend-subtitle 2) :to-equal 33)
(expect (buffer-string) :to-equal (concat "2\n"
"00:00:00,000 -->
00:00:01,000\n\n"))
(expect (point) :to-equal 33)))
(it "passing ID and start time."
(with-temp-srt-buffer
- (expect (subed-srt--prepend-subtitle 3 60000) :to-equal 33)
+ (expect (subed-prepend-subtitle 3 60000) :to-equal 33)
(expect (buffer-string) :to-equal (concat "3\n"
"00:01:00,000 -->
00:01:01,000\n\n"))
(expect (point) :to-equal 33)))
(it "passing ID, start time and stop time."
(with-temp-srt-buffer
- (expect (subed-srt--prepend-subtitle 4 60000 65000) :to-equal 33)
+ (expect (subed-prepend-subtitle 4 60000 65000) :to-equal 33)
(expect (buffer-string) :to-equal (concat "4\n"
"00:01:00,000 -->
00:01:05,000\n\n"))
(expect (point) :to-equal 33)))
(it "passing ID, start time, stop time and text."
(with-temp-srt-buffer
- (expect (subed-srt--prepend-subtitle 5 60000 65000 "Foo, bar\nbaz.")
:to-equal 33)
+ (expect (subed-prepend-subtitle 5 60000 65000 "Foo, bar\nbaz.")
:to-equal 33)
(expect (buffer-string) :to-equal (concat "5\n"
"00:01:00,000 -->
00:01:05,000\n"
"Foo, bar\nbaz.\n"))
@@ -719,31 +719,31 @@ Baz.
(describe "after"
(it "passing nothing."
(with-temp-srt-buffer
- (expect (subed-srt--append-subtitle) :to-equal 33)
+ (expect (subed-append-subtitle) :to-equal 33)
(expect (buffer-string) :to-equal (concat "0\n"
"00:00:00,000 -->
00:00:01,000\n\n"))
(expect (point) :to-equal 33)))
(it "passing ID."
(with-temp-srt-buffer
- (expect (subed-srt--append-subtitle 2) :to-equal 33)
+ (expect (subed-append-subtitle 2) :to-equal 33)
(expect (buffer-string) :to-equal (concat "2\n"
"00:00:00,000 -->
00:00:01,000\n\n"))
(expect (point) :to-equal 33)))
(it "passing ID and start time."
(with-temp-srt-buffer
- (expect (subed-srt--append-subtitle 3 60000) :to-equal 33)
+ (expect (subed-append-subtitle 3 60000) :to-equal 33)
(expect (buffer-string) :to-equal (concat "3\n"
"00:01:00,000 -->
00:01:01,000\n\n"))
(expect (point) :to-equal 33)))
(it "passing ID, start time and stop time."
(with-temp-srt-buffer
- (expect (subed-srt--append-subtitle 4 60000 65000) :to-equal 33)
+ (expect (subed-append-subtitle 4 60000 65000) :to-equal 33)
(expect (buffer-string) :to-equal (concat "4\n"
"00:01:00,000 -->
00:01:05,000\n\n"))
(expect (point) :to-equal 33)))
(it "passing ID, start time, stop time and text."
(with-temp-srt-buffer
- (expect (subed-srt--append-subtitle 5 60000 65000 "Foo, bar\nbaz.")
:to-equal 33)
+ (expect (subed-append-subtitle 5 60000 65000 "Foo, bar\nbaz.")
:to-equal 33)
(expect (buffer-string) :to-equal (concat "5\n"
"00:01:00,000 -->
00:01:05,000\n"
"Foo, bar\nbaz.\n"))
@@ -758,8 +758,8 @@ Baz.
(insert (concat "1\n"
"00:00:05,000 --> 00:00:06,000\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-time-stop)
- (expect (subed-srt--prepend-subtitle) :to-equal 33)
+ (subed-jump-to-subtitle-time-stop)
+ (expect (subed-prepend-subtitle) :to-equal 33)
(expect (buffer-string) :to-equal (concat "0\n"
"00:00:00,000 -->
00:00:01,000\n"
"\n\n"
@@ -772,8 +772,8 @@ Baz.
(insert (concat "1\n"
"00:00:05,000 --> 00:00:06,000\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-time-stop)
- (expect (subed-srt--prepend-subtitle 7) :to-equal 33)
+ (subed-jump-to-subtitle-time-stop)
+ (expect (subed-prepend-subtitle 7) :to-equal 33)
(expect (buffer-string) :to-equal (concat "7\n"
"00:00:00,000 -->
00:00:01,000\n"
"\n\n"
@@ -786,8 +786,8 @@ Baz.
(insert (concat "1\n"
"00:00:05,000 --> 00:00:06,000\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-time-stop)
- (expect (subed-srt--prepend-subtitle 6 1500) :to-equal 33)
+ (subed-jump-to-subtitle-time-stop)
+ (expect (subed-prepend-subtitle 6 1500) :to-equal 33)
(expect (buffer-string) :to-equal (concat "6\n"
"00:00:01,500 -->
00:00:02,500\n"
"\n\n"
@@ -800,8 +800,8 @@ Baz.
(insert (concat "1\n"
"00:00:05,000 --> 00:00:06,000\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-time-stop)
- (expect (subed-srt--prepend-subtitle 5 1500 2000) :to-equal 33)
+ (subed-jump-to-subtitle-time-stop)
+ (expect (subed-prepend-subtitle 5 1500 2000) :to-equal 33)
(expect (buffer-string) :to-equal (concat "5\n"
"00:00:01,500 -->
00:00:02,000\n"
"\n\n"
@@ -814,8 +814,8 @@ Baz.
(insert (concat "1\n"
"00:00:05,000 --> 00:00:06,000\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-time-stop)
- (expect (subed-srt--prepend-subtitle 4 1500 3000 "Bar.") :to-equal
33)
+ (subed-jump-to-subtitle-time-stop)
+ (expect (subed-prepend-subtitle 4 1500 3000 "Bar.") :to-equal 33)
(expect (buffer-string) :to-equal (concat "4\n"
"00:00:01,500 -->
00:00:03,000\n"
"Bar.\n\n"
@@ -833,8 +833,8 @@ Baz.
"2\n"
"00:00:10,000 --> 00:00:12,000\n"
"Bar.\n"))
- (subed-srt--jump-to-subtitle-text 2)
- (expect (subed-srt--prepend-subtitle) :to-equal 71)
+ (subed-jump-to-subtitle-text 2)
+ (expect (subed-prepend-subtitle) :to-equal 71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:05,000 -->
00:00:06,000\n"
"Foo.\n\n"
@@ -853,8 +853,8 @@ Baz.
"2\n"
"00:00:10,000 --> 00:00:12,000\n"
"Bar.\n"))
- (subed-srt--jump-to-subtitle-text 2)
- (expect (subed-srt--prepend-subtitle 9) :to-equal 71)
+ (subed-jump-to-subtitle-text 2)
+ (expect (subed-prepend-subtitle 9) :to-equal 71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:05,000 -->
00:00:06,000\n"
"Foo.\n\n"
@@ -873,8 +873,8 @@ Baz.
"2\n"
"00:00:10,000 --> 00:00:12,000\n"
"Bar.\n"))
- (subed-srt--jump-to-subtitle-text 2)
- (expect (subed-srt--prepend-subtitle 9 7000) :to-equal 71)
+ (subed-jump-to-subtitle-text 2)
+ (expect (subed-prepend-subtitle 9 7000) :to-equal 71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:05,000 -->
00:00:06,000\n"
"Foo.\n\n"
@@ -893,8 +893,8 @@ Baz.
"2\n"
"00:00:10,000 --> 00:00:12,000\n"
"Bar.\n"))
- (subed-srt--jump-to-subtitle-text 2)
- (expect (subed-srt--prepend-subtitle 9 7000 7123) :to-equal 71)
+ (subed-jump-to-subtitle-text 2)
+ (expect (subed-prepend-subtitle 9 7000 7123) :to-equal 71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:05,000 -->
00:00:06,000\n"
"Foo.\n\n"
@@ -913,8 +913,8 @@ Baz.
"2\n"
"00:00:10,000 --> 00:00:12,000\n"
"Bar.\n"))
- (subed-srt--jump-to-subtitle-text 2)
- (expect (subed-srt--prepend-subtitle 9 7000 7123 "Baz.") :to-equal
71)
+ (subed-jump-to-subtitle-text 2)
+ (expect (subed-prepend-subtitle 9 7000 7123 "Baz.") :to-equal 71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:05,000 -->
00:00:06,000\n"
"Foo.\n\n"
@@ -934,8 +934,8 @@ Baz.
(insert (concat "1\n"
"00:00:05,000 --> 00:00:06,000\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-text)
- (expect (subed-srt--append-subtitle) :to-equal 71)
+ (subed-jump-to-subtitle-text)
+ (expect (subed-append-subtitle) :to-equal 71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:05,000 -->
00:00:06,000\n"
"Foo.\n\n"
@@ -948,8 +948,8 @@ Baz.
(insert (concat "1\n"
"00:00:05,000 --> 00:00:06,000\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-text)
- (expect (subed-srt--append-subtitle 5) :to-equal 71)
+ (subed-jump-to-subtitle-text)
+ (expect (subed-append-subtitle 5) :to-equal 71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:05,000 -->
00:00:06,000\n"
"Foo.\n\n"
@@ -962,8 +962,8 @@ Baz.
(insert (concat "1\n"
"00:00:05,000 --> 00:00:06,000\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-text)
- (expect (subed-srt--append-subtitle 5 12345) :to-equal 71)
+ (subed-jump-to-subtitle-text)
+ (expect (subed-append-subtitle 5 12345) :to-equal 71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:05,000 -->
00:00:06,000\n"
"Foo.\n\n"
@@ -976,8 +976,8 @@ Baz.
(insert (concat "1\n"
"00:00:05,000 --> 00:00:06,000\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-text)
- (expect (subed-srt--append-subtitle 5 12345 15000) :to-equal 71)
+ (subed-jump-to-subtitle-text)
+ (expect (subed-append-subtitle 5 12345 15000) :to-equal 71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:05,000 -->
00:00:06,000\n"
"Foo.\n\n"
@@ -990,8 +990,8 @@ Baz.
(insert (concat "1\n"
"00:00:05,000 --> 00:00:06,000\n"
"Foo.\n"))
- (subed-srt--jump-to-subtitle-text)
- (expect (subed-srt--append-subtitle 5 12345 15000 "Bar.")
:to-equal 71)
+ (subed-jump-to-subtitle-text)
+ (expect (subed-append-subtitle 5 12345 15000 "Bar.") :to-equal 71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:05,000 -->
00:00:06,000\n"
"Foo.\n\n"
@@ -1009,8 +1009,8 @@ Baz.
"2\n"
"00:00:05,000 --> 00:00:06,000\n"
"Bar.\n"))
- (subed-srt--jump-to-subtitle-time-start 1)
- (expect (subed-srt--append-subtitle) :to-equal 71)
+ (subed-jump-to-subtitle-time-start 1)
+ (expect (subed-append-subtitle) :to-equal 71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:01,000 -->
00:00:02,000\n"
"Foo.\n\n"
@@ -1029,8 +1029,8 @@ Baz.
"2\n"
"00:00:05,000 --> 00:00:06,000\n"
"Bar.\n"))
- (subed-srt--jump-to-subtitle-time-start 1)
- (expect (subed-srt--append-subtitle 7) :to-equal 71)
+ (subed-jump-to-subtitle-time-start 1)
+ (expect (subed-append-subtitle 7) :to-equal 71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:01,000 -->
00:00:02,000\n"
"Foo.\n\n"
@@ -1049,8 +1049,8 @@ Baz.
"2\n"
"00:00:05,000 --> 00:00:06,000\n"
"Bar.\n"))
- (subed-srt--jump-to-subtitle-time-start 1)
- (expect (subed-srt--append-subtitle 7 2500) :to-equal 71)
+ (subed-jump-to-subtitle-time-start 1)
+ (expect (subed-append-subtitle 7 2500) :to-equal 71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:01,000 -->
00:00:02,000\n"
"Foo.\n\n"
@@ -1069,8 +1069,8 @@ Baz.
"2\n"
"00:00:05,000 --> 00:00:06,000\n"
"Bar.\n"))
- (subed-srt--jump-to-subtitle-time-start 1)
- (expect (subed-srt--append-subtitle 7 2500 4000) :to-equal 71)
+ (subed-jump-to-subtitle-time-start 1)
+ (expect (subed-append-subtitle 7 2500 4000) :to-equal 71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:01,000 -->
00:00:02,000\n"
"Foo.\n\n"
@@ -1089,8 +1089,8 @@ Baz.
"2\n"
"00:00:05,000 --> 00:00:06,000\n"
"Bar.\n"))
- (subed-srt--jump-to-subtitle-time-start 1)
- (expect (subed-srt--append-subtitle 7 2500 4000 "Baz.") :to-equal
71)
+ (subed-jump-to-subtitle-time-start 1)
+ (expect (subed-append-subtitle 7 2500 4000 "Baz.") :to-equal 71)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:01,000 -->
00:00:02,000\n"
"Foo.\n\n"
@@ -1109,7 +1109,7 @@ Baz.
"00:00:01,000 --> 00:00:02,000\n"
"\n"))
(subed-jump-to-subtitle-text)
- (expect (subed-srt--append-subtitle) :to-equal 67)
+ (expect (subed-append-subtitle) :to-equal 67)
(expect (buffer-string) :to-equal (concat "1\n"
"00:00:01,000 -->
00:00:02,000\n"
"\n\n"
@@ -1124,8 +1124,8 @@ Baz.
(it "removes the first subtitle."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-text 1)
- (subed-srt--kill-subtitle)
+ (subed-jump-to-subtitle-text 1)
+ (subed-kill-subtitle)
(expect (buffer-string) :to-equal (concat "2\n"
"00:02:02,234 -->
00:02:10,345\n"
"Bar.\n\n"
@@ -1135,8 +1135,8 @@ Baz.
(it "removes it in between."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-text 2)
- (subed-srt--kill-subtitle)
+ (subed-jump-to-subtitle-text 2)
+ (subed-kill-subtitle)
(expect (buffer-string) :to-equal (concat "1\n"
"00:01:01,000 -->
00:01:05,123\n"
"Foo.\n\n"
@@ -1146,8 +1146,8 @@ Baz.
(it "removes the last subtitle."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-text 3)
- (subed-srt--kill-subtitle)
+ (subed-jump-to-subtitle-text 3)
+ (subed-kill-subtitle)
(expect (buffer-string) :to-equal (concat "1\n"
"00:01:01,000 -->
00:01:05,123\n"
"Foo.\n\n"
@@ -1161,7 +1161,7 @@ Baz.
(subed-jump-to-subtitle-id 3)
(backward-char)
(expect (looking-at "^\n3\n") :to-be t)
- (subed-srt--kill-subtitle)
+ (subed-kill-subtitle)
(expect (buffer-string) :to-equal (concat "1\n"
"00:01:01,000 -->
00:01:05,123\n"
"Foo.\n\n"
@@ -1174,7 +1174,7 @@ Baz.
(subed-jump-to-subtitle-id 2)
(backward-char)
(expect (looking-at "^\n2\n") :to-be t)
- (subed-srt--kill-subtitle)
+ (subed-kill-subtitle)
(expect (buffer-string) :to-equal (concat "2\n"
"00:02:02,234 -->
00:02:10,345\n"
"Bar.\n\n"
@@ -1187,86 +1187,86 @@ Baz.
(describe "Validating"
(it "works in empty buffer."
(with-temp-srt-buffer
- (subed-srt--validate)))
+ (subed-validate)))
(it "works in buffer that contains only newlines."
(with-temp-srt-buffer
(cl-loop for _ from 1 to 10 do
(insert "\n")
- (subed-srt--validate))))
+ (subed-validate))))
(it "works in buffer that contains only spaces."
(with-temp-srt-buffer
(cl-loop for _ from 1 to 10 do
(insert " ")
- (subed-srt--validate))))
+ (subed-validate))))
(it "works in buffer that contains only spaces and newlines."
(with-temp-srt-buffer
(cl-loop for _ from 1 to 10 do
(if (eq (random 2) 0)
(insert " ")
(insert "\n"))
- (subed-srt--validate))))
+ (subed-validate))))
(it "reports invalid IDs."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-id 1)
+ (subed-jump-to-subtitle-id 1)
(insert "x")
- (expect (subed-srt--validate) :to-throw
+ (expect (subed-validate) :to-throw
'error '("Found invalid subtitle ID: \"x1\""))
(expect (point) :to-equal 1)))
(it "reports invalid start time."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-time-start 1)
+ (subed-jump-to-subtitle-time-start 1)
(forward-char 5)
(delete-char 1)
- (expect (subed-srt--validate) :to-throw
+ (expect (subed-validate) :to-throw
'error '("Found invalid start time: \"00:0101,000 -->
00:01:05,123\""))
(expect (point) :to-equal 3)))
(it "reports invalid stop time."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-time-stop 1)
+ (subed-jump-to-subtitle-time-stop 1)
(forward-char 10)
(insert "3")
- (expect (subed-srt--validate) :to-throw
+ (expect (subed-validate) :to-throw
'error '("Found invalid stop time: \"00:01:01,000 -->
00:01:05,1323\""))
(expect (point) :to-equal 20)))
(it "reports invalid time separator."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-time-stop 1)
+ (subed-jump-to-subtitle-time-stop 1)
(delete-char -1)
- (expect (subed-srt--validate) :to-throw
+ (expect (subed-validate) :to-throw
'error '("Found invalid separator between start and stop time:
\"00:01:01,000 -->00:01:05,123\""))
(expect (point) :to-equal 15)))
(it "reports invalid start time in later entries."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-time-start 3)
+ (subed-jump-to-subtitle-time-start 3)
(forward-char 3)
(insert "##")
- (expect (subed-srt--validate) :to-throw
+ (expect (subed-validate) :to-throw
'error '("Found invalid start time: \"00:##03:03,45 -->
00:03:15,5\""))
(expect (point) :to-equal 79)))
(it "does not report error when last subtitle text is empty."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-text 3)
+ (subed-jump-to-subtitle-text 3)
(kill-whole-line)
(forward-char -2)
- (subed-srt--validate)
+ (subed-validate)
(expect (point) :to-equal 104)))
(it "preserves point if there is no error."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-text 2)
+ (subed-jump-to-subtitle-text 2)
(forward-char 2)
- (subed-srt--validate)
+ (subed-validate)
(expect (point) :to-equal 73)))
(it "runs before saving."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-time-start 3)
+ (subed-jump-to-subtitle-time-start 3)
(forward-char 3)
(insert "##")
(expect (subed-prepare-to-save) :to-throw
@@ -1281,7 +1281,7 @@ Baz.
(while (re-search-forward "\n" nil t)
(replace-match " \n"))
(expect (buffer-string) :not :to-equal mock-srt-data)
- (subed-srt--sanitize)
+ (subed-sanitize)
(expect (buffer-string) :to-equal mock-srt-data))
(with-temp-srt-buffer
(insert mock-srt-data)
@@ -1289,7 +1289,7 @@ Baz.
(while (re-search-forward "\n" nil t)
(replace-match "\t\n"))
(expect (buffer-string) :not :to-equal mock-srt-data)
- (subed-srt--sanitize)
+ (subed-sanitize)
(expect (buffer-string) :to-equal mock-srt-data)))
(it "removes leading tabs and spaces from all lines."
(with-temp-srt-buffer
@@ -1298,7 +1298,7 @@ Baz.
(while (re-search-forward "\n" nil t)
(replace-match "\n "))
(expect (buffer-string) :not :to-equal mock-srt-data)
- (subed-srt--sanitize)
+ (subed-sanitize)
(expect (buffer-string) :to-equal mock-srt-data))
(with-temp-srt-buffer
(insert mock-srt-data)
@@ -1306,7 +1306,7 @@ Baz.
(while (re-search-forward "\n" nil t)
(replace-match "\n\t"))
(expect (buffer-string) :not :to-equal mock-srt-data)
- (subed-srt--sanitize)
+ (subed-sanitize)
(expect (buffer-string) :to-equal mock-srt-data)))
(it "removes excessive empty lines between subtitles."
(with-temp-srt-buffer
@@ -1315,12 +1315,12 @@ Baz.
(while (re-search-forward "\n\n" nil t)
(replace-match "\n \n \t \t\t \n\n \t\n"))
(expect (buffer-string) :not :to-equal mock-srt-data)
- (subed-srt--sanitize)
+ (subed-sanitize)
(expect (buffer-string) :to-equal mock-srt-data)))
(it "ensures double newline between subtitles if text of previous subtitle
is empty."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-text 1)
+ (subed-jump-to-subtitle-text 1)
(kill-whole-line)
(expect (buffer-string) :to-equal (concat "1\n"
"00:01:01,000 -->
00:01:05,123\n"
@@ -1331,7 +1331,7 @@ Baz.
"3\n"
"00:03:03,45 --> 00:03:15,5\n"
"Baz.\n"))
- (subed-srt--sanitize)
+ (subed-sanitize)
(expect (buffer-string) :to-equal (concat "1\n"
"00:01:01,000 -->
00:01:05,123\n"
"\n\n"
@@ -1347,7 +1347,7 @@ Baz.
(goto-char (point-min))
(insert " \n\t\n")
(expect (buffer-string) :not :to-equal mock-srt-data)
- (subed-srt--sanitize)
+ (subed-sanitize)
(expect (buffer-string) :to-equal mock-srt-data)))
(it "removes empty lines from end of buffer."
(with-temp-srt-buffer
@@ -1355,7 +1355,7 @@ Baz.
(goto-char (point-max))
(insert " \n\t\n\n")
(expect (buffer-string) :not :to-equal mock-srt-data)
- (subed-srt--sanitize)
+ (subed-sanitize)
(expect (buffer-string) :to-equal mock-srt-data)))
(it "ensures a single newline after the last subtitle."
(with-temp-srt-buffer
@@ -1364,12 +1364,12 @@ Baz.
(while (eq (char-before (point-max)) ?\n)
(delete-backward-char 1))
(expect (buffer-string) :not :to-equal mock-srt-data)
- (subed-srt--sanitize)
+ (subed-sanitize)
(expect (buffer-string) :to-equal mock-srt-data)))
(it "ensures single newline after last subtitle if text is empty."
(with-temp-srt-buffer
(insert mock-srt-data)
- (subed-srt--jump-to-subtitle-text 3)
+ (subed-jump-to-subtitle-text 3)
(kill-whole-line)
(expect (buffer-string) :to-equal (concat "1\n"
"00:01:01,000 -->
00:01:05,123\n"
@@ -1380,7 +1380,7 @@ Baz.
"3\n"
"00:03:03,45 --> 00:03:15,5\n"
""))
- (subed-srt--sanitize)
+ (subed-sanitize)
(expect (buffer-string) :to-equal (concat "1\n"
"00:01:01,000 -->
00:01:05,123\n"
"Foo.\n\n"
@@ -1401,12 +1401,12 @@ Baz.
(re-search-forward " --> ")
(replace-match "-->")
(expect (buffer-string) :not :to-equal mock-srt-data)
- (subed-srt--sanitize)
+ (subed-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)
+ (subed-sanitize)
(expect (buffer-string) :to-equal "")))
(it "runs before saving."
(with-temp-srt-buffer
@@ -1469,7 +1469,7 @@ Baz.
(goto-char (point-min))
(re-search-forward "03:03")
(replace-match "11:03")
- (subed-srt--sort)
+ (subed-sort)
(expect (buffer-string) :to-equal
(concat
"1\n"
@@ -1492,13 +1492,13 @@ Baz.
(replace-match "12:01")
(search-forward "\n")
(expect (current-word) :to-equal "Foo")
- (subed-srt--sort)
+ (subed-sort)
(expect (current-word) :to-equal "Foo")))
(it "when subtitle text is empty."
(with-temp-srt-buffer
(insert "1\n00:12:01,000 --> 00:01:05,123\n")
(goto-char (point-max))
- (subed-srt--sort)
+ (subed-sort)
(expect (point) :to-equal 33)))
)
)
diff --git a/tests/test-subed-vtt.el b/tests/test-subed-vtt.el
index 427b055795..5f4eb20c1f 100644
--- a/tests/test-subed-vtt.el
+++ b/tests/test-subed-vtt.el
@@ -28,94 +28,94 @@ Baz.
(it "returns the time in milliseconds."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-id "00:02:02.234")
- (expect (subed-vtt--subtitle-msecs-start) :to-equal (+ (* 2 60000) (*
2 1000) 234))
- (expect (subed-vtt--subtitle-msecs-stop) :to-equal (+ (* 2 60000) (*
10 1000) 345))))
+ (subed-jump-to-subtitle-id "00:02:02.234")
+ (expect (subed-subtitle-msecs-start) :to-equal (+ (* 2 60000) (* 2
1000) 234))
+ (expect (subed-subtitle-msecs-stop) :to-equal (+ (* 2 60000) (* 10
1000) 345))))
(it "handles lack of digits in milliseconds gracefully."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-id "00:03:03.45")
- (expect (save-excursion (subed-vtt--jump-to-subtitle-time-start)
+ (subed-jump-to-subtitle-id "00:03:03.45")
+ (expect (save-excursion (subed-jump-to-subtitle-time-start)
(thing-at-point 'line)) :to-equal
"00:03:03.45 --> 00:03:15.5\n")
- (expect (subed-vtt--subtitle-msecs-start) :to-equal (+ (* 3 60 1000)
(* 3 1000) 450))
- (expect (subed-vtt--subtitle-msecs-stop) :to-equal (+ (* 3 60 1000)
(* 15 1000) 500))))
+ (expect (subed-subtitle-msecs-start) :to-equal (+ (* 3 60 1000) (* 3
1000) 450))
+ (expect (subed-subtitle-msecs-stop) :to-equal (+ (* 3 60 1000) (* 15
1000) 500))))
(it "handles lack of hours in milliseconds gracefully."
(with-temp-vtt-buffer
(insert "WEBVTT\n\n01:02.000 --> 03:04.000\nHello\n")
- (expect (subed-vtt--subtitle-msecs-start) :to-equal (+ (* 1 60 1000)
(* 2 1000)))
- (expect (subed-vtt--subtitle-msecs-stop) :to-equal (+ (* 3 60 1000)
(* 4 1000)))))
+ (expect (subed-subtitle-msecs-start) :to-equal (+ (* 1 60 1000) (* 2
1000)))
+ (expect (subed-subtitle-msecs-stop) :to-equal (+ (* 3 60 1000) (* 4
1000)))))
(it "returns nil if time can't be found."
(with-temp-vtt-buffer
- (expect (subed-vtt--subtitle-msecs-start) :to-be nil)
- (expect (subed-vtt--subtitle-msecs-stop) :to-be nil)))
+ (expect (subed-subtitle-msecs-start) :to-be nil)
+ (expect (subed-subtitle-msecs-stop) :to-be nil)))
)
(describe "the subtitle text"
(describe "when text is empty"
(it "and at the beginning with a trailing newline."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-text "00:01:01.000")
+ (subed-jump-to-subtitle-text "00:01:01.000")
(kill-line)
- (expect (subed-vtt--subtitle-text) :to-equal "")))
+ (expect (subed-subtitle-text) :to-equal "")))
(it "and at the beginning without a trailing newline."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-text "00:01:01.000")
+ (subed-jump-to-subtitle-text "00:01:01.000")
(kill-whole-line)
- (expect (subed-vtt--subtitle-text) :to-equal "")))
+ (expect (subed-subtitle-text) :to-equal "")))
(it "and in the middle."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-text "00:02:02.234")
+ (subed-jump-to-subtitle-text "00:02:02.234")
(kill-line)
- (expect (subed-vtt--subtitle-text) :to-equal "")))
+ (expect (subed-subtitle-text) :to-equal "")))
(it "and at the end with a trailing newline."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-text "00:03:03.45")
+ (subed-jump-to-subtitle-text "00:03:03.45")
(kill-line)
- (expect (subed-vtt--subtitle-text) :to-equal "")))
+ (expect (subed-subtitle-text) :to-equal "")))
(it "and at the end without a trailing newline."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-text "00:03:03.45")
+ (subed-jump-to-subtitle-text "00:03:03.45")
(kill-whole-line)
- (expect (subed-vtt--subtitle-text) :to-equal "")))
+ (expect (subed-subtitle-text) :to-equal "")))
)
(describe "when text is not empty"
(it "and has no linebreaks."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-text "00:02:02.234")
- (expect (subed-vtt--subtitle-text) :to-equal "Bar.")))
+ (subed-jump-to-subtitle-text "00:02:02.234")
+ (expect (subed-subtitle-text) :to-equal "Bar.")))
(it "and has linebreaks."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-text "00:02:02.234")
+ (subed-jump-to-subtitle-text "00:02:02.234")
(insert "Bar.\n")
- (expect (subed-vtt--subtitle-text) :to-equal "Bar.\nBar.")))
+ (expect (subed-subtitle-text) :to-equal "Bar.\nBar.")))
)
)
(describe "the point within the subtitle"
(it "returns the relative point if we can find an ID."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-id "00:02:02.234")
- (expect (subed-vtt--subtitle-relative-point) :to-equal 0)
+ (subed-jump-to-subtitle-id "00:02:02.234")
+ (expect (subed-subtitle-relative-point) :to-equal 0)
(forward-line)
- (expect (subed-vtt--subtitle-relative-point) :to-equal 30)
+ (expect (subed-subtitle-relative-point) :to-equal 30)
(forward-char)
- (expect (subed-vtt--subtitle-relative-point) :to-equal 31)
+ (expect (subed-subtitle-relative-point) :to-equal 31)
(forward-line)
- (expect (subed-vtt--subtitle-relative-point) :to-equal 35)
+ (expect (subed-subtitle-relative-point) :to-equal 35)
(forward-line)
- (expect (subed-vtt--subtitle-relative-point) :to-equal 0)))
+ (expect (subed-subtitle-relative-point) :to-equal 0)))
(it "returns nil if we can't find an ID."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-id "00:01:01.000")
+ (subed-jump-to-subtitle-id "00:01:01.000")
(insert "foo")
- (expect (subed-vtt--subtitle-relative-point) :to-equal nil)))
+ (expect (subed-subtitle-relative-point) :to-equal nil)))
)
)
@@ -125,17 +125,17 @@ Baz.
(with-temp-vtt-buffer
(insert mock-vtt-data)
(goto-char (point-min))
- (subed-vtt--jump-to-subtitle-id "00:01:01.000")
- (expect (subed-vtt--jump-to-subtitle-time-start) :to-equal (point))
- (expect (looking-at subed-vtt--regexp-timestamp) :to-be t)
+ (subed-jump-to-subtitle-id "00:01:01.000")
+ (expect (subed-jump-to-subtitle-time-start) :to-equal (point))
+ (expect (looking-at subed--regexp-timestamp) :to-be t)
(expect (match-string 0) :to-equal "00:01:01.000")))
(it "returns timestamp's point when point is on the text."
(with-temp-vtt-buffer
(insert mock-vtt-data)
(search-backward "Baz.")
(expect (thing-at-point 'word) :to-equal "Baz")
- (expect (subed-vtt--jump-to-subtitle-time-start) :to-equal 81)
- (expect (looking-at subed-vtt--regexp-timestamp) :to-be t)
+ (expect (subed-jump-to-subtitle-time-start) :to-equal 81)
+ (expect (looking-at subed--regexp-timestamp) :to-be t)
(expect (match-string 0) :to-equal "00:03:03.45")))
(it "returns timestamp's point when point is between subtitles."
(with-temp-vtt-buffer
@@ -143,20 +143,20 @@ Baz.
(goto-char (point-min))
(search-forward "Bar.\n")
(expect (thing-at-point 'line) :to-equal "\n")
- (expect (subed-vtt--jump-to-subtitle-time-start) :to-equal 45)
- (expect (looking-at subed-vtt--regexp-timestamp) :to-be t)
+ (expect (subed-jump-to-subtitle-time-start) :to-equal 45)
+ (expect (looking-at subed--regexp-timestamp) :to-be t)
(expect (match-string 0) :to-equal "00:02:02.234")))
(it "returns nil if buffer is empty."
(with-temp-vtt-buffer
(expect (buffer-string) :to-equal "")
- (expect (subed-vtt--jump-to-subtitle-time-start) :to-equal nil)))
+ (expect (subed-jump-to-subtitle-time-start) :to-equal nil)))
(it "returns timestamp's point when buffer starts with blank lines."
(with-temp-vtt-buffer
(insert (concat "WEBVTT \n \t \n" (replace-regexp-in-string "WEBVTT"
"" mock-vtt-data)))
(search-backward "Foo.")
(expect (thing-at-point 'line) :to-equal "Foo.\n")
- (expect (subed-vtt--jump-to-subtitle-time-start) :to-equal 15)
- (expect (looking-at subed-vtt--regexp-timestamp) :to-be t)
+ (expect (subed-jump-to-subtitle-time-start) :to-equal 15)
+ (expect (looking-at subed--regexp-timestamp) :to-be t)
(expect (match-string 0) :to-equal "00:01:01.000")))
(it "returns timestamp's point when subtitles are separated with blank
lines."
(with-temp-vtt-buffer
@@ -164,8 +164,8 @@ Baz.
(goto-char (point-min))
(search-forward "Foo.\n")
(insert " \n \t \n")
- (expect (subed-vtt--jump-to-subtitle-time-start) :to-equal 9)
- (expect (looking-at subed-vtt--regexp-timestamp) :to-be t)
+ (expect (subed-jump-to-subtitle-time-start) :to-equal 9)
+ (expect (looking-at subed--regexp-timestamp) :to-be t)
(expect (match-string 0) :to-equal "00:01:01.000")))
)
(describe "to specific subtitle by timestamp"
@@ -173,9 +173,9 @@ Baz.
(with-temp-vtt-buffer
(insert mock-vtt-data)
(goto-char (point-max))
- (expect (subed-vtt--jump-to-subtitle-id "00:02:02.234") :to-equal 45)
+ (expect (subed-jump-to-subtitle-id "00:02:02.234") :to-equal 45)
(expect (looking-at (regexp-quote "00:02:02.234")) :to-be t)
- (expect (subed-vtt--jump-to-subtitle-id "00:01:01.000") :to-equal 9)
+ (expect (subed-jump-to-subtitle-id "00:01:01.000") :to-equal 9)
(expect (looking-at (regexp-quote "00:01:01.000")) :to-be t)))
(it "returns nil and does not move if wanted ID does not exists."
(with-temp-vtt-buffer
@@ -183,7 +183,7 @@ Baz.
(goto-char (point-min))
(search-forward "Foo")
(let ((stored-point (point)))
- (expect (subed-vtt--jump-to-subtitle-id "0:08:00") :to-equal nil)
+ (expect (subed-jump-to-subtitle-id "0:08:00") :to-equal nil)
(expect stored-point :to-equal (point)))))
)
(describe "to subtitle start time"
@@ -191,74 +191,74 @@ Baz.
(with-temp-vtt-buffer
(insert mock-vtt-data)
(goto-char (point-min))
- (expect (subed-vtt--jump-to-subtitle-time-start) :to-equal 9)
- (expect (looking-at subed-vtt--regexp-timestamp) :to-be t)
+ (expect (subed-jump-to-subtitle-time-start) :to-equal 9)
+ (expect (looking-at subed--regexp-timestamp) :to-be t)
(expect (match-string 0) :to-equal "00:01:01.000")
(re-search-forward "\n\n")
- (expect (subed-vtt--jump-to-subtitle-time-start) :to-equal 45)
- (expect (looking-at subed-vtt--regexp-timestamp) :to-be t)
+ (expect (subed-jump-to-subtitle-time-start) :to-equal 45)
+ (expect (looking-at subed--regexp-timestamp) :to-be t)
(expect (match-string 0) :to-equal "00:02:02.234")
(re-search-forward "\n\n")
- (expect (subed-vtt--jump-to-subtitle-time-start) :to-equal 81)
- (expect (looking-at subed-vtt--regexp-timestamp) :to-be t)
+ (expect (subed-jump-to-subtitle-time-start) :to-equal 81)
+ (expect (looking-at subed--regexp-timestamp) :to-be t)
(expect (match-string 0) :to-equal "00:03:03.45")))
(it "returns nil if movement failed."
(with-temp-vtt-buffer
- (expect (subed-vtt--jump-to-subtitle-time-start) :to-equal nil)))
+ (expect (subed-jump-to-subtitle-time-start) :to-equal nil)))
)
(describe "to subtitle stop time"
(it "returns stop time's point if movement was successful."
(with-temp-vtt-buffer
(insert mock-vtt-data)
(goto-char (point-min))
- (expect (subed-vtt--jump-to-subtitle-time-stop) :to-equal 26)
- (expect (looking-at subed-vtt--regexp-timestamp) :to-be t)
+ (expect (subed-jump-to-subtitle-time-stop) :to-equal 26)
+ (expect (looking-at subed--regexp-timestamp) :to-be t)
(expect (match-string 0) :to-equal "00:01:05.123")
(re-search-forward "\n\n")
- (expect (subed-vtt--jump-to-subtitle-time-stop) :to-equal 62)
- (expect (looking-at subed-vtt--regexp-timestamp) :to-be t)
+ (expect (subed-jump-to-subtitle-time-stop) :to-equal 62)
+ (expect (looking-at subed--regexp-timestamp) :to-be t)
(expect (match-string 0) :to-equal "00:02:10.345")
(re-search-forward "\n\n")
- (expect (subed-vtt--jump-to-subtitle-time-stop) :to-equal 97)
- (expect (looking-at subed-vtt--regexp-timestamp) :to-be t)
+ (expect (subed-jump-to-subtitle-time-stop) :to-equal 97)
+ (expect (looking-at subed--regexp-timestamp) :to-be t)
(expect (match-string 0) :to-equal "00:03:15.5")))
(it "returns nil if movement failed."
(with-temp-vtt-buffer
- (expect (subed-vtt--jump-to-subtitle-time-stop) :to-equal nil)))
+ (expect (subed-jump-to-subtitle-time-stop) :to-equal nil)))
)
(describe "to subtitle text"
(it "returns subtitle text's point if movement was successful."
(with-temp-vtt-buffer
(insert mock-vtt-data)
(goto-char (point-min))
- (expect (subed-vtt--jump-to-subtitle-text) :to-equal 39)
+ (expect (subed-jump-to-subtitle-text) :to-equal 39)
(expect (point) :to-equal (save-excursion (goto-char (point-max))
(search-backward "Foo.")))
(re-search-forward "\n\n")
- (expect (subed-vtt--jump-to-subtitle-text) :to-equal 75)
+ (expect (subed-jump-to-subtitle-text) :to-equal 75)
(expect (point) :to-equal (save-excursion (goto-char (point-max))
(search-backward "Bar.")))
(re-search-forward "\n\n")
- (expect (subed-vtt--jump-to-subtitle-text) :to-equal 108)
+ (expect (subed-jump-to-subtitle-text) :to-equal 108)
(expect (point) :to-equal (save-excursion (goto-char (point-max))
(search-backward "Baz.")))))
(it "returns nil if movement failed."
(with-temp-vtt-buffer
- (expect (subed-vtt--jump-to-subtitle-time-stop) :to-equal nil)))
+ (expect (subed-jump-to-subtitle-time-stop) :to-equal nil)))
)
(describe "to end of subtitle text"
(it "returns point if subtitle end can be found."
(with-temp-vtt-buffer
(insert mock-vtt-data)
(goto-char (point-min))
- (expect (subed-vtt--jump-to-subtitle-end) :to-be 43)
+ (expect (subed-jump-to-subtitle-end) :to-be 43)
(expect (looking-back "^Foo.$") :to-be t)
(forward-char 2)
- (expect (subed-vtt--jump-to-subtitle-end) :to-be 79)
+ (expect (subed-jump-to-subtitle-end) :to-be 79)
(expect (looking-back "^Bar.$") :to-be t)
(forward-char 2)
- (expect (subed-vtt--jump-to-subtitle-end) :to-be 112)
+ (expect (subed-jump-to-subtitle-end) :to-be 112)
(expect (looking-back "^Baz.$") :to-be t)
(goto-char (point-max))
(backward-char 2)
- (expect (subed-vtt--jump-to-subtitle-end) :to-be 112)
+ (expect (subed-jump-to-subtitle-end) :to-be 112)
(expect (looking-back "^Baz.$") :to-be t)))
(it "handles spaces in between subtitles."
(with-temp-vtt-buffer
@@ -267,263 +267,263 @@ Baz.
(re-search-forward "Foo\\.\n")
(replace-match "Foo.\n ")
(goto-char (point-min))
- (expect (subed-vtt--jump-to-subtitle-end) :to-be 43)
+ (expect (subed-jump-to-subtitle-end) :to-be 43)
(expect (looking-back "^Foo.$") :to-be t)))
(it "returns nil if subtitle end cannot be found."
(with-temp-vtt-buffer
- (expect (subed-vtt--jump-to-subtitle-end) :to-be nil)))
+ (expect (subed-jump-to-subtitle-end) :to-be nil)))
(it "returns nil if point did not move."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-text "00:01:01.000")
+ (subed-jump-to-subtitle-text "00:01:01.000")
(kill-line)
- (expect (subed-vtt--jump-to-subtitle-end) :to-be nil)))
+ (expect (subed-jump-to-subtitle-end) :to-be nil)))
(it "works if text is empty with trailing newline."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-text "00:01:01.000")
+ (subed-jump-to-subtitle-text "00:01:01.000")
(kill-line)
(backward-char)
- (expect (subed-vtt--jump-to-subtitle-end) :to-be 39)
+ (expect (subed-jump-to-subtitle-end) :to-be 39)
(expect (looking-at "^$") :to-be t)
- (subed-vtt--jump-to-subtitle-text "00:02:02.234")
+ (subed-jump-to-subtitle-text "00:02:02.234")
(kill-line)
(backward-char)
- (expect (subed-vtt--jump-to-subtitle-end) :to-be 71)
+ (expect (subed-jump-to-subtitle-end) :to-be 71)
(expect (looking-at "^$") :to-be t)
- (subed-vtt--jump-to-subtitle-text "00:03:03.45")
+ (subed-jump-to-subtitle-text "00:03:03.45")
(kill-line)
(backward-char)
- (expect (subed-vtt--jump-to-subtitle-end) :to-be 100)
+ (expect (subed-jump-to-subtitle-end) :to-be 100)
(expect (looking-at "^$") :to-be t)))
(it "works if text is empty without trailing newline."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-text "00:01:01.000")
+ (subed-jump-to-subtitle-text "00:01:01.000")
(kill-whole-line)
- (expect (subed-vtt--jump-to-subtitle-end) :to-be nil)
+ (expect (subed-jump-to-subtitle-end) :to-be nil)
(expect (looking-at "^$") :to-be t)
(goto-char (point-min))
- (expect (subed-vtt--jump-to-subtitle-end) :to-be 39)
+ (expect (subed-jump-to-subtitle-end) :to-be 39)
(expect (looking-at "^$") :to-be t)
- (subed-vtt--jump-to-subtitle-text "00:02:02.234")
+ (subed-jump-to-subtitle-text "00:02:02.234")
(kill-whole-line)
- (expect (subed-vtt--jump-to-subtitle-end) :to-be nil)
+ (expect (subed-jump-to-subtitle-end) :to-be nil)
(expect (looking-at "^$") :to-be t)
(backward-char)
- (expect (subed-vtt--jump-to-subtitle-end) :to-be 70)
+ (expect (subed-jump-to-subtitle-end) :to-be 70)
(expect (looking-at "^$") :to-be t)
- (subed-vtt--jump-to-subtitle-text "00:03:03.45")
+ (subed-jump-to-subtitle-text "00:03:03.45")
(kill-whole-line)
- (expect (subed-vtt--jump-to-subtitle-end) :to-be nil)
+ (expect (subed-jump-to-subtitle-end) :to-be nil)
(expect (looking-at "^$") :to-be t)
(backward-char)
- (expect (subed-vtt--jump-to-subtitle-end) :to-be 98)
+ (expect (subed-jump-to-subtitle-end) :to-be 98)
(expect (looking-at "^$") :to-be t)))
)
(describe "to next subtitle ID"
(it "returns point when there is a next subtitle."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-id "00:01:01.000")
+ (subed-jump-to-subtitle-id "00:01:01.000")
(expect (looking-at (regexp-quote "00:01:01.000")) :to-be t)
- (expect (subed-vtt--forward-subtitle-id) :to-be 45)
+ (expect (subed-forward-subtitle-id) :to-be 45)
(expect (looking-at (regexp-quote "00:02:02.234")) :to-be t)
- (subed-vtt--jump-to-subtitle-time-start "00:02:02.234")
+ (subed-jump-to-subtitle-time-start "00:02:02.234")
(expect (looking-at (regexp-quote "00:02:02.234")) :to-be t)
- (expect (subed-vtt--forward-subtitle-id) :to-be 81)
+ (expect (subed-forward-subtitle-id) :to-be 81)
(expect (looking-at (regexp-quote "00:03:03.45")) :to-be t)))
(it "returns nil and doesn't move when there is no next subtitle."
(with-temp-vtt-buffer
(expect (thing-at-point 'word) :to-equal nil)
- (expect (subed-vtt--forward-subtitle-id) :to-be nil))
+ (expect (subed-forward-subtitle-id) :to-be nil))
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-text "00:01:01.000")
+ (subed-jump-to-subtitle-text "00:01:01.000")
(expect (thing-at-point 'word) :to-equal "Foo")
- (expect (subed-vtt--forward-subtitle-id) :to-be 45)
+ (expect (subed-forward-subtitle-id) :to-be 45)
(expect (looking-at (regexp-quote "00:02:02.234")) :to-be t)
- (subed-vtt--jump-to-subtitle-time-stop "00:02:02.234")
+ (subed-jump-to-subtitle-time-stop "00:02:02.234")
(expect (looking-at (regexp-quote "00:02:10.345")) :to-be t)
- (expect (subed-vtt--forward-subtitle-id) :to-be 81)
+ (expect (subed-forward-subtitle-id) :to-be 81)
(expect (looking-at (regexp-quote "00:03:03.45")) :to-be t))
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-text "00:03:03.45")
+ (subed-jump-to-subtitle-text "00:03:03.45")
(expect (thing-at-point 'word) :to-equal "Baz")
- (expect (subed-vtt--forward-subtitle-id) :to-be nil)
+ (expect (subed-forward-subtitle-id) :to-be nil)
(expect (thing-at-point 'word) :to-equal "Baz"))
(with-temp-vtt-buffer
(insert (concat mock-vtt-data "\n\n"))
- (subed-vtt--jump-to-subtitle-time-stop "00:03:03.45")
+ (subed-jump-to-subtitle-time-stop "00:03:03.45")
(expect (thing-at-point 'word) :to-equal "00")
- (expect (subed-vtt--forward-subtitle-id) :to-be nil)
+ (expect (subed-forward-subtitle-id) :to-be nil)
(expect (thing-at-point 'word) :to-equal "00")))
)
(describe "to previous subtitle ID"
(it "returns point when there is a previous subtitle."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-text "00:02:02.234")
+ (subed-jump-to-subtitle-text "00:02:02.234")
(expect (thing-at-point 'word) :to-equal "Bar")
- (expect (subed-vtt--backward-subtitle-id) :to-be 9)
+ (expect (subed-backward-subtitle-id) :to-be 9)
(expect (looking-at (regexp-quote "00:01:01.000")) :to-be t)
- (subed-vtt--jump-to-subtitle-time-stop "00:03:03.45")
+ (subed-jump-to-subtitle-time-stop "00:03:03.45")
(expect (looking-at (regexp-quote "00:03:15.5")) :to-be t)
- (expect (subed-vtt--backward-subtitle-id) :to-be 45)
+ (expect (subed-backward-subtitle-id) :to-be 45)
(expect (looking-at (regexp-quote "00:02:02.234")) :to-be t)))
(it "returns nil and doesn't move when there is no previous subtitle."
(with-temp-vtt-buffer
- (expect (subed-vtt--backward-subtitle-id) :to-be nil))
+ (expect (subed-backward-subtitle-id) :to-be nil))
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-id "00:01:01.000")
+ (subed-jump-to-subtitle-id "00:01:01.000")
(expect (looking-at (regexp-quote "00:01:01.000")) :to-be t)
- (expect (subed-vtt--backward-subtitle-id) :to-be nil)
+ (expect (subed-backward-subtitle-id) :to-be nil)
(expect (looking-at (regexp-quote "00:01:01.000")) :to-be t))
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-text "00:01:01.000")
+ (subed-jump-to-subtitle-text "00:01:01.000")
(expect (thing-at-point 'word) :to-equal "Foo")
- (expect (subed-vtt--backward-subtitle-id) :to-be nil)
+ (expect (subed-backward-subtitle-id) :to-be nil)
(expect (thing-at-point 'word) :to-equal "Foo"))
(with-temp-vtt-buffer
(insert (concat "\n\n\n" mock-vtt-data))
- (subed-vtt--jump-to-subtitle-time-stop "00:01:01.000")
+ (subed-jump-to-subtitle-time-stop "00:01:01.000")
(expect (thing-at-point 'word) :to-equal "00")
- (expect (subed-vtt--backward-subtitle-id) :to-be nil)
+ (expect (subed-backward-subtitle-id) :to-be nil)
(expect (thing-at-point 'word) :to-equal "00")))
)
(describe "to next subtitle text"
(it "returns point when there is a next subtitle."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-id "00:01:01.000")
+ (subed-jump-to-subtitle-id "00:01:01.000")
(expect (looking-at (regexp-quote "00:01:01.000")) :to-be t)
- (expect (subed-vtt--forward-subtitle-text) :to-be 75)
+ (expect (subed-forward-subtitle-text) :to-be 75)
(expect (thing-at-point 'word) :to-equal "Bar")))
(it "returns nil and doesn't move when there is no next subtitle."
(with-temp-vtt-buffer
(goto-char (point-max))
(insert (concat mock-vtt-data "\n\n"))
- (subed-vtt--jump-to-subtitle-id "00:03:03.45")
+ (subed-jump-to-subtitle-id "00:03:03.45")
(expect (looking-at (regexp-quote "00:03:03.45")) :to-be t)
- (expect (subed-vtt--forward-subtitle-text) :to-be nil)
+ (expect (subed-forward-subtitle-text) :to-be nil)
(expect (looking-at (regexp-quote "00:03:03.45")) :to-be t)))
)
(describe "to previous subtitle text"
(it "returns point when there is a previous subtitle."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-id "00:03:03.45")
+ (subed-jump-to-subtitle-id "00:03:03.45")
(expect (looking-at (regexp-quote "00:03:03.45")) :to-be t)
- (expect (subed-vtt--backward-subtitle-text) :to-be 75)
+ (expect (subed-backward-subtitle-text) :to-be 75)
(expect (thing-at-point 'word) :to-equal "Bar")))
(it "returns nil and doesn't move when there is no previous subtitle."
(with-temp-vtt-buffer
(insert mock-vtt-data)
(goto-char (point-min))
- (subed-vtt--forward-subtitle-time-start)
+ (subed-forward-subtitle-time-start)
(expect (looking-at (regexp-quote "00:01:01.000")) :to-be t)
- (expect (subed-vtt--backward-subtitle-text) :to-be nil)
+ (expect (subed-backward-subtitle-text) :to-be nil)
(expect (looking-at (regexp-quote "00:01:01.000")) :to-be t)))
)
(describe "to next subtitle end"
(it "returns point when there is a next subtitle."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-text "00:02:02.234")
+ (subed-jump-to-subtitle-text "00:02:02.234")
(expect (thing-at-point 'word) :to-equal "Bar")
- (expect (subed-vtt--forward-subtitle-end) :to-be 112)
+ (expect (subed-forward-subtitle-end) :to-be 112)
(expect (thing-at-point 'word) :to-equal nil)))
(it "returns nil and doesn't move when there is no next subtitle."
(with-temp-vtt-buffer
(insert (concat mock-vtt-data "\n\n"))
- (subed-vtt--jump-to-subtitle-text "00:03:03.45")
+ (subed-jump-to-subtitle-text "00:03:03.45")
(end-of-line)
(expect (thing-at-point 'word) :to-equal nil)
- (expect (subed-vtt--forward-subtitle-end) :to-be nil)
+ (expect (subed-forward-subtitle-end) :to-be nil)
(expect (thing-at-point 'word) :to-equal nil)))
)
(describe "to previous subtitle end"
(it "returns point when there is a previous subtitle."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-id "00:03:03.45")
+ (subed-jump-to-subtitle-id "00:03:03.45")
(expect (looking-at (regexp-quote "00:03:03.45")) :to-be t)
- (expect (subed-vtt--backward-subtitle-text) :to-be 75)
+ (expect (subed-backward-subtitle-text) :to-be 75)
(expect (thing-at-point 'word) :to-equal "Bar")))
(it "returns nil and doesn't move when there is no previous subtitle."
(with-temp-vtt-buffer
(insert mock-vtt-data)
(goto-char (point-min))
- (subed-vtt--forward-subtitle-id)
+ (subed-forward-subtitle-id)
(expect (looking-at (regexp-quote "00:01:01.000")) :to-be t)
- (expect (subed-vtt--backward-subtitle-text) :to-be nil)
+ (expect (subed-backward-subtitle-text) :to-be nil)
(expect (looking-at (regexp-quote "00:01:01.000")) :to-be t)))
)
(describe "to next subtitle start time"
(it "returns point when there is a next subtitle."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-text "00:01:01.000")
+ (subed-jump-to-subtitle-text "00:01:01.000")
(expect (thing-at-point 'word) :to-equal "Foo")
- (expect (subed-vtt--forward-subtitle-time-start) :to-be 45)
+ (expect (subed-forward-subtitle-time-start) :to-be 45)
(expect (looking-at (regexp-quote "00:02:02.234")) :to-be t)))
(it "returns nil and doesn't move when there is no next subtitle."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-id "00:03:03.45")
+ (subed-jump-to-subtitle-id "00:03:03.45")
(expect (looking-at (regexp-quote "00:03:03.45")) :to-be t)
- (expect (subed-vtt--forward-subtitle-time-start) :to-be nil)
+ (expect (subed-forward-subtitle-time-start) :to-be nil)
(expect (looking-at (regexp-quote "00:03:03.45")) :to-be t)))
)
(describe "to previous subtitle start time"
(it "returns point when there is a previous subtitle."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-id "00:02:02.234")
+ (subed-jump-to-subtitle-id "00:02:02.234")
(expect (looking-at (regexp-quote "00:02:02.234")) :to-be t)
- (expect (subed-vtt--backward-subtitle-time-start) :to-be 9)
+ (expect (subed-backward-subtitle-time-start) :to-be 9)
(expect (looking-at (regexp-quote "00:01:01.000")) :to-be t)))
(it "returns nil and doesn't move when there is no previous subtitle."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-id "00:01:01.000")
+ (subed-jump-to-subtitle-id "00:01:01.000")
(expect (looking-at (regexp-quote "00:01:01.000")) :to-be t)
- (expect (subed-vtt--backward-subtitle-time-start) :to-be nil)
+ (expect (subed-backward-subtitle-time-start) :to-be nil)
(expect (looking-at (regexp-quote "00:01:01.000")) :to-be t)))
)
(describe "to next subtitle stop time"
(it "returns point when there is a next subtitle."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-text "00:01:01.000")
+ (subed-jump-to-subtitle-text "00:01:01.000")
(expect (thing-at-point 'word) :to-equal "Foo")
- (expect (subed-vtt--forward-subtitle-time-stop) :to-be 62)
+ (expect (subed-forward-subtitle-time-stop) :to-be 62)
(expect (looking-at (regexp-quote "00:02:10.345")) :to-be t)))
(it "returns nil and doesn't move when there is no next subtitle."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-id "00:03:03.45")
+ (subed-jump-to-subtitle-id "00:03:03.45")
(expect (looking-at (regexp-quote "00:03:03.45")) :to-be t)
- (expect (subed-vtt--forward-subtitle-time-stop) :to-be nil)
+ (expect (subed-forward-subtitle-time-stop) :to-be nil)
(expect (looking-at (regexp-quote "00:03:03.45")) :to-be t)))
)
(describe "to previous subtitle stop time"
(it "returns point when there is a previous subtitle."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-id "00:03:03.45")
+ (subed-jump-to-subtitle-id "00:03:03.45")
(expect (looking-at (regexp-quote "00:03:03.45")) :to-be t)
- (expect (subed-vtt--backward-subtitle-time-stop) :to-be 62)
+ (expect (subed-backward-subtitle-time-stop) :to-be 62)
(expect (looking-at (regexp-quote "00:02:10.345")) :to-be t)))
(it "returns nil and doesn't move when there is no previous subtitle."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-id "00:01:01.000")
+ (subed-jump-to-subtitle-id "00:01:01.000")
(expect (looking-at (regexp-quote "00:01:01.000")) :to-be t)
- (expect (subed-vtt--backward-subtitle-time-stop) :to-be nil)
+ (expect (subed-backward-subtitle-time-stop) :to-be nil)
(expect (looking-at (regexp-quote "00:01:01.000")) :to-be t)))
)
)
@@ -532,8 +532,8 @@ Baz.
(it "of current subtitle."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-end "00:02:02.234")
- (subed-vtt--set-subtitle-time-start (+ (* 1 60 60 1000) (* 2 60 1000)
(* 3 1000) 400))
+ (subed-jump-to-subtitle-end "00:02:02.234")
+ (subed-set-subtitle-time-start (+ (* 1 60 60 1000) (* 2 60 1000) (* 3
1000) 400))
(expect (buffer-string) :to-equal (concat "WEBVTT\n\n"
"00:01:01.000 -->
00:01:05.123\n"
"Foo.\n\n"
@@ -541,7 +541,7 @@ Baz.
"Bar.\n\n"
"00:03:03.45 --> 00:03:15.5\n"
"Baz.\n"))
- (subed-vtt--set-subtitle-time-stop (+ (* 5 60 60 1000) (* 6 60 1000) (*
7 1000) 800))
+ (subed-set-subtitle-time-stop (+ (* 5 60 60 1000) (* 6 60 1000) (* 7
1000) 800))
(expect (buffer-string) :to-equal (concat "WEBVTT\n\n"
"00:01:01.000 -->
00:01:05.123\n"
"Foo.\n\n"
@@ -552,8 +552,8 @@ Baz.
(it "of specific subtitle."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-time-stop "00:01:01.000")
- (subed-vtt--set-subtitle-time-start (+ (* 2 60 60 1000) (* 4 60 1000)
(* 6 1000) 800) 1)
+ (subed-jump-to-subtitle-time-stop "00:01:01.000")
+ (subed-set-subtitle-time-start (+ (* 2 60 60 1000) (* 4 60 1000) (* 6
1000) 800) 1)
(expect (buffer-string) :to-equal (concat "WEBVTT\n\n"
"02:04:06.800 -->
00:01:05.123\n"
"Foo.\n\n"
@@ -561,8 +561,8 @@ Baz.
"Bar.\n\n"
"00:03:03.45 --> 00:03:15.5\n"
"Baz.\n"))
- (subed-vtt--jump-to-subtitle-text "00:03:03.45")
- (subed-vtt--set-subtitle-time-stop (+ (* 3 60 60 1000) (* 5 60 1000) (*
7 1000) 900) 3)
+ (subed-jump-to-subtitle-text "00:03:03.45")
+ (subed-set-subtitle-time-stop (+ (* 3 60 60 1000) (* 5 60 1000) (* 7
1000) 900) 3)
(expect (buffer-string) :to-equal (concat "WEBVTT\n\n"
"02:04:06.800 -->
00:01:05.123\n"
"Foo.\n\n"
@@ -574,10 +574,10 @@ Baz.
(with-temp-vtt-buffer
(insert mock-vtt-data)
(subed-jump-to-subtitle-id "00:03:03.45")
- (subed-vtt--set-subtitle-time-start (+ (* 1 60 60 1000) (* 2 60 1000)
(* 3 1000) 4) 3)
+ (subed-set-subtitle-time-start (+ (* 1 60 60 1000) (* 2 60 1000) (* 3
1000) 4) 3)
(expect (save-excursion (subed-jump-to-subtitle-time-start)
(thing-at-point 'line)) :to-equal "01:02:03.004
--> 00:03:15.5\n")
- (subed-vtt--set-subtitle-time-stop (+ (* 2 60 60 1000) (* 3 60 1000) (*
4 1000) 60) 3)
+ (subed-set-subtitle-time-stop (+ (* 2 60 60 1000) (* 3 60 1000) (* 4
1000) 60) 3)
(expect (save-excursion (subed-jump-to-subtitle-time-start)
(thing-at-point 'line)) :to-equal "01:02:03.004
--> 02:03:04.060\n")))
)
@@ -587,22 +587,22 @@ Baz.
(describe "before"
(it "passing nothing."
(with-temp-vtt-buffer
- (expect (subed-vtt--prepend-subtitle) :to-equal 31)
+ (expect (subed-prepend-subtitle) :to-equal 31)
(expect (buffer-string) :to-equal (concat "00:00:00.000 -->
00:00:01.000\n\n"))
(expect (point) :to-equal 31)))
(it "passing start time."
(with-temp-vtt-buffer
- (expect (subed-vtt--prepend-subtitle nil 60000) :to-equal 31)
+ (expect (subed-prepend-subtitle nil 60000) :to-equal 31)
(expect (buffer-string) :to-equal (concat "00:01:00.000 -->
00:01:01.000\n\n"))
(expect (point) :to-equal 31)))
(it "passing start time and stop time."
(with-temp-vtt-buffer
- (expect (subed-vtt--prepend-subtitle nil 60000 65000) :to-equal 31)
+ (expect (subed-prepend-subtitle nil 60000 65000) :to-equal 31)
(expect (buffer-string) :to-equal (concat "00:01:00.000 -->
00:01:05.000\n\n"))
(expect (point) :to-equal 31)))
(it "passing start time, stop time and text."
(with-temp-vtt-buffer
- (expect (subed-vtt--prepend-subtitle nil 60000 65000 "Foo.
bar\nbaz.") :to-equal 31)
+ (expect (subed-prepend-subtitle nil 60000 65000 "Foo. bar\nbaz.")
:to-equal 31)
(expect (buffer-string) :to-equal (concat "00:01:00.000 -->
00:01:05.000\n"
"Foo. bar\nbaz.\n"))
(expect (point) :to-equal 31)))
@@ -610,22 +610,22 @@ Baz.
(describe "after"
(it "passing nothing."
(with-temp-vtt-buffer
- (expect (subed-vtt--append-subtitle) :to-equal 31)
+ (expect (subed-append-subtitle) :to-equal 31)
(expect (buffer-string) :to-equal (concat "00:00:00.000 -->
00:00:01.000\n\n"))
(expect (point) :to-equal 31)))
(it "passing start time."
(with-temp-vtt-buffer
- (expect (subed-vtt--append-subtitle nil 60000) :to-equal 31)
+ (expect (subed-append-subtitle nil 60000) :to-equal 31)
(expect (buffer-string) :to-equal (concat "00:01:00.000 -->
00:01:01.000\n\n"))
(expect (point) :to-equal 31)))
(it "passing start time and stop time."
(with-temp-vtt-buffer
- (expect (subed-vtt--append-subtitle nil 60000 65000) :to-equal 31)
+ (expect (subed-append-subtitle nil 60000 65000) :to-equal 31)
(expect (buffer-string) :to-equal (concat "00:01:00.000 -->
00:01:05.000\n\n"))
(expect (point) :to-equal 31)))
(it "passing start time, stop time and text."
(with-temp-vtt-buffer
- (expect (subed-vtt--append-subtitle nil 60000 65000 "Foo,
bar\nbaz.") :to-equal 31)
+ (expect (subed-append-subtitle nil 60000 65000 "Foo, bar\nbaz.")
:to-equal 31)
(expect (buffer-string) :to-equal (concat "00:01:00.000 -->
00:01:05.000\n"
"Foo, bar\nbaz.\n"))
(expect (point) :to-equal 31)))
@@ -638,8 +638,8 @@ Baz.
(with-temp-vtt-buffer
(insert (concat "00:00:05.000 --> 00:00:06.000\n"
"Foo.\n"))
- (subed-vtt--jump-to-subtitle-time-stop)
- (expect (subed-vtt--prepend-subtitle) :to-equal 31)
+ (subed-jump-to-subtitle-time-stop)
+ (expect (subed-prepend-subtitle) :to-equal 31)
(expect (buffer-string) :to-equal (concat "00:00:00.000 -->
00:00:01.000\n"
"\n\n"
"00:00:05.000 -->
00:00:06.000\n"
@@ -649,8 +649,8 @@ Baz.
(with-temp-vtt-buffer
(insert (concat "00:00:05.000 --> 00:00:06.000\n"
"Foo.\n"))
- (subed-vtt--jump-to-subtitle-time-stop)
- (expect (subed-vtt--prepend-subtitle nil 1500) :to-equal 31)
+ (subed-jump-to-subtitle-time-stop)
+ (expect (subed-prepend-subtitle nil 1500) :to-equal 31)
(expect (buffer-string) :to-equal (concat "00:00:01.500 -->
00:00:02.500\n"
"\n\n"
"00:00:05.000 -->
00:00:06.000\n"
@@ -660,8 +660,8 @@ Baz.
(with-temp-vtt-buffer
(insert (concat "00:00:05.000 --> 00:00:06.000\n"
"Foo.\n"))
- (subed-vtt--jump-to-subtitle-time-stop)
- (expect (subed-vtt--prepend-subtitle nil 1500 2000) :to-equal 31)
+ (subed-jump-to-subtitle-time-stop)
+ (expect (subed-prepend-subtitle nil 1500 2000) :to-equal 31)
(expect (buffer-string) :to-equal (concat "00:00:01.500 -->
00:00:02.000\n"
"\n\n"
"00:00:05.000 -->
00:00:06.000\n"
@@ -671,8 +671,8 @@ Baz.
(with-temp-vtt-buffer
(insert (concat "00:00:05.000 --> 00:00:06.000\n"
"Foo.\n"))
- (subed-vtt--jump-to-subtitle-time-stop)
- (expect (subed-vtt--prepend-subtitle nil 1500 3000 "Bar.")
:to-equal 31)
+ (subed-jump-to-subtitle-time-stop)
+ (expect (subed-prepend-subtitle nil 1500 3000 "Bar.") :to-equal
31)
(expect (buffer-string) :to-equal (concat "00:00:01.500 -->
00:00:03.000\n"
"Bar.\n\n"
"00:00:05.000 -->
00:00:06.000\n"
@@ -686,8 +686,8 @@ Baz.
"Foo.\n\n"
"00:00:10.000 --> 00:00:12.000\n"
"Bar.\n"))
- (subed-vtt--jump-to-subtitle-text "00:00:10.000")
- (expect (subed-vtt--prepend-subtitle) :to-equal 67)
+ (subed-jump-to-subtitle-text "00:00:10.000")
+ (expect (subed-prepend-subtitle) :to-equal 67)
(expect (buffer-string) :to-equal (concat "00:00:05.000 -->
00:00:06.000\n"
"Foo.\n\n"
"00:00:00.000 -->
00:00:01.000\n"
@@ -701,8 +701,8 @@ Baz.
"Foo.\n\n"
"00:00:10.000 --> 00:00:12.000\n"
"Bar.\n"))
- (subed-vtt--jump-to-subtitle-text "00:00:10.000")
- (expect (subed-vtt--prepend-subtitle nil 7000) :to-equal 67)
+ (subed-jump-to-subtitle-text "00:00:10.000")
+ (expect (subed-prepend-subtitle nil 7000) :to-equal 67)
(expect (buffer-string) :to-equal (concat "00:00:05.000 -->
00:00:06.000\n"
"Foo.\n\n"
"00:00:07.000 -->
00:00:08.000\n"
@@ -716,8 +716,8 @@ Baz.
"Foo.\n\n"
"00:00:10.000 --> 00:00:12.000\n"
"Bar.\n"))
- (subed-vtt--jump-to-subtitle-text "00:00:10.000")
- (expect (subed-vtt--prepend-subtitle nil 7000 7123) :to-equal 67)
+ (subed-jump-to-subtitle-text "00:00:10.000")
+ (expect (subed-prepend-subtitle nil 7000 7123) :to-equal 67)
(expect (buffer-string) :to-equal (concat "00:00:05.000 -->
00:00:06.000\n"
"Foo.\n\n"
"00:00:07.000 -->
00:00:07.123\n"
@@ -731,8 +731,8 @@ Baz.
"Foo.\n\n"
"00:00:10.000 --> 00:00:12.000\n"
"Bar.\n"))
- (subed-vtt--jump-to-subtitle-text "00:00:10.000")
- (expect (subed-vtt--prepend-subtitle nil 7000 7123 "Baz.")
:to-equal 67)
+ (subed-jump-to-subtitle-text "00:00:10.000")
+ (expect (subed-prepend-subtitle nil 7000 7123 "Baz.") :to-equal
67)
(expect (buffer-string) :to-equal (concat "00:00:05.000 -->
00:00:06.000\n"
"Foo.\n\n"
"00:00:07.000 -->
00:00:07.123\n"
@@ -748,8 +748,8 @@ Baz.
(with-temp-vtt-buffer
(insert (concat "00:00:05.000 --> 00:00:06.000\n"
"Foo.\n"))
- (subed-vtt--jump-to-subtitle-text)
- (expect (subed-vtt--append-subtitle) :to-equal 67)
+ (subed-jump-to-subtitle-text)
+ (expect (subed-append-subtitle) :to-equal 67)
(expect (buffer-string) :to-equal (concat "00:00:05.000 -->
00:00:06.000\n"
"Foo.\n\n"
"00:00:00.000 -->
00:00:01.000\n"
@@ -759,8 +759,8 @@ Baz.
(with-temp-vtt-buffer
(insert (concat "00:00:05.000 --> 00:00:06.000\n"
"Foo.\n"))
- (subed-vtt--jump-to-subtitle-text)
- (expect (subed-vtt--append-subtitle nil 12345) :to-equal 67)
+ (subed-jump-to-subtitle-text)
+ (expect (subed-append-subtitle nil 12345) :to-equal 67)
(expect (buffer-string) :to-equal (concat "00:00:05.000 -->
00:00:06.000\n"
"Foo.\n\n"
"00:00:12.345 -->
00:00:13.345\n"
@@ -770,8 +770,8 @@ Baz.
(with-temp-vtt-buffer
(insert (concat "00:00:05.000 --> 00:00:06.000\n"
"Foo.\n"))
- (subed-vtt--jump-to-subtitle-text)
- (expect (subed-vtt--append-subtitle nil 12345 15000) :to-equal 67)
+ (subed-jump-to-subtitle-text)
+ (expect (subed-append-subtitle nil 12345 15000) :to-equal 67)
(expect (buffer-string) :to-equal (concat "00:00:05.000 -->
00:00:06.000\n"
"Foo.\n\n"
"00:00:12.345 -->
00:00:15.000\n"
@@ -781,8 +781,8 @@ Baz.
(with-temp-vtt-buffer
(insert (concat "00:00:05.000 --> 00:00:06.000\n"
"Foo.\n"))
- (subed-vtt--jump-to-subtitle-text)
- (expect (subed-vtt--append-subtitle nil 12345 15000 "Bar.")
:to-equal 67)
+ (subed-jump-to-subtitle-text)
+ (expect (subed-append-subtitle nil 12345 15000 "Bar.") :to-equal
67)
(expect (buffer-string) :to-equal (concat "00:00:05.000 -->
00:00:06.000\n"
"Foo.\n\n"
"00:00:12.345 -->
00:00:15.000\n"
@@ -796,8 +796,8 @@ Baz.
"Foo.\n\n"
"00:00:05.000 --> 00:00:06.000\n"
"Bar.\n"))
- (subed-vtt--jump-to-subtitle-time-start "00:00:01.000")
- (expect (subed-vtt--append-subtitle) :to-equal 67)
+ (subed-jump-to-subtitle-time-start "00:00:01.000")
+ (expect (subed-append-subtitle) :to-equal 67)
(expect (buffer-string) :to-equal (concat "00:00:01.000 -->
00:00:02.000\n"
"Foo.\n\n"
"00:00:00.000 -->
00:00:01.000\n"
@@ -811,8 +811,8 @@ Baz.
"Foo.\n\n"
"00:00:05.000 --> 00:00:06.000\n"
"Bar.\n"))
- (subed-vtt--jump-to-subtitle-time-start "00:00:01.000")
- (expect (subed-vtt--append-subtitle nil 2500) :to-equal 67)
+ (subed-jump-to-subtitle-time-start "00:00:01.000")
+ (expect (subed-append-subtitle nil 2500) :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:03.500\n"
@@ -826,8 +826,8 @@ Baz.
"Foo.\n\n"
"00:00:05.000 --> 00:00:06.000\n"
"Bar.\n"))
- (subed-vtt--jump-to-subtitle-time-start "00:00:01.000")
- (expect (subed-vtt--append-subtitle nil 2500 4000) :to-equal 67)
+ (subed-jump-to-subtitle-time-start "00:00:01.000")
+ (expect (subed-append-subtitle nil 2500 4000) :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"
@@ -841,8 +841,8 @@ Baz.
"Foo.\n\n"
"00:00:05.000 --> 00:00:06.000\n"
"Bar.\n"))
- (subed-vtt--jump-to-subtitle-time-start "00:00:01.000")
- (expect (subed-vtt--append-subtitle nil 2500 4000 "Baz.")
:to-equal 67)
+ (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"
@@ -857,7 +857,7 @@ Baz.
(insert (concat "00:00:01.000 --> 00:00:02.000\n"
"\n"))
(subed-jump-to-subtitle-text)
- (expect (subed-vtt--append-subtitle) :to-equal 63)
+ (expect (subed-append-subtitle) :to-equal 63)
(expect (buffer-string) :to-equal (concat "00:00:01.000 -->
00:00:02.000\n"
"\n\n"
"00:00:00.000 -->
00:00:01.000\n"
@@ -870,8 +870,8 @@ Baz.
(it "removes the first subtitle."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-text "00:01:01.000")
- (subed-vtt--kill-subtitle)
+ (subed-jump-to-subtitle-text "00:01:01.000")
+ (subed-kill-subtitle)
(expect (buffer-string) :to-equal (concat "WEBVTT\n\n"
"00:02:02.234 -->
00:02:10.345\n"
"Bar.\n\n"
@@ -880,8 +880,8 @@ Baz.
(it "removes it in between."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-text "00:02:02.234")
- (subed-vtt--kill-subtitle)
+ (subed-jump-to-subtitle-text "00:02:02.234")
+ (subed-kill-subtitle)
(expect (buffer-string) :to-equal (concat "WEBVTT\n\n"
"00:01:01.000 -->
00:01:05.123\n"
"Foo.\n\n"
@@ -890,8 +890,8 @@ Baz.
(it "removes the last subtitle."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-text "00:03:03.45")
- (subed-vtt--kill-subtitle)
+ (subed-jump-to-subtitle-text "00:03:03.45")
+ (subed-kill-subtitle)
(expect (buffer-string) :to-equal (concat "WEBVTT\n\n"
"00:01:01.000 -->
00:01:05.123\n"
"Foo.\n\n"
@@ -904,7 +904,7 @@ Baz.
(subed-jump-to-subtitle-id "00:03:03.45")
(backward-char)
(expect (looking-at "^\n00:03:03.45") :to-be t)
- (subed-vtt--kill-subtitle)
+ (subed-kill-subtitle)
(expect (buffer-string) :to-equal (concat "WEBVTT\n\n"
"00:01:01.000 -->
00:01:05.123\n"
"Foo.\n\n"
@@ -916,7 +916,7 @@ Baz.
(subed-jump-to-subtitle-id "00:02:02.234")
(backward-char)
(expect (looking-at "^\n00:02:02.234") :to-be t)
- (subed-vtt--kill-subtitle)
+ (subed-kill-subtitle)
(expect (buffer-string) :to-equal (concat "WEBVTT\n\n"
"00:02:02.234 -->
00:02:10.345\n"
"Bar.\n\n"
@@ -928,37 +928,37 @@ Baz.
(describe "Validating"
(it "works in empty buffer."
(with-temp-vtt-buffer
- (subed-vtt--validate)))
+ (subed-validate)))
(it "works in buffer that contains only newlines."
(with-temp-vtt-buffer
(cl-loop for _ from 1 to 10 do
(insert "\n")
- (subed-vtt--validate))))
+ (subed-validate))))
(it "works in buffer that contains only spaces."
(with-temp-vtt-buffer
(cl-loop for _ from 1 to 10 do
(insert " ")
- (subed-vtt--validate))))
+ (subed-validate))))
(it "works in buffer that contains only spaces and newlines."
(with-temp-vtt-buffer
(cl-loop for _ from 1 to 10 do
(if (eq (random 2) 0)
(insert " ")
(insert "\n"))
- (subed-vtt--validate))))
+ (subed-validate))))
(it "reports invalid stop time."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-time-stop "00:01:01.000")
+ (subed-jump-to-subtitle-time-stop "00:01:01.000")
(forward-char 10)
(insert "3")
- (expect (subed-vtt--validate) :to-throw
+ (expect (subed-validate) :to-throw
'error '("Found invalid stop time: \"00:01:01.000 -->
00:01:05.1323\""))
(expect (point) :to-equal 26)))
(it "runs before saving."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-time-stop "00:01:01.000")
+ (subed-jump-to-subtitle-time-stop "00:01:01.000")
(forward-char 10)
(insert "3")
(expect (subed-prepare-to-save) :to-throw
@@ -967,25 +967,25 @@ Baz.
(it "reports invalid time separator."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-time-stop "00:01:01.000")
+ (subed-jump-to-subtitle-time-stop "00:01:01.000")
(delete-char -1)
- (expect (subed-vtt--validate) :to-throw
+ (expect (subed-validate) :to-throw
'error '("Found invalid separator between start and stop time:
\"00:01:01.000 -->00:01:05.123\""))
(expect (point) :to-equal 21)))
(it "does not report error when last subtitle text is empty."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-text "00:03:03.45")
+ (subed-jump-to-subtitle-text "00:03:03.45")
(kill-whole-line)
(forward-char -2)
- (subed-vtt--validate)
+ (subed-validate)
(expect (point) :to-equal 106)))
(it "preserves point if there is no error."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-text "00:02:02.234")
+ (subed-jump-to-subtitle-text "00:02:02.234")
(forward-char 2)
- (subed-vtt--validate)
+ (subed-validate)
(expect (point) :to-equal 77)))
)
@@ -997,7 +997,7 @@ Baz.
(while (re-search-forward "\n" nil t)
(replace-match " \n"))
(expect (buffer-string) :not :to-equal mock-vtt-data)
- (subed-vtt--sanitize)
+ (subed-sanitize)
(expect (buffer-string) :to-equal mock-vtt-data))
(with-temp-vtt-buffer
(insert mock-vtt-data)
@@ -1005,7 +1005,7 @@ Baz.
(while (re-search-forward "\n" nil t)
(replace-match "\t\n"))
(expect (buffer-string) :not :to-equal mock-vtt-data)
- (subed-vtt--sanitize)
+ (subed-sanitize)
(expect (buffer-string) :to-equal mock-vtt-data)))
(it "removes leading tabs and spaces from all lines."
(with-temp-vtt-buffer
@@ -1014,7 +1014,7 @@ Baz.
(while (re-search-forward "\n" nil t)
(replace-match "\n "))
(expect (buffer-string) :not :to-equal mock-vtt-data)
- (subed-vtt--sanitize)
+ (subed-sanitize)
(expect (buffer-string) :to-equal mock-vtt-data))
(with-temp-vtt-buffer
(insert mock-vtt-data)
@@ -1022,7 +1022,7 @@ Baz.
(while (re-search-forward "\n" nil t)
(replace-match "\n\t"))
(expect (buffer-string) :not :to-equal mock-vtt-data)
- (subed-vtt--sanitize)
+ (subed-sanitize)
(expect (buffer-string) :to-equal mock-vtt-data)))
(it "removes excessive empty lines between subtitles."
(with-temp-vtt-buffer
@@ -1032,12 +1032,12 @@ Baz.
(while (re-search-forward "\n\n" nil t)
(replace-match "\n \n \t \t\t \n\n \t\n"))
(expect (buffer-string) :not :to-equal mock-vtt-data)
- (subed-vtt--sanitize)
+ (subed-sanitize)
(expect (buffer-string) :to-equal mock-vtt-data)))
(it "ensures double newline between subtitles if text of previous subtitle
is empty."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-text "00:01:01.000")
+ (subed-jump-to-subtitle-text "00:01:01.000")
(kill-whole-line)
(expect (buffer-string) :to-equal (concat "WEBVTT\n\n"
"00:01:01.000 -->
00:01:05.123\n"
@@ -1046,7 +1046,7 @@ Baz.
"Bar.\n\n"
"00:03:03.45 --> 00:03:15.5\n"
"Baz.\n"))
- (subed-vtt--sanitize)
+ (subed-sanitize)
(expect (buffer-string) :to-equal (concat "WEBVTT\n\n"
"00:01:01.000 -->
00:01:05.123\n"
"\n\n"
@@ -1060,7 +1060,7 @@ Baz.
(goto-char (point-max))
(insert " \n\t\n\n")
(expect (buffer-string) :not :to-equal mock-vtt-data)
- (subed-vtt--sanitize)
+ (subed-sanitize)
(expect (buffer-string) :to-equal mock-vtt-data)))
(it "ensures a single newline after the last subtitle."
(with-temp-vtt-buffer
@@ -1069,12 +1069,12 @@ Baz.
(while (eq (char-before (point-max)) ?\n)
(delete-backward-char 1))
(expect (buffer-string) :not :to-equal mock-vtt-data)
- (subed-vtt--sanitize)
+ (subed-sanitize)
(expect (buffer-string) :to-equal mock-vtt-data)))
(it "ensures single newline after last subtitle if text is empty."
(with-temp-vtt-buffer
(insert mock-vtt-data)
- (subed-vtt--jump-to-subtitle-text "00:03:03.45")
+ (subed-jump-to-subtitle-text "00:03:03.45")
(kill-whole-line)
(expect (buffer-string) :to-equal (concat "WEBVTT\n\n"
"00:01:01.000 -->
00:01:05.123\n"
@@ -1083,7 +1083,7 @@ Baz.
"Bar.\n\n"
"00:03:03.45 --> 00:03:15.5\n"
""))
- (subed-vtt--sanitize)
+ (subed-sanitize)
(expect (buffer-string) :to-equal (concat "WEBVTT\n\n"
"00:01:01.000 -->
00:01:05.123\n"
"Foo.\n\n"
@@ -1102,7 +1102,7 @@ Baz.
(re-search-forward " --> ")
(replace-match "-->")
(expect (buffer-string) :not :to-equal mock-vtt-data)
- (subed-vtt--sanitize)
+ (subed-sanitize)
(expect (buffer-string) :to-equal mock-vtt-data)))
(it "runs before saving."
(with-temp-vtt-buffer
@@ -1120,7 +1120,7 @@ Baz.
(it "does not insert newline in empty buffer."
(with-temp-vtt-buffer
(expect (buffer-string) :to-equal "")
- (subed-vtt--sanitize)
+ (subed-sanitize)
(expect (buffer-string) :to-equal "")))
)
@@ -1138,7 +1138,7 @@ Baz.
(goto-char (point-min))
(re-search-forward "03:03")
(replace-match "11:03")
- (subed-vtt--sort)
+ (subed-sort)
(expect (buffer-string) :to-equal
(concat
"WEBVTT\n"
@@ -1185,13 +1185,13 @@ Baz.
(replace-match "12:01")
(search-forward "\n")
(expect (current-word) :to-equal "Foo")
- (subed-vtt--sort)
+ (subed-sort)
(expect (current-word) :to-equal "Foo")))
(it "when subtitle text is empty."
(with-temp-vtt-buffer
(insert "WEBVTT\n\n00:12:01.000 --> 00:01:05.123\n")
(goto-char (point-max))
- (subed-vtt--sort)
+ (subed-sort)
(expect (point) :to-equal (1- (point-max)))))
)
)
- [nongnu] elpa/subed 0264eb4ef1 08/22: Bump version to 0.1.0 and add missing undercover-init.el, (continued)
- [nongnu] elpa/subed 0264eb4ef1 08/22: Bump version to 0.1.0 and add missing undercover-init.el, ELPA Syncer, 2022/02/01
- [nongnu] elpa/subed a0d633d7ac 09/22: Fix spaces in Makefile, ELPA Syncer, 2022/02/01
- [nongnu] elpa/subed 4cab871f58 03/22: Add undercover support for coverage testing, ELPA Syncer, 2022/02/01
- [nongnu] elpa/subed 3c7ac78393 12/22: Define jump-to-subtitle-text-at-msecs, ELPA Syncer, 2022/02/01
- [nongnu] elpa/subed f1f8e2ad56 13/22: Bugfixes to make VTT editing work, ELPA Syncer, 2022/02/01
- [nongnu] elpa/subed d6b46496f8 11/22: Fix save hook name, ELPA Syncer, 2022/02/01
- [nongnu] elpa/subed e1b24bff31 05/22: Remove duplicate functions, ELPA Syncer, 2022/02/01
- [nongnu] elpa/subed 5c4ac92ddc 07/22: Add NEWS.org file, ELPA Syncer, 2022/02/01
- [nongnu] elpa/subed f3b48e319e 16/22: Use function instead of quote in subed-define-generic-function, ELPA Syncer, 2022/02/01
- [nongnu] elpa/subed 5e9518da77 18/22: Work around direct call of subed-mode by guessing format, ELPA Syncer, 2022/02/01
- [nongnu] elpa/subed 5ed05ad398 02/22: Implement mode-specific functions with cl-defmethod,
ELPA Syncer <=
- [nongnu] elpa/subed 1f7e32e176 06/22: README.org: document branches, mention autoloads, ELPA Syncer, 2022/02/01
- [nongnu] elpa/subed a58b002fe9 15/22: Clean up undercover-init.el, ELPA Syncer, 2022/02/01
- [nongnu] elpa/subed 3e99c6cb6f 22/22: Merge branch 'derived-mode' into main, ELPA Syncer, 2022/02/01
- [nongnu] elpa/subed b3a4ae08ab 10/22: Add missing tests for merging and subtitle ID at msecs, ELPA Syncer, 2022/02/01
- [nongnu] elpa/subed 94c28993b7 21/22: Define obsolete function aliases, ELPA Syncer, 2022/02/01
- [nongnu] elpa/subed 00d5525712 17/22: Add autoloads, ELPA Syncer, 2022/02/01
- [nongnu] elpa/subed 52fa457512 20/22: subed-define-generic-function: edebug and indent like a defun, ELPA Syncer, 2022/02/01
- [nongnu] elpa/subed 3199cd60d8 19/22: Document subed-define-generic-function, ELPA Syncer, 2022/02/01