Mercurial > hg > mercurial-crew-with-dirclash
comparison contrib/mq.el @ 3370:b7fe334ff4fb
mq.el: add mode-line hook
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Thu, 12 Oct 2006 12:15:56 -0700 |
parents | 06696f9c30c0 |
children | 7b0d0acea6d6 |
comparison
equal
deleted
inserted
replaced
3369:4bad632913d8 | 3370:b7fe334ff4fb |
---|---|
37 :group 'mercurial) | 37 :group 'mercurial) |
38 | 38 |
39 | 39 |
40 ;;; Internal variables. | 40 ;;; Internal variables. |
41 | 41 |
42 (defvar mq-mode nil | |
43 "Is this file managed by MQ?") | |
44 (make-variable-buffer-local 'mq-mode) | |
45 (put 'mq-mode 'permanent-local t) | |
46 | |
42 (defvar mq-patch-history nil) | 47 (defvar mq-patch-history nil) |
48 | |
49 (defvar mq-top-patch '(nil)) | |
43 | 50 |
44 (defvar mq-prev-buffer nil) | 51 (defvar mq-prev-buffer nil) |
45 (make-variable-buffer-local 'mq-prev-buffer) | 52 (make-variable-buffer-local 'mq-prev-buffer) |
46 (put 'mq-prev-buffer 'permanent-local t) | 53 (put 'mq-prev-buffer 'permanent-local t) |
47 | 54 |
59 (define-key mq-global-map "e" 'mq-refresh-edit) | 66 (define-key mq-global-map "e" 'mq-refresh-edit) |
60 (define-key mq-global-map "n" 'mq-next) | 67 (define-key mq-global-map "n" 'mq-next) |
61 (define-key mq-global-map "p" 'mq-previous) | 68 (define-key mq-global-map "p" 'mq-previous) |
62 (define-key mq-global-map "t" 'mq-top) | 69 (define-key mq-global-map "t" 'mq-top) |
63 | 70 |
71 (add-minor-mode 'mq-mode 'mq-mode) | |
72 | |
64 | 73 |
65 ;;; Refresh edit mode keymap. | 74 ;;; Refresh edit mode keymap. |
66 | 75 |
67 (defvar mq-edit-mode-map (make-sparse-keymap)) | 76 (defvar mq-edit-mode-map (make-sparse-keymap)) |
68 (define-key mq-edit-mode-map "\C-c\C-c" 'mq-edit-finish) | 77 (define-key mq-edit-mode-map "\C-c\C-c" 'mq-edit-finish) |
92 (let ((ctx (hg-buffer-context))) | 101 (let ((ctx (hg-buffer-context))) |
93 (message "Refreshing %s..." (buffer-name)) | 102 (message "Refreshing %s..." (buffer-name)) |
94 (revert-buffer t t t) | 103 (revert-buffer t t t) |
95 (hg-restore-context ctx) | 104 (hg-restore-context ctx) |
96 (message "Refreshing %s...done" (buffer-name)))))) | 105 (message "Refreshing %s...done" (buffer-name)))))) |
97 (hg-update-mode-lines root)) | 106 (hg-update-mode-lines root) |
107 (mq-update-mode-lines root)) | |
98 | 108 |
99 (defun mq-last-line () | 109 (defun mq-last-line () |
100 (goto-char (point-max)) | 110 (goto-char (point-max)) |
101 (beginning-of-line) | 111 (beginning-of-line) |
102 (when (looking-at "^$") | 112 (when (looking-at "^$") |
232 (when (or (not (buffer-modified-p)) (y-or-n-p "Really kill this edit? ")) | 242 (when (or (not (buffer-modified-p)) (y-or-n-p "Really kill this edit? ")) |
233 (let ((buf mq-prev-buffer)) | 243 (let ((buf mq-prev-buffer)) |
234 (kill-buffer nil) | 244 (kill-buffer nil) |
235 (switch-to-buffer buf)))) | 245 (switch-to-buffer buf)))) |
236 | 246 |
247 (defun mq-get-top (root) | |
248 (let ((entry (assoc root mq-top-patch))) | |
249 (if entry | |
250 (cdr entry)))) | |
251 | |
252 (defun mq-set-top (root patch) | |
253 (let ((entry (assoc root mq-top-patch))) | |
254 (if entry | |
255 (if patch | |
256 (setcdr entry patch) | |
257 (setq mq-top-patch (delq entry mq-top-patch))) | |
258 (setq mq-top-patch (cons (cons root patch) mq-top-patch))))) | |
259 | |
260 (defun mq-update-mode-lines (root) | |
261 (let ((cwd default-directory)) | |
262 (cd root) | |
263 (condition-case nil | |
264 (mq-set-top root (mq-patch-info "qtop")) | |
265 (error (mq-set-top root nil))) | |
266 (cd cwd)) | |
267 (let ((patch (mq-get-top root))) | |
268 (save-excursion | |
269 (dolist (buf (hg-buffers-visiting-repo root)) | |
270 (set-buffer buf) | |
271 (if mq-mode | |
272 (setq mq-mode (or (and patch (concat " MQ:" patch)) " MQ"))))))) | |
273 | |
274 (defun mq-mode (&optional arg) | |
275 "Minor mode for Mercurial repositories with an MQ patch queue" | |
276 (interactive "i") | |
277 (cond ((hg-root) | |
278 (setq mq-mode (if (null arg) (not mq-mode) | |
279 arg)) | |
280 (mq-update-mode-lines (hg-root)))) | |
281 (run-hooks 'mq-mode-hook)) | |
282 | |
237 (defun mq-edit-mode () | 283 (defun mq-edit-mode () |
238 "Mode for editing the description of a patch. | 284 "Mode for editing the description of a patch. |
239 | 285 |
240 Key bindings | 286 Key bindings |
241 ------------ | 287 ------------ |