Skip to content

Instantly share code, notes, and snippets.

@mfisher911
Created February 4, 2012 05:14
Show Gist options
  • Save mfisher911/1735538 to your computer and use it in GitHub Desktop.
Save mfisher911/1735538 to your computer and use it in GitHub Desktop.
Movie List Cleanup Helper Functions
(defun maf-tidy ()
"Tidy a ratings file to be more Org-mode ready."
(interactive)
(save-excursion
(let ((beg (point)))
;; put "|" at the beginning of the line
(while (< (point) (point-max))
(forward-line 0)
(unless (string= "|" (string (char-after)))
(insert "|"))
;; and the end of the line
(end-of-line)
(unless (string= "|" (string (char-before)))
(insert "|"))
(end-of-line)
(backward-char)
;; if the movie's noted as a first/new watching ("3N"), split
;; between "3" and "N"... if the movie's not new, add a blank
;; column where N could be.
(if (string= "N" (string (char-before)))
(backward-char))
(insert "|")
(forward-line))
;; go back to the top
(goto-char beg)
;; Split tab-delimited areas to be pipe-delimited
(while (re-search-forward "\t+" nil t)
(replace-match "|"))
(goto-char beg)
;; and finally two or more spaces to be a pipe-delmiter
(while (re-search-forward " +" nil t)
(replace-match "|")))))
(defun maf-fix-dates ()
"Correct the formatting of the dates from MM/DD/YY to YYYY-MM-DD."
(interactive)
(save-excursion
(let ((beg (point)))
(while (re-search-forward
"\\([0-9]+\\)/\\([0-9]+\\)/\\([0-9]+\\)" nil t)
(replace-match "20\\3-\\1-\\2")))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment