Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(defvar autocommit-dir-set '()
"Set of directories for which there is a pending timer job")
(defun autocommit-schedule-commit (dn)
"Schedule an autocommit (and push) if one is not already scheduled for the given dir."
(if (null (member dn autocommit-dir-set))
10 nil
(lambda (dn)
(setq autocommit-dir-set (remove dn autocommit-dir-set))
(message (concat "Committing org files in " dn))
(shell-command (concat "cd " dn " && git commit -m 'Updated org files.'"))
(shell-command (concat "cd " dn " && git push & /usr/bin/true"))
(run-hooks 'dustin-autocommit-hooks))
(setq autocommit-dir-set (cons dn autocommit-dir-set)))))
(defun autocommit-after-save-hook ()
"After-save-hook to 'git add' the modified file and schedule a commit and push in the idle loop."
(let ((fn (buffer-file-name)))
(message "git adding %s" fn)
(shell-command (concat "git add " fn))
(autocommit-schedule-commit (file-name-directory fn))))
(defun autocommit-setup-save-hook ()
"Set up the autocommit save hook for the current file."
(message "Set up autocommit save hook for this buffer.")
(add-hook 'after-save-hook 'autocommit-after-save-hook nil t))
;; Integration
(defun dustin-visiting-a-file ()
(let* ((fn (buffer-file-name))
(dn (file-name-directory fn)))
(if (equal dn (expand-file-name "~/org/"))
(message "Setting up local hook for %s (in %s)"
(file-name-nondirectory fn) dn)
(add-hook 'dustin-autocommit-hooks 'org-mobile-push)))))
(add-hook 'find-file-hook 'dustin-visiting-a-file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment