branch: elpa/subed commit 727275df9eb43c97d835a5984dd7dd0de55d1e32 Author: Random User <rnd...@posteo.de> Commit: Random User <rnd...@posteo.de>
subed-srt-sanitize: Wrap function body in atomic-change-group --- subed/subed-srt.el | 59 +++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/subed/subed-srt.el b/subed/subed-srt.el index 6e711e0..ae8e4e1 100644 --- a/subed/subed-srt.el +++ b/subed/subed-srt.el @@ -461,35 +461,36 @@ each subtitle." (defun subed-srt-sanitize () "Remove surplus newlines and whitespace" (interactive) - (save-match-data - (subed--save-excursion - ;; Remove trailing whitespace from each line and empty lines from end of buffer - (delete-trailing-whitespace (point-min) nil) - - ;; Remove leading spaces and tabs from each line - (goto-char (point-min)) - (while (re-search-forward "^[[:blank:]]+" nil t) - (replace-match "")) - - ;; Remove leading newlines - (goto-char (point-min)) - (while (looking-at "\\`\n+") - (replace-match "")) - - ;; 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) - (point))))) - (when prev-sub-end - (delete-region prev-sub-end (point)) - (insert "\n\n")))) - - ;; Remove trailing newlines - (goto-char (point-max)) - (subed-srt-move-to-subtitle-end) - (when (looking-at "\n*") - (replace-match "\n"))))) + (atomic-change-group + (save-match-data + (subed--save-excursion + ;; Remove trailing whitespace from each line and empty lines from end of buffer + (delete-trailing-whitespace (point-min) nil) + + ;; Remove leading spaces and tabs from each line + (goto-char (point-min)) + (while (re-search-forward "^[[:blank:]]+" nil t) + (replace-match "")) + + ;; Remove leading newlines + (goto-char (point-min)) + (while (looking-at "\\`\n+") + (replace-match "")) + + ;; 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) + (point))))) + (when prev-sub-end + (delete-region prev-sub-end (point)) + (insert "\n\n")))) + + ;; Remove trailing newlines + (goto-char (point-max)) + (subed-srt-move-to-subtitle-end) + (when (looking-at "\n*") + (replace-match "\n")))))) (defun subed-srt-sort () "Sanitize, then sort subtitles by start time and re-number them."