[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/subed 651c6de 031/389: Wrap some function bodies in save-m
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/subed 651c6de 031/389: Wrap some function bodies in save-match-data |
Date: |
Fri, 3 Dec 2021 10:59:51 -0500 (EST) |
branch: elpa/subed
commit 651c6ded17b69aeb4c0fd3a95ba254c111f8d567
Author: Random User <rndusr@posteo.de>
Commit: Random User <rndusr@posteo.de>
Wrap some function bodies in save-match-data
---
subed/subed-srt.el | 105 ++++++++++++++++++++++++++++-------------------------
1 file changed, 56 insertions(+), 49 deletions(-)
diff --git a/subed/subed-srt.el b/subed/subed-srt.el
index da1b86a..a99adff 100644
--- a/subed/subed-srt.el
+++ b/subed/subed-srt.el
@@ -43,15 +43,16 @@
(defun subed-srt--timestamp-to-msecs (time-string)
"Find HH:MM:SS,MS pattern in TIME-STRING and convert it to milliseconds.
Return nil if TIME-STRING doesn't match the pattern."
- (when (string-match subed-srt--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)))
- (msecs (string-to-number (match-string 4 time-string))))
- (+ (* (truncate hours) 3600000)
- (* (truncate mins) 60000)
- (* (truncate secs) 1000)
- (truncate msecs)))))
+ (save-match-data
+ (when (string-match subed-srt--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)))
+ (msecs (string-to-number (match-string 4 time-string))))
+ (+ (* (truncate hours) 3600000)
+ (* (truncate mins) 60000)
+ (* (truncate secs) 1000)
+ (truncate msecs))))))
(defun subed-srt--msecs-to-timestamp (msecs)
"Convert MSECS to string in the format HH:MM:SS,MS."
@@ -69,26 +70,27 @@ Return nil if TIME-STRING doesn't match the pattern."
If MSECS is between subtitles, return the subtitle that starts
after MSECS if there is one and its start time is >= MSECS +
1000. Otherwise return the closest subtitle before MSECS."
- (save-excursion
- (goto-char (point-min))
- (let* ((secs (/ msecs 1000))
- (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 "\\(\n\n\\|\\`\\)[0-9]+\n%02d:"
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 'last-subtitle-reached
- (while (<= (subed-srt--subtitle-msecs-start) msecs)
- (unless (subed-srt-forward-subtitle-id)
- (throw 'last-subtitle-reached nil))))
- ;; Move back to previous subtitle if start of current subtitle is in the
- ;; future (i.e. MSECS is between subtitles)
- (when (> (subed-srt--subtitle-msecs-start) msecs)
- (subed-srt-backward-subtitle-id))
- (subed-srt--subtitle-id)))
+ (save-match-data
+ (save-excursion
+ (goto-char (point-min))
+ (let* ((secs (/ msecs 1000))
+ (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)
+ (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 'last-subtitle-reached
+ (while (<= (subed-srt--subtitle-msecs-start) msecs)
+ (unless (subed-srt-forward-subtitle-id)
+ (throw 'last-subtitle-reached nil))))
+ ;; Move back to previous subtitle if start of current subtitle is in the
+ ;; future (i.e. MSECS is between subtitles)
+ (when (> (subed-srt--subtitle-msecs-start) msecs)
+ (subed-srt-backward-subtitle-id))
+ (subed-srt--subtitle-id))))
(defun subed-srt--subtitle-msecs-start (&optional sub-id)
"Subtitle start time in milliseconds or nil if it can't be found."
@@ -167,27 +169,30 @@ See also `subed-srt--subtitle-id-at-msecs'."
"Move point to subtitle's start time.
Return point or nil if no start time could be found."
(interactive)
- (when (subed-srt-move-to-subtitle-id sub-id)
- (forward-line)
- (when (looking-at subed-srt--regexp-timestamp)
- (point))))
+ (save-match-data
+ (when (subed-srt-move-to-subtitle-id sub-id)
+ (forward-line)
+ (when (looking-at subed-srt--regexp-timestamp)
+ (point)))))
(defun subed-srt-move-to-subtitle-time-stop (&optional sub-id)
"Move point to subtitle's stop time.
Return point or nil if no stop time could be found."
(interactive)
- (when (subed-srt-move-to-subtitle-id sub-id)
- (search-forward " --> " nil t)
- (when (looking-at subed-srt--regexp-timestamp)
- (point))))
+ (save-match-data
+ (when (subed-srt-move-to-subtitle-id sub-id)
+ (search-forward " --> " nil t)
+ (when (looking-at subed-srt--regexp-timestamp)
+ (point)))))
(defun subed-srt-move-to-subtitle-text (&optional sub-id)
"Move point on the first character of subtitle's text.
Return point."
(interactive)
(when (subed-srt-move-to-subtitle-id sub-id)
- (forward-line 2)
- (point)))
+ (save-match-data
+ (when (re-search-forward (concat subed-srt--regexp-duration
"[[:blank:]]*\n") nil t)
+ (point)))))
(defun subed-srt-move-to-subtitle-text-at-msecs (msecs)
"Move point to the text of the subtitle that is playing at MSECS.
@@ -210,8 +215,9 @@ Return point unless point did not change."
Return point or nil if point didn't change (e.g. if called on the
last subtitle)."
(interactive)
- (when (re-search-forward (concat subed-srt--regexp-separator "[[:alnum:]]")
nil t)
- (subed-srt-move-to-subtitle-id)))
+ (save-match-data
+ (when (re-search-forward (concat subed-srt--regexp-separator "[0-9]+\n")
nil t)
+ (subed-srt-move-to-subtitle-id))))
(defun subed-srt-backward-subtitle-id ()
"Move point to previous subtitle's ID.
@@ -420,14 +426,15 @@ Return point or nil if there is no previous subtitle."
(defun subed-srt--regenerate-ids ()
"Ensure subtitle IDs start at 1 and are incremented by 1 for
each subtitle."
- (save-excursion
- (goto-char (point-min))
- (let ((id 1))
- (while (looking-at "^[0-9]+$")
- (kill-word 1)
- (insert (format "%d" id))
- (setq id (1+ id))
- (subed-srt-forward-subtitle-id)))))
+ (save-match-data
+ (save-excursion
+ (goto-char (point-min))
+ (let ((id 1))
+ (while (looking-at "^[0-9]+$")
+ (kill-word 1)
+ (insert (format "%d" id))
+ (setq id (1+ id))
+ (subed-srt-forward-subtitle-id))))))
(defun subed-srt-sanitize ()
"Remove surplus newlines and whitespace"
- [nongnu] elpa/subed 42199eb 095/389: Workaround for GitHub's lack of support for ~~/path/in/home~, (continued)
- [nongnu] elpa/subed 42199eb 095/389: Workaround for GitHub's lack of support for ~~/path/in/home~, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 5c51000 101/389: Call time-adjusted-hook functions with start time, not stop time, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 53d1e33 102/389: Fix error when adjusting start/stop time in empty buffer, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed a0cb0f1 108/389: Keep region active during subtitle movement, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 2c7554a 109/389: Wrap subed--for-each-subtitle in atomic-change-group, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed e792e0f 122/389: Fix test description, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 489bbea 130/389: Remove subed-milliseconds-move, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed a7dda70 137/389: Add subtitle shifting to features, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed a819a93 139/389: Fix test description, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 06851d8 143/389: Prevent overlapping when adjusting subtitle start/stop time, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 651c6de 031/389: Wrap some function bodies in save-match-data,
ELPA Syncer <=
- [nongnu] elpa/subed 57c902a 068/389: subed-srt-sanitize: Don't change buffer unless it's necessary, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 1571de4 070/389: Use prefix arg to set start/stop time adjustment, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed f832a1d 075/389: Add more tests for subed-srt-move-to-subtitle-end, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 8374498 076/389: README: Split feature list and some rewording, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed d0708e5 080/389: Fix screenshot, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 03cd2bf 097/389: Wrap msecs-to-timestamp in save-match-data, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 4960c74 098/389: Make timestamp parsing more robust, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed 9b95137 104/389: Test subed--for-each-subtitle more thoroughly, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed ec03689 105/389: Fix subed--for-each-subtitle, ELPA Syncer, 2021/12/03
- [nongnu] elpa/subed a7cbce6 107/389: Test subed-move-subtitle-forward/backward more thoroughly, ELPA Syncer, 2021/12/03