;;; -*- lexical-binding: t -*- ;; ;; this file: ;; https://dataswamp.org/~incal/emacs-init/mpv-incal.el (require 'cl-lib) (defun insert-time-dash () "If you for some reason want to begin edit from 00:00:00.000, rather than just type it. Looks for a \" - \" sequence, every such line gets time." (interactive) (let ((beg (point-min))) (goto-char (point-max)) (save-excursion (while (re-search-backward " - " beg t) (beginning-of-line) (delete-horizontal-space) (insert "00:00:00.000") )))) (defun convert-time () "Convert incomplete time data, that is all of either HH:MM:SS, MM:SS.sss or MM:SS, into HH:MM:SS.sss. When converting, pad with zero hours (00:) and/or zero milliseconds (.000)." (interactive) (goto-char (point-min)) (while (re-search-forward "\\([[:digit:]]\\{2\\}:[[:digit:]]\\{2\\}\\)" nil t) (goto-char (match-beginning 0)) (if (looking-at "[[:digit:]]\\{2\\}:[[:digit:]]\\{2\\}:[[:digit:]]\\{2\\}.[[:digit:]]\\{3\\}") (goto-char (match-end 0)) (if (looking-at "\\([[:digit:]]\\{2\\}:[[:digit:]]\\{2\\}:[[:digit:]]\\{2\\}\\)") (replace-match "\\1.000") (if (looking-at "\\([[:digit:]]\\{2\\}:[[:digit:]]\\{2\\}.[[:digit:]]\\{3\\}\\)") (replace-match "00:\\1") (replace-match "00:\\1.000") ))))) ;; 11:22:33.444 -> 11:22:33.444 (complete so no change) ;; 11:22:33 -> 11:22:33.000 (add milliseconds) ;; 22:33.444 -> 00:22:33.444 (add hours) ;; 22:33 -> 00:22:33.000 (add hours and milliseconds) (defun clear-whitespace () (interactive) (goto-char (point-min)) (save-excursion (while (re-search-forward "[[:blank:]]+" nil t) (replace-match " ") )) (save-excursion (while (re-search-forward "^[[:blank:]]+" nil t) (replace-match "") ))) (defun clear-lang () (interactive) (goto-char (point-min)) (capitalize-region (point-min) (point-max)) (save-excursion (while (re-search-forward "And" nil t) (replace-match "&") )) (save-excursion (while (re-search-forward "Dj\\.\\(.\\)" nil t) (replace-match "DJ \\1") )) (save-excursion (while (re-search-forward "Dj" nil t) (replace-match "DJ") )) (save-excursion (while (re-search-forward "F\\(ea\\)\\{0,1\\}t\\.?" nil t) (replace-match "ft") (downcase-word -1) ))) (defun clear-all () (interactive) (goto-char (point-min)) (flush-lines "^[^0-9]") (clear-whitespace) (convert-time) (clear-lang) ) (defun chapters () (interactive) (goto-char (point-min)) (clear-all) (save-excursion (let ((n 1) (name) ) (while (< (point) (point-max)) (beginning-of-line) (insert (format "CHAPTER%.2d=" n)) (when (re-search-forward " \\(.+\\)" nil t) (setq name (match-string 1)) (replace-match "") (open-line 1) (forward-line) (insert (format "CHAPTER%.2dNAME=%s" n name)) ) (cl-incf n) (forward-line) )))) (defalias 'cc #'clear-all) (defalias 'ch #'chapters) (provide 'mpv-incal)