Mercurial > hg
changeset 3370:b7fe334ff4fb
mq.el: add mode-line hook
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Thu, 12 Oct 2006 12:15:56 -0700 |
parents | 4bad632913d8 |
children | 8c36b33a27c7 9851f46d6ecc |
files | contrib/mq.el |
diffstat | 1 files changed, 47 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/mq.el Thu Oct 12 14:04:11 2006 -0300 +++ b/contrib/mq.el Thu Oct 12 12:15:56 2006 -0700 @@ -39,8 +39,15 @@ ;;; Internal variables. +(defvar mq-mode nil + "Is this file managed by MQ?") +(make-variable-buffer-local 'mq-mode) +(put 'mq-mode 'permanent-local t) + (defvar mq-patch-history nil) +(defvar mq-top-patch '(nil)) + (defvar mq-prev-buffer nil) (make-variable-buffer-local 'mq-prev-buffer) (put 'mq-prev-buffer 'permanent-local t) @@ -61,6 +68,8 @@ (define-key mq-global-map "p" 'mq-previous) (define-key mq-global-map "t" 'mq-top) +(add-minor-mode 'mq-mode 'mq-mode) + ;;; Refresh edit mode keymap. @@ -94,7 +103,8 @@ (revert-buffer t t t) (hg-restore-context ctx) (message "Refreshing %s...done" (buffer-name)))))) - (hg-update-mode-lines root)) + (hg-update-mode-lines root) + (mq-update-mode-lines root)) (defun mq-last-line () (goto-char (point-max)) @@ -234,6 +244,42 @@ (kill-buffer nil) (switch-to-buffer buf)))) +(defun mq-get-top (root) + (let ((entry (assoc root mq-top-patch))) + (if entry + (cdr entry)))) + +(defun mq-set-top (root patch) + (let ((entry (assoc root mq-top-patch))) + (if entry + (if patch + (setcdr entry patch) + (setq mq-top-patch (delq entry mq-top-patch))) + (setq mq-top-patch (cons (cons root patch) mq-top-patch))))) + +(defun mq-update-mode-lines (root) + (let ((cwd default-directory)) + (cd root) + (condition-case nil + (mq-set-top root (mq-patch-info "qtop")) + (error (mq-set-top root nil))) + (cd cwd)) + (let ((patch (mq-get-top root))) + (save-excursion + (dolist (buf (hg-buffers-visiting-repo root)) + (set-buffer buf) + (if mq-mode + (setq mq-mode (or (and patch (concat " MQ:" patch)) " MQ"))))))) + +(defun mq-mode (&optional arg) + "Minor mode for Mercurial repositories with an MQ patch queue" + (interactive "i") + (cond ((hg-root) + (setq mq-mode (if (null arg) (not mq-mode) + arg)) + (mq-update-mode-lines (hg-root)))) + (run-hooks 'mq-mode-hook)) + (defun mq-edit-mode () "Mode for editing the description of a patch.