diff --git a/lisp/git-auto-fast-forward-mode.el b/lisp/git-auto-fast-forward-mode.el index 16327e0..cf127e9 100644 --- a/lisp/git-auto-fast-forward-mode.el +++ b/lisp/git-auto-fast-forward-mode.el @@ -23,9 +23,7 @@ ;;; Commentary: ;;; Code: -(require 'my-org-agenda-files) - -(defvar gaff/watch-directories (list (list my/agenda-folder "origin/desktop" "origin/gaming-laptop" "origin/puppet" "origin/mobile"))) +(defvar gaff/watch-directories nil) (defun ga/magit-not-in-progress () (and (not (magit-rebase-in-progress-p)) diff --git a/lisp/org-config/my-agenda-lib.el b/lisp/org-config/my-agenda-lib.el new file mode 100644 index 0000000..325f54f --- /dev/null +++ b/lisp/org-config/my-agenda-lib.el @@ -0,0 +1,28 @@ +;;; my-agenda-lib.el --- -*- lexical-binding: t -*- + +;; Copyright (C) 2022 Benson Chu + +;; Author: Benson Chu +;; Created: [2022-06-13 10:57] + +;; This file is not part of GNU Emacs + +;; This program is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;;; Code: + +(provide 'my-agenda-lib) +;;; my-agenda-lib.el ends here diff --git a/lisp/org-config/my-org-autosync.el b/lisp/org-config/my-org-autosync.el new file mode 100644 index 0000000..df5df38 --- /dev/null +++ b/lisp/org-config/my-org-autosync.el @@ -0,0 +1,119 @@ +;;; my-org-autosync.el --- -*- lexical-binding: t -*- + +;; Copyright (C) 2022 Benson Chu + +;; Author: Benson Chu +;; Created: [2022-09-01 10:09] + +;; This file is not part of GNU Emacs + +;; This program is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;;; Code: +(require 'use-package) +(use-package git-auto-commit-mode) +(require 'git-auto-fast-forward-mode) +(require 'ssh-key-management) +(use-package keychain-environment) + +(require 'my-org-agenda-files) +(setq gaff/watch-directories (list (list my/agenda-folder "origin/desktop" "origin/gaming-laptop" "origin/puppet" "origin/mobile"))) + +(setq gac-automatically-add-new-files-p nil) +(setq-default gac-debounce-interval 300) + +(defmacro defun-cached (name args &rest body) + (let ((var-name (intern (concat (symbol-name name) "--cached")))) + `(progn + (defvar ,var-name t) + + (defun ,name ,args + (when ,var-name + (setq ,var-name nil) + (run-with-timer 15 nil #'(lambda () (setq ,var-name t))) + ,@body))))) + +(defun gac-use-magit-push (buffer) + (let ((default-directory (file-name-directory (buffer-file-name buffer)))) + (magit-push-current-to-pushremote nil))) + +(advice-add #'gac-push :override #'gac-use-magit-push) + + ;; (defvar gac-auto-merge-branch-list nil) + ;; (make-variable-buffer-local 'gac-auto-merge-branch-list) + + +(defun-cached gac-run-gaff () + (gaff/trigger)) + +(defun-cached gac-run-ssh-add () + (rb/ssh-add)) + +(add-hook 'git-auto-commit-mode-hook + #'gac-run-gaff) + +(add-hook 'git-auto-commit-mode-hook + #'gac-run-ssh-add) + +(add-hook 'git-auto-commit-mode-hook + #'gac-after-save-func t t) + +(add-hook 'git-auto-commit-mode-hook + #'keychain-refresh-environment) + +(add-to-list 'safe-local-variable-values + '(gac-automatically-push-p . t)) + +(add-to-list 'safe-local-variable-values + '(gac-automatically-push-p . nil)) + +(defun gac-commit-message (filename) + (format "%s autocommit: %s\n\n%s" + (system-name) + (format-time-string "%Y/%m/%d %H:%M:%S") + filename)) + +(setq gac-default-message + #'gac-commit-message) + +(defun my/gac--debounced-save () + (let* ((actual-buffer (current-buffer))) + (when-let (current-timer (gethash actual-buffer gac--debounce-timers)) + (remhash actual-buffer gac--debounce-timers) + (cancel-timer current-timer)) + (puthash actual-buffer + (run-at-time gac-debounce-interval nil + #'gac--after-save + actual-buffer) + gac--debounce-timers))) + +(advice-add #'gac--debounced-save + :override + #'my/gac--debounced-save) + +(defun gac-debounce-again-if-magit-in-progress (buf) + (with-current-buffer buf + (if (ga/should-be-automatic) + t + (gac--debounced-save) + nil))) + +(advice-add #'gac--after-save + :before-while + #'gac-debounce-again-if-magit-in-progress) + +(provide 'my-org-autosync) +;;; my-org-autosync.el ends here diff --git a/lisp/org-config/my-org-misc.el b/lisp/org-config/my-org-misc.el index 87b0b8e..4d1817f 100644 --- a/lisp/org-config/my-org-misc.el +++ b/lisp/org-config/my-org-misc.el @@ -129,93 +129,6 @@ (setq org-html-table-default-attributes '(:border "2" :cellspacing "0" :cellpadding "6"))) -(use-package git-auto-commit-mode - :config - (require 'git-auto-fast-forward-mode) - (require 'ssh-key-management) - (use-package keychain-environment) - (setq gac-automatically-add-new-files-p nil) - (setq-default gac-debounce-interval 300) - - (defmacro defun-cached (name args &rest body) - (let ((var-name (intern (concat (symbol-name name) "--cached")))) - `(progn - (defvar ,var-name t) - - (defun ,name ,args - (when ,var-name - (setq ,var-name nil) - (run-with-timer 15 nil #'(lambda () (setq ,var-name t))) - ,@body))))) - - (defun gac-use-magit-push (buffer) - (let ((default-directory (file-name-directory (buffer-file-name buffer)))) - (magit-push-current-to-pushremote nil))) - - (advice-add #'gac-push :override #'gac-use-magit-push) - - ;; (defvar gac-auto-merge-branch-list nil) - ;; (make-variable-buffer-local 'gac-auto-merge-branch-list) - - (defun-cached gac-run-gaff () - (gaff/trigger)) - - (defun-cached gac-run-ssh-add () - (rb/ssh-add)) - - (add-hook 'git-auto-commit-mode-hook - #'gac-run-gaff) - - (add-hook 'git-auto-commit-mode-hook - #'gac-run-ssh-add) - - (add-hook 'git-auto-commit-mode-hook - #'gac-after-save-func t t) - - (add-hook 'git-auto-commit-mode-hook - #'keychain-refresh-environment) - - (add-to-list 'safe-local-variable-values - '(gac-automatically-push-p . t)) - - (add-to-list 'safe-local-variable-values - '(gac-automatically-push-p . nil)) - - (defun gac-commit-message (filename) - (format "%s autocommit: %s\n\n%s" - (system-name) - (format-time-string "%Y/%m/%d %H:%M:%S") - filename)) - - (setq gac-default-message - #'gac-commit-message) - - (defun my/gac--debounced-save () - (let* ((actual-buffer (current-buffer))) - (when-let (current-timer (gethash actual-buffer gac--debounce-timers)) - (remhash actual-buffer gac--debounce-timers) - (cancel-timer current-timer)) - (puthash actual-buffer - (run-at-time gac-debounce-interval nil - #'gac--after-save - actual-buffer) - gac--debounce-timers))) - - (advice-add #'gac--debounced-save - :override - #'my/gac--debounced-save) - - (defun gac-debounce-again-if-magit-in-progress (buf) - (with-current-buffer buf - (if (ga/should-be-automatic) - t - (gac--debounced-save) - nil))) - - (advice-add #'gac--after-save - :before-while - #'gac-debounce-again-if-magit-in-progress)) - (when (eq window-system 'x) (define-key org-mode-map (kbd "C-S-b") diff --git a/lisp/org-config/my-org.el b/lisp/org-config/my-org.el index 7ac1eaf..8701a67 100644 --- a/lisp/org-config/my-org.el +++ b/lisp/org-config/my-org.el @@ -32,6 +32,7 @@ (require 'org-delay) (require 'my-org-misc) +(require 'my-org-autosync) (require 'my-org-indent) (require 'my-org-agenda-commands) (require 'my-org-capture-templates) diff --git a/lisp/work-config/work-org-autosync.el b/lisp/work-config/work-org-autosync.el new file mode 100644 index 0000000..4ca5a97 --- /dev/null +++ b/lisp/work-config/work-org-autosync.el @@ -0,0 +1,101 @@ +;;; my-org-autosync.el --- -*- lexical-binding: t -*- + +;; Copyright (C) 2022 Benson Chu + +;; Author: Benson Chu +;; Created: [2022-09-01 10:09] + +;; This file is not part of GNU Emacs + +;; This program is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;;; Code: +(require 'use-package) +(use-package git-auto-commit-mode) +(use-package keychain-environment) + +(setq gac-automatically-add-new-files-p nil) +(setq-default gac-debounce-interval 300) + +(defmacro defun-cached (name args &rest body) + (let ((var-name (intern (concat (symbol-name name) "--cached")))) + `(progn + (defvar ,var-name t) + + (defun ,name ,args + (when ,var-name + (setq ,var-name nil) + (run-with-timer 15 nil #'(lambda () (setq ,var-name t))) + ,@body))))) + +(defun gac-use-magit-push (buffer) + (let ((default-directory (file-name-directory (buffer-file-name buffer)))) + (magit-push-current-to-pushremote nil))) + +(advice-add #'gac-push :override #'gac-use-magit-push) + + ;; (defvar gac-auto-merge-branch-list nil) + ;; (make-variable-buffer-local 'gac-auto-merge-branch-list) + +(add-hook 'git-auto-commit-mode-hook + #'gac-after-save-func t t) + +(add-hook 'git-auto-commit-mode-hook + #'keychain-refresh-environment) + +(add-to-list 'safe-local-variable-values + '(gac-automatically-push-p . t)) + +(add-to-list 'safe-local-variable-values + '(gac-automatically-push-p . nil)) + +(defun gac-commit-message (filename) + (format "%s autocommit: %s\n\n%s" + (system-name) + (format-time-string "%Y/%m/%d %H:%M:%S") + filename)) + +(setq gac-default-message + #'gac-commit-message) + +(defun my/gac--debounced-save () + (let* ((actual-buffer (current-buffer))) + (when-let (current-timer (gethash actual-buffer gac--debounce-timers)) + (remhash actual-buffer gac--debounce-timers) + (cancel-timer current-timer)) + (puthash actual-buffer + (run-at-time gac-debounce-interval nil + #'gac--after-save + actual-buffer) + gac--debounce-timers))) + +(advice-add #'gac--debounced-save + :override + #'my/gac--debounced-save) + +(defun gac-debounce-again-if-magit-in-progress (buf) + (with-current-buffer buf + (if (ga/should-be-automatic) + t + (gac--debounced-save) + nil))) + +(advice-add #'gac--after-save + :before-while + #'gac-debounce-again-if-magit-in-progress) + +(provide 'my-org-autosync) +;;; my-org-autosync.el ends here