annotate contrib/mercurial.el @ 995:1e4b009b379e

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