From e4f02647a2fff8eb8bff0dfbbbe341e57606b5ce Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Sun, 17 Jan 2021 09:15:01 +0100 Subject: [PATCH] Refactor code to update magit's repository list to separate function This allows easier updates of this list, without having resort to executing the corresponding code manually. In the future, we could even update that list automatically by attaching the new function to some of projectile's hooks or something. --- init.el | 17 ++++------------- site-lisp/db-utils.el | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/init.el b/init.el index 9e5779a..d9849f1 100644 --- a/init.el +++ b/init.el @@ -617,7 +617,8 @@ db/switch-to-light-theme keyboard-quit-context+ db/convert-lf-to-crlf-in-buffer - db/convert-crlf-to-lf-in-buffer)) + db/convert-crlf-to-lf-in-buffer + db/sync-magit-repos-from-projectile)) (use-package db-hydras :commands (hydra-toggle/body @@ -1405,20 +1406,10 @@ magit-commit-show-diff nil) :config (progn (when (fboundp 'global-magit-file-mode) - (global-magit-file-mode -1)) + (global-magit-file-mode -1)) (global-git-commit-mode +1) - (with-demoted-errors "Non-Fatal Error: %s" - (require 'projectile) - (setq magit-repository-directories - (mapcar - (lambda (dir) - (cons (substring dir 0 -1) 0)) - (cl-remove-if-not - (lambda (project) - (unless (file-remote-p project) - (file-exists-p (concat project "/.git")))) - projectile-known-projects)))))) + (db/sync-magit-repos-from-projectile))) (use-package magit-repos :commands (magit-list-repositories)) diff --git a/site-lisp/db-utils.el b/site-lisp/db-utils.el index 5e1cfc8..3137133 100644 --- a/site-lisp/db-utils.el +++ b/site-lisp/db-utils.el @@ -424,6 +424,21 @@ Does not replace CRLF with CRCRLF, and so on." (while (re-search-forward "\r\n" nil 'noerror) (replace-match "\n"))))) +(defun db/sync-magit-repos-from-projectile () + "Update repositories known to magit from projectile's." + (interactive) + (require 'projectile) + (require 'magit) + (setq magit-repository-directories + (mapcar + (lambda (dir) + (cons (substring dir 0 -1) 0)) + (cl-remove-if-not + (lambda (project) + (unless (file-remote-p project) + (file-exists-p (concat project "/.git")))) + projectile-known-projects)))) + ;;; Extend Input Methods