author | Bryan O'Sullivan <bos@serpentine.com> |
Tue, 22 Aug 2006 16:04:58 -0700 | |
changeset 3007 | 425413d9ef59 |
child 3009 | e2bad806ccc3 |
permissions | -rw-r--r-- |
3007
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
1 |
;;; mq.el --- Emacs support for Mercurial Queues |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
2 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
3 |
;; Copyright (C) 2006 Bryan O'Sullivan |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
4 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
5 |
;; Author: Bryan O'Sullivan <bos@serpentine.com> |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
6 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
7 |
;; mq.el is free software; you can redistribute it and/or modify it |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
8 |
;; under the terms of version 2 of the GNU General Public License as |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
9 |
;; published by the Free Software Foundation. |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
10 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
11 |
;; mq.el is distributed in the hope that it will be useful, but |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
12 |
;; WITHOUT ANY WARRANTY; without even the implied warranty of |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
13 |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
14 |
;; General Public License for more details. |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
15 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
16 |
;; You should have received a copy of the GNU General Public License |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
17 |
;; along with mq.el, GNU Emacs, or XEmacs; see the file COPYING (`C-h |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
18 |
;; C-l'). If not, write to the Free Software Foundation, Inc., 59 |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
19 |
;; Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
20 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
21 |
(require 'mercurial) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
22 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
23 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
24 |
(defcustom mq-mode-hook nil |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
25 |
"Hook run when a buffer enters mq-mode." |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
26 |
:type 'sexp |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
27 |
:group 'mercurial) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
28 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
29 |
(defcustom mq-global-prefix "\C-cq" |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
30 |
"The global prefix for Mercurial Queues keymap bindings." |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
31 |
:type 'sexp |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
32 |
:group 'mercurial) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
33 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
34 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
35 |
;;; Internal variables. |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
36 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
37 |
(defvar mq-patch-history nil) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
38 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
39 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
40 |
;;; Global keymap. |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
41 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
42 |
(defvar mq-global-map (make-sparse-keymap)) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
43 |
(fset 'mq-global-map mq-global-map) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
44 |
(global-set-key mq-global-prefix 'mq-global-map) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
45 |
(define-key mq-global-map "." 'mq-push) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
46 |
(define-key mq-global-map ">" 'mq-push-all) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
47 |
(define-key mq-global-map "," 'mq-pop) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
48 |
(define-key mq-global-map "<" 'mq-pop-all) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
49 |
(define-key mq-global-map "r" 'mq-refresh) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
50 |
(define-key mq-global-map "e" 'mq-refresh-edit) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
51 |
(define-key mq-global-map "n" 'mq-next) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
52 |
(define-key mq-global-map "p" 'mq-previous) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
53 |
(define-key mq-global-map "t" 'mq-top) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
54 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
55 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
56 |
;;; Helper functions. |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
57 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
58 |
(defun mq-read-patch-name (&optional source prompt) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
59 |
"Read a patch name to use with a command. |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
60 |
May return nil, meaning \"use the default\"." |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
61 |
(let ((patches (split-string |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
62 |
(hg-chomp (hg-run0 (or source "qseries"))) "\n"))) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
63 |
(when current-prefix-arg |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
64 |
(completing-read (format "Patch%s: " (or prompt "")) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
65 |
(map 'list 'cons patches patches) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
66 |
nil |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
67 |
nil |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
68 |
nil |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
69 |
'mq-patch-history)))) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
70 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
71 |
(defun mq-refresh-buffers (root) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
72 |
(save-excursion |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
73 |
(dolist (buf (hg-buffers-visiting-repo root)) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
74 |
(when (not (verify-visited-file-modtime buf)) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
75 |
(set-buffer buf) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
76 |
(let ((ctx (hg-buffer-context))) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
77 |
(message "Refreshing %s..." (buffer-name)) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
78 |
(revert-buffer t t t) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
79 |
(hg-restore-context ctx) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
80 |
(message "Refreshing %s...done" (buffer-name)))))) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
81 |
(hg-update-mode-lines root)) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
82 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
83 |
(defun mq-last-line () |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
84 |
(goto-char (point-max)) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
85 |
(beginning-of-line) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
86 |
(when (looking-at "^$") |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
87 |
(forward-line -1)) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
88 |
(let ((bol (point))) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
89 |
(end-of-line) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
90 |
(let ((line (buffer-substring bol (point)))) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
91 |
(when (> (length line) 0) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
92 |
line)))) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
93 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
94 |
(defun mq-push (&optional patch) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
95 |
"Push patches until PATCH is reached. |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
96 |
If PATCH is nil, push at most one patch." |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
97 |
(interactive (list (mq-read-patch-name "qunapplied" " to push"))) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
98 |
(let ((root (hg-root)) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
99 |
(prev-buf (current-buffer)) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
100 |
last-line ok) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
101 |
(unless root |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
102 |
(error "Cannot push outside a repository!")) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
103 |
(hg-sync-buffers root) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
104 |
(let ((buf-name (format "MQ: Push %s" (or patch "next patch")))) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
105 |
(kill-buffer (get-buffer-create buf-name)) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
106 |
(split-window-vertically) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
107 |
(other-window 1) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
108 |
(switch-to-buffer (get-buffer-create buf-name)) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
109 |
(cd root) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
110 |
(message "Pushing...") |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
111 |
(setq ok (= 0 (apply 'call-process (hg-binary) nil t t "qpush" |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
112 |
(if patch (list patch)))) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
113 |
last-line (mq-last-line)) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
114 |
(let ((lines (count-lines (point-min) (point-max)))) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
115 |
(if (and (equal lines 2) (string-match "Now at:" last-line)) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
116 |
(progn |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
117 |
(kill-buffer (current-buffer)) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
118 |
(delete-window)) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
119 |
(hg-view-mode prev-buf)))) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
120 |
(mq-refresh-buffers root) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
121 |
(sit-for 0) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
122 |
(when last-line |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
123 |
(if ok |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
124 |
(message "Pushing... %s" last-line) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
125 |
(error "Pushing... %s" last-line))))) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
126 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
127 |
(defun mq-push-all () |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
128 |
"Push patches until all are applied." |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
129 |
(interactive) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
130 |
(mq-push "-a")) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
131 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
132 |
(defun mq-pop (&optional patch) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
133 |
"Pop patches until PATCH is reached. |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
134 |
If PATCH is nil, pop at most one patch." |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
135 |
(interactive (list (mq-read-patch-name "qapplied" " to pop to"))) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
136 |
(let ((root (hg-root)) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
137 |
last-line ok) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
138 |
(unless root |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
139 |
(error "Cannot pop outside a repository!")) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
140 |
(hg-sync-buffers root) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
141 |
(set-buffer (generate-new-buffer "qpop")) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
142 |
(cd root) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
143 |
(message "Popping...") |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
144 |
(setq ok (= 0 (apply 'call-process (hg-binary) nil t t "qpop" |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
145 |
(if patch (list patch)))) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
146 |
last-line (mq-last-line)) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
147 |
(kill-buffer (current-buffer)) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
148 |
(mq-refresh-buffers root) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
149 |
(sit-for 0) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
150 |
(when last-line |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
151 |
(if ok |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
152 |
(message "Popping... %s" last-line) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
153 |
(error "Popping... %s" last-line))))) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
154 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
155 |
(defun mq-pop-all () |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
156 |
"Push patches until none are applied." |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
157 |
(interactive) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
158 |
(mq-pop "-a")) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
159 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
160 |
(defun mq-refresh () |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
161 |
"Refresh the topmost applied patch." |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
162 |
(interactive) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
163 |
(let ((root (hg-root))) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
164 |
(unless root |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
165 |
(error "Cannot refresh outside a repository!")) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
166 |
(hg-sync-buffers root) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
167 |
(message "Refreshing patch...") |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
168 |
(let ((ret (hg-run "qrefresh"))) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
169 |
(if (equal (car ret) 0) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
170 |
(message "Refreshing patch... done.") |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
171 |
(error "Refreshing patch... %s" (hg-chomp (cdr ret))))))) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
172 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
173 |
(defun mq-patch-info (msg cmd) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
174 |
(let ((ret (hg-run cmd))) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
175 |
(if (equal (car ret) 0) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
176 |
(message "%s %s" msg (hg-chomp (cdr ret))) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
177 |
(error "%s" (cdr ret))))) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
178 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
179 |
(defun mq-top () |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
180 |
"Print the name of the topmost applied patch." |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
181 |
(interactive) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
182 |
(mq-patch-info "Top patch is " "qtop")) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
183 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
184 |
(defun mq-next () |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
185 |
"Print the name of the next patch to be pushed." |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
186 |
(interactive) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
187 |
(mq-patch-info "Next patch is " "qnext")) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
188 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
189 |
(defun mq-previous () |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
190 |
"Print the name of the first patch below the topmost applied patch. |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
191 |
This would become the active patch if popped to." |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
192 |
(interactive) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
193 |
(mq-patch-info "Previous patch is " "qprev")) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
194 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
195 |
(defun mq-refresh-edit () |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
196 |
"Refresh the topmost applied patch, editing the patch description." |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
197 |
(interactive) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
198 |
(error "Not yet implemented")) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
199 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
200 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
201 |
(provide 'mq) |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
202 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
203 |
|
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
204 |
;;; Local Variables: |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
205 |
;;; prompt-to-byte-compile: nil |
425413d9ef59
Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
206 |
;;; end: |