From d5dadb6ad107dd6fa2e57feb32158013b4dd49a1 Mon Sep 17 00:00:00 2001 From: MitchMarq42 Date: Tue, 15 Nov 2022 21:03:37 -0900 Subject: [PATCH] Add function `madots` to use magit for dotfiles. Hacky but mostly works. --- lisp/mitch-packages.el | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/lisp/mitch-packages.el b/lisp/mitch-packages.el index 6dd9193..e51704c 100644 --- a/lisp/mitch-packages.el +++ b/lisp/mitch-packages.el @@ -784,8 +784,30 @@ See https://emacs.stackexchange.com/questions/2538/how-to-define-additional-mode (corfu-terminal-mode +1))) (use-package magit - :commands magit - :hook (magit-mode . turn-off-line-numbers)) + :commands (madots magit-status magit) + :hook (magit-mode . turn-off-line-numbers) + :config + (defun madots--magit-buffers-p () + (not (not ; converts all non-nil values to t + (remove nil ; clean useless elements + (mapcar (lambda (buffer) + (if (string-match-p "magit: " (buffer-name buffer)) + buffer)) + (buffer-list)))))) + (defun madots--cleanup () + "Remove modifications made for `madots' once all magit buffers are killed." + (if (not (madots--magit-buffers-p)) + (progn + (setq magit-git-executable madots--old-magit-exe) + (cancel-function-timers #'madots--cleanup)))) + (defun madots (&optional exe) + "Magit but with custom EXE, default \"dots\"." + (interactive) + (require 'magit) + (setq madots--old-magit-exe magit-git-executable) + (setq magit-git-executable (or exe "dots")) + (magit-status) + (run-with-timer 5 3 #'madots--cleanup))) (use-package hyperbole ;; :straight (:type built-in) ;; doesn't work