contrib/mercurial.el
author mpm@selenic.com
Fri, 19 Aug 2005 16:51:44 -0800
changeset 955 307ca8ca234f
parent 948 ffb0665028f0
child 958 d845a1f174bb
permissions -rw-r--r--
Remove -C alias for --cwd
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
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
    91
(defcustom hg-rev-completion-limit 100
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
    92
  "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
    93
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
    94
in a repository with a lot of history."
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
    95
  :type 'integer
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
    96
  :group 'mercurial)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
    97
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
    98
(defcustom hg-log-limit 50
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
    99
  "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
   100
  :type 'integer
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   101
  :group 'mercurial)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   102
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   103

41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   104
;;; Other variables.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   105
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   106
(defconst hg-running-xemacs (string-match "XEmacs" emacs-version)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   107
  "Is mercurial.el running under XEmacs?")
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   108
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   109
(defvar hg-mode nil
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   110
  "Is this file managed by Mercurial?")
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   111
(make-variable-buffer-local 'hg-mode)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   112
(put 'hg-mode 'permanent-local t)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   113
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   114
(defvar hg-status nil)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   115
(make-variable-buffer-local 'hg-status)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   116
(put 'hg-status 'permanent-local t)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   117
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   118
(defvar hg-output-buffer-name "*Hg*"
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   119
  "The name to use for Mercurial output buffers.")
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   120
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   121
(defvar hg-file-history nil)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   122
(defvar hg-rev-history nil)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   123
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
;;; hg-mode keymap.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   126
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   127
(defvar hg-prefix-map
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   128
  (let ((map (copy-keymap vc-prefix-map)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   129
    (set-keymap-name map 'hg-prefix-map)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   130
    map)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   131
  "This keymap overrides some default vc-mode bindings.")
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   132
(fset 'hg-prefix-map hg-prefix-map)
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   133
(define-key hg-prefix-map "=" 'hg-diff)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   134
(define-key hg-prefix-map "c" 'hg-undo)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   135
(define-key hg-prefix-map "g" 'hg-annotate)
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   136
(define-key hg-prefix-map "l" 'hg-log)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   137
(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
   138
;; (define-key hg-prefix-map "r" 'hg-update)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   139
(define-key hg-prefix-map "u" 'hg-revert-file)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   140
(define-key hg-prefix-map "~" 'hg-version-other-window)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   141
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   142
(defvar hg-mode-map (make-sparse-keymap))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   143
(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
   144
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   145
(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
   146
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   147

41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   148
;;; Global keymap.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   149
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   150
(global-set-key "\C-xvi" 'hg-add)
944
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-global-map (make-sparse-keymap))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   153
(fset 'hg-global-map hg-global-map)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   154
(global-set-key hg-global-prefix 'hg-global-map)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   155
(define-key hg-global-map "," 'hg-incoming)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   156
(define-key hg-global-map "." 'hg-outgoing)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   157
(define-key hg-global-map "<" 'hg-pull)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   158
(define-key hg-global-map "=" 'hg-diff)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   159
(define-key hg-global-map ">" 'hg-push)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   160
(define-key hg-global-map "?" 'hg-help-overview)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   161
(define-key hg-global-map "A" 'hg-addremove)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   162
(define-key hg-global-map "U" 'hg-revert)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   163
(define-key hg-global-map "a" 'hg-add)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   164
(define-key hg-global-map "c" 'hg-commit)
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   165
(define-key hg-global-map "f" 'hg-forget)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   166
(define-key hg-global-map "h" 'hg-help-overview)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   167
(define-key hg-global-map "i" 'hg-init)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   168
(define-key hg-global-map "l" 'hg-log)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   169
(define-key hg-global-map "r" 'hg-root)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   170
(define-key hg-global-map "s" 'hg-status)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   171
(define-key hg-global-map "u" 'hg-update)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   172
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
;;; View mode keymap.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   175
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   176
(defvar hg-view-mode-map
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   177
  (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
   178
			      view-minor-mode-map
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   179
			    view-mode-map))))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   180
    (set-keymap-name map 'hg-view-mode-map)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   181
    map))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   182
(fset 'hg-view-mode-map hg-view-mode-map)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   183
(define-key hg-view-mode-map
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   184
  (if hg-running-xemacs [button2] [mouse-2])
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   185
  'hg-buffer-mouse-clicked)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   186
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   187

41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   188
;;; Convenience functions.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   189
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   190
(defun hg-binary ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   191
  (if hg-binary
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   192
      hg-binary
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   193
    (error "No `hg' executable found!")))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   194
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   195
(defun hg-replace-in-string (str regexp newtext &optional literal)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   196
  "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
   197
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
   198
replacement.
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
This function bridges yet another pointless impedance gap between
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   201
XEmacs and GNU Emacs."
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   202
  (if (fboundp 'replace-in-string)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   203
      (replace-in-string str regexp newtext literal)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   204
    (replace-regexp-in-string regexp newtext str nil literal)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   205
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   206
(defun hg-chomp (str)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   207
  "Strip trailing newlines from a string."
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   208
  (hg-replace-in-string str "[\r\n]+$" ""))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   209
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   210
(defun hg-run-command (command &rest args)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   211
  "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
   212
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
   213
  (let* (exit-code
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   214
	 (output
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   215
	  (with-output-to-string
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   216
	    (with-current-buffer
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   217
		standard-output
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   218
	      (setq exit-code
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   219
		    (apply 'call-process command nil t nil args))))))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   220
    (cons exit-code output)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   221
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   222
(defun hg-run (command &rest args)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   223
  "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
   224
  (apply 'hg-run-command (hg-binary) command args))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   225
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   226
(defun hg-run0 (command &rest args)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   227
  "Run the Mercurial command COMMAND, returning its output.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   228
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
   229
  (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
   230
    (if (not (eq (car res) 0))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   231
	(error "Mercurial command failed %s - exit code %s"
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   232
	       (cons command args)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   233
	       (car res))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   234
      (cdr res))))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   235
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   236
(defun hg-buffer-commands (pnt)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   237
  "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
   238
  (interactive "d")
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   239
  (let ((rev (get-char-property pnt 'rev))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   240
	(file (get-char-property pnt 'file))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   241
	(date (get-char-property pnt 'date))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   242
	(user (get-char-property pnt 'user))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   243
	(host (get-char-property pnt 'host))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   244
	(prev-buf (current-buffer)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   245
    (cond
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   246
     (file
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   247
      (find-file-other-window file))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   248
     (rev
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   249
      (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
   250
     ((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
   251
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   252
(defun hg-buffer-mouse-clicked (event)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   253
  "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
   254
These are then handed off to `hg-buffer-commands'.
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
Handle frickin' frackin' gratuitous event-related incompatibilities."
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   257
  (interactive "e")
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   258
  (if hg-running-xemacs
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   259
      (progn
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   260
	(select-window (event-window event))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   261
	(hg-buffer-commands (event-point event)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   262
    (select-window (posn-window (event-end event)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   263
    (hg-buffer-commands (posn-point (event-start event)))))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   264
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   265
(unless (fboundp 'view-minor-mode)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   266
  (defun view-minor-mode (prev-buffer exit-func)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   267
    (view-mode)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   268
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   269
(defun hg-abbrev-file-name (file)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   270
  (if hg-running-xemacs
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   271
      (abbreviate-file-name file t)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   272
    (abbreviate-file-name file)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   273
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   274
(defun hg-read-file-name (&optional prompt default)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   275
  "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
   276
  (let ((path (or default (buffer-file-name))))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   277
    (if (or (not path) current-prefix-arg)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   278
	(expand-file-name
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   279
	 (read-file-name (format "File, directory or pattern%s: "
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   280
				 (or prompt ""))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   281
			 (and path (file-name-directory path))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   282
			 nil nil
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   283
			 (and path (file-name-nondirectory path))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   284
			 'hg-file-history))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   285
      path)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   286
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   287
(defun hg-read-rev (&optional prompt default)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   288
  "Read a revision or tag, offering completions."
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   289
  (let ((rev (or default "tip")))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   290
    (if (or (not rev) current-prefix-arg)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   291
	(let ((revs (split-string (hg-chomp
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   292
				   (hg-run0 "-q" "log" "-r"
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   293
					    (format "-%d"
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   294
						    hg-rev-completion-limit)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   295
					    "-r" "tip"))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   296
				  "[\n:]")))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   297
	  (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
   298
	    (setq revs (cons (car (split-string line "\\s-")) revs)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   299
	  (completing-read (format "Revision%s (%s): "
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   300
				   (or prompt "")
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   301
				   (or default "tip"))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   302
			   (map 'list 'cons revs revs)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   303
			   nil
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   304
			   nil
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   305
			   nil
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   306
			   'hg-rev-history
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   307
			   (or default "tip")))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   308
      rev)))
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   309

41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   310
;;; View mode bits.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   311
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   312
(defun hg-exit-view-mode (buf)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   313
  "Exit from hg-view-mode.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   314
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
   315
current frame."
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   316
  (when (and (eq buf (current-buffer))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   317
	     (> (length (window-list)) 1))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   318
    (delete-window))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   319
  (when (buffer-live-p buf)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   320
    (kill-buffer buf)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   321
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   322
(defun hg-view-mode (prev-buffer &optional file-name)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   323
  (goto-char (point-min))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   324
  (set-buffer-modified-p nil)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   325
  (toggle-read-only t)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   326
  (view-minor-mode prev-buffer 'hg-exit-view-mode)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   327
  (use-local-map hg-view-mode-map)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   328
  (setq truncate-lines t)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   329
  (when file-name
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   330
    (set (make-local-variable 'hg-view-file-name)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   331
	 (hg-abbrev-file-name file-name))))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   332
  
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   333
(defun hg-file-status (file)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   334
  "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
   335
  (let* ((s (hg-run "status" file))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   336
	 (exit (car s))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   337
	 (output (cdr s)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   338
    (if (= exit 0)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   339
	(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
   340
			    '(("M " . modified)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   341
			      ("A " . added)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   342
			      ("R " . removed)))))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   343
	  (if state
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   344
	      (cdr state)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   345
	    'normal)))))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   346
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   347
(defun hg-tip ()
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   348
  (split-string (hg-chomp (hg-run0 "-q" "tip")) ":"))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   349
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   350
(defmacro hg-view-output (args &rest body)
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   351
  "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
   352
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
   353
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
   354
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
   355
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
   356
being viewed."
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   357
  (let ((prev-buf (gensym "prev-buf-"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   358
	(v-b-name (car args))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   359
	(v-m-rest (cdr args)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   360
    `(let ((view-buf-name ,v-b-name)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   361
	   (,prev-buf (current-buffer)))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   362
       (get-buffer-create view-buf-name)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   363
       (kill-buffer view-buf-name)
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   364
       (get-buffer-create view-buf-name)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   365
       (set-buffer view-buf-name)
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   366
       (save-excursion
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   367
	 ,@body)
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   368
       (case (count-lines (point-min) (point-max))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   369
	 ((0)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   370
	  (kill-buffer view-buf-name)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   371
	  (message "(No output)"))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   372
	 ((1)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   373
	  (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
   374
	    (kill-buffer view-buf-name)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   375
	    (message "%s" msg)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   376
	 (t
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   377
	  (pop-to-buffer view-buf-name)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   378
	  (hg-view-mode ,prev-buf ,@v-m-rest))))))
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   379
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   380
(put 'hg-view-output 'lisp-indent-function 1)
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   381

4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   382
;;; Hooks.
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   383
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   384
(defun hg-mode-line ()
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   385
  (when (hg-root)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   386
    (let ((status (hg-file-status buffer-file-name)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   387
      (setq hg-status status
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   388
	    hg-mode (and status (concat " Hg:"
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   389
					(car (hg-tip))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   390
					(cdr (assq status
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   391
						   '((normal . "")
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   392
						     (removed . "r")
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   393
						     (added . "a")
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   394
						     (modified . "m")))))))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   395
      status)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   396
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   397
(defun hg-find-file-hook ()
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   398
  (when (hg-mode-line)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   399
    (run-hooks 'hg-mode-hook)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   400
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   401
(add-hook 'find-file-hooks 'hg-find-file-hook)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   402
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   403
(defun hg-after-save-hook ()
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   404
  (let ((old-status hg-status))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   405
    (hg-mode-line)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   406
    (if (and (not old-status) hg-status)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   407
	(run-hooks 'hg-mode-hook))))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   408
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   409
(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
   410
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   411

41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   412
;;; User interface functions.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   413
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   414
(defun hg-help-overview ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   415
  "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
   416
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   417
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
   418
code by typing `M-x find-library mercurial RET'.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   419
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   420
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
   421
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
   422
functions will generally work.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   423
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   424
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
   425
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
   426
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   427
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
   428
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
   429
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
   430
of Mercurial.  Many commands take a prefix argument.
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   431
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   432
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   433
SCM Task                              G/L  Key Binding  Command Name
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   434
--------                              ---  -----------  ------------
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   435
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
   436
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   437
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
   438
Commit changes to current file only   L    C-x v n      hg-commit
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   439
Undo changes to file since commit     L    C-x v u      hg-revert-file
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   440
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   441
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
   442
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   443
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
   444
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
   445
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   446
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
   447
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
   448
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
   449
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   450
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
   451
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
   452
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   453
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
   454
Pull changes                          G    C-c h <      hg-pull
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   455
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
   456
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
   457
Push changes                          G    C-c h >      hg-push"
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   458
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   459
  (hg-view-output ("Mercurial Help Overview")
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   460
    (insert (documentation 'hg-help-overview))))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   461
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   462
(defun hg-add (path)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   463
  (interactive (list (hg-read-file-name " to add")))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   464
  (let ((buf (current-buffer))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   465
	(update (equal buffer-file-name path)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   466
    (hg-view-output (hg-output-buffer-name)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   467
      (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
   468
    (when update
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   469
      (with-current-buffer buf
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   470
	(hg-mode-line)))))
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   471
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   472
(defun hg-addremove ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   473
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   474
  (error "not implemented"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   475
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   476
(defun hg-annotate ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   477
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   478
  (error "not implemented"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   479
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   480
(defun hg-commit ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   481
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   482
  (error "not implemented"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   483
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   484
(defun hg-diff (path &optional rev1 rev2)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   485
  (interactive (list (hg-read-file-name " to diff")
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   486
		     (hg-read-rev " to start with")
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   487
		     (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
   488
		       (and (not (eq rev2 'working-dir)) rev2))))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   489
  (let ((a-path (hg-abbrev-file-name path)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   490
    (hg-view-output ((if (equal rev1 rev2)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   491
			 (format "Mercurial: Rev %s of %s" rev1 a-path)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   492
		       (format "Mercurial: Rev %s to %s of %s"
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   493
			       rev1 (or rev2 "Current") a-path)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   494
      (if rev2
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   495
	  (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
   496
	(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
   497
      (diff-mode)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   498
      (font-lock-fontify-buffer))))
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   499
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   500
(defun hg-forget (path)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   501
  (interactive (list (hg-read-file-name " to forget")))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   502
  (let ((buf (current-buffer))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   503
	(update (equal buffer-file-name path)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   504
    (hg-view-output (hg-output-buffer-name)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   505
      (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
   506
    (when update
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   507
      (with-current-buffer buf
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   508
	(hg-mode-line)))))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   509
  
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   510
(defun hg-incoming ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   511
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   512
  (error "not implemented"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   513
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   514
(defun hg-init ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   515
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   516
  (error "not implemented"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   517
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   518
(defun hg-log (path &optional rev1 rev2)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   519
  (interactive (list (hg-read-file-name " to log")
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   520
		     (hg-read-rev " to start with" "-1")
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   521
		     (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
   522
  (message "log %s %s" rev1 rev2)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   523
  (sit-for 1)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   524
  (let ((a-path (hg-abbrev-file-name path)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   525
    (hg-view-output ((if (equal rev1 rev2)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   526
			 (format "Mercurial: Rev %s of %s" rev1 a-path)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   527
		       (format "Mercurial: Rev %s to %s of %s"
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   528
			       rev1 (or rev2 "Current") a-path)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   529
      (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
   530
      (diff-mode)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   531
      (font-lock-fontify-buffer))))
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   532
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   533
(defun hg-outgoing ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   534
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   535
  (error "not implemented"))
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
(defun hg-pull ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   538
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   539
  (error "not implemented"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   540
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   541
(defun hg-push ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   542
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   543
  (error "not implemented"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   544
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   545
(defun hg-revert ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   546
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   547
  (error "not implemented"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   548
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   549
(defun hg-revert-file ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   550
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   551
  (error "not implemented"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   552
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   553
(defun hg-root (&optional path)
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   554
  (interactive (list (hg-read-file-name)))
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   555
  (let ((root (do ((prev nil dir)
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   556
		   (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
   557
			(file-name-directory (directory-file-name dir))))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   558
		  ((equal prev dir))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   559
		(when (file-directory-p (concat dir ".hg"))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   560
		  (return dir)))))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   561
    (when (interactive-p)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   562
      (if root
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   563
	  (message "The root of this repository is `%s'." root)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   564
	(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
   565
		 (abbreviate-file-name path t))))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   566
    root))
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   567
947
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   568
(defun hg-status (path)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   569
  (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
   570
  (let ((root (hg-root)))
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   571
    (hg-view-output (hg-output-buffer-name)
4cabedfab66e In-progress Emacs snapshot.
Bryan O'Sullivan <bos@serpentine.com>
parents: 945
diff changeset
   572
      (apply 'call-process (hg-binary) nil t nil
955
307ca8ca234f Remove -C alias for --cwd
mpm@selenic.com
parents: 948
diff changeset
   573
	     (list "--cwd" root "status" path)))))
944
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   574
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   575
(defun hg-undo ()
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   576
  (interactive)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   577
  (error "not implemented"))
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-version-other-window ()
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

41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   584
(provide 'mercurial)
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   585
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   586

41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   587
;;; Local Variables:
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   588
;;; mode: emacs-lisp
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   589
;;; prompt-to-byte-compile: nil
41ca6bf19735 Initial skeleton for mercurial.el.
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   590
;;; end: