contrib/mercurial.el
author Bryan O'Sullivan <bos@serpentine.com>
Mon, 22 Aug 2005 03:27:27 -0700
changeset 1000 3362b410c219
parent 999 bb391518bc28
child 1001 ab3939ccbf10
permissions -rw-r--r--
Emacs: kill commit buffer once it's done with.
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
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
     7
;; $Id$
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
     8
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
     9
;; 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
    10
;; 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
    11
;; License as published by the Free Software Foundation.
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    12
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
    13
;; 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
    14
;; WITHOUT ANY WARRANTY; without even the implied warranty of
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    15
;; 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
    16
;; General Public License for more details.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    17
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    18
;; 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
    19
;; 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
    20
;; (`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
    21
;; 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
    22
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    23
;;; Commentary:
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    24
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    25
;; This mode builds upon Emacs's VC mode to provide flexible
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    26
;; integration with the Mercurial distributed SCM tool.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    27
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
    28
;; 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
    29
;; 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
    30
;; usage overview.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    31
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    32
;; 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
    33
;; 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
    34
;; 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
    35
;; chunks of code are adapted from p4.el.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    36
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    37
;; This code has been developed under XEmacs 21.5, and may will not
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    38
;; work as well under GNU Emacs (albeit tested under 21.2).  Patches
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    39
;; to enhance the portability of this code, fix bugs, and add features
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    40
;; 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
    41
;; package from http://www.serpentine.com/hg/hg-emacs
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
;; 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
    44
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
;;; Code:
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    47
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    48
(require 'advice)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    49
(require 'cl)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    50
(require 'diff-mode)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    51
(require 'easymenu)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    52
(require 'vc)
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

41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    55
;;; 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
    56
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    57
(condition-case nil
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    58
    (require 'view-less)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    59
  (error nil))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    60
(condition-case nil
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    61
    (require 'view)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    62
  (error nil))
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

41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    65
;;; Variables accessible through the custom system.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    66
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
    67
(defgroup mercurial nil
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    68
  "Mercurial distributed SCM."
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    69
  :group 'tools)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    70
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    71
(defcustom hg-binary
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    72
  (dolist (path '("~/bin/hg"
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    73
		  "/usr/bin/hg"
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    74
		  "/usr/local/bin/hg"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    75
    (when (file-executable-p path)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    76
      (return path)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    77
  "The path to Mercurial's hg executable."
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    78
  :type '(file :must-match t)
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
    79
  :group 'mercurial)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    80
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    81
(defcustom hg-mode-hook nil
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    82
  "Hook run when a buffer enters hg-mode."
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    83
  :type 'sexp
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
    84
  :group 'mercurial)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    85
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    86
(defcustom hg-global-prefix "\C-ch"
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    87
  "The global prefix for Mercurial keymap bindings."
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    88
  :type 'sexp
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
    89
  :group 'mercurial)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
    90
999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
    91
(defcustom hg-commit-allow-empty-message nil
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
    92
  "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
    93
  :type 'boolean
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
    94
  :group 'mercurial)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
    95
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
    96
(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
    97
  "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
    98
  :type 'boolean
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
    99
  :group 'mercurial)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   100
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   101
(defcustom hg-rev-completion-limit 100
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   102
  "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
   103
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
   104
in a repository with a lot of history."
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   105
  :type 'integer
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   106
  :group 'mercurial)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   107
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   108
(defcustom hg-log-limit 50
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   109
  "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
   110
  :type 'integer
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   111
  :group 'mercurial)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   112
995
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   113
(defcustom hg-update-modeline t
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   114
  "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
   115
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
   116
  :type 'boolean
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   117
  :group 'mercurial)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   118
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   119

41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   120
;;; Other variables.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   121
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   122
(defconst hg-running-xemacs (string-match "XEmacs" emacs-version)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   123
  "Is mercurial.el running under XEmacs?")
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   124
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   125
(defvar hg-mode nil
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   126
  "Is this file managed by Mercurial?")
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   127
(make-variable-buffer-local 'hg-mode)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   128
(put 'hg-mode 'permanent-local t)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   129
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   130
(defvar hg-status nil)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   131
(make-variable-buffer-local 'hg-status)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   132
(put 'hg-status 'permanent-local t)
944
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-output-buffer-name "*Hg*"
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   135
  "The name to use for Mercurial output buffers.")
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   136
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   137
(defvar hg-file-history nil)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   138
(defvar hg-rev-history nil)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   139
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   140

999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   141
;;; Random constants.
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   142
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   143
(defconst hg-commit-message-start
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   144
  "--- 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
   145
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   146
(defconst hg-commit-message-end
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   147
  "--- 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
   148
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   149

944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   150
;;; hg-mode keymap.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   151
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   152
(defvar hg-prefix-map
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   153
  (let ((map (copy-keymap vc-prefix-map)))
958
d845a1f174bb Make mercurial.el load with GNU emacs
mpm@selenic.com
parents: 955
diff changeset
   154
    (if (functionp 'set-keymap-name)
d845a1f174bb Make mercurial.el load with GNU emacs
mpm@selenic.com
parents: 955
diff changeset
   155
      (set-keymap-name map 'hg-prefix-map)); XEmacs
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   156
    map)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   157
  "This keymap overrides some default vc-mode bindings.")
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   158
(fset 'hg-prefix-map hg-prefix-map)
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   159
(define-key hg-prefix-map "=" 'hg-diff)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   160
(define-key hg-prefix-map "c" 'hg-undo)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   161
(define-key hg-prefix-map "g" 'hg-annotate)
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   162
(define-key hg-prefix-map "l" 'hg-log)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   163
(define-key hg-prefix-map "n" 'hg-commit-file)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   164
;; (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
   165
(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
   166
(define-key hg-prefix-map "~" 'hg-version-other-window)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   167
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   168
(defvar hg-mode-map (make-sparse-keymap))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   169
(define-key hg-mode-map "\C-xv" 'hg-prefix-map)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   170
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   171
(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
   172
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   173

41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   174
;;; Global keymap.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   175
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   176
(global-set-key "\C-xvi" 'hg-add)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   177
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   178
(defvar hg-global-map (make-sparse-keymap))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   179
(fset 'hg-global-map hg-global-map)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   180
(global-set-key hg-global-prefix 'hg-global-map)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   181
(define-key hg-global-map "," 'hg-incoming)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   182
(define-key hg-global-map "." 'hg-outgoing)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   183
(define-key hg-global-map "<" 'hg-pull)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   184
(define-key hg-global-map "=" 'hg-diff)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   185
(define-key hg-global-map ">" 'hg-push)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   186
(define-key hg-global-map "?" 'hg-help-overview)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   187
(define-key hg-global-map "A" 'hg-addremove)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   188
(define-key hg-global-map "U" 'hg-revert)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   189
(define-key hg-global-map "a" 'hg-add)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   190
(define-key hg-global-map "c" 'hg-commit)
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   191
(define-key hg-global-map "f" 'hg-forget)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   192
(define-key hg-global-map "h" 'hg-help-overview)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   193
(define-key hg-global-map "i" 'hg-init)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   194
(define-key hg-global-map "l" 'hg-log)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   195
(define-key hg-global-map "r" 'hg-root)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   196
(define-key hg-global-map "s" 'hg-status)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   197
(define-key hg-global-map "u" 'hg-update)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   198
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   199

41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   200
;;; View mode keymap.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   201
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   202
(defvar hg-view-mode-map
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   203
  (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
   204
			      view-minor-mode-map
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   205
			    view-mode-map))))
958
d845a1f174bb Make mercurial.el load with GNU emacs
mpm@selenic.com
parents: 955
diff changeset
   206
    (if (functionp 'set-keymap-name)
d845a1f174bb Make mercurial.el load with GNU emacs
mpm@selenic.com
parents: 955
diff changeset
   207
      (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
   208
    map))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   209
(fset 'hg-view-mode-map hg-view-mode-map)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   210
(define-key hg-view-mode-map
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   211
  (if hg-running-xemacs [button2] [mouse-2])
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   212
  'hg-buffer-mouse-clicked)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   213
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   214

999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   215
;;; Commit mode keymaps.
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   216
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   217
(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
   218
(define-key hg-commit-mode-map "\C-c\C-c" 'hg-commit-finish)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   219
(define-key hg-commit-mode-map "\C-c\C-k" 'hg-commit-abort)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   220
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   221
(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
   222
(define-key hg-commit-mode-file-map
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   223
  (if hg-running-xemacs [button2] [mouse-2])
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   224
  'hg-commit-mouse-clicked)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   225
(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
   226
(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
   227
  
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   228

944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   229
;;; Convenience functions.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   230
995
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   231
(defsubst hg-binary ()
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   232
  (if hg-binary
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   233
      hg-binary
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   234
    (error "No `hg' executable found!")))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   235
995
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   236
(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
   237
  "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
   238
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
   239
replacement.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   240
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   241
This function bridges yet another pointless impedance gap between
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   242
XEmacs and GNU Emacs."
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   243
  (if (fboundp 'replace-in-string)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   244
      (replace-in-string str regexp newtext literal)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   245
    (replace-regexp-in-string regexp newtext str nil literal)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   246
999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   247
(defsubst hg-strip (str)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   248
  "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
   249
  (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
   250
			"^[ \t\r\n]+" ""))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   251
995
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   252
(defsubst hg-chomp (str)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   253
  "Strip trailing newlines from a string."
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   254
  (hg-replace-in-string str "[\r\n]+$" ""))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   255
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   256
(defun hg-run-command (command &rest args)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   257
  "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
   258
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
   259
  (let* (exit-code
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   260
	 (output
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   261
	  (with-output-to-string
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   262
	    (with-current-buffer
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   263
		standard-output
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   264
	      (setq exit-code
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   265
		    (apply 'call-process command nil t nil args))))))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   266
    (cons exit-code output)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   267
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   268
(defun hg-run (command &rest args)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   269
  "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
   270
  (apply 'hg-run-command (hg-binary) command args))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   271
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   272
(defun hg-run0 (command &rest args)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   273
  "Run the Mercurial command COMMAND, returning its output.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   274
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
   275
  (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
   276
    (if (not (eq (car res) 0))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   277
	(error "Mercurial command failed %s - exit code %s"
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   278
	       (cons command args)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   279
	       (car res))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   280
      (cdr res))))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   281
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   282
(defun hg-buffer-commands (pnt)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   283
  "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
   284
  (interactive "d")
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   285
  (let ((rev (get-char-property pnt 'rev))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   286
	(file (get-char-property pnt 'file))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   287
	(date (get-char-property pnt 'date))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   288
	(user (get-char-property pnt 'user))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   289
	(host (get-char-property pnt 'host))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   290
	(prev-buf (current-buffer)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   291
    (cond
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   292
     (file
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   293
      (find-file-other-window file))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   294
     (rev
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   295
      (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
   296
     ((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
   297
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   298
(defun hg-buffer-mouse-clicked (event)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   299
  "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
   300
These are then handed off to `hg-buffer-commands'.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   301
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   302
Handle frickin' frackin' gratuitous event-related incompatibilities."
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   303
  (interactive "e")
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   304
  (if hg-running-xemacs
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   305
      (progn
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   306
	(select-window (event-window event))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   307
	(hg-buffer-commands (event-point event)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   308
    (select-window (posn-window (event-end event)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   309
    (hg-buffer-commands (posn-point (event-start event)))))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   310
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   311
(unless (fboundp 'view-minor-mode)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   312
  (defun view-minor-mode (prev-buffer exit-func)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   313
    (view-mode)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   314
995
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   315
(defsubst hg-abbrev-file-name (file)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   316
  "Portable wrapper around abbreviate-file-name."
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   317
  (if hg-running-xemacs
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   318
      (abbreviate-file-name file t)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   319
    (abbreviate-file-name file)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   320
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   321
(defun hg-read-file-name (&optional prompt default)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   322
  "Read a file or directory name, or a pattern, to use with a command."
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   323
  (let ((path (or default (buffer-file-name))))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   324
    (if (or (not path) current-prefix-arg)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   325
	(expand-file-name
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   326
	 (read-file-name (format "File, directory or pattern%s: "
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   327
				 (or prompt ""))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   328
			 (and path (file-name-directory path))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   329
			 nil nil
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   330
			 (and path (file-name-nondirectory path))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   331
			 'hg-file-history))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   332
      path)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   333
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   334
(defun hg-read-rev (&optional prompt default)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   335
  "Read a revision or tag, offering completions."
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   336
  (let ((rev (or default "tip")))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   337
    (if (or (not rev) current-prefix-arg)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   338
	(let ((revs (split-string (hg-chomp
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   339
				   (hg-run0 "-q" "log" "-r"
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   340
					    (format "-%d"
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   341
						    hg-rev-completion-limit)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   342
					    "-r" "tip"))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   343
				  "[\n:]")))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   344
	  (dolist (line (split-string (hg-chomp (hg-run0 "tags")) "\n"))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   345
	    (setq revs (cons (car (split-string line "\\s-")) revs)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   346
	  (completing-read (format "Revision%s (%s): "
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   347
				   (or prompt "")
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   348
				   (or default "tip"))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   349
			   (map 'list 'cons revs revs)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   350
			   nil
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   351
			   nil
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   352
			   nil
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   353
			   'hg-rev-history
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   354
			   (or default "tip")))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   355
      rev)))
999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   356
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   357
(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
   358
  (let ((root-name (gensym "root-"))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   359
	(buf-name (gensym "buf-")))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   360
    `(let ((,root-name (hg-root ,path)))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   361
       (save-excursion
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   362
	 (dolist (,buf-name (buffer-list))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   363
	   (set-buffer ,buf-name)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   364
	   (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
   365
	     ,@body))))))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   366
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   367
(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
   368
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   369

41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   370
;;; View mode bits.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   371
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   372
(defun hg-exit-view-mode (buf)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   373
  "Exit from hg-view-mode.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   374
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
   375
current frame."
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   376
  (when (and (eq buf (current-buffer))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   377
	     (> (length (window-list)) 1))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   378
    (delete-window))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   379
  (when (buffer-live-p buf)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   380
    (kill-buffer buf)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   381
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   382
(defun hg-view-mode (prev-buffer &optional file-name)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   383
  (goto-char (point-min))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   384
  (set-buffer-modified-p nil)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   385
  (toggle-read-only t)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   386
  (view-minor-mode prev-buffer 'hg-exit-view-mode)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   387
  (use-local-map hg-view-mode-map)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   388
  (setq truncate-lines t)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   389
  (when file-name
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   390
    (set (make-local-variable 'hg-view-file-name)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   391
	 (hg-abbrev-file-name file-name))))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   392
  
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   393
(defun hg-file-status (file)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   394
  "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
   395
  (let* ((s (hg-run "status" file))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   396
	 (exit (car s))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   397
	 (output (cdr s)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   398
    (if (= exit 0)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   399
	(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
   400
			    '(("M " . modified)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   401
			      ("A " . added)
995
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   402
			      ("R " . removed)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   403
			      ("? " . nil)))))
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   404
	  (if state
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   405
	      (cdr state)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   406
	    'normal)))))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   407
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   408
(defun hg-tip ()
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   409
  (split-string (hg-chomp (hg-run0 "-q" "tip")) ":"))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   410
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   411
(defmacro hg-view-output (args &rest body)
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   412
  "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
   413
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
   414
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
   415
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
   416
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
   417
being viewed."
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   418
  (let ((prev-buf (gensym "prev-buf-"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   419
	(v-b-name (car args))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   420
	(v-m-rest (cdr args)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   421
    `(let ((view-buf-name ,v-b-name)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   422
	   (,prev-buf (current-buffer)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   423
       (get-buffer-create view-buf-name)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   424
       (kill-buffer view-buf-name)
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   425
       (get-buffer-create view-buf-name)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   426
       (set-buffer view-buf-name)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   427
       (save-excursion
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   428
	 ,@body)
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   429
       (case (count-lines (point-min) (point-max))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   430
	 ((0)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   431
	  (kill-buffer view-buf-name)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   432
	  (message "(No output)"))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   433
	 ((1)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   434
	  (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
   435
	    (kill-buffer view-buf-name)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   436
	    (message "%s" msg)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   437
	 (t
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   438
	  (pop-to-buffer view-buf-name)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   439
	  (hg-view-mode ,prev-buf ,@v-m-rest))))))
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   440
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   441
(put 'hg-view-output 'lisp-indent-function 1)
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   442

995
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   443
;;; Context save and restore across revert.
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   444
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   445
(defun hg-position-context (pos)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   446
  "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
   447
  (let* ((end (min (point-max) (+ pos 98))))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   448
    (list pos
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   449
	  (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
   450
	  (- end pos))))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   451
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   452
(defun hg-buffer-context ()
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   453
  "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
   454
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
   455
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
   456
  (let ((point-context (hg-position-context (point)))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   457
	(mark-context (let ((mark (mark-marker)))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   458
			(and mark (hg-position-context mark)))))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   459
    (list point-context mark-context)))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   460
	
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   461
(defun hg-find-context (ctx)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   462
  "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
   463
Always returns a valid, hopefully sane, position."
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   464
  (let ((pos (nth 0 ctx))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   465
	(str (nth 1 ctx))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   466
	(fixup (nth 2 ctx)))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   467
    (save-excursion
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   468
      (goto-char (max (point-min) (- pos 15000)))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   469
      (if (and (not (equal str ""))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   470
	       (search-forward str nil t))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   471
	  (- (point) fixup)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   472
	(max pos (point-min))))))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   473
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   474
(defun hg-restore-context (ctx)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   475
  "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
   476
  (let ((point-context (nth 0 ctx))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   477
	(mark-context (nth 1 ctx)))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   478
    (goto-char (hg-find-context point-context))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   479
    (when mark-context
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   480
      (set-mark (hg-find-context mark-context)))))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   481
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   482

947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   483
;;; Hooks.
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   484
995
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   485
(defun hg-mode-line (&optional force)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   486
  "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
   487
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
   488
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
   489
the file."
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   490
  (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
   491
    (let ((status (hg-file-status buffer-file-name)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   492
      (setq hg-status status
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   493
	    hg-mode (and status (concat " Hg:"
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   494
					(car (hg-tip))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   495
					(cdr (assq status
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   496
						   '((normal . "")
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   497
						     (removed . "r")
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   498
						     (added . "a")
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   499
						     (modified . "m")))))))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   500
      status)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   501
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   502
(defun hg-find-file-hook ()
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   503
  (when (hg-mode-line)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   504
    (run-hooks 'hg-mode-hook)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   505
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   506
(add-hook 'find-file-hooks 'hg-find-file-hook)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   507
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   508
(defun hg-after-save-hook ()
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   509
  (let ((old-status hg-status))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   510
    (hg-mode-line)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   511
    (if (and (not old-status) hg-status)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   512
	(run-hooks 'hg-mode-hook))))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   513
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   514
(add-hook 'after-save-hook 'hg-after-save-hook)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   515
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   516

41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   517
;;; User interface functions.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   518
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   519
(defun hg-help-overview ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   520
  "This is an overview of the Mercurial SCM mode for Emacs.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   521
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   522
You can find the source code, license (GPL v2), and credits for this
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   523
code by typing `M-x find-library mercurial RET'.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   524
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   525
The Mercurial mode user interface is based on that of the older VC
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   526
mode, so if you're already familiar with VC, the same keybindings and
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   527
functions will generally work.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   528
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   529
Below is a list of common SCM tasks, with the key bindings needed to
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   530
perform them, and the command names.  This list is not exhaustive.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   531
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   532
In the list below, `G/L' indicates whether a key binding is global (G)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   533
or local (L).  Global keybindings work on any file inside a Mercurial
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   534
repository.  Local keybindings only apply to files under the control
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   535
of Mercurial.  Many commands take a prefix argument.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   536
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   537
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   538
SCM Task                              G/L  Key Binding  Command Name
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   539
--------                              ---  -----------  ------------
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   540
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
   541
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   542
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
   543
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
   544
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
   545
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   546
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
   547
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   548
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
   549
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
   550
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   551
Diff repo vs last checkin             G    C-c h =      hg-diff
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   552
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
   553
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
   554
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   555
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
   556
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
   557
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   558
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
   559
Pull changes                          G    C-c h <      hg-pull
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   560
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
   561
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
   562
Push changes                          G    C-c h >      hg-push"
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   563
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   564
  (hg-view-output ("Mercurial Help Overview")
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   565
    (insert (documentation 'hg-help-overview))))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   566
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   567
(defun hg-add (path)
996
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   568
  "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
   569
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
   570
  (interactive (list (hg-read-file-name " to add")))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   571
  (let ((buf (current-buffer))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   572
	(update (equal buffer-file-name path)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   573
    (hg-view-output (hg-output-buffer-name)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   574
      (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
   575
    (when update
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   576
      (with-current-buffer buf
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   577
	(hg-mode-line)))))
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   578
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   579
(defun hg-addremove ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   580
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   581
  (error "not implemented"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   582
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   583
(defun hg-annotate ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   584
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   585
  (error "not implemented"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   586
999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   587
(defun hg-commit-toggle-file (pos)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   588
  "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
   589
  (interactive "d")
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   590
  (save-excursion
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   591
    (goto-char pos)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   592
    (let ((face (get-text-property pos 'face))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   593
	  bol)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   594
      (beginning-of-line)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   595
      (setq bol (+ (point) 4))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   596
      (end-of-line)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   597
      (if (eq face 'bold)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   598
	  (progn
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   599
	    (remove-text-properties bol (point) '(face nil))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   600
	    (message "%s will not be committed"
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   601
		     (buffer-substring bol (point))))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   602
	(add-text-properties bol (point) '(face bold))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   603
	(message "%s will be committed"
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   604
		 (buffer-substring bol (point)))))))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   605
	
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   606
(defun hg-commit-mouse-clicked (event)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   607
  "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
   608
  (interactive "@e")
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   609
  (hg-commit-toggle-file (event-point event)))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   610
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   611
(defun hg-commit-abort ()
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   612
  (interactive)
1000
3362b410c219 Emacs: kill commit buffer once it's done with.
Bryan O'Sullivan <bos@serpentine.com>
parents: 999
diff changeset
   613
  (let ((buf hg-prev-buffer))
3362b410c219 Emacs: kill commit buffer once it's done with.
Bryan O'Sullivan <bos@serpentine.com>
parents: 999
diff changeset
   614
    (kill-buffer nil)
3362b410c219 Emacs: kill commit buffer once it's done with.
Bryan O'Sullivan <bos@serpentine.com>
parents: 999
diff changeset
   615
    (switch-to-buffer buf)))
999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   616
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   617
(defun hg-commit-finish ()
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   618
  (interactive)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   619
  (goto-char (point-min))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   620
  (search-forward hg-commit-message-start)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   621
  (let (message files)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   622
    (let ((start (point)))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   623
      (goto-char (point-max))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   624
      (search-backward hg-commit-message-end)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   625
      (setq message (hg-strip (buffer-substring start (point)))))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   626
    (when (and (= (length message) 0)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   627
	       (not hg-commit-allow-empty-message))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   628
      (error "Cannot proceed - commit message is empty"))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   629
    (forward-line 1)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   630
    (beginning-of-line)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   631
    (while (< (point) (point-max))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   632
      (let ((pos (+ (point) 4)))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   633
	(end-of-line)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   634
	(when (eq (get-text-property pos 'face) 'bold)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   635
	  (end-of-line)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   636
	  (setq files (cons (buffer-substring pos (point)) files))))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   637
      (forward-line 1))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   638
    (when (and (= (length files) 0)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   639
	       (not hg-commit-allow-empty-file-list))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   640
      (error "Cannot proceed - no files to commit"))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   641
    (setq message (concat message "\n"))
1000
3362b410c219 Emacs: kill commit buffer once it's done with.
Bryan O'Sullivan <bos@serpentine.com>
parents: 999
diff changeset
   642
    (apply 'hg-run0 "--cwd" hg-root "commit" "-m" message files)
3362b410c219 Emacs: kill commit buffer once it's done with.
Bryan O'Sullivan <bos@serpentine.com>
parents: 999
diff changeset
   643
    (let ((buf hg-prev-buffer))
3362b410c219 Emacs: kill commit buffer once it's done with.
Bryan O'Sullivan <bos@serpentine.com>
parents: 999
diff changeset
   644
      (kill-buffer nil)
3362b410c219 Emacs: kill commit buffer once it's done with.
Bryan O'Sullivan <bos@serpentine.com>
parents: 999
diff changeset
   645
      (switch-to-buffer buf))))
999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   646
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   647
(defun hg-commit-mode ()
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   648
  "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
   649
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
   650
message, and choosing the files to commit.
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   651
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   652
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
   653
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   654
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
   655
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
   656
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
   657
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   658
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
   659
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
   660
on the file.
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   661
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   662
When you are finished with preparations, type \\[hg-commit-finish] to
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   663
proceed with the commit."
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   664
  (interactive)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   665
  (use-local-map hg-commit-mode-map)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   666
  (set-syntax-table text-mode-syntax-table)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   667
  (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
   668
	major-mode 'hg-commit-mode
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   669
	mode-name "Hg-Commit")
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   670
  (set-buffer-modified-p nil)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   671
  (setq buffer-undo-list nil)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   672
  (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
   673
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   674
(defun hg-commit ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   675
  (interactive)
999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   676
  (let ((root (hg-root))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   677
	(prev-buffer (current-buffer)))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   678
    (unless root
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   679
      (error "Cannot commit outside a repository!"))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   680
    (hg-do-across-repo
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   681
	(vc-buffer-sync))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   682
    (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
   683
      (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
   684
      (when (= (point-min) (point-max))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   685
	(set (make-local-variable 'hg-root) root)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   686
	(set (make-local-variable 'hg-prev-buffer) prev-buffer)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   687
	(insert "\n")
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   688
	(let ((bol (point)))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   689
	  (insert hg-commit-message-end)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   690
	  (add-text-properties bol (point) '(read-only t face bold-italic)))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   691
	(let ((file-area (point)))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   692
	  (insert (hg-chomp (hg-run0 "--cwd" root "status" "-arm")))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   693
	  (goto-char file-area)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   694
	  (while (< (point) (point-max))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   695
	    (let ((bol (point)))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   696
	      (forward-char 1)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   697
	      (insert "  ")
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   698
	      (end-of-line)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   699
	      (add-text-properties (+ bol 4) (point)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   700
				   '(face bold mouse-face highlight)))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   701
	    (forward-line 1))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   702
	  (goto-char file-area)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   703
	  (add-text-properties (point) (point-max)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   704
			       `(read-only t keymap ,hg-commit-mode-file-map))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   705
	  (goto-char (point-min))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   706
	  (insert hg-commit-message-start)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   707
	  (add-text-properties (point-min) (point)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   708
			       '(read-only t face bold-italic))
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   709
	  (insert "\n\n")
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   710
	  (forward-line -1)
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   711
	  (hg-commit-mode))))))
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   712
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   713
(defun hg-diff (path &optional rev1 rev2)
996
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   714
  "Show the differences between REV1 and REV2 of PATH.
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   715
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
   716
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
   717
PATH as the file edited in the current buffer.
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   718
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
   719
  (interactive (list (hg-read-file-name " to diff")
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   720
		     (hg-read-rev " to start with")
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   721
		     (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
   722
		       (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
   723
  (unless rev1
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   724
    (setq rev1 "-1"))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   725
  (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
   726
	diff)
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   727
    (hg-view-output ((if (equal rev1 rev2)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   728
			 (format "Mercurial: Rev %s of %s" rev1 a-path)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   729
		       (format "Mercurial: Rev %s to %s of %s"
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   730
			       rev1 (or rev2 "Current") a-path)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   731
      (if rev2
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   732
	  (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
   733
	(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
   734
      (diff-mode)
995
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   735
      (setq diff (not (= (point-min) (point-max))))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   736
      (font-lock-fontify-buffer))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   737
    diff))
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   738
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   739
(defun hg-forget (path)
996
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   740
  "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
   741
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
   742
repository on the next commit.
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   743
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
   744
  (interactive (list (hg-read-file-name " to forget")))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   745
  (let ((buf (current-buffer))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   746
	(update (equal buffer-file-name path)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   747
    (hg-view-output (hg-output-buffer-name)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   748
      (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
   749
    (when update
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   750
      (with-current-buffer buf
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   751
	(hg-mode-line)))))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   752
  
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   753
(defun hg-incoming ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   754
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   755
  (error "not implemented"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   756
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   757
(defun hg-init ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   758
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   759
  (error "not implemented"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   760
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   761
(defun hg-log (path &optional rev1 rev2)
996
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   762
  "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
   763
REV1 defaults to the initial revision, while REV2 defaults to the tip.
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   764
With a prefix argument, prompt for each parameter."
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   765
  (interactive (list (hg-read-file-name " to log")
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   766
		     (hg-read-rev " to start with" "-1")
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   767
		     (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
   768
  (let ((a-path (hg-abbrev-file-name path)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   769
    (hg-view-output ((if (equal rev1 rev2)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   770
			 (format "Mercurial: Rev %s of %s" rev1 a-path)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   771
		       (format "Mercurial: Rev %s to %s of %s"
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   772
			       rev1 (or rev2 "Current") a-path)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   773
      (call-process (hg-binary) nil t nil "log" "-r" rev1 "-r" rev2 path)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   774
      (diff-mode)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   775
      (font-lock-fontify-buffer))))
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   776
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   777
(defun hg-outgoing ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   778
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   779
  (error "not implemented"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   780
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   781
(defun hg-pull ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   782
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   783
  (error "not implemented"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   784
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   785
(defun hg-push ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   786
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   787
  (error "not implemented"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   788
995
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   789
(defun hg-revert-buffer-internal ()
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   790
  (let ((ctx (hg-buffer-context)))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   791
    (message "Reverting %s..." buffer-file-name)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   792
    (hg-run0 "revert" buffer-file-name)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   793
    (revert-buffer t t t)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   794
    (hg-restore-context ctx)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   795
    (hg-mode-line)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   796
    (message "Reverting %s...done" buffer-file-name)))
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   797
995
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   798
(defun hg-revert-buffer ()
996
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   799
  "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
   800
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
   801
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
   802
  (interactive)
995
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   803
  (let ((vc-suppress-confirm nil)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   804
	(obuf (current-buffer))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   805
	diff)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   806
    (vc-buffer-sync)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   807
    (unwind-protect
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   808
	(setq diff (hg-diff buffer-file-name))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   809
      (when diff
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   810
	(unless (yes-or-no-p "Discard changes? ")
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   811
	  (error "Revert cancelled")))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   812
      (when diff
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   813
	(let ((buf (current-buffer)))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   814
	  (delete-window (selected-window))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   815
	  (kill-buffer buf))))
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   816
    (set-buffer obuf)
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   817
    (when diff
1e4b009b379e Emacs support: add hg-revert-buffer.
Bryan O'Sullivan <bos@serpentine.com>
parents: 958
diff changeset
   818
      (hg-revert-buffer-internal))))
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   819
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   820
(defun hg-root (&optional path)
996
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   821
  "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
   822
If the path is outside a repository, return nil.
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   823
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
   824
prompts for a path to check."
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   825
  (interactive (list (hg-read-file-name)))
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   826
  (let ((root (do ((prev nil dir)
999
bb391518bc28 Emacs: first cut at commit support.
Bryan O'Sullivan <bos@serpentine.com>
parents: 996
diff changeset
   827
		   (dir (file-name-directory (or path buffer-file-name ""))
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   828
			(file-name-directory (directory-file-name dir))))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   829
		  ((equal prev dir))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   830
		(when (file-directory-p (concat dir ".hg"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   831
		  (return dir)))))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   832
    (when (interactive-p)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   833
      (if root
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   834
	  (message "The root of this repository is `%s'." root)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   835
	(message "The path `%s' is not in a Mercurial repository."
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   836
		 (abbreviate-file-name path t))))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   837
    root))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   838
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   839
(defun hg-status (path)
996
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   840
  "Print revision control status of a file or directory.
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   841
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
   842
Names are displayed relative to the repository root."
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   843
  (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
   844
  (let ((root (hg-root)))
996
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   845
    (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
   846
			     (let ((name (substring (expand-file-name path)
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   847
						    (length root))))
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   848
			       (if (> (length name) 0)
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   849
				   name
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   850
				 "*"))
5ed566574486 Emacs: document existing functions.
Bryan O'Sullivan <bos@serpentine.com>
parents: 995
diff changeset
   851
			     (hg-abbrev-file-name root)))
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   852
      (apply 'call-process (hg-binary) nil t nil
955
307ca8ca234f Remove -C alias for --cwd
mpm@selenic.com
parents: 948
diff changeset
   853
	     (list "--cwd" root "status" path)))))
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   854
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   855
(defun hg-undo ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   856
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   857
  (error "not implemented"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   858
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   859
(defun hg-version-other-window ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   860
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   861
  (error "not implemented"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   862
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   863

41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   864
(provide 'mercurial)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   865
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   866

41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   867
;;; Local Variables:
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   868
;;; prompt-to-byte-compile: nil
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   869
;;; end: