Mercurial > hg-stable
comparison contrib/mq.el @ 4422:7b0d0acea6d6
mq.el: add mq-new function.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Tue, 08 May 2007 11:54:39 -0700 |
parents | b7fe334ff4fb |
children | 2647f1fbc24c |
comparison
equal
deleted
inserted
replaced
4421:d0be96c694f7 | 4422:7b0d0acea6d6 |
---|---|
62 (define-key mq-global-map ">" 'mq-push-all) | 62 (define-key mq-global-map ">" 'mq-push-all) |
63 (define-key mq-global-map "," 'mq-pop) | 63 (define-key mq-global-map "," 'mq-pop) |
64 (define-key mq-global-map "<" 'mq-pop-all) | 64 (define-key mq-global-map "<" 'mq-pop-all) |
65 (define-key mq-global-map "r" 'mq-refresh) | 65 (define-key mq-global-map "r" 'mq-refresh) |
66 (define-key mq-global-map "e" 'mq-refresh-edit) | 66 (define-key mq-global-map "e" 'mq-refresh-edit) |
67 (define-key mq-global-map "i" 'mq-new) | |
67 (define-key mq-global-map "n" 'mq-next) | 68 (define-key mq-global-map "n" 'mq-next) |
68 (define-key mq-global-map "p" 'mq-previous) | 69 (define-key mq-global-map "p" 'mq-previous) |
69 (define-key mq-global-map "t" 'mq-top) | 70 (define-key mq-global-map "t" 'mq-top) |
70 | 71 |
71 (add-minor-mode 'mq-mode 'mq-mode) | 72 (add-minor-mode 'mq-mode 'mq-mode) |
78 (define-key mq-edit-mode-map "\C-c\C-k" 'mq-edit-kill) | 79 (define-key mq-edit-mode-map "\C-c\C-k" 'mq-edit-kill) |
79 | 80 |
80 | 81 |
81 ;;; Helper functions. | 82 ;;; Helper functions. |
82 | 83 |
83 (defun mq-read-patch-name (&optional source prompt) | 84 (defun mq-read-patch-name (&optional source prompt force) |
84 "Read a patch name to use with a command. | 85 "Read a patch name to use with a command. |
85 May return nil, meaning \"use the default\"." | 86 May return nil, meaning \"use the default\"." |
86 (let ((patches (split-string | 87 (let ((patches (split-string |
87 (hg-chomp (hg-run0 (or source "qseries"))) "\n"))) | 88 (hg-chomp (hg-run0 (or source "qseries"))) "\n"))) |
88 (when current-prefix-arg | 89 (when force |
89 (completing-read (format "Patch%s: " (or prompt "")) | 90 (completing-read (format "Patch%s: " (or prompt "")) |
90 (map 'list 'cons patches patches) | 91 (map 'list 'cons patches patches) |
91 nil | 92 nil |
92 nil | 93 nil |
93 nil | 94 nil |
118 line)))) | 119 line)))) |
119 | 120 |
120 (defun mq-push (&optional patch) | 121 (defun mq-push (&optional patch) |
121 "Push patches until PATCH is reached. | 122 "Push patches until PATCH is reached. |
122 If PATCH is nil, push at most one patch." | 123 If PATCH is nil, push at most one patch." |
123 (interactive (list (mq-read-patch-name "qunapplied" " to push"))) | 124 (interactive (list (mq-read-patch-name "qunapplied" " to push" |
125 current-prefix-arg))) | |
124 (let ((root (hg-root)) | 126 (let ((root (hg-root)) |
125 (prev-buf (current-buffer)) | 127 (prev-buf (current-buffer)) |
126 last-line ok) | 128 last-line ok) |
127 (unless root | 129 (unless root |
128 (error "Cannot push outside a repository!")) | 130 (error "Cannot push outside a repository!")) |
156 (mq-push "-a")) | 158 (mq-push "-a")) |
157 | 159 |
158 (defun mq-pop (&optional patch) | 160 (defun mq-pop (&optional patch) |
159 "Pop patches until PATCH is reached. | 161 "Pop patches until PATCH is reached. |
160 If PATCH is nil, pop at most one patch." | 162 If PATCH is nil, pop at most one patch." |
161 (interactive (list (mq-read-patch-name "qapplied" " to pop to"))) | 163 (interactive (list (mq-read-patch-name "qapplied" " to pop to" |
164 current-prefix-arg))) | |
162 (let ((root (hg-root)) | 165 (let ((root (hg-root)) |
163 last-line ok) | 166 last-line ok) |
164 (unless root | 167 (unless root |
165 (error "Cannot pop outside a repository!")) | 168 (error "Cannot pop outside a repository!")) |
166 (hg-sync-buffers root) | 169 (hg-sync-buffers root) |
316 (goto-char (point-min))) | 319 (goto-char (point-min))) |
317 (mq-edit-mode) | 320 (mq-edit-mode) |
318 (cd root))) | 321 (cd root))) |
319 (message "Type `C-c C-c' to finish editing and refresh the patch.")) | 322 (message "Type `C-c C-c' to finish editing and refresh the patch.")) |
320 | 323 |
324 (defun mq-new (name) | |
325 "Create a new empty patch named NAME. | |
326 The patch is applied on top of the current topmost patch. | |
327 With a prefix argument, forcibly create the patch even if the working | |
328 directory is modified." | |
329 (interactive (list (mq-read-patch-name "qseries" " to create" t))) | |
330 (message "Creating patch...") | |
331 (let ((ret (if current-prefix-arg | |
332 (hg-run "qnew" "-f" name) | |
333 (hg-run "qnew" name)))) | |
334 (if (equal (car ret) 0) | |
335 (progn | |
336 (hg-update-mode-lines (buffer-file-name)) | |
337 (message "Creating patch... done.")) | |
338 (error "Creating patch... %s" (hg-chomp (cdr ret)))))) | |
339 | |
321 | 340 |
322 (provide 'mq) | 341 (provide 'mq) |
323 | 342 |
324 | 343 |
325 ;;; Local Variables: | 344 ;;; Local Variables: |