contrib/mercurial.el
author Bryan O'Sullivan <bos@serpentine.com>
Tue, 23 Aug 2005 15:42:06 -0700
changeset 1026 a5539638c5a3
parent 1024 5b257e419816
parent 1025 ba08f2ef8cbe
child 1027 cb31576ed3e4
permissions -rw-r--r--
Merge with MPM.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
     1
;;; mercurial.el --- Emacs support for the Mercurial distributed SCM
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
     2
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
     3
;; Copyright (C) 2005 Bryan O'Sullivan
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
     4
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
     5
;; Author: Bryan O'Sullivan <bos@serpentine.com>
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
     6
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
     7
;; mercurial.el is free software; you can redistribute it and/or
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
     8
;; modify it under the terms of version 2 of the GNU General Public
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
     9
;; License as published by the Free Software Foundation.
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    10
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
    11
;; mercurial.el is distributed in the hope that it will be useful, but
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    12
;; WITHOUT ANY WARRANTY; without even the implied warranty of
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    13
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    14
;; General Public License for more details.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    15
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    16
;; You should have received a copy of the GNU General Public License
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
    17
;; along with mercurial.el, GNU Emacs, or XEmacs; see the file COPYING
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    18
;; (`C-h C-l').  If not, write to the Free Software Foundation, Inc.,
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    19
;; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    20
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    21
;;; Commentary:
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    22
1004
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
    23
;; mercurial.el builds upon Emacs's VC mode to provide flexible
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    24
;; integration with the Mercurial distributed SCM tool.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    25
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
    26
;; To get going as quickly as possible, load mercurial.el into Emacs and
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    27
;; type `C-c h h'; this runs hg-help-overview, which prints a helpful
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    28
;; usage overview.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    29
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    30
;; Much of the inspiration for mercurial.el comes from Rajesh
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    31
;; Vaidheeswarran's excellent p4.el, which does an admirably thorough
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    32
;; job for the commercial Perforce SCM product.  In fact, substantial
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    33
;; chunks of code are adapted from p4.el.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    34
1004
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
    35
;; This code has been developed under XEmacs 21.5, and may not work as
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
    36
;; well under GNU Emacs (albeit tested under 21.4).  Patches to
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
    37
;; enhance the portability of this code, fix bugs, and add features
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    38
;; are most welcome.  You can clone a Mercurial repository for this
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    39
;; package from http://www.serpentine.com/hg/hg-emacs
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    40
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    41
;; Please send problem reports and suggestions to bos@serpentine.com.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    42
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    43

41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    44
;;; Code:
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    45
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    46
(require 'advice)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    47
(require 'cl)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    48
(require 'diff-mode)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    49
(require 'easymenu)
1024
5b257e419816 Sync buffers prior to doing a diff.
bos@serpentine.internal.keyresearch.com
parents: 1011
diff changeset
    50
(require 'executable)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    51
(require 'vc)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    52
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    53

41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    54
;;; XEmacs has view-less, while GNU Emacs has view.  Joy.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    55
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    56
(condition-case nil
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    57
    (require 'view-less)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    58
  (error nil))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    59
(condition-case nil
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    60
    (require 'view)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    61
  (error nil))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    62
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    63

41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    64
;;; Variables accessible through the custom system.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    65
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
    66
(defgroup mercurial nil
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    67
  "Mercurial distributed SCM."
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    68
  :group 'tools)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    69
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    70
(defcustom hg-binary
1011
d06420c90d8b Emacs: search for hg in path before looking in funny places.
bos@serpentine.internal.keyresearch.com
parents: 1004
diff changeset
    71
    (or (executable-find "hg")
d06420c90d8b Emacs: search for hg in path before looking in funny places.
bos@serpentine.internal.keyresearch.com
parents: 1004
diff changeset
    72
	(dolist (path '("~/bin/hg" "/usr/bin/hg" "/usr/local/bin/hg"))
d06420c90d8b Emacs: search for hg in path before looking in funny places.
bos@serpentine.internal.keyresearch.com
parents: 1004
diff changeset
    73
	  (when (file-executable-p path)
d06420c90d8b Emacs: search for hg in path before looking in funny places.
bos@serpentine.internal.keyresearch.com
parents: 1004
diff changeset
    74
	    (return path))))
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    75
  "The path to Mercurial's hg executable."
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    76
  :type '(file :must-match t)
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
    77
  :group 'mercurial)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    78
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    79
(defcustom hg-mode-hook nil
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    80
  "Hook run when a buffer enters hg-mode."
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    81
  :type 'sexp
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
    82
  :group 'mercurial)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    83
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
    84
(defcustom hg-commit-mode-hook nil
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
    85
  "Hook run when a buffer is created to prepare a commit."
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
    86
  :type 'sexp
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
    87
  :group 'mercurial)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
    88
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
    89
(defcustom hg-pre-commit-hook nil
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
    90
  "Hook run before a commit is performed.
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
    91
If you want to prevent the commit from proceeding, raise an error."
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
    92
  :type 'sexp
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
    93
  :group 'mercurial)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
    94
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    95
(defcustom hg-global-prefix "\C-ch"
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    96
  "The global prefix for Mercurial keymap bindings."
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    97
  :type 'sexp
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
    98
  :group 'mercurial)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
    99
999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   100
(defcustom hg-commit-allow-empty-message nil
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   101
  "Whether to allow changes to be committed with empty descriptions."
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   102
  :type 'boolean
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   103
  :group 'mercurial)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   104
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   105
(defcustom hg-commit-allow-empty-file-list nil
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   106
  "Whether to allow changes to be committed without any modified files."
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   107
  :type 'boolean
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   108
  :group 'mercurial)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   109
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   110
(defcustom hg-rev-completion-limit 100
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   111
  "The maximum number of revisions that hg-read-rev will offer to complete.
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   112
This affects memory usage and performance when prompting for revisions
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   113
in a repository with a lot of history."
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   114
  :type 'integer
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   115
  :group 'mercurial)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   116
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   117
(defcustom hg-log-limit 50
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   118
  "The maximum number of revisions that hg-log will display."
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   119
  :type 'integer
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   120
  :group 'mercurial)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   121
995
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   122
(defcustom hg-update-modeline t
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   123
  "Whether to update the modeline with the status of a file after every save.
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   124
Set this to nil on platforms with poor process management, such as Windows."
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   125
  :type 'boolean
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   126
  :group 'mercurial)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   127
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   128

41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   129
;;; Other variables.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   130
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   131
(defconst hg-running-xemacs (string-match "XEmacs" emacs-version)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   132
  "Is mercurial.el running under XEmacs?")
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   133
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   134
(defvar hg-mode nil
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   135
  "Is this file managed by Mercurial?")
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   136
(make-variable-buffer-local 'hg-mode)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   137
(put 'hg-mode 'permanent-local t)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   138
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   139
(defvar hg-status nil)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   140
(make-variable-buffer-local 'hg-status)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   141
(put 'hg-status 'permanent-local t)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   142
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   143
(defvar hg-prev-buffer nil)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   144
(make-variable-buffer-local 'hg-prev-buffer)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   145
(put 'hg-prev-buffer 'permanent-local t)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   146
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   147
(defvar hg-root nil)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   148
(make-variable-buffer-local 'hg-root)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   149
(put 'hg-root 'permanent-local t)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   150
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   151
(defvar hg-output-buffer-name "*Hg*"
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   152
  "The name to use for Mercurial output buffers.")
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   153
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   154
(defvar hg-file-history nil)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   155
(defvar hg-rev-history nil)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   156
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   157

999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   158
;;; Random constants.
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   159
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   160
(defconst hg-commit-message-start
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   161
  "--- Enter your commit message.  Type `C-c C-c' to commit. ---\n")
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   162
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   163
(defconst hg-commit-message-end
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   164
  "--- Files in bold will be committed.  Click to toggle selection. ---\n")
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   165
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   166

944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   167
;;; hg-mode keymap.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   168
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   169
(defvar hg-mode-map (make-sparse-keymap))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   170
(define-key hg-mode-map "\C-xv" 'hg-prefix-map)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   171
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   172
(defvar hg-prefix-map
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   173
  (let ((map (copy-keymap vc-prefix-map)))
958
d845a1f174bb Make mercurial.el load with GNU emacs
mpm@selenic.com
parents: 955
diff changeset
   174
    (if (functionp 'set-keymap-name)
d845a1f174bb Make mercurial.el load with GNU emacs
mpm@selenic.com
parents: 955
diff changeset
   175
      (set-keymap-name map 'hg-prefix-map)); XEmacs
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   176
    map)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   177
  "This keymap overrides some default vc-mode bindings.")
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   178
(fset 'hg-prefix-map hg-prefix-map)
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   179
(define-key hg-prefix-map "=" 'hg-diff)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   180
(define-key hg-prefix-map "c" 'hg-undo)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   181
(define-key hg-prefix-map "g" 'hg-annotate)
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   182
(define-key hg-prefix-map "l" 'hg-log)
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   183
(define-key hg-prefix-map "n" 'hg-commit-start)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   184
;; (define-key hg-prefix-map "r" 'hg-update)
995
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   185
(define-key hg-prefix-map "u" 'hg-revert-buffer)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   186
(define-key hg-prefix-map "~" 'hg-version-other-window)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   187
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   188
(add-minor-mode 'hg-mode 'hg-mode hg-mode-map)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   189
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   190

41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   191
;;; Global keymap.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   192
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   193
(global-set-key "\C-xvi" 'hg-add)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   194
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   195
(defvar hg-global-map (make-sparse-keymap))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   196
(fset 'hg-global-map hg-global-map)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   197
(global-set-key hg-global-prefix 'hg-global-map)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   198
(define-key hg-global-map "," 'hg-incoming)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   199
(define-key hg-global-map "." 'hg-outgoing)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   200
(define-key hg-global-map "<" 'hg-pull)
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   201
(define-key hg-global-map "=" 'hg-diff-repo)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   202
(define-key hg-global-map ">" 'hg-push)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   203
(define-key hg-global-map "?" 'hg-help-overview)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   204
(define-key hg-global-map "A" 'hg-addremove)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   205
(define-key hg-global-map "U" 'hg-revert)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   206
(define-key hg-global-map "a" 'hg-add)
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   207
(define-key hg-global-map "c" 'hg-commit-start)
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   208
(define-key hg-global-map "f" 'hg-forget)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   209
(define-key hg-global-map "h" 'hg-help-overview)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   210
(define-key hg-global-map "i" 'hg-init)
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   211
(define-key hg-global-map "l" 'hg-log-repo)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   212
(define-key hg-global-map "r" 'hg-root)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   213
(define-key hg-global-map "s" 'hg-status)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   214
(define-key hg-global-map "u" 'hg-update)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   215
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   216

41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   217
;;; View mode keymap.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   218
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   219
(defvar hg-view-mode-map
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   220
  (let ((map (copy-keymap (if (boundp 'view-minor-mode-map)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   221
			      view-minor-mode-map
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   222
			    view-mode-map))))
958
d845a1f174bb Make mercurial.el load with GNU emacs
mpm@selenic.com
parents: 955
diff changeset
   223
    (if (functionp 'set-keymap-name)
d845a1f174bb Make mercurial.el load with GNU emacs
mpm@selenic.com
parents: 955
diff changeset
   224
      (set-keymap-name map 'hg-view-mode-map)); XEmacs
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   225
    map))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   226
(fset 'hg-view-mode-map hg-view-mode-map)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   227
(define-key hg-view-mode-map
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   228
  (if hg-running-xemacs [button2] [mouse-2])
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   229
  'hg-buffer-mouse-clicked)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   230
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   231

999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   232
;;; Commit mode keymaps.
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   233
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   234
(defvar hg-commit-mode-map (make-sparse-keymap))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   235
(define-key hg-commit-mode-map "\C-c\C-c" 'hg-commit-finish)
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   236
(define-key hg-commit-mode-map "\C-c\C-k" 'hg-commit-kill)
999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   237
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   238
(defvar hg-commit-mode-file-map (make-sparse-keymap))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   239
(define-key hg-commit-mode-file-map
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   240
  (if hg-running-xemacs [button2] [mouse-2])
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   241
  'hg-commit-mouse-clicked)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   242
(define-key hg-commit-mode-file-map " " 'hg-commit-toggle-file)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   243
(define-key hg-commit-mode-file-map "\r" 'hg-commit-toggle-file)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   244
  
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   245

944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   246
;;; Convenience functions.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   247
995
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   248
(defsubst hg-binary ()
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   249
  (if hg-binary
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   250
      hg-binary
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   251
    (error "No `hg' executable found!")))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   252
995
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   253
(defsubst hg-replace-in-string (str regexp newtext &optional literal)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   254
  "Replace all matches in STR for REGEXP with NEWTEXT string.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   255
Return the new string.  Optional LITERAL non-nil means do a literal
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   256
replacement.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   257
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   258
This function bridges yet another pointless impedance gap between
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   259
XEmacs and GNU Emacs."
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   260
  (if (fboundp 'replace-in-string)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   261
      (replace-in-string str regexp newtext literal)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   262
    (replace-regexp-in-string regexp newtext str nil literal)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   263
999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   264
(defsubst hg-strip (str)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   265
  "Strip leading and trailing white space from a string."
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   266
  (hg-replace-in-string (hg-replace-in-string str "[ \t\r\n]+$" "")
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   267
			"^[ \t\r\n]+" ""))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   268
995
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   269
(defsubst hg-chomp (str)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   270
  "Strip trailing newlines from a string."
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   271
  (hg-replace-in-string str "[\r\n]+$" ""))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   272
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   273
(defun hg-run-command (command &rest args)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   274
  "Run the shell command COMMAND, returning (EXIT-CODE . COMMAND-OUTPUT).
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   275
The list ARGS contains a list of arguments to pass to the command."
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   276
  (let* (exit-code
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   277
	 (output
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   278
	  (with-output-to-string
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   279
	    (with-current-buffer
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   280
		standard-output
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   281
	      (setq exit-code
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   282
		    (apply 'call-process command nil t nil args))))))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   283
    (cons exit-code output)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   284
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   285
(defun hg-run (command &rest args)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   286
  "Run the Mercurial command COMMAND, returning (EXIT-CODE . COMMAND-OUTPUT)."
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   287
  (apply 'hg-run-command (hg-binary) command args))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   288
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   289
(defun hg-run0 (command &rest args)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   290
  "Run the Mercurial command COMMAND, returning its output.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   291
If the command does not exit with a zero status code, raise an error."
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   292
  (let ((res (apply 'hg-run-command (hg-binary) command args)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   293
    (if (not (eq (car res) 0))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   294
	(error "Mercurial command failed %s - exit code %s"
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   295
	       (cons command args)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   296
	       (car res))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   297
      (cdr res))))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   298
1024
5b257e419816 Sync buffers prior to doing a diff.
bos@serpentine.internal.keyresearch.com
parents: 1011
diff changeset
   299
(defun hg-sync-buffers (path)
5b257e419816 Sync buffers prior to doing a diff.
bos@serpentine.internal.keyresearch.com
parents: 1011
diff changeset
   300
  "Sync buffers visiting PATH with their on-disk copies.
5b257e419816 Sync buffers prior to doing a diff.
bos@serpentine.internal.keyresearch.com
parents: 1011
diff changeset
   301
If PATH is not being visited, but is under the repository root, sync
5b257e419816 Sync buffers prior to doing a diff.
bos@serpentine.internal.keyresearch.com
parents: 1011
diff changeset
   302
all buffers visiting files in the repository."
5b257e419816 Sync buffers prior to doing a diff.
bos@serpentine.internal.keyresearch.com
parents: 1011
diff changeset
   303
  (let ((buf (find-buffer-visiting path)))
5b257e419816 Sync buffers prior to doing a diff.
bos@serpentine.internal.keyresearch.com
parents: 1011
diff changeset
   304
    (if buf
5b257e419816 Sync buffers prior to doing a diff.
bos@serpentine.internal.keyresearch.com
parents: 1011
diff changeset
   305
	(with-current-buffer buf
5b257e419816 Sync buffers prior to doing a diff.
bos@serpentine.internal.keyresearch.com
parents: 1011
diff changeset
   306
	  (vc-buffer-sync))
5b257e419816 Sync buffers prior to doing a diff.
bos@serpentine.internal.keyresearch.com
parents: 1011
diff changeset
   307
      (hg-do-across-repo path
5b257e419816 Sync buffers prior to doing a diff.
bos@serpentine.internal.keyresearch.com
parents: 1011
diff changeset
   308
	(vc-buffer-sync)))))
5b257e419816 Sync buffers prior to doing a diff.
bos@serpentine.internal.keyresearch.com
parents: 1011
diff changeset
   309
  
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   310
(defun hg-buffer-commands (pnt)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   311
  "Use the properties of a character to do something sensible."
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   312
  (interactive "d")
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   313
  (let ((rev (get-char-property pnt 'rev))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   314
	(file (get-char-property pnt 'file))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   315
	(date (get-char-property pnt 'date))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   316
	(user (get-char-property pnt 'user))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   317
	(host (get-char-property pnt 'host))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   318
	(prev-buf (current-buffer)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   319
    (cond
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   320
     (file
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   321
      (find-file-other-window file))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   322
     (rev
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   323
      (hg-diff hg-view-file-name rev rev prev-buf))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   324
     ((message "I don't know how to do that yet")))))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   325
1004
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
   326
(defsubst hg-event-point (event)
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
   327
  "Return the character position of the mouse event EVENT."
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
   328
  (if hg-running-xemacs
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
   329
      (event-point event)
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
   330
    (posn-point (event-start event))))
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
   331
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
   332
(defsubst hg-event-window (event)
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
   333
  "Return the window over which mouse event EVENT occurred."
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
   334
  (if hg-running-xemacs
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
   335
      (event-window event)
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
   336
    (posn-window (event-start event))))
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
   337
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   338
(defun hg-buffer-mouse-clicked (event)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   339
  "Translate the mouse clicks in a HG log buffer to character events.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   340
These are then handed off to `hg-buffer-commands'.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   341
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   342
Handle frickin' frackin' gratuitous event-related incompatibilities."
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   343
  (interactive "e")
1004
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
   344
  (select-window (hg-event-window event))
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
   345
  (hg-buffer-commands (hg-event-point event)))
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   346
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   347
(unless (fboundp 'view-minor-mode)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   348
  (defun view-minor-mode (prev-buffer exit-func)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   349
    (view-mode)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   350
995
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   351
(defsubst hg-abbrev-file-name (file)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   352
  "Portable wrapper around abbreviate-file-name."
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   353
  (if hg-running-xemacs
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   354
      (abbreviate-file-name file t)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   355
    (abbreviate-file-name file)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   356
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   357
(defun hg-read-file-name (&optional prompt default)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   358
  "Read a file or directory name, or a pattern, to use with a command."
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   359
  (save-excursion
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   360
    (while hg-prev-buffer
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   361
      (set-buffer hg-prev-buffer))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   362
    (let ((path (or default (buffer-file-name))))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   363
      (if (or (not path) current-prefix-arg)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   364
	  (expand-file-name
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   365
	   (read-file-name (format "File, directory or pattern%s: "
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   366
				   (or prompt ""))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   367
			   (and path (file-name-directory path))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   368
			   nil nil
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   369
			   (and path (file-name-nondirectory path))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   370
			   'hg-file-history))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   371
	path))))
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   372
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   373
(defun hg-read-rev (&optional prompt default)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   374
  "Read a revision or tag, offering completions."
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   375
  (save-excursion
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   376
    (while hg-prev-buffer
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   377
      (set-buffer hg-prev-buffer))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   378
    (let ((rev (or default "tip")))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   379
      (if (or (not rev) current-prefix-arg)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   380
	  (let ((revs (split-string (hg-chomp
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   381
				     (hg-run0 "-q" "log" "-r"
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   382
					      (format "-%d"
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   383
						      hg-rev-completion-limit)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   384
					      "-r" "tip"))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   385
				    "[\n:]")))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   386
	    (dolist (line (split-string (hg-chomp (hg-run0 "tags")) "\n"))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   387
	      (setq revs (cons (car (split-string line "\\s-")) revs)))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   388
	    (completing-read (format "Revision%s (%s): "
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   389
				     (or prompt "")
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   390
				     (or default "tip"))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   391
			     (map 'list 'cons revs revs)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   392
			     nil
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   393
			     nil
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   394
			     nil
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   395
			     'hg-rev-history
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   396
			     (or default "tip")))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   397
	rev))))
999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   398
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   399
(defmacro hg-do-across-repo (path &rest body)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   400
  (let ((root-name (gensym "root-"))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   401
	(buf-name (gensym "buf-")))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   402
    `(let ((,root-name (hg-root ,path)))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   403
       (save-excursion
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   404
	 (dolist (,buf-name (buffer-list))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   405
	   (set-buffer ,buf-name)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   406
	   (when (and hg-status (equal (hg-root buffer-file-name) ,root-name))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   407
	     ,@body))))))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   408
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   409
(put 'hg-do-across-repo 'lisp-indent-function 1)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   410
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   411

41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   412
;;; View mode bits.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   413
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   414
(defun hg-exit-view-mode (buf)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   415
  "Exit from hg-view-mode.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   416
We delete the current window if entering hg-view-mode split the
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   417
current frame."
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   418
  (when (and (eq buf (current-buffer))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   419
	     (> (length (window-list)) 1))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   420
    (delete-window))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   421
  (when (buffer-live-p buf)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   422
    (kill-buffer buf)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   423
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   424
(defun hg-view-mode (prev-buffer &optional file-name)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   425
  (goto-char (point-min))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   426
  (set-buffer-modified-p nil)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   427
  (toggle-read-only t)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   428
  (view-minor-mode prev-buffer 'hg-exit-view-mode)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   429
  (use-local-map hg-view-mode-map)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   430
  (setq truncate-lines t)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   431
  (when file-name
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   432
    (set (make-local-variable 'hg-view-file-name)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   433
	 (hg-abbrev-file-name file-name))))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   434
  
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   435
(defun hg-file-status (file)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   436
  "Return status of FILE, or nil if FILE does not exist or is unmanaged."
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   437
  (let* ((s (hg-run "status" file))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   438
	 (exit (car s))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   439
	 (output (cdr s)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   440
    (if (= exit 0)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   441
	(let ((state (assoc (substring output 0 (min (length output) 2))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   442
			    '(("M " . modified)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   443
			      ("A " . added)
995
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   444
			      ("R " . removed)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   445
			      ("? " . nil)))))
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   446
	  (if state
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   447
	      (cdr state)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   448
	    'normal)))))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   449
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   450
(defun hg-tip ()
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   451
  (split-string (hg-chomp (hg-run0 "-q" "tip")) ":"))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   452
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   453
(defmacro hg-view-output (args &rest body)
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   454
  "Execute BODY in a clean buffer, then quickly display that buffer.
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   455
If the buffer contains one line, its contents are displayed in the
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   456
minibuffer.  Otherwise, the buffer is displayed in view-mode.
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   457
ARGS is of the form (BUFFER-NAME &optional FILE), where BUFFER-NAME is
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   458
the name of the buffer to create, and FILE is the name of the file
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   459
being viewed."
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   460
  (let ((prev-buf (gensym "prev-buf-"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   461
	(v-b-name (car args))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   462
	(v-m-rest (cdr args)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   463
    `(let ((view-buf-name ,v-b-name)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   464
	   (,prev-buf (current-buffer)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   465
       (get-buffer-create view-buf-name)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   466
       (kill-buffer view-buf-name)
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   467
       (get-buffer-create view-buf-name)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   468
       (set-buffer view-buf-name)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   469
       (save-excursion
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   470
	 ,@body)
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   471
       (case (count-lines (point-min) (point-max))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   472
	 ((0)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   473
	  (kill-buffer view-buf-name)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   474
	  (message "(No output)"))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   475
	 ((1)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   476
	  (let ((msg (hg-chomp (buffer-substring (point-min) (point-max)))))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   477
	    (kill-buffer view-buf-name)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   478
	    (message "%s" msg)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   479
	 (t
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   480
	  (pop-to-buffer view-buf-name)
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   481
	  (setq hg-prev-buffer ,prev-buf)
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   482
	  (hg-view-mode ,prev-buf ,@v-m-rest))))))
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   483
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   484
(put 'hg-view-output 'lisp-indent-function 1)
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   485

995
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   486
;;; Context save and restore across revert.
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   487
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   488
(defun hg-position-context (pos)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   489
  "Return information to help find the given position again."
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   490
  (let* ((end (min (point-max) (+ pos 98))))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   491
    (list pos
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   492
	  (buffer-substring (max (point-min) (- pos 2)) end)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   493
	  (- end pos))))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   494
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   495
(defun hg-buffer-context ()
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   496
  "Return information to help restore a user's editing context.
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   497
This is useful across reverts and merges, where a context is likely
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   498
to have moved a little, but not really changed."
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   499
  (let ((point-context (hg-position-context (point)))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   500
	(mark-context (let ((mark (mark-marker)))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   501
			(and mark (hg-position-context mark)))))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   502
    (list point-context mark-context)))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   503
	
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   504
(defun hg-find-context (ctx)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   505
  "Attempt to find a context in the given buffer.
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   506
Always returns a valid, hopefully sane, position."
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   507
  (let ((pos (nth 0 ctx))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   508
	(str (nth 1 ctx))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   509
	(fixup (nth 2 ctx)))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   510
    (save-excursion
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   511
      (goto-char (max (point-min) (- pos 15000)))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   512
      (if (and (not (equal str ""))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   513
	       (search-forward str nil t))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   514
	  (- (point) fixup)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   515
	(max pos (point-min))))))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   516
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   517
(defun hg-restore-context (ctx)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   518
  "Attempt to restore the user's editing context."
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   519
  (let ((point-context (nth 0 ctx))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   520
	(mark-context (nth 1 ctx)))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   521
    (goto-char (hg-find-context point-context))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   522
    (when mark-context
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   523
      (set-mark (hg-find-context mark-context)))))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   524
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   525

947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   526
;;; Hooks.
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   527
995
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   528
(defun hg-mode-line (&optional force)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   529
  "Update the modeline with the current status of a file.
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   530
An update occurs if optional argument FORCE is non-nil,
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   531
hg-update-modeline is non-nil, or we have not yet checked the state of
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   532
the file."
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   533
  (when (and (hg-root) (or force hg-update-modeline (not hg-mode)))
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   534
    (let ((status (hg-file-status buffer-file-name)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   535
      (setq hg-status status
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   536
	    hg-mode (and status (concat " Hg:"
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   537
					(car (hg-tip))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   538
					(cdr (assq status
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   539
						   '((normal . "")
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   540
						     (removed . "r")
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   541
						     (added . "a")
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   542
						     (modified . "m")))))))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   543
      status)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   544
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   545
(defun hg-mode ()
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   546
  "Minor mode for Mercurial distributed SCM integration.
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   547
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   548
The Mercurial mode user interface is based on that of VC mode, so if
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   549
you're already familiar with VC, the same keybindings and functions
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   550
will generally work.
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   551
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   552
Below is a list of many common SCM tasks.  In the list, `G/L'
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   553
indicates whether a key binding is global (G) to a repository or local
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   554
(L) to a file.  Many commands take a prefix argument.
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   555
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   556
SCM Task                              G/L  Key Binding  Command Name
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   557
--------                              ---  -----------  ------------
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   558
Help overview (what you are reading)  G    C-c h h      hg-help-overview
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   559
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   560
Tell Mercurial to manage a file       G    C-c h a      hg-add
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   561
Commit changes to current file only   L    C-x v n      hg-commit
995
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   562
Undo changes to file since commit     L    C-x v u      hg-revert-buffer
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   563
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   564
Diff file vs last checkin             L    C-x v =      hg-diff
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   565
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   566
View file change history              L    C-x v l      hg-log
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   567
View annotated file                   L    C-x v a      hg-annotate
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   568
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   569
Diff repo vs last checkin             G    C-c h =      hg-diff-repo
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   570
View status of files in repo          G    C-c h s      hg-status
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   571
Commit all changes                    G    C-c h c      hg-commit
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   572
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   573
Undo all changes since last commit    G    C-c h U      hg-revert
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   574
View repo change history              G    C-c h l      hg-log
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   575
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   576
See changes that can be pulled        G    C-c h ,      hg-incoming
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   577
Pull changes                          G    C-c h <      hg-pull
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   578
Update working directory after pull   G    C-c h u      hg-update
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   579
See changes that can be pushed        G    C-c h .      hg-outgoing
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   580
Push changes                          G    C-c h >      hg-push"
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   581
  (run-hooks 'hg-mode-hook))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   582
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   583
(defun hg-find-file-hook ()
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   584
  (when (hg-mode-line)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   585
    (hg-mode)))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   586
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   587
(add-hook 'find-file-hooks 'hg-find-file-hook)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   588
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   589
(defun hg-after-save-hook ()
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   590
  (let ((old-status hg-status))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   591
    (hg-mode-line)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   592
    (if (and (not old-status) hg-status)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   593
	(hg-mode))))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   594
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   595
(add-hook 'after-save-hook 'hg-after-save-hook)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   596
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   597

6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   598
;;; User interface functions.
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   599
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   600
(defun hg-help-overview ()
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   601
  "This is an overview of the Mercurial SCM mode for Emacs.
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   602
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   603
You can find the source code, license (GPL v2), and credits for this
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   604
code by typing `M-x find-library mercurial RET'."
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   605
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   606
  (hg-view-output ("Mercurial Help Overview")
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   607
    (insert (documentation 'hg-help-overview))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   608
    (let ((pos (point)))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   609
      (insert (documentation 'hg-mode))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   610
      (goto-char pos)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   611
      (kill-line))))
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   612
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   613
(defun hg-add (path)
996
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   614
  "Add PATH to the Mercurial repository on the next commit.
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   615
With a prefix argument, prompt for the path to add."
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   616
  (interactive (list (hg-read-file-name " to add")))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   617
  (let ((buf (current-buffer))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   618
	(update (equal buffer-file-name path)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   619
    (hg-view-output (hg-output-buffer-name)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   620
      (apply 'call-process (hg-binary) nil t nil (list "add" path)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   621
    (when update
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   622
      (with-current-buffer buf
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   623
	(hg-mode-line)))))
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   624
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   625
(defun hg-addremove ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   626
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   627
  (error "not implemented"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   628
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   629
(defun hg-annotate ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   630
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   631
  (error "not implemented"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   632
999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   633
(defun hg-commit-toggle-file (pos)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   634
  "Toggle whether or not the file at POS will be committed."
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   635
  (interactive "d")
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   636
  (save-excursion
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   637
    (goto-char pos)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   638
    (let ((face (get-text-property pos 'face))
1004
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
   639
	  (inhibit-read-only t)
999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   640
	  bol)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   641
      (beginning-of-line)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   642
      (setq bol (+ (point) 4))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   643
      (end-of-line)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   644
      (if (eq face 'bold)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   645
	  (progn
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   646
	    (remove-text-properties bol (point) '(face nil))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   647
	    (message "%s will not be committed"
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   648
		     (buffer-substring bol (point))))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   649
	(add-text-properties bol (point) '(face bold))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   650
	(message "%s will be committed"
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   651
		 (buffer-substring bol (point)))))))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   652
	
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   653
(defun hg-commit-mouse-clicked (event)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   654
  "Toggle whether or not the file at POS will be committed."
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   655
  (interactive "@e")
1004
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
   656
  (hg-commit-toggle-file (hg-event-point event)))
999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   657
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   658
(defun hg-commit-kill ()
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   659
  "Kill the commit currently being prepared."
999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   660
  (interactive)
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   661
  (when (or (not (buffer-modified-p)) (y-or-n-p "Really kill this commit? "))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   662
    (let ((buf hg-prev-buffer))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   663
      (kill-buffer nil)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   664
      (switch-to-buffer buf))))
999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   665
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   666
(defun hg-commit-finish ()
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   667
  "Finish preparing a commit, and perform the actual commit.
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   668
The hook hg-pre-commit-hook is run before anything else is done.  If
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   669
the commit message is empty and hg-commit-allow-empty-message is nil,
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   670
an error is raised.  If the list of files to commit is empty and
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   671
hg-commit-allow-empty-file-list is nil, an error is raised."
999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   672
  (interactive)
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   673
  (let ((root hg-root))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   674
    (save-excursion
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   675
      (run-hooks 'hg-pre-commit-hook)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   676
      (goto-char (point-min))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   677
      (search-forward hg-commit-message-start)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   678
      (let (message files)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   679
	(let ((start (point)))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   680
	  (goto-char (point-max))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   681
	  (search-backward hg-commit-message-end)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   682
	  (setq message (hg-strip (buffer-substring start (point)))))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   683
	(when (and (= (length message) 0)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   684
		   (not hg-commit-allow-empty-message))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   685
	  (error "Cannot proceed - commit message is empty"))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   686
	(forward-line 1)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   687
	(beginning-of-line)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   688
	(while (< (point) (point-max))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   689
	  (let ((pos (+ (point) 4)))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   690
	    (end-of-line)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   691
	    (when (eq (get-text-property pos 'face) 'bold)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   692
	      (end-of-line)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   693
	      (setq files (cons (buffer-substring pos (point)) files))))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   694
	  (forward-line 1))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   695
	(when (and (= (length files) 0)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   696
		   (not hg-commit-allow-empty-file-list))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   697
	  (error "Cannot proceed - no files to commit"))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   698
	(setq message (concat message "\n"))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   699
	(apply 'hg-run0 "--cwd" hg-root "commit" "-m" message files))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   700
      (let ((buf hg-prev-buffer))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   701
	(kill-buffer nil)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   702
	(switch-to-buffer buf))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   703
      (hg-do-across-repo root
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   704
	(hg-mode-line)))))
999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   705
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   706
(defun hg-commit-mode ()
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   707
  "Mode for describing a commit of changes to a Mercurial repository.
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   708
This involves two actions: describing the changes with a commit
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   709
message, and choosing the files to commit.
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   710
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   711
To describe the commit, simply type some text in the designated area.
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   712
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   713
By default, all modified, added and removed files are selected for
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   714
committing.  Files that will be committed are displayed in bold face\;
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   715
those that will not are displayed in normal face.
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   716
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   717
To toggle whether a file will be committed, move the cursor over a
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   718
particular file and hit space or return.  Alternatively, middle click
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   719
on the file.
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   720
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   721
Key bindings
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   722
------------
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   723
\\[hg-commit-finish]		proceed with commit
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   724
\\[hg-commit-kill]		kill commit
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   725
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   726
\\[hg-diff-repo]		view diff of pending changes"
999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   727
  (interactive)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   728
  (use-local-map hg-commit-mode-map)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   729
  (set-syntax-table text-mode-syntax-table)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   730
  (setq local-abbrev-table text-mode-abbrev-table
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   731
	major-mode 'hg-commit-mode
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   732
	mode-name "Hg-Commit")
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   733
  (set-buffer-modified-p nil)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   734
  (setq buffer-undo-list nil)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   735
  (run-hooks 'text-mode-hook 'hg-commit-mode-hook))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   736
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   737
(defun hg-commit-start ()
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   738
  "Prepare a commit of changes to the repository containing the current file."
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   739
  (interactive)
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   740
  (while hg-prev-buffer
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   741
    (set-buffer hg-prev-buffer))
999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   742
  (let ((root (hg-root))
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   743
	(prev-buffer (current-buffer))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   744
	modified-files)
999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   745
    (unless root
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   746
      (error "Cannot commit outside a repository!"))
1024
5b257e419816 Sync buffers prior to doing a diff.
bos@serpentine.internal.keyresearch.com
parents: 1011
diff changeset
   747
    (hg-sync-buffers root)
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   748
    (setq modified-files (hg-chomp (hg-run0 "--cwd" root "status" "-arm")))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   749
    (when (and (= (length modified-files) 0)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   750
	       (not hg-commit-allow-empty-file-list))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   751
      (error "No pending changes to commit"))
999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   752
    (let* ((buf-name (format "*Mercurial: Commit %s*" root)))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   753
      (pop-to-buffer (get-buffer-create buf-name))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   754
      (when (= (point-min) (point-max))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   755
	(set (make-local-variable 'hg-root) root)
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   756
	(setq hg-prev-buffer prev-buffer)
999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   757
	(insert "\n")
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   758
	(let ((bol (point)))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   759
	  (insert hg-commit-message-end)
1004
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
   760
	  (add-text-properties bol (point) '(face bold-italic)))
999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   761
	(let ((file-area (point)))
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   762
	  (insert modified-files)
999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   763
	  (goto-char file-area)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   764
	  (while (< (point) (point-max))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   765
	    (let ((bol (point)))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   766
	      (forward-char 1)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   767
	      (insert "  ")
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   768
	      (end-of-line)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   769
	      (add-text-properties (+ bol 4) (point)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   770
				   '(face bold mouse-face highlight)))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   771
	    (forward-line 1))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   772
	  (goto-char file-area)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   773
	  (add-text-properties (point) (point-max)
1004
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
   774
			       `(keymap ,hg-commit-mode-file-map))
999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   775
	  (goto-char (point-min))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   776
	  (insert hg-commit-message-start)
1004
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
   777
	  (add-text-properties (point-min) (point) '(face bold-italic))
999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   778
	  (insert "\n\n")
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   779
	  (forward-line -1)
1004
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
   780
	  (save-excursion
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
   781
	    (goto-char (point-max))
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
   782
	    (search-backward hg-commit-message-end)
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
   783
	    (add-text-properties (match-beginning 0) (point-max)
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
   784
				 '(read-only t))
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
   785
	    (goto-char (point-min))
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
   786
	    (search-forward hg-commit-message-start)
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
   787
	    (add-text-properties (match-beginning 0) (match-end 0)
ad6fcceaf59b Emacs: improved GNU Emacs support.
bos@serpentine.internal.keyresearch.com
parents: 1003
diff changeset
   788
				 '(read-only t)))
999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   789
	  (hg-commit-mode))))))
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   790
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   791
(defun hg-diff (path &optional rev1 rev2)
996
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   792
  "Show the differences between REV1 and REV2 of PATH.
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   793
When called interactively, the default behaviour is to treat REV1 as
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   794
the tip revision, REV2 as the current edited version of the file, and
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   795
PATH as the file edited in the current buffer.
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   796
With a prefix argument, prompt for all of these."
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   797
  (interactive (list (hg-read-file-name " to diff")
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   798
		     (hg-read-rev " to start with")
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   799
		     (let ((rev2 (hg-read-rev " to end with" 'working-dir)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   800
		       (and (not (eq rev2 'working-dir)) rev2))))
995
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   801
  (unless rev1
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   802
    (setq rev1 "-1"))
1024
5b257e419816 Sync buffers prior to doing a diff.
bos@serpentine.internal.keyresearch.com
parents: 1011
diff changeset
   803
  (hg-sync-buffers path)
995
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   804
  (let ((a-path (hg-abbrev-file-name path))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   805
	diff)
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   806
    (hg-view-output ((if (equal rev1 rev2)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   807
			 (format "Mercurial: Rev %s of %s" rev1 a-path)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   808
		       (format "Mercurial: Rev %s to %s of %s"
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   809
			       rev1 (or rev2 "Current") a-path)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   810
      (if rev2
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   811
	  (call-process (hg-binary) nil t nil "diff" "-r" rev1 "-r" rev2 path)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   812
	(call-process (hg-binary) nil t nil "diff" "-r" rev1 path))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   813
      (diff-mode)
995
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   814
      (setq diff (not (= (point-min) (point-max))))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   815
      (font-lock-fontify-buffer))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   816
    diff))
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   817
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   818
(defun hg-diff-repo ()
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   819
  "Show the differences between the working copy and the tip revision."
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   820
  (interactive)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   821
  (hg-diff (hg-root)))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   822
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   823
(defun hg-forget (path)
996
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   824
  "Lose track of PATH, which has been added, but not yet committed.
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   825
This will prevent the file from being incorporated into the Mercurial
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   826
repository on the next commit.
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   827
With a prefix argument, prompt for the path to forget."
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   828
  (interactive (list (hg-read-file-name " to forget")))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   829
  (let ((buf (current-buffer))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   830
	(update (equal buffer-file-name path)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   831
    (hg-view-output (hg-output-buffer-name)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   832
      (apply 'call-process (hg-binary) nil t nil (list "forget" path)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   833
    (when update
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   834
      (with-current-buffer buf
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   835
	(hg-mode-line)))))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   836
  
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   837
(defun hg-incoming ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   838
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   839
  (error "not implemented"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   840
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   841
(defun hg-init ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   842
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   843
  (error "not implemented"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   844
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   845
(defun hg-log (path &optional rev1 rev2)
996
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   846
  "Display the revision history of PATH, between REV1 and REV2.
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   847
REV1 defaults to the initial revision, while REV2 defaults to the tip.
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   848
With a prefix argument, prompt for each parameter.
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   849
Variable hg-log-limit controls the number of log entries displayed."
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   850
  (interactive (list (hg-read-file-name " to log")
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   851
		     (hg-read-rev " to start with" "-1")
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   852
		     (hg-read-rev " to end with" (format "-%d" hg-log-limit))))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   853
  (let ((a-path (hg-abbrev-file-name path)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   854
    (hg-view-output ((if (equal rev1 rev2)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   855
			 (format "Mercurial: Rev %s of %s" rev1 a-path)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   856
		       (format "Mercurial: Rev %s to %s of %s"
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   857
			       rev1 (or rev2 "Current") a-path)))
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   858
      (if (> (length path) (length (hg-root path)))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   859
	  (call-process (hg-binary) nil t nil "log" "-r" rev1 "-r" rev2 path)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   860
	(call-process (hg-binary) nil t nil "log" "-r" rev1 "-r" rev2))
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   861
      (font-lock-fontify-buffer))))
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   862
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   863
(defun hg-log-repo (path &optional rev1 rev2)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   864
  "Display the revision history of the repository containing PATH.
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   865
History is displayed between REV1, which defaults to the tip, and
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   866
REV2, which defaults to the initial revision.
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   867
Variable hg-log-limit controls the number of log entries displayed."
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   868
  (interactive (list (hg-read-file-name " to log")
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   869
		     (hg-read-rev " to start with" "tip")
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   870
		     (hg-read-rev " to end with" (format "-%d" hg-log-limit))))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   871
  (hg-log (hg-root path) rev1 rev2))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   872
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   873
(defun hg-outgoing ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   874
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   875
  (error "not implemented"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   876
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   877
(defun hg-pull ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   878
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   879
  (error "not implemented"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   880
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   881
(defun hg-push ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   882
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   883
  (error "not implemented"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   884
995
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   885
(defun hg-revert-buffer-internal ()
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   886
  (let ((ctx (hg-buffer-context)))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   887
    (message "Reverting %s..." buffer-file-name)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   888
    (hg-run0 "revert" buffer-file-name)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   889
    (revert-buffer t t t)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   890
    (hg-restore-context ctx)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   891
    (hg-mode-line)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   892
    (message "Reverting %s...done" buffer-file-name)))
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   893
995
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   894
(defun hg-revert-buffer ()
996
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   895
  "Revert current buffer's file back to the latest committed version.
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   896
If the file has not changed, nothing happens.  Otherwise, this
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   897
displays a diff and asks for confirmation before reverting."
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   898
  (interactive)
995
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   899
  (let ((vc-suppress-confirm nil)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   900
	(obuf (current-buffer))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   901
	diff)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   902
    (vc-buffer-sync)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   903
    (unwind-protect
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   904
	(setq diff (hg-diff buffer-file-name))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   905
      (when diff
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   906
	(unless (yes-or-no-p "Discard changes? ")
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   907
	  (error "Revert cancelled")))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   908
      (when diff
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   909
	(let ((buf (current-buffer)))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   910
	  (delete-window (selected-window))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   911
	  (kill-buffer buf))))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   912
    (set-buffer obuf)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   913
    (when diff
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   914
      (hg-revert-buffer-internal))))
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   915
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   916
(defun hg-root (&optional path)
996
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   917
  "Return the root of the repository that contains the given path.
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   918
If the path is outside a repository, return nil.
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   919
When called interactively, the root is printed.  A prefix argument
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   920
prompts for a path to check."
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   921
  (interactive (list (hg-read-file-name)))
1003
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   922
  (if (or path (not hg-root))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   923
      (let ((root (do ((prev nil dir)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   924
		       (dir (file-name-directory (or path buffer-file-name ""))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   925
			    (file-name-directory (directory-file-name dir))))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   926
		      ((equal prev dir))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   927
		    (when (file-directory-p (concat dir ".hg"))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   928
		      (return dir)))))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   929
	(when (interactive-p)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   930
	  (if root
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   931
	      (message "The root of this repository is `%s'." root)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   932
	    (message "The path `%s' is not in a Mercurial repository."
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   933
		     (abbreviate-file-name path t))))
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   934
	root)
6dfc9cc71f42 Emacs support: numerous changes.
bos@serpentine.internal.keyresearch.com
parents: 1001
diff changeset
   935
    hg-root))
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   936
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   937
(defun hg-status (path)
996
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   938
  "Print revision control status of a file or directory.
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   939
With prefix argument, prompt for the path to give status for.
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   940
Names are displayed relative to the repository root."
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   941
  (interactive (list (hg-read-file-name " for status" (hg-root))))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   942
  (let ((root (hg-root)))
996
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   943
    (hg-view-output ((format "Mercurial: Status of %s in %s"
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   944
			     (let ((name (substring (expand-file-name path)
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   945
						    (length root))))
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   946
			       (if (> (length name) 0)
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   947
				   name
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   948
				 "*"))
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   949
			     (hg-abbrev-file-name root)))
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   950
      (apply 'call-process (hg-binary) nil t nil
955
307ca8ca234f Remove -C alias for --cwd
mpm@selenic.com
parents: 948
diff changeset
   951
	     (list "--cwd" root "status" path)))))
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   952
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   953
(defun hg-undo ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   954
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   955
  (error "not implemented"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   956
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   957
(defun hg-version-other-window ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   958
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   959
  (error "not implemented"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   960
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   961

41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   962
(provide 'mercurial)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   963
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   964

41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   965
;;; Local Variables:
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   966
;;; prompt-to-byte-compile: nil
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   967
;;; end: