From: Mark Wooding Date: Fri, 7 Jul 2017 19:58:05 +0000 (+0100) Subject: el/dot-emacs.el: Basic configuration (and fixes) for Magit's repo list. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/profile/commitdiff_plain/ff6a7bee1d2f9953fa7e87247cc15d89b41d3de8?ds=sidebyside el/dot-emacs.el: Basic configuration (and fixes) for Magit's repo list. By default it should look in `~/src/' for repositories -- duh. A `~/.emacs-local' can override the list as appropriate. Unfortunately, Magit's repo list is rather buggy. * The function `magit-rep-list' returns filenames rather than directory names, and Emacs (24, at least) then sets the wrong current directory when running inferior processes to find out about the repos. * The functions `magit-repolist-column-un{pulled-from,pushed-to}- {upstream,pushremote}' are just screwed because they expect `magit- get-{push,upstream}-branch' to magically turn `nil' into the current branch name, which isn't going to happen. So, configure things, and hack around the bugs. --- diff --git a/dot/emacs b/dot/emacs index d89f442..1062254 100644 --- a/dot/emacs +++ b/dot/emacs @@ -605,6 +605,7 @@ (global-set-key [?\C-c ?m ?m] 'magit-status) (global-set-key [?\C-c ?m ?d] 'magit-dispatch-popup) (global-set-key [?\C-c ?m ?w] 'magit-wip-log) + (global-set-key [?\C-c ?m ?r] 'magit-list-repositories) (global-set-key [?\C-c ?k] 'compile) (global-set-key [?\C-x ?3] 'mdw-split-window-horizontally) (global-set-key [?\M-#] 'calc-dispatch) diff --git a/el/dot-emacs.el b/el/dot-emacs.el index 03946d6..403a5e4 100644 --- a/el/dot-emacs.el +++ b/el/dot-emacs.el @@ -3637,6 +3637,39 @@ (eval-after-load "magit" (magit-wip-before-change-mode 1) (add-to-list 'magit-no-confirm 'safe-with-wip))) +(setq magit-repolist-columns + '(("Name" 16 magit-repolist-column-ident nil) + ("Version" 18 magit-repolist-column-version nil) + ("St" 2 magit-repolist-column-dirty nil) + ("LU" 3 mdw-repolist-column-unpushed-to-upstream nil) + ("Path" 32 magit-repolist-column-path nil))) + +(setq magit-repository-directories '(("~/etc/profile" . 0) + ("~/src/" . 1))) + +(defadvice magit-list-repos (around mdw-dirname () activate compile) + "Make sure the returned names are directory names. +Otherwise child processes get started in the wrong directory and +there is sadness." + (setq ad-return-value (mapcar #'file-name-as-directory ad-do-it))) + +(defun mdw-repolist-column-unpulled-from-upstream (_id) + "Insert number of upstream commits not in the current branch." + (let ((upstream (magit-get-upstream-branch (magit-get-current-branch) t))) + (and upstream + (let ((n (cadr (magit-rev-diff-count "HEAD" upstream)))) + (propertize (number-to-string n) 'face + (if (> n 0) 'bold 'shadow)))))) + +(defun mdw-repolist-column-unpushed-to-upstream (_id) + "Insert number of commits in the current branch but not its upstream." + (let ((upstream (magit-get-upstream-branch (magit-get-current-branch) t))) + (and upstream + (let ((n (car (magit-rev-diff-count "HEAD" upstream)))) + (propertize (number-to-string n) 'face + (if (> n 0) 'bold 'shadow)))))) + ;;;-------------------------------------------------------------------------- ;;; Inferior Emacs Lisp.