##// END OF EJS Templates
mq.el: add hook to run when finishing the edit of a patch.
Bryan O'Sullivan -
r4427:b59611e9 default
parent child Browse files
Show More
@@ -1,368 +1,374 b''
1 ;;; mq.el --- Emacs support for Mercurial Queues
1 ;;; mq.el --- Emacs support for Mercurial Queues
2
2
3 ;; Copyright (C) 2006 Bryan O'Sullivan
3 ;; Copyright (C) 2006 Bryan O'Sullivan
4
4
5 ;; Author: Bryan O'Sullivan <bos@serpentine.com>
5 ;; Author: Bryan O'Sullivan <bos@serpentine.com>
6
6
7 ;; mq.el is free software; you can redistribute it and/or modify it
7 ;; mq.el is free software; you can redistribute it and/or modify it
8 ;; under the terms of version 2 of the GNU General Public License as
8 ;; under the terms of version 2 of the GNU General Public License as
9 ;; published by the Free Software Foundation.
9 ;; published by the Free Software Foundation.
10
10
11 ;; mq.el is distributed in the hope that it will be useful, but
11 ;; mq.el is distributed in the hope that it will be useful, but
12 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ;; General Public License for more details.
14 ;; General Public License for more details.
15
15
16 ;; You should have received a copy of the GNU General Public License
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with mq.el, GNU Emacs, or XEmacs; see the file COPYING (`C-h
17 ;; along with mq.el, GNU Emacs, or XEmacs; see the file COPYING (`C-h
18 ;; C-l'). If not, write to the Free Software Foundation, Inc., 59
18 ;; C-l'). If not, write to the Free Software Foundation, Inc., 59
19 ;; Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 ;; Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
20
21 (require 'mercurial)
21 (require 'mercurial)
22
22
23
23
24 (defcustom mq-mode-hook nil
24 (defcustom mq-mode-hook nil
25 "Hook run when a buffer enters mq-mode."
25 "Hook run when a buffer enters mq-mode."
26 :type 'sexp
26 :type 'sexp
27 :group 'mercurial)
27 :group 'mercurial)
28
28
29 (defcustom mq-global-prefix "\C-cq"
29 (defcustom mq-global-prefix "\C-cq"
30 "The global prefix for Mercurial Queues keymap bindings."
30 "The global prefix for Mercurial Queues keymap bindings."
31 :type 'sexp
31 :type 'sexp
32 :group 'mercurial)
32 :group 'mercurial)
33
33
34 (defcustom mq-edit-mode-hook nil
34 (defcustom mq-edit-mode-hook nil
35 "Hook run after a buffer is populated to edit a patch description."
35 "Hook run after a buffer is populated to edit a patch description."
36 :type 'sexp
36 :type 'sexp
37 :group 'mercurial)
37 :group 'mercurial)
38
38
39 (defcustom mq-edit-finish-hook nil
40 "Hook run before a patch description is finished up with."
41 :type 'sexp
42 :group 'mercurial)
43
39
44
40 ;;; Internal variables.
45 ;;; Internal variables.
41
46
42 (defvar mq-mode nil
47 (defvar mq-mode nil
43 "Is this file managed by MQ?")
48 "Is this file managed by MQ?")
44 (make-variable-buffer-local 'mq-mode)
49 (make-variable-buffer-local 'mq-mode)
45 (put 'mq-mode 'permanent-local t)
50 (put 'mq-mode 'permanent-local t)
46
51
47 (defvar mq-patch-history nil)
52 (defvar mq-patch-history nil)
48
53
49 (defvar mq-top-patch '(nil))
54 (defvar mq-top-patch '(nil))
50
55
51 (defvar mq-prev-buffer nil)
56 (defvar mq-prev-buffer nil)
52 (make-variable-buffer-local 'mq-prev-buffer)
57 (make-variable-buffer-local 'mq-prev-buffer)
53 (put 'mq-prev-buffer 'permanent-local t)
58 (put 'mq-prev-buffer 'permanent-local t)
54
59
55
60
56 ;;; Global keymap.
61 ;;; Global keymap.
57
62
58 (defvar mq-global-map (make-sparse-keymap))
63 (defvar mq-global-map (make-sparse-keymap))
59 (fset 'mq-global-map mq-global-map)
64 (fset 'mq-global-map mq-global-map)
60 (global-set-key mq-global-prefix 'mq-global-map)
65 (global-set-key mq-global-prefix 'mq-global-map)
61 (define-key mq-global-map "." 'mq-push)
66 (define-key mq-global-map "." 'mq-push)
62 (define-key mq-global-map ">" 'mq-push-all)
67 (define-key mq-global-map ">" 'mq-push-all)
63 (define-key mq-global-map "," 'mq-pop)
68 (define-key mq-global-map "," 'mq-pop)
64 (define-key mq-global-map "<" 'mq-pop-all)
69 (define-key mq-global-map "<" 'mq-pop-all)
65 (define-key mq-global-map "=" 'mq-diff)
70 (define-key mq-global-map "=" 'mq-diff)
66 (define-key mq-global-map "r" 'mq-refresh)
71 (define-key mq-global-map "r" 'mq-refresh)
67 (define-key mq-global-map "e" 'mq-refresh-edit)
72 (define-key mq-global-map "e" 'mq-refresh-edit)
68 (define-key mq-global-map "i" 'mq-new)
73 (define-key mq-global-map "i" 'mq-new)
69 (define-key mq-global-map "n" 'mq-next)
74 (define-key mq-global-map "n" 'mq-next)
70 (define-key mq-global-map "p" 'mq-previous)
75 (define-key mq-global-map "p" 'mq-previous)
71 (define-key mq-global-map "s" 'mq-edit-series)
76 (define-key mq-global-map "s" 'mq-edit-series)
72 (define-key mq-global-map "t" 'mq-top)
77 (define-key mq-global-map "t" 'mq-top)
73
78
74 (add-minor-mode 'mq-mode 'mq-mode)
79 (add-minor-mode 'mq-mode 'mq-mode)
75
80
76
81
77 ;;; Refresh edit mode keymap.
82 ;;; Refresh edit mode keymap.
78
83
79 (defvar mq-edit-mode-map (make-sparse-keymap))
84 (defvar mq-edit-mode-map (make-sparse-keymap))
80 (define-key mq-edit-mode-map "\C-c\C-c" 'mq-edit-finish)
85 (define-key mq-edit-mode-map "\C-c\C-c" 'mq-edit-finish)
81 (define-key mq-edit-mode-map "\C-c\C-k" 'mq-edit-kill)
86 (define-key mq-edit-mode-map "\C-c\C-k" 'mq-edit-kill)
82
87
83
88
84 ;;; Helper functions.
89 ;;; Helper functions.
85
90
86 (defun mq-read-patch-name (&optional source prompt force)
91 (defun mq-read-patch-name (&optional source prompt force)
87 "Read a patch name to use with a command.
92 "Read a patch name to use with a command.
88 May return nil, meaning \"use the default\"."
93 May return nil, meaning \"use the default\"."
89 (let ((patches (split-string
94 (let ((patches (split-string
90 (hg-chomp (hg-run0 (or source "qseries"))) "\n")))
95 (hg-chomp (hg-run0 (or source "qseries"))) "\n")))
91 (when force
96 (when force
92 (completing-read (format "Patch%s: " (or prompt ""))
97 (completing-read (format "Patch%s: " (or prompt ""))
93 (map 'list 'cons patches patches)
98 (map 'list 'cons patches patches)
94 nil
99 nil
95 nil
100 nil
96 nil
101 nil
97 'mq-patch-history))))
102 'mq-patch-history))))
98
103
99 (defun mq-refresh-buffers (root)
104 (defun mq-refresh-buffers (root)
100 (save-excursion
105 (save-excursion
101 (dolist (buf (hg-buffers-visiting-repo root))
106 (dolist (buf (hg-buffers-visiting-repo root))
102 (when (not (verify-visited-file-modtime buf))
107 (when (not (verify-visited-file-modtime buf))
103 (set-buffer buf)
108 (set-buffer buf)
104 (let ((ctx (hg-buffer-context)))
109 (let ((ctx (hg-buffer-context)))
105 (message "Refreshing %s..." (buffer-name))
110 (message "Refreshing %s..." (buffer-name))
106 (revert-buffer t t t)
111 (revert-buffer t t t)
107 (hg-restore-context ctx)
112 (hg-restore-context ctx)
108 (message "Refreshing %s...done" (buffer-name))))))
113 (message "Refreshing %s...done" (buffer-name))))))
109 (hg-update-mode-lines root)
114 (hg-update-mode-lines root)
110 (mq-update-mode-lines root))
115 (mq-update-mode-lines root))
111
116
112 (defun mq-last-line ()
117 (defun mq-last-line ()
113 (goto-char (point-max))
118 (goto-char (point-max))
114 (beginning-of-line)
119 (beginning-of-line)
115 (when (looking-at "^$")
120 (when (looking-at "^$")
116 (forward-line -1))
121 (forward-line -1))
117 (let ((bol (point)))
122 (let ((bol (point)))
118 (end-of-line)
123 (end-of-line)
119 (let ((line (buffer-substring bol (point))))
124 (let ((line (buffer-substring bol (point))))
120 (when (> (length line) 0)
125 (when (> (length line) 0)
121 line))))
126 line))))
122
127
123 (defun mq-push (&optional patch)
128 (defun mq-push (&optional patch)
124 "Push patches until PATCH is reached.
129 "Push patches until PATCH is reached.
125 If PATCH is nil, push at most one patch."
130 If PATCH is nil, push at most one patch."
126 (interactive (list (mq-read-patch-name "qunapplied" " to push"
131 (interactive (list (mq-read-patch-name "qunapplied" " to push"
127 current-prefix-arg)))
132 current-prefix-arg)))
128 (let ((root (hg-root))
133 (let ((root (hg-root))
129 (prev-buf (current-buffer))
134 (prev-buf (current-buffer))
130 last-line ok)
135 last-line ok)
131 (unless root
136 (unless root
132 (error "Cannot push outside a repository!"))
137 (error "Cannot push outside a repository!"))
133 (hg-sync-buffers root)
138 (hg-sync-buffers root)
134 (let ((buf-name (format "MQ: Push %s" (or patch "next patch"))))
139 (let ((buf-name (format "MQ: Push %s" (or patch "next patch"))))
135 (kill-buffer (get-buffer-create buf-name))
140 (kill-buffer (get-buffer-create buf-name))
136 (split-window-vertically)
141 (split-window-vertically)
137 (other-window 1)
142 (other-window 1)
138 (switch-to-buffer (get-buffer-create buf-name))
143 (switch-to-buffer (get-buffer-create buf-name))
139 (cd root)
144 (cd root)
140 (message "Pushing...")
145 (message "Pushing...")
141 (setq ok (= 0 (apply 'call-process (hg-binary) nil t t "qpush"
146 (setq ok (= 0 (apply 'call-process (hg-binary) nil t t "qpush"
142 (if patch (list patch))))
147 (if patch (list patch))))
143 last-line (mq-last-line))
148 last-line (mq-last-line))
144 (let ((lines (count-lines (point-min) (point-max))))
149 (let ((lines (count-lines (point-min) (point-max))))
145 (if (and (equal lines 2) (string-match "Now at:" last-line))
150 (if (and (equal lines 2) (string-match "Now at:" last-line))
146 (progn
151 (progn
147 (kill-buffer (current-buffer))
152 (kill-buffer (current-buffer))
148 (delete-window))
153 (delete-window))
149 (hg-view-mode prev-buf))))
154 (hg-view-mode prev-buf))))
150 (mq-refresh-buffers root)
155 (mq-refresh-buffers root)
151 (sit-for 0)
156 (sit-for 0)
152 (when last-line
157 (when last-line
153 (if ok
158 (if ok
154 (message "Pushing... %s" last-line)
159 (message "Pushing... %s" last-line)
155 (error "Pushing... %s" last-line)))))
160 (error "Pushing... %s" last-line)))))
156
161
157 (defun mq-push-all ()
162 (defun mq-push-all ()
158 "Push patches until all are applied."
163 "Push patches until all are applied."
159 (interactive)
164 (interactive)
160 (mq-push "-a"))
165 (mq-push "-a"))
161
166
162 (defun mq-pop (&optional patch)
167 (defun mq-pop (&optional patch)
163 "Pop patches until PATCH is reached.
168 "Pop patches until PATCH is reached.
164 If PATCH is nil, pop at most one patch."
169 If PATCH is nil, pop at most one patch."
165 (interactive (list (mq-read-patch-name "qapplied" " to pop to"
170 (interactive (list (mq-read-patch-name "qapplied" " to pop to"
166 current-prefix-arg)))
171 current-prefix-arg)))
167 (let ((root (hg-root))
172 (let ((root (hg-root))
168 last-line ok)
173 last-line ok)
169 (unless root
174 (unless root
170 (error "Cannot pop outside a repository!"))
175 (error "Cannot pop outside a repository!"))
171 (hg-sync-buffers root)
176 (hg-sync-buffers root)
172 (set-buffer (generate-new-buffer "qpop"))
177 (set-buffer (generate-new-buffer "qpop"))
173 (cd root)
178 (cd root)
174 (message "Popping...")
179 (message "Popping...")
175 (setq ok (= 0 (apply 'call-process (hg-binary) nil t t "qpop"
180 (setq ok (= 0 (apply 'call-process (hg-binary) nil t t "qpop"
176 (if patch (list patch))))
181 (if patch (list patch))))
177 last-line (mq-last-line))
182 last-line (mq-last-line))
178 (kill-buffer (current-buffer))
183 (kill-buffer (current-buffer))
179 (mq-refresh-buffers root)
184 (mq-refresh-buffers root)
180 (sit-for 0)
185 (sit-for 0)
181 (when last-line
186 (when last-line
182 (if ok
187 (if ok
183 (message "Popping... %s" last-line)
188 (message "Popping... %s" last-line)
184 (error "Popping... %s" last-line)))))
189 (error "Popping... %s" last-line)))))
185
190
186 (defun mq-pop-all ()
191 (defun mq-pop-all ()
187 "Push patches until none are applied."
192 "Push patches until none are applied."
188 (interactive)
193 (interactive)
189 (mq-pop "-a"))
194 (mq-pop "-a"))
190
195
191 (defun mq-refresh-internal (root &rest args)
196 (defun mq-refresh-internal (root &rest args)
192 (hg-sync-buffers root)
197 (hg-sync-buffers root)
193 (let ((patch (mq-patch-info "qtop")))
198 (let ((patch (mq-patch-info "qtop")))
194 (message "Refreshing %s..." patch)
199 (message "Refreshing %s..." patch)
195 (let ((ret (apply 'hg-run "qrefresh" args)))
200 (let ((ret (apply 'hg-run "qrefresh" args)))
196 (if (equal (car ret) 0)
201 (if (equal (car ret) 0)
197 (message "Refreshing %s... done." patch)
202 (message "Refreshing %s... done." patch)
198 (error "Refreshing %s... %s" patch (hg-chomp (cdr ret)))))))
203 (error "Refreshing %s... %s" patch (hg-chomp (cdr ret)))))))
199
204
200 (defun mq-refresh (&optional git)
205 (defun mq-refresh (&optional git)
201 "Refresh the topmost applied patch.
206 "Refresh the topmost applied patch.
202 With a prefix argument, generate a git-compatible patch."
207 With a prefix argument, generate a git-compatible patch."
203 (interactive "P")
208 (interactive "P")
204 (let ((root (hg-root)))
209 (let ((root (hg-root)))
205 (unless root
210 (unless root
206 (error "Cannot refresh outside of a repository!"))
211 (error "Cannot refresh outside of a repository!"))
207 (apply 'mq-refresh-internal root (if git '("--git")))))
212 (apply 'mq-refresh-internal root (if git '("--git")))))
208
213
209 (defun mq-patch-info (cmd &optional msg)
214 (defun mq-patch-info (cmd &optional msg)
210 (let* ((ret (hg-run cmd))
215 (let* ((ret (hg-run cmd))
211 (info (hg-chomp (cdr ret))))
216 (info (hg-chomp (cdr ret))))
212 (if (equal (car ret) 0)
217 (if (equal (car ret) 0)
213 (if msg
218 (if msg
214 (message "%s patch: %s" msg info)
219 (message "%s patch: %s" msg info)
215 info)
220 info)
216 (error "%s" info))))
221 (error "%s" info))))
217
222
218 (defun mq-top ()
223 (defun mq-top ()
219 "Print the name of the topmost applied patch."
224 "Print the name of the topmost applied patch."
220 (interactive)
225 (interactive)
221 (mq-patch-info "qtop" "Top"))
226 (mq-patch-info "qtop" "Top"))
222
227
223 (defun mq-next ()
228 (defun mq-next ()
224 "Print the name of the next patch to be pushed."
229 "Print the name of the next patch to be pushed."
225 (interactive)
230 (interactive)
226 (mq-patch-info "qnext" "Next"))
231 (mq-patch-info "qnext" "Next"))
227
232
228 (defun mq-previous ()
233 (defun mq-previous ()
229 "Print the name of the first patch below the topmost applied patch.
234 "Print the name of the first patch below the topmost applied patch.
230 This would become the active patch if popped to."
235 This would become the active patch if popped to."
231 (interactive)
236 (interactive)
232 (mq-patch-info "qprev" "Previous"))
237 (mq-patch-info "qprev" "Previous"))
233
238
234 (defun mq-edit-finish ()
239 (defun mq-edit-finish ()
235 "Finish editing the description of this patch, and refresh the patch."
240 "Finish editing the description of this patch, and refresh the patch."
236 (interactive)
241 (interactive)
237 (unless (equal (mq-patch-info "qtop") mq-top)
242 (unless (equal (mq-patch-info "qtop") mq-top)
238 (error "Topmost patch has changed!"))
243 (error "Topmost patch has changed!"))
239 (hg-sync-buffers hg-root)
244 (hg-sync-buffers hg-root)
245 (run-hooks 'mq-edit-finish-hook)
240 (mq-refresh-internal hg-root "-m" (buffer-substring (point-min) (point-max)))
246 (mq-refresh-internal hg-root "-m" (buffer-substring (point-min) (point-max)))
241 (let ((buf mq-prev-buffer))
247 (let ((buf mq-prev-buffer))
242 (kill-buffer nil)
248 (kill-buffer nil)
243 (switch-to-buffer buf)))
249 (switch-to-buffer buf)))
244
250
245 (defun mq-edit-kill ()
251 (defun mq-edit-kill ()
246 "Kill the edit currently being prepared."
252 "Kill the edit currently being prepared."
247 (interactive)
253 (interactive)
248 (when (or (not (buffer-modified-p)) (y-or-n-p "Really kill this edit? "))
254 (when (or (not (buffer-modified-p)) (y-or-n-p "Really kill this edit? "))
249 (let ((buf mq-prev-buffer))
255 (let ((buf mq-prev-buffer))
250 (kill-buffer nil)
256 (kill-buffer nil)
251 (switch-to-buffer buf))))
257 (switch-to-buffer buf))))
252
258
253 (defun mq-get-top (root)
259 (defun mq-get-top (root)
254 (let ((entry (assoc root mq-top-patch)))
260 (let ((entry (assoc root mq-top-patch)))
255 (if entry
261 (if entry
256 (cdr entry))))
262 (cdr entry))))
257
263
258 (defun mq-set-top (root patch)
264 (defun mq-set-top (root patch)
259 (let ((entry (assoc root mq-top-patch)))
265 (let ((entry (assoc root mq-top-patch)))
260 (if entry
266 (if entry
261 (if patch
267 (if patch
262 (setcdr entry patch)
268 (setcdr entry patch)
263 (setq mq-top-patch (delq entry mq-top-patch)))
269 (setq mq-top-patch (delq entry mq-top-patch)))
264 (setq mq-top-patch (cons (cons root patch) mq-top-patch)))))
270 (setq mq-top-patch (cons (cons root patch) mq-top-patch)))))
265
271
266 (defun mq-update-mode-lines (root)
272 (defun mq-update-mode-lines (root)
267 (let ((cwd default-directory))
273 (let ((cwd default-directory))
268 (cd root)
274 (cd root)
269 (condition-case nil
275 (condition-case nil
270 (mq-set-top root (mq-patch-info "qtop"))
276 (mq-set-top root (mq-patch-info "qtop"))
271 (error (mq-set-top root nil)))
277 (error (mq-set-top root nil)))
272 (cd cwd))
278 (cd cwd))
273 (let ((patch (mq-get-top root)))
279 (let ((patch (mq-get-top root)))
274 (save-excursion
280 (save-excursion
275 (dolist (buf (hg-buffers-visiting-repo root))
281 (dolist (buf (hg-buffers-visiting-repo root))
276 (set-buffer buf)
282 (set-buffer buf)
277 (if mq-mode
283 (if mq-mode
278 (setq mq-mode (or (and patch (concat " MQ:" patch)) " MQ")))))))
284 (setq mq-mode (or (and patch (concat " MQ:" patch)) " MQ")))))))
279
285
280 (defun mq-mode (&optional arg)
286 (defun mq-mode (&optional arg)
281 "Minor mode for Mercurial repositories with an MQ patch queue"
287 "Minor mode for Mercurial repositories with an MQ patch queue"
282 (interactive "i")
288 (interactive "i")
283 (cond ((hg-root)
289 (cond ((hg-root)
284 (setq mq-mode (if (null arg) (not mq-mode)
290 (setq mq-mode (if (null arg) (not mq-mode)
285 arg))
291 arg))
286 (mq-update-mode-lines (hg-root))))
292 (mq-update-mode-lines (hg-root))))
287 (run-hooks 'mq-mode-hook))
293 (run-hooks 'mq-mode-hook))
288
294
289 (defun mq-edit-mode ()
295 (defun mq-edit-mode ()
290 "Mode for editing the description of a patch.
296 "Mode for editing the description of a patch.
291
297
292 Key bindings
298 Key bindings
293 ------------
299 ------------
294 \\[mq-edit-finish] use this description
300 \\[mq-edit-finish] use this description
295 \\[mq-edit-kill] abandon this description"
301 \\[mq-edit-kill] abandon this description"
296 (interactive)
302 (interactive)
297 (use-local-map mq-edit-mode-map)
303 (use-local-map mq-edit-mode-map)
298 (set-syntax-table text-mode-syntax-table)
304 (set-syntax-table text-mode-syntax-table)
299 (setq local-abbrev-table text-mode-abbrev-table
305 (setq local-abbrev-table text-mode-abbrev-table
300 major-mode 'mq-edit-mode
306 major-mode 'mq-edit-mode
301 mode-name "MQ-Edit")
307 mode-name "MQ-Edit")
302 (set-buffer-modified-p nil)
308 (set-buffer-modified-p nil)
303 (setq buffer-undo-list nil)
309 (setq buffer-undo-list nil)
304 (run-hooks 'text-mode-hook 'mq-edit-mode-hook))
310 (run-hooks 'text-mode-hook 'mq-edit-mode-hook))
305
311
306 (defun mq-refresh-edit ()
312 (defun mq-refresh-edit ()
307 "Refresh the topmost applied patch, editing the patch description."
313 "Refresh the topmost applied patch, editing the patch description."
308 (interactive)
314 (interactive)
309 (while mq-prev-buffer
315 (while mq-prev-buffer
310 (set-buffer mq-prev-buffer))
316 (set-buffer mq-prev-buffer))
311 (let ((root (hg-root))
317 (let ((root (hg-root))
312 (prev-buffer (current-buffer))
318 (prev-buffer (current-buffer))
313 (patch (mq-patch-info "qtop")))
319 (patch (mq-patch-info "qtop")))
314 (hg-sync-buffers root)
320 (hg-sync-buffers root)
315 (let ((buf-name (format "*MQ: Edit description of %s*" patch)))
321 (let ((buf-name (format "*MQ: Edit description of %s*" patch)))
316 (switch-to-buffer (get-buffer-create buf-name))
322 (switch-to-buffer (get-buffer-create buf-name))
317 (when (= (point-min) (point-max))
323 (when (= (point-min) (point-max))
318 (set (make-local-variable 'hg-root) root)
324 (set (make-local-variable 'hg-root) root)
319 (set (make-local-variable 'mq-top) patch)
325 (set (make-local-variable 'mq-top) patch)
320 (setq mq-prev-buffer prev-buffer)
326 (setq mq-prev-buffer prev-buffer)
321 (insert (hg-run0 "qheader"))
327 (insert (hg-run0 "qheader"))
322 (goto-char (point-min)))
328 (goto-char (point-min)))
323 (mq-edit-mode)
329 (mq-edit-mode)
324 (cd root)))
330 (cd root)))
325 (message "Type `C-c C-c' to finish editing and refresh the patch."))
331 (message "Type `C-c C-c' to finish editing and refresh the patch."))
326
332
327 (defun mq-new (name)
333 (defun mq-new (name)
328 "Create a new empty patch named NAME.
334 "Create a new empty patch named NAME.
329 The patch is applied on top of the current topmost patch.
335 The patch is applied on top of the current topmost patch.
330 With a prefix argument, forcibly create the patch even if the working
336 With a prefix argument, forcibly create the patch even if the working
331 directory is modified."
337 directory is modified."
332 (interactive (list (mq-read-patch-name "qseries" " to create" t)))
338 (interactive (list (mq-read-patch-name "qseries" " to create" t)))
333 (message "Creating patch...")
339 (message "Creating patch...")
334 (let ((ret (if current-prefix-arg
340 (let ((ret (if current-prefix-arg
335 (hg-run "qnew" "-f" name)
341 (hg-run "qnew" "-f" name)
336 (hg-run "qnew" name))))
342 (hg-run "qnew" name))))
337 (if (equal (car ret) 0)
343 (if (equal (car ret) 0)
338 (progn
344 (progn
339 (hg-update-mode-lines (buffer-file-name))
345 (hg-update-mode-lines (buffer-file-name))
340 (message "Creating patch... done."))
346 (message "Creating patch... done."))
341 (error "Creating patch... %s" (hg-chomp (cdr ret))))))
347 (error "Creating patch... %s" (hg-chomp (cdr ret))))))
342
348
343 (defun mq-edit-series ()
349 (defun mq-edit-series ()
344 "Edit the MQ series file directly."
350 "Edit the MQ series file directly."
345 (interactive)
351 (interactive)
346 (let ((root (hg-root)))
352 (let ((root (hg-root)))
347 (unless root
353 (unless root
348 (error "Not in an MQ repository!"))
354 (error "Not in an MQ repository!"))
349 (find-file (concat root ".hg/patches/series"))))
355 (find-file (concat root ".hg/patches/series"))))
350
356
351 (defun mq-diff (&optional git)
357 (defun mq-diff (&optional git)
352 "Display a diff of the topmost applied patch.
358 "Display a diff of the topmost applied patch.
353 With a prefix argument, display a git-compatible diff."
359 With a prefix argument, display a git-compatible diff."
354 (interactive "P")
360 (interactive "P")
355 (hg-view-output ((format "MQ: Diff of %s" (mq-patch-info "qtop")))
361 (hg-view-output ((format "MQ: Diff of %s" (mq-patch-info "qtop")))
356 (if git
362 (if git
357 (call-process (hg-binary) nil t nil "qdiff" "--git")
363 (call-process (hg-binary) nil t nil "qdiff" "--git")
358 (call-process (hg-binary) nil t nil "qdiff"))
364 (call-process (hg-binary) nil t nil "qdiff"))
359 (diff-mode)
365 (diff-mode)
360 (font-lock-fontify-buffer)))
366 (font-lock-fontify-buffer)))
361
367
362
368
363 (provide 'mq)
369 (provide 'mq)
364
370
365
371
366 ;;; Local Variables:
372 ;;; Local Variables:
367 ;;; prompt-to-byte-compile: nil
373 ;;; prompt-to-byte-compile: nil
368 ;;; end:
374 ;;; end:
General Comments 0
You need to be logged in to leave comments. Login now