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

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

[nongnu] elpa/subed 3c1a1b4 065/389: Don't validate anything if buffer i


From: ELPA Syncer
Subject: [nongnu] elpa/subed 3c1a1b4 065/389: Don't validate anything if buffer is empty
Date: Fri, 3 Dec 2021 10:59:58 -0500 (EST)

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

    Don't validate anything if buffer is empty
---
 subed/subed-srt.el | 47 ++++++++++++++++++++++++-----------------------
 1 file changed, 24 insertions(+), 23 deletions(-)

diff --git a/subed/subed-srt.el b/subed/subed-srt.el
index be301f1..13e93a0 100644
--- a/subed/subed-srt.el
+++ b/subed/subed-srt.el
@@ -507,29 +507,30 @@ each subtitle."
 (defun subed-srt-validate ()
   "Move point to the first invalid subtitle and report an error."
   (interactive)
-  (atomic-change-group
-    (save-match-data
-      (let ((orig-point (point)))
-        (goto-char (point-min))
-        (while (re-search-forward (format "\\(%s\\|\\`\\)" 
subed-srt--regexp-separator) nil t)
-          (unless (looking-at "^[0-9]+$")
-            (error "Found invalid subtitle ID: %S" (substring (or 
(thing-at-point 'line :no-properties) "\n") 0 -1)))
-          (forward-line)
-          ;; This regex is stricter than `subed-srt--regexp-timestamp'
-          (unless (looking-at 
"^[0-9]\\{2\\}:[0-9]\\{2\\}:[0-9]\\{2\\},[0-9]\\{3\\}")
-            (error "Found invalid start time: %S"  (substring (or 
(thing-at-point 'line :no-properties) "\n") 0 -1)))
-          (condition-case nil
-              (forward-char subed-srt--length-timestamp)
-            (error nil))
-          (unless (looking-at " --> ")
-            (error "Found invalid separator between start and stop time: %S"
-                   (substring (or (thing-at-point 'line :no-properties) "\n") 
0 -1)))
-          (condition-case nil
-              (forward-char 5)
-            (error nil))
-          (unless (looking-at 
"[0-9]\\{2\\}:[0-9]\\{2\\}:[0-9]\\{2\\},[0-9]\\{3\\}$")
-            (error "Found invalid stop time: %S" (substring (or 
(thing-at-point 'line :no-properties) "\n") 0 -1))))
-        (goto-char orig-point)))))
+  (when (> (buffer-size) 0)
+    (atomic-change-group
+      (save-match-data
+        (let ((orig-point (point)))
+          (goto-char (point-min))
+          (while (re-search-forward (format "\\(%s[[^\\']]\\|\\`\\)" 
subed-srt--regexp-separator) nil t)
+            (unless (looking-at "^[0-9]+$")
+              (error "Found invalid subtitle ID: %S" (substring (or 
(thing-at-point 'line :no-properties) "\n") 0 -1)))
+            (forward-line)
+            ;; This regex is stricter than `subed-srt--regexp-timestamp'
+            (unless (looking-at 
"^[0-9]\\{2\\}:[0-9]\\{2\\}:[0-9]\\{2\\},[0-9]\\{3\\}")
+              (error "Found invalid start time: %S"  (substring (or 
(thing-at-point 'line :no-properties) "\n") 0 -1)))
+            (condition-case nil
+                (forward-char subed-srt--length-timestamp)
+              (error nil))
+            (unless (looking-at " --> ")
+              (error "Found invalid separator between start and stop time: %S"
+                     (substring (or (thing-at-point 'line :no-properties) 
"\n") 0 -1)))
+            (condition-case nil
+                (forward-char 5)
+              (error nil))
+            (unless (looking-at 
"[0-9]\\{2\\}:[0-9]\\{2\\}:[0-9]\\{2\\},[0-9]\\{3\\}$")
+              (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."



reply via email to

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