contrib/mq.el
author Bryan O'Sullivan <bos@serpentine.com>
Tue, 22 Aug 2006 16:59:22 -0700
changeset 3009 e2bad806ccc3
parent 3007 425413d9ef59
child 3010 06696f9c30c0
permissions -rw-r--r--
mq.el: add ability to edit a patch.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
3009
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
    34
(defcustom mq-edit-mode-hook nil
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
    35
  "Hook run after a buffer is populated to edit a patch description."
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
    36
  :type 'sexp
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
    37
  :group 'mercurial)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
    38
3007
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
;;; Internal variables.
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-patch-history nil)
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    43
3009
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
    44
(defvar mq-prev-buffer nil)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
    45
(make-variable-buffer-local 'mq-prev-buffer)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
    46
(put 'mq-prev-buffer 'permanent-local t)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
    47
3007
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    48
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    49
;;; Global keymap.
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    50
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    51
(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
    52
(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
    53
(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
    54
(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
    55
(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
    56
(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
    57
(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
    58
(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
    59
(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
    60
(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
    61
(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
    62
(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
    63
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    64
3009
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
    65
;;; Refresh edit mode keymap.
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
    66
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
    67
(defvar mq-edit-mode-map (make-sparse-keymap))
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
    68
(define-key mq-edit-mode-map "\C-c\C-c" 'mq-edit-finish)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
    69
(define-key mq-edit-mode-map "\C-c\C-k" 'mq-edit-kill)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
    70
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
    71
3007
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    72
;;; Helper functions.
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    73
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    74
(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
    75
  "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
    76
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
    77
  (let ((patches (split-string
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    78
		  (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
    79
    (when current-prefix-arg
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    80
      (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
    81
		       (map 'list 'cons patches patches)
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    82
		       nil
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    83
		       nil
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    84
		       nil
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    85
		       'mq-patch-history))))
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    86
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    87
(defun mq-refresh-buffers (root)
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    88
  (save-excursion
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    89
    (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
    90
      (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
    91
	(set-buffer buf)
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    92
	(let ((ctx (hg-buffer-context)))
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    93
	  (message "Refreshing %s..." (buffer-name))
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    94
	  (revert-buffer t t t)
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    95
	  (hg-restore-context ctx)
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    96
	  (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
    97
  (hg-update-mode-lines root))
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    98
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    99
(defun mq-last-line ()
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   100
  (goto-char (point-max))
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   101
  (beginning-of-line)
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   102
  (when (looking-at "^$")
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   103
    (forward-line -1))
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   104
  (let ((bol (point)))
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   105
    (end-of-line)
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   106
    (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
   107
      (when (> (length line) 0)
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   108
	line))))
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   109
  
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   110
(defun mq-push (&optional patch)
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   111
  "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
   112
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
   113
  (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
   114
  (let ((root (hg-root))
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   115
	(prev-buf (current-buffer))
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   116
	last-line ok)
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   117
    (unless root
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   118
      (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
   119
    (hg-sync-buffers root)
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   120
    (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
   121
      (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
   122
      (split-window-vertically)
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   123
      (other-window 1)
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   124
      (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
   125
      (cd root)
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   126
      (message "Pushing...")
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   127
      (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
   128
			   (if patch (list patch))))
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   129
	    last-line (mq-last-line))
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   130
      (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
   131
	(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
   132
	    (progn
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   133
	      (kill-buffer (current-buffer))
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   134
	      (delete-window))
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   135
	  (hg-view-mode prev-buf))))
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   136
    (mq-refresh-buffers root)
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   137
    (sit-for 0)
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   138
    (when last-line
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   139
      (if ok
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   140
	  (message "Pushing... %s" last-line)
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   141
	(error "Pushing... %s" last-line)))))
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   142
  
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   143
(defun mq-push-all ()
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   144
  "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
   145
  (interactive)
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   146
  (mq-push "-a"))
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   147
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   148
(defun mq-pop (&optional patch)
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   149
  "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
   150
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
   151
  (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
   152
  (let ((root (hg-root))
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   153
	last-line ok)
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   154
    (unless root
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   155
      (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
   156
    (hg-sync-buffers root)
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   157
    (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
   158
    (cd root)
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   159
    (message "Popping...")
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   160
    (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
   161
			 (if patch (list patch))))
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   162
	  last-line (mq-last-line))
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   163
    (kill-buffer (current-buffer))
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   164
    (mq-refresh-buffers root)
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   165
    (sit-for 0)
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   166
    (when last-line
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   167
      (if ok
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   168
	  (message "Popping... %s" last-line)
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   169
	(error "Popping... %s" last-line)))))
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   170
  
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   171
(defun mq-pop-all ()
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   172
  "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
   173
  (interactive)
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   174
  (mq-pop "-a"))
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   175
3009
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   176
(defun mq-refresh-internal (root &rest args)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   177
  (hg-sync-buffers root)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   178
  (let ((patch (mq-patch-info "qtop")))
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   179
    (message "Refreshing %s..." patch)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   180
    (let ((ret (apply 'hg-run "qrefresh" args)))
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   181
      (if (equal (car ret) 0)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   182
	  (message "Refreshing %s... done." patch)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   183
	(error "Refreshing %s... %s" patch (hg-chomp (cdr ret)))))))
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   184
3007
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   185
(defun mq-refresh ()
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   186
  "Refresh the topmost applied patch."
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   187
  (interactive)
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   188
  (let ((root (hg-root)))
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   189
    (unless root
3009
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   190
      (error "Cannot refresh outside of a repository!"))
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   191
  (mq-refresh-internal root)))
3007
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   192
3009
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   193
(defun mq-patch-info (cmd &optional msg)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   194
  (let* ((ret (hg-run cmd))
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   195
	 (info (hg-chomp (cdr ret))))
3007
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   196
    (if (equal (car ret) 0)
3009
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   197
	(if msg
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   198
	    (message "%s patch: %s" msg info)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   199
	  info)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   200
      (error "%s" info))))
3007
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   201
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   202
(defun mq-top ()
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   203
  "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
   204
  (interactive)
3009
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   205
  (mq-patch-info "qtop" "Top"))
3007
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   206
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   207
(defun mq-next ()
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   208
  "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
   209
  (interactive)
3009
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   210
  (mq-patch-info "qnext" "Next"))
3007
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   211
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   212
(defun mq-previous ()
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   213
  "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
   214
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
   215
  (interactive)
3009
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   216
  (mq-patch-info "qprev" "Previous"))
3007
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   217
3009
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   218
(defun mq-edit-finish ()
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   219
  (interactive)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   220
  (unless (equal (mq-patch-info "qtop") mq-top)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   221
    (error "Topmost patch has changed!"))
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   222
  (hg-sync-buffers hg-root)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   223
  (mq-refresh-internal hg-root "-m" (buffer-substring (point-min) (point-max)))
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   224
  (let ((buf mq-prev-buffer))
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   225
    (kill-buffer nil)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   226
    (switch-to-buffer buf)))
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   227
  
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   228
(defun mq-edit-kill ()
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   229
  "Kill the edit currently being prepared."
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   230
  (interactive)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   231
  (when (or (not (buffer-modified-p)) (y-or-n-p "Really kill this edit? "))
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   232
    (let ((buf mq-prev-buffer))
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   233
      (kill-buffer nil)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   234
      (switch-to-buffer buf))))
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   235
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   236
(defun mq-edit-mode ()
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   237
  "Mode for editing the description of a patch.
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   238
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   239
Key bindings
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   240
------------
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   241
\\[mq-edit-finish]	use this description
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   242
\\[mq-edit-kill]	abandon this description"
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   243
  (interactive)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   244
  (use-local-map mq-edit-mode-map)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   245
  (set-syntax-table text-mode-syntax-table)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   246
  (setq local-abbrev-table text-mode-abbrev-table
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   247
	major-mode 'mq-edit-mode
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   248
	mode-name "MQ-Edit")
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   249
  (set-buffer-modified-p nil)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   250
  (setq buffer-undo-list nil)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   251
  (run-hooks 'text-mode-hook 'mq-edit-mode-hook))
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   252
  
3007
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   253
(defun mq-refresh-edit ()
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   254
  "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
   255
  (interactive)
3009
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   256
  (while mq-prev-buffer
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   257
    (set-buffer mq-prev-buffer))
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   258
  (let ((root (hg-root))
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   259
	(prev-buffer (current-buffer))
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   260
	(patch (mq-patch-info "qtop")))
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   261
    (hg-sync-buffers root)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   262
    (let ((buf-name (format "*MQ: Edit description of %s*" patch)))
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   263
      (switch-to-buffer (get-buffer-create buf-name))
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   264
      (when (= (point-min) (point-max))
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   265
	(set (make-local-variable 'hg-root) root)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   266
	(set (make-local-variable 'mq-top) patch)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   267
	(setq mq-prev-buffer prev-buffer)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   268
	(insert (hg-run0 "qheader"))
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   269
	(goto-char (point-min)))
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   270
      (mq-edit-mode)
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   271
      (cd root)))
e2bad806ccc3 mq.el: add ability to edit a patch.
Bryan O'Sullivan <bos@serpentine.com>
parents: 3007
diff changeset
   272
  (message "Type `C-c C-c' to finish editing and refresh the patch."))
3007
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   273
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   274
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   275
(provide 'mq)
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   276
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   277
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   278
;;; Local Variables:
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   279
;;; prompt-to-byte-compile: nil
425413d9ef59 Emacs: add mq.el, early support for Mercurial Queues.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   280
;;; end: