X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/blobdiff_plain/bc11fb0841e6d41ea7471d8c0f526b111b06b2ef..6fdc354699860c63cc7fbab9c25b2b6c874074a8:/contrib/stgit.el diff --git a/contrib/stgit.el b/contrib/stgit.el index dd3c92b..f08b007 100644 --- a/contrib/stgit.el +++ b/contrib/stgit.el @@ -118,8 +118,8 @@ variable is used instead." (defcustom stgit-noname-patch-line-format "%s%m%e%D" "The alternate format string used to format patch lines. It has the same semantics as `stgit-patch-line-format', and the -display can be toggled between the two formats using -\\>\\[stgit-toggle-patch-names]. +display can be toggled between the two formats using \ +\\\\[stgit-toggle-patch-names]. The alternate form is used when the patch name is hidden." :type 'string @@ -129,8 +129,8 @@ The alternate form is used when the patch name is hidden." (defcustom stgit-default-show-patch-names t "If non-nil, default to showing patch names in a new stgit buffer. -Use \\\\[stgit-toggle-patch-names] to toggle the -this setting in an already-started StGit buffer." +Use \\\\[stgit-toggle-patch-names] \ +to toggle the this setting in an already-started StGit buffer." :type 'boolean :group 'stgit :link '(variable-link stgit-show-patch-names)) @@ -289,14 +289,19 @@ A newline is appended." (error)) (insert (match-string 1 text) ?\n)) +(defun stgit-line-format () + "Return the current line format; one of +`stgit-patch-line-format' and `stgit-noname-patch-line-format'" + (if stgit-show-patch-names + stgit-patch-line-format + stgit-noname-patch-line-format)) + (defun stgit-patch-pp (patch) (let* ((status (stgit-patch->status patch)) (start (point)) (name (stgit-patch->name patch)) (face (cdr (assq status stgit-patch-status-face-alist))) - (fmt (if stgit-show-patch-names - stgit-patch-line-format - stgit-noname-patch-line-format)) + (fmt (stgit-line-format)) (spec (format-spec-make ?s (case status ('applied "+") @@ -1261,17 +1266,17 @@ See also \\[customize-group] for the \"stgit\" group." major-mode 'stgit-mode goal-column 2) (use-local-map stgit-mode-map) - (set (make-local-variable 'list-buffers-directory) default-directory) - (set (make-local-variable 'stgit-marked-patches) nil) - (set (make-local-variable 'stgit-expanded-patches) (list :work :index)) - (set (make-local-variable 'stgit-show-patch-names) - stgit-default-show-patch-names) - (set (make-local-variable 'stgit-show-worktree) stgit-default-show-worktree) - (set (make-local-variable 'stgit-show-ignored) stgit-default-show-ignored) - (set (make-local-variable 'stgit-show-unknown) stgit-default-show-unknown) - (set (make-local-variable 'stgit-index-node) nil) - (set (make-local-variable 'stgit-worktree-node) nil) - (set (make-local-variable 'parse-sexp-lookup-properties) t) + (mapc (lambda (x) (set (make-local-variable (car x)) (cdr x))) + `((list-buffers-directory . ,default-directory) + (parse-sexp-lookup-properties . t) + (stgit-expanded-patches . (:work :index)) + (stgit-index-node . nil) + (stgit-worktree-node . nil) + (stgit-marked-patches . nil) + (stgit-show-ignored . ,stgit-default-show-ignored) + (stgit-show-patch-names . ,stgit-default-show-patch-names) + (stgit-show-unknown . ,stgit-default-show-unknown) + (stgit-show-worktree . ,stgit-default-show-worktree))) (set-variable 'truncate-lines 't) (add-hook 'after-save-hook 'stgit-update-stgit-for-buffer) (unless stgit-did-advise @@ -1300,15 +1305,53 @@ refresh the stgit buffers as the git status of files change." (add-to-list 'after-load-alist `(,feature (stgit-advise-funlist (quote ,funlist))))))) + ;; lists of ( ...) to be advised '((vc-git vc-git-rename-file vc-git-revert vc-git-register) - (git git-add-file git-checkout git-revert-file git-remove-file)))) + (git git-add-file git-checkout git-revert-file git-remove-file) + (dired dired-delete-file)))) + +(defvar stgit-pending-refresh-buffers nil + "Alist of (cons `buffer' `refresh-index') of buffers that need +to be refreshed. `refresh-index' is non-nil if both work tree +and index need to be refreshed.") + +(defun stgit-run-pending-refreshs () + "Run all pending stgit buffer updates as posted by `stgit-post-refresh'." + (let ((buffers stgit-pending-refresh-buffers) + (stgit-inhibit-messages t)) + (setq stgit-pending-refresh-buffers nil) + (while buffers + (let* ((elem (car buffers)) + (buffer (car elem)) + (refresh-index (cdr elem))) + (when (buffer-name buffer) + (with-current-buffer buffer + (stgit-refresh-worktree) + (when refresh-index (stgit-refresh-index))))) + (setq buffers (cdr buffers))))) + +(defun stgit-post-refresh (buffer refresh-index) + "Update worktree status in BUFFER when Emacs becomes idle. If +REFRESH-INDEX is non-nil, also update the index." + (unless stgit-pending-refresh-buffers + (run-with-idle-timer 0.1 nil 'stgit-run-pending-refreshs)) + (let ((elem (assq buffer stgit-pending-refresh-buffers))) + (if elem + ;; if buffer is already present, set its refresh-index flag if + ;; necessary + (when refresh-index + (setcdr elem t)) + ;; new entry + (setq stgit-pending-refresh-buffers + (cons (cons buffer refresh-index) + stgit-pending-refresh-buffers))))) (defun stgit-update-stgit-for-buffer (&optional refresh-index) - "Refresh worktree status in any `stgit-mode' buffer that shows -the status of the current buffer. + "When Emacs becomes idle, refresh worktree status in any +`stgit-mode' buffer that shows the status of the current buffer. -If REFRESH-INDEX is not-nil, also update the index." - (let* ((dir (cond ((eq major-mode 'git-status-mode) +If REFRESH-INDEX is non-nil, also update the index." + (let* ((dir (cond ((derived-mode-p 'stgit-status-mode 'dired-mode) default-directory) (buffer-file-name (file-name-directory @@ -1317,9 +1360,7 @@ If REFRESH-INDEX is not-nil, also update the index." (error nil)))) (buffer (and gitdir (stgit-find-buffer gitdir)))) (when buffer - (with-current-buffer buffer - (stgit-refresh-worktree) - (when refresh-index (stgit-refresh-index)))))) + (stgit-post-refresh buffer refresh-index)))) (defun stgit-add-mark (patchsym) "Mark the patch PATCHSYM."