├── README.creole └── nic-magit-check.el /README.creole: -------------------------------------------------------------------------------- 1 | Check the status of git repositories with a simple minor mode. 2 | 3 | This is very simple, it just lists your buffers for magit buffers and 4 | then checks those buffers for git changes that haven't been pushed. 5 | 6 | This at least helps you remember when the buffers are still open. 7 | 8 | It's a minor mode so just turn it on with: 9 | 10 | {{{ 11 | M-x nic-magit-track 12 | }}} 13 | 14 | If you have unpushed magit buffers they will appear in the modeline. 15 | 16 | Doing: 17 | 18 | {{{ 19 | M-x nic-magit-next-buffer 20 | }}} 21 | 22 | will move you to the next buffer that you have unpushed commits in. 23 | -------------------------------------------------------------------------------- /nic-magit-check.el: -------------------------------------------------------------------------------- 1 | ;;; nic-magit-check.el --- check magit buffers for unpushed things 2 | 3 | ;; Copyright (C) 2014 Nic Ferrier 4 | 5 | ;; Author: Nic Ferrier 6 | ;; Keywords: vc 7 | ;; Package-requires: ((dash "1.5.0")) 8 | 9 | ;; This program is free software; you can redistribute it and/or modify 10 | ;; it under the terms of the GNU General Public License as published by 11 | ;; the Free Software Foundation, either version 3 of the License, or 12 | ;; (at your option) any later version. 13 | 14 | ;; This program is distributed in the hope that it will be useful, 15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | ;; GNU General Public License for more details. 18 | 19 | ;; You should have received a copy of the GNU General Public License 20 | ;; along with this program. If not, see . 21 | 22 | ;;; Commentary: 23 | 24 | ;; Checks your open magit buffers for things that aren't pushed. 25 | 26 | ;;; Code: 27 | 28 | (require 'dash) 29 | 30 | (defvar nic-magit-check-status "" 31 | "Whether there is an unpushed magit buffer or not. 32 | 33 | The value is a propertized string, the `:unpushed' property 34 | contains the list of the unpushed repositories.") 35 | 36 | (defun nic-magit/check-set (unpushed) 37 | (setq nic-magit-check-status 38 | (propertize 39 | (if unpushed 40 | (propertize 41 | (format "%s[%d]" 42 | (replace-regexp-in-string 43 | "^\\*magit: " "*" 44 | (buffer-name (car unpushed))) 45 | (length unpushed)) 46 | :unpushed unpushed) 47 | "") 'help-echo "Which magit buffers need pushing"))) 48 | 49 | 50 | (defvar nic-magit/idle-timer nil 51 | "Contains the idle timer for idly checking magit buffers.") 52 | 53 | (defun nic-magit/check-init () 54 | "Initializes `nic-magit/idle-timer'." 55 | (unless (timerp nic-magit/idle-timer) 56 | (setq nic-magit/idle-timer 57 | (run-with-idle-timer 10.0 t 'nic-magit-check)))) 58 | 59 | (defun nic-magit-check () 60 | "Main function, checks unpushed magits. 61 | 62 | Updates the variable `nic-magit-check-status'. 63 | 64 | This also calls `nic-magit/check-init' which spawns a timer to 65 | repeatedly do this if no timer is present." 66 | (interactive) 67 | (let ((unpushed 68 | (->> (buffer-list) 69 | (-filter 70 | (lambda (b) 71 | (with-current-buffer b 72 | (eq major-mode 'magit-status-mode)))) 73 | (-filter 74 | (lambda (b) 75 | (with-current-buffer b 76 | (save-excursion 77 | (save-match-data 78 | (goto-char (point-min)) 79 | (re-search-forward "Unpushed commits" nil t))))))))) 80 | (nic-magit/check-set unpushed) 81 | ;; FIXME - the timer spawning should probably be a customize option 82 | (nic-magit/check-init))) 83 | 84 | (defun nic-magit-next-buffer () 85 | "Pop the next unpushed buffer into view." 86 | (interactive) 87 | (pop-to-buffer 88 | (let* ((ll (text-properties-at 0 nic-magit-check-status)) 89 | (unpushed-l (plist-get ll :unpushed)) 90 | (top (car unpushed-l))) 91 | (nic-magit/check-set (append (cdr unpushed-l) (list top))) 92 | top))) 93 | 94 | (defun nic-magit/modeline-content () 95 | (concat " " nic-magit-check-status)) 96 | 97 | ;;;###autoload 98 | (define-minor-mode nic-magit-track 99 | "Track `magit' buffers that are unsynced." 100 | nil nil nil 101 | :global t 102 | :lighter (:eval (nic-magit/modeline-content)) 103 | (nic-magit-check)) 104 | 105 | (provide 'nic-magit-check) 106 | 107 | ;;; nic-magit-check.el ends here 108 | --------------------------------------------------------------------------------