From: Carl Worth Date: Sun, 5 Jul 2020 18:23:32 +0000 (-0700) Subject: Add code for integrating nogit with emacs X-Git-Url: https://git.cworth.org/git?p=nogit;a=commitdiff_plain;h=6c2268e15b68765e5e5c093ee7dc293fc1be9f66 Add code for integrating nogit with emacs With hooks for invoking "nogit sync" whenever a nogit-controlled file is opened, edited, or saved. --- diff --git a/README b/README index 0923e5c..fcf7d32 100644 --- a/README +++ b/README @@ -35,6 +35,43 @@ sync" should not ever ask for user input, so it's appropriate to call "nogit sync" from an autoamted system, (such as a text editor's hook when saving a file). +Integration with emacs +====================== +If you're an emacs user, here is some code you could put into your +.emacs file to have "nogit sync" called automatically for you for any +nogit-controlled files whenever you open one, begin editing it, or +save it: + + ; Run "nogit sync" if there is a .noggit directory here. + ; + ; Note: There is an important protection built into this implementation: + ; + ; We bind 'in-nogit-sync and test whether it's bound to avoid + ; infinite recursion. This could otherwise come about because + ; the revert-buffer function could trigger the find-file-hook + ; and recurse. + (defun nogit-sync-if-configured () + (interactive) + (if (and + (buffer-file-name) + (file-exists-p (format "%s/../.nogit" (buffer-file-name))) + (not (boundp 'in-nogit-sync)) + ) + (let ((in-nogit-sync t)) + (message (substring (shell-command-to-string "nogit sync") 0 -1)) + (revert-buffer nil t) + ) + ) + ) + + ; Arrange to run "nogit sync" when the user loads a nogit-controlled file, + ; starts editing it for the first time, or saves it. + (add-hook 'find-file-hook 'nogit-sync-if-configured) + (add-hook 'first-change-hook 'nogit-sync-if-configured) + (add-hook 'after-save-hook 'nogit-sync-if-configured) + +Preparing git repositories for use with nogit +============================================= If you're interested in setting up a parent and child repository for use with nogit, here's what you'll want to do: @@ -61,7 +98,6 @@ use with nogit, here's what you'll want to do: Motivation ========== - I originally came up with nogit when I started maintaining a simple TODO file for a project which had a code implementation split across multiple code repositories. I was intentionally keeping my TODO file