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