annotate contrib/vim/hgcommand.vim @ 2592:457846f400e8

Vim script: Adaptation from CVS to Mercurial
author "Mathieu Clabaut <mathieu.clabaut@gmail.com>"
date Mon, 10 Jul 2006 23:45:16 +0200
parents 61f2008cd6bf
children f80057407c07
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1 " vim600: set foldmethod=marker:
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
2 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
3 " Vim plugin to assist in working with HG-controlled files.
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
4 "
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
5 " Last Change: 2006/02/22
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
6 " Version: 1.76
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
7 " Maintainer: Mathieu Clabaut <mathieu.clabaut@gmail.com>
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
8 " License: This file is placed in the public domain.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
9 " Credits: {{{1
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
10 " Bob Hiestand <bob.hiestand@gmail.com> for the fabulous
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
11 " cvscommand.vim from which this script was directly created by
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
12 " means of sed commands and minor tweaks.
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
13
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
14 " Section: Documentation {{{1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
15 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
16 " Provides functions to invoke various HG commands on the current file
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
17 " (either the current buffer, or, in the case of an directory buffer, the file
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
18 " on the current line). The output of the commands is captured in a new
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
19 " scratch window. For convenience, if the functions are invoked on a HG
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
20 " output window, the original file is used for the hg operation instead after
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
21 " the window is split. This is primarily useful when running HGCommit and
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
22 " you need to see the changes made, so that HGDiff is usable and shows up in
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
23 " another window.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
24 "
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
25 " Command documentation {{{2
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
26 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
27 " HGAdd Performs "hg add" on the current file.
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
28 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
29 " HGAnnotate Performs "hg annotate" on the current file. If an
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
30 " argument is given, the argument is used as a revision
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
31 " number to display. If not given an argument, it uses the
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
32 " most recent version of the file on the current branch.
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
33 " Additionally, if the current buffer is a HGAnnotate buffer
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
34 " already, the version number on the current line is used.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
35 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
36 " If the 'HGCommandAnnotateParent' variable is set to a
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
37 " non-zero value, the version previous to the one on the
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
38 " current line is used instead. This allows one to navigate
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
39 " back to examine the previous version of a line.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
40 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
41 " HGCommit[!] If called with arguments, this performs "hg commit" using
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
42 " the arguments as the log message.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
43 "
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
44 " If '!' is used, an empty log message is committed.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
45 "
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
46 " If called with no arguments, this is a two-step command.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
47 " The first step opens a buffer to accept a log message.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
48 " When that buffer is written, it is automatically closed and
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
49 " the file is committed using the information from that log
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
50 " message. The commit can be abandoned if the log message
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
51 " buffer is deleted or wiped before being written.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
52 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
53 " HGDiff With no arguments, this performs "hg diff" on the current
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
54 " file. With one argument, "hg diff" is performed on the
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
55 " current file against the specified revision. With two
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
56 " arguments, hg diff is performed between the specified
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
57 " revisions of the current file. This command uses the
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
58 " 'HGCommandDiffOpt' variable to specify diff options. If
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
59 " that variable does not exist, then 'wbBc' is assumed. If
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
60 " you wish to have no options, then set it to the empty
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
61 " string.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
62 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
63 " HGGotoOriginal Returns the current window to the source buffer if the
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
64 " current buffer is a HG output buffer.
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
65 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
66 " HGLog Performs "hg log" on the current file.
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
67 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
68 " HGRevert Replaces the modified version of the current file with the
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
69 " most recent version from the repository.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
70 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
71 " HGReview Retrieves a particular version of the current file. If no
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
72 " argument is given, the most recent version of the file on
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
73 " the current branch is retrieved. The specified revision is
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
74 " retrieved into a new buffer.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
75 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
76 " HGStatus Performs "hg status" on the current file.
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
77 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
78 " HGUpdate Performs "hg update" on the current file.
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
79 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
80 " HGVimDiff With no arguments, this prompts the user for a revision and
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
81 " then uses vimdiff to display the differences between the
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
82 " current file and the specified revision. If no revision is
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
83 " specified, the most recent version of the file on the
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
84 " current branch is used. With one argument, that argument
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
85 " is used as the revision as above. With two arguments, the
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
86 " differences between the two revisions is displayed using
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
87 " vimdiff.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
88 "
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
89 " With either zero or one argument, the original buffer is used
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
90 " to perform the vimdiff. When the other buffer is closed, the
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
91 " original buffer will be returned to normal mode.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
92 "
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
93 " Once vimdiff mode is started using the above methods,
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
94 " additional vimdiff buffers may be added by passing a single
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
95 " version argument to the command. There may be up to 4
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
96 " vimdiff buffers total.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
97 "
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
98 " Using the 2-argument form of the command resets the vimdiff
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
99 " to only those 2 versions. Additionally, invoking the
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
100 " command on a different file will close the previous vimdiff
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
101 " buffers.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
102 "
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
103 "
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
104 " Mapping documentation: {{{2
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
105 "
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
106 " By default, a mapping is defined for each command. User-provided mappings
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
107 " can be used instead by mapping to <Plug>CommandName, for instance:
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
108 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
109 " nnoremap ,ca <Plug>HGAdd
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
110 "
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
111 " The default mappings are as follow:
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
112 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
113 " <Leader>hga HGAdd
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
114 " <Leader>hgn HGAnnotate
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
115 " <Leader>hgc HGCommit
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
116 " <Leader>hgd HGDiff
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
117 " <Leader>hgg HGGotoOriginal
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
118 " <Leader>hgG HGGotoOriginal!
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
119 " <Leader>hgl HGLog
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
120 " <Leader>hgr HGReview
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
121 " <Leader>hgs HGStatus
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
122 " <Leader>hgu HGUpdate
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
123 " <Leader>hgv HGVimDiff
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
124 "
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
125 " Options documentation: {{{2
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
126 "
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
127 " Several variables are checked by the script to determine behavior as follow:
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
128 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
129 " HGCommandAnnotateParent
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
130 " This variable, if set to a non-zero value, causes the zero-argument form
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
131 " of HGAnnotate when invoked on a HGAnnotate buffer to go to the version
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
132 " previous to that displayed on the current line. If not set, it defaults
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
133 " to 0.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
134 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
135 " HGCommandCommitOnWrite
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
136 " This variable, if set to a non-zero value, causes the pending hg commit
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
137 " to take place immediately as soon as the log message buffer is written.
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
138 " If set to zero, only the HGCommit mapping will cause the pending commit
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
139 " to occur. If not set, it defaults to 1.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
140 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
141 " HGCommandDeleteOnHide
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
142 " This variable, if set to a non-zero value, causes the temporary HG result
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
143 " buffers to automatically delete themselves when hidden.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
144 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
145 " HGCommandDiffOpt
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
146 " This variable, if set, determines the options passed to the diff command
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
147 " of HG. If not set, it defaults to 'wbBc'.
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
148 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
149 " HGCommandDiffSplit
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
150 " This variable overrides the HGCommandSplit variable, but only for buffers
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
151 " created with HGVimDiff.
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
152 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
153 " HGCommandEdit
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
154 " This variable controls whether the original buffer is replaced ('edit') or
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
155 " split ('split'). If not set, it defaults to 'edit'.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
156 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
157 " HGCommandEnableBufferSetup
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
158 " This variable, if set to a non-zero value, activates HG buffer management
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
159 " mode. This mode means that two buffer variables, 'HGRevision' and
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
160 " 'HGBranch', are set if the file is HG-controlled. This is useful for
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
161 " displaying version information in the status bar.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
162 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
163 " HGCommandInteractive
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
164 " This variable, if set to a non-zero value, causes appropriate functions (for
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
165 " the moment, only HGReview) to query the user for a revision to use
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
166 " instead of the current revision if none is specified.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
167 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
168 " HGCommandNameMarker
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
169 " This variable, if set, configures the special attention-getting characters
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
170 " that appear on either side of the hg buffer type in the buffer name.
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
171 " This has no effect unless 'HGCommandNameResultBuffers' is set to a true
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
172 " value. If not set, it defaults to '_'.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
173 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
174 " HGCommandNameResultBuffers
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
175 " This variable, if set to a true value, causes the hg result buffers to be
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
176 " named in the old way ('<source file name> _<hg command>_'). If not set
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
177 " or set to a false value, the result buffer is nameless.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
178 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
179 " HGCommandSplit
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
180 " This variable controls the orientation of the various window splits that
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
181 " may occur (such as with HGVimDiff, when using a HG command on a HG
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
182 " command buffer, or when the 'HGCommandEdit' variable is set to 'split'.
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
183 " If set to 'horizontal', the resulting windows will be on stacked on top of
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
184 " one another. If set to 'vertical', the resulting windows will be
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
185 " side-by-side. If not set, it defaults to 'horizontal' for all but
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
186 " HGVimDiff windows.
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
187 "
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
188 " Event documentation {{{2
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
189 " For additional customization, hgcommand.vim uses User event autocommand
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
190 " hooks. Each event is in the HGCommand group, and different patterns
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
191 " match the various hooks.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
192 "
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
193 " For instance, the following could be added to the vimrc to provide a 'q'
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
194 " mapping to quit a HG buffer:
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
195 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
196 " augroup HGCommand
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
197 " au HGCommand User HGBufferCreated silent! nmap <unique> <buffer> q :bwipeout<cr>
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
198 " augroup END
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
199 "
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
200 " The following hooks are available:
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
201 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
202 " HGBufferCreated This event is fired just after a hg command
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
203 " result buffer is created and filled with the
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
204 " result of a hg command. It is executed within
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
205 " the context of the new buffer.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
206 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
207 " HGBufferSetup This event is fired just after HG buffer setup
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
208 " occurs, if enabled.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
209 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
210 " HGPluginInit This event is fired when the HGCommand plugin
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
211 " first loads.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
212 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
213 " HGPluginFinish This event is fired just after the HGCommand
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
214 " plugin loads.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
215 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
216 " HGVimDiffFinish This event is fired just after the HGVimDiff
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
217 " command executes to allow customization of,
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
218 " for instance, window placement and focus.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
219 "
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
220 " Section: Plugin header {{{1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
221
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
222 " loaded_hgcommand is set to 1 when the initialization begins, and 2 when it
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
223 " completes. This allows various actions to only be taken by functions after
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
224 " system initialization.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
225
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
226 if exists("loaded_hgcommand")
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
227 finish
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
228 endif
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
229 let loaded_hgcommand = 1
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
230
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
231 if v:version < 602
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
232 echohl WarningMsg|echomsg "HGCommand 1.69 or later requires VIM 6.2 or later"|echohl None
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
233 finish
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
234 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
235
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
236 " Section: Event group setup {{{1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
237
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
238 augroup HGCommand
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
239 augroup END
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
240
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
241 " Section: Plugin initialization {{{1
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
242 silent do HGCommand User HGPluginInit
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
243
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
244 " Section: Script variable initialization {{{1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
245
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
246 let s:HGCommandEditFileRunning = 0
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
247 unlet! s:vimDiffRestoreCmd
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
248 unlet! s:vimDiffSourceBuffer
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
249 unlet! s:vimDiffBufferCount
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
250 unlet! s:vimDiffScratchList
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
251
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
252 " Section: Utility functions {{{1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
253
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
254 " Function: s:HGResolveLink() {{{2
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
255 " Fully resolve the given file name to remove shortcuts or symbolic links.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
256
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
257 function! s:HGResolveLink(fileName)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
258 let resolved = resolve(a:fileName)
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
259 if resolved != a:fileName
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
260 let resolved = s:HGResolveLink(resolved)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
261 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
262 return resolved
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
263 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
264
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
265 " Function: s:HGChangeToCurrentFileDir() {{{2
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
266 " Go to the directory in which the current HG-controlled file is located.
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
267 " If this is a HG command buffer, first switch to the original file.
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
268
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
269 function! s:HGChangeToCurrentFileDir(fileName)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
270 let oldCwd=getcwd()
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
271 let fileName=s:HGResolveLink(a:fileName)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
272 let newCwd=fnamemodify(fileName, ':h')
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
273 if strlen(newCwd) > 0
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
274 execute 'cd' escape(newCwd, ' ')
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
275 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
276 return oldCwd
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
277 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
278
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
279 " Function: s:HGGetOption(name, default) {{{2
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
280 " Grab a user-specified option to override the default provided. Options are
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
281 " searched in the window, buffer, then global spaces.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
282
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
283 function! s:HGGetOption(name, default)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
284 if exists("s:" . a:name . "Override")
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
285 execute "return s:".a:name."Override"
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
286 elseif exists("w:" . a:name)
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
287 execute "return w:".a:name
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
288 elseif exists("b:" . a:name)
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
289 execute "return b:".a:name
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
290 elseif exists("g:" . a:name)
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
291 execute "return g:".a:name
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
292 else
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
293 return a:default
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
294 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
295 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
296
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
297 " Function: s:HGEditFile(name, origBuffNR) {{{2
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
298 " Wrapper around the 'edit' command to provide some helpful error text if the
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
299 " current buffer can't be abandoned. If name is provided, it is used;
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
300 " otherwise, a nameless scratch buffer is used.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
301 " Returns: 0 if successful, -1 if an error occurs.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
302
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
303 function! s:HGEditFile(name, origBuffNR)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
304 "Name parameter will be pasted into expression.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
305 let name = escape(a:name, ' *?\')
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
306
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
307 let editCommand = s:HGGetOption('HGCommandEdit', 'edit')
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
308 if editCommand != 'edit'
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
309 if s:HGGetOption('HGCommandSplit', 'horizontal') == 'horizontal'
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
310 if name == ""
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
311 let editCommand = 'rightbelow new'
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
312 else
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
313 let editCommand = 'rightbelow split ' . name
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
314 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
315 else
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
316 if name == ""
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
317 let editCommand = 'vert rightbelow new'
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
318 else
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
319 let editCommand = 'vert rightbelow split ' . name
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
320 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
321 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
322 else
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
323 if name == ""
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
324 let editCommand = 'enew'
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
325 else
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
326 let editCommand = 'edit ' . name
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
327 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
328 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
329
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
330 " Protect against useless buffer set-up
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
331 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning + 1
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
332 try
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
333 execute editCommand
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
334 finally
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
335 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning - 1
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
336 endtry
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
337
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
338 let b:HGOrigBuffNR=a:origBuffNR
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
339 let b:HGCommandEdit='split'
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
340 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
341
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
342 " Function: s:HGCreateCommandBuffer(cmd, cmdName, statusText, filename) {{{2
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
343 " Creates a new scratch buffer and captures the output from execution of the
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
344 " given command. The name of the scratch buffer is returned.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
345
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
346 function! s:HGCreateCommandBuffer(cmd, cmdName, statusText, origBuffNR)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
347 let fileName=bufname(a:origBuffNR)
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
348
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
349 let resultBufferName=''
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
350
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
351 if s:HGGetOption("HGCommandNameResultBuffers", 0)
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
352 let nameMarker = s:HGGetOption("HGCommandNameMarker", '_')
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
353 if strlen(a:statusText) > 0
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
354 let bufName=a:cmdName . ' -- ' . a:statusText
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
355 else
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
356 let bufName=a:cmdName
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
357 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
358 let bufName=fileName . ' ' . nameMarker . bufName . nameMarker
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
359 let counter=0
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
360 let resultBufferName = bufName
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
361 while buflisted(resultBufferName)
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
362 let counter=counter + 1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
363 let resultBufferName=bufName . ' (' . counter . ')'
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
364 endwhile
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
365 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
366
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
367 let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " " . a:cmd
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
368 echomsg "DBG :".hgCommand
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
369 let hgOut = system(hgCommand)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
370 " HACK: diff command does not return proper error codes
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
371 if v:shell_error && a:cmdName != 'hgdiff'
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
372 if strlen(hgOut) == 0
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
373 echoerr "HG command failed"
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
374 else
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
375 echoerr "HG command failed: " . hgOut
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
376 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
377 return -1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
378 endif
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
379 if strlen(hgOut) == 0
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
380 " Handle case of no output. In this case, it is important to check the
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
381 " file status, especially since hg edit/unedit may change the attributes
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
382 " of the file with no visible output.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
383
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
384 echomsg "No output from HG command"
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
385 checktime
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
386 return -1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
387 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
388
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
389 if s:HGEditFile(resultBufferName, a:origBuffNR) == -1
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
390 return -1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
391 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
392
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
393 set buftype=nofile
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
394 set noswapfile
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
395 set filetype=
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
396
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
397 if s:HGGetOption("HGCommandDeleteOnHide", 0)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
398 set bufhidden=delete
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
399 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
400
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
401 silent 0put=hgOut
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
402
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
403 " The last command left a blank line at the end of the buffer. If the
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
404 " last line is folded (a side effect of the 'put') then the attempt to
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
405 " remove the blank line will kill the last fold.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
406 "
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
407 " This could be fixed by explicitly detecting whether the last line is
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
408 " within a fold, but I prefer to simply unfold the result buffer altogether.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
409
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
410 if has('folding')
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
411 normal zR
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
412 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
413
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
414 $d
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
415 1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
416
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
417 " Define the environment and execute user-defined hooks.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
418
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
419 let b:HGSourceFile=fileName
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
420 let b:HGCommand=a:cmdName
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
421 if a:statusText != ""
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
422 let b:HGStatusText=a:statusText
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
423 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
424
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
425 silent do HGCommand User HGBufferCreated
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
426 return bufnr("%")
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
427 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
428
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
429 " Function: s:HGBufferCheck(hgBuffer) {{{2
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
430 " Attempts to locate the original file to which HG operations were applied
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
431 " for a given buffer.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
432
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
433 function! s:HGBufferCheck(hgBuffer)
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
434 let origBuffer = getbufvar(a:hgBuffer, "HGOrigBuffNR")
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
435 if origBuffer
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
436 if bufexists(origBuffer)
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
437 return origBuffer
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
438 else
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
439 " Original buffer no longer exists.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
440 return -1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
441 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
442 else
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
443 " No original buffer
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
444 return a:hgBuffer
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
445 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
446 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
447
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
448 " Function: s:HGCurrentBufferCheck() {{{2
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
449 " Attempts to locate the original file to which HG operations were applied
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
450 " for the current buffer.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
451
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
452 function! s:HGCurrentBufferCheck()
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
453 return s:HGBufferCheck(bufnr("%"))
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
454 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
455
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
456 " Function: s:HGToggleDeleteOnHide() {{{2
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
457 " Toggles on and off the delete-on-hide behavior of HG buffers
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
458
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
459 function! s:HGToggleDeleteOnHide()
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
460 if exists("g:HGCommandDeleteOnHide")
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
461 unlet g:HGCommandDeleteOnHide
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
462 else
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
463 let g:HGCommandDeleteOnHide=1
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
464 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
465 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
466
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
467 " Function: s:HGDoCommand(hgcmd, cmdName, statusText) {{{2
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
468 " General skeleton for HG function execution.
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
469 " Returns: name of the new command buffer containing the command results
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
470
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
471 function! s:HGDoCommand(cmd, cmdName, statusText)
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
472 let hgBufferCheck=s:HGCurrentBufferCheck()
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
473 if hgBufferCheck == -1
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
474 echo "Original buffer no longer exists, aborting."
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
475 return -1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
476 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
477
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
478 let fileName=bufname(hgBufferCheck)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
479 if isdirectory(fileName)
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
480 let fileName=fileName . "/" . getline(".")
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
481 endif
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
482 let realFileName = fnamemodify(s:HGResolveLink(fileName), ':t')
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
483 let oldCwd=s:HGChangeToCurrentFileDir(fileName)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
484 try
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
485 " TODO
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
486 "if !filereadable('HG/Root')
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
487 "throw fileName . ' is not a HG-controlled file.'
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
488 "endif
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
489 let fullCmd = a:cmd . ' "' . realFileName . '"'
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
490 "echomsg "DEBUG".fullCmd
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
491 let resultBuffer=s:HGCreateCommandBuffer(fullCmd, a:cmdName, a:statusText, hgBufferCheck)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
492 return resultBuffer
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
493 catch
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
494 echoerr v:exception
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
495 return -1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
496 finally
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
497 execute 'cd' escape(oldCwd, ' ')
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
498 endtry
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
499 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
500
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
501
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
502 " Function: s:HGGetStatusVars(revision, branch, repository) {{{2
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
503 "
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
504 " Obtains a HG revision number and branch name. The 'revisionVar',
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
505 " 'branchVar'and 'repositoryVar' arguments, if non-empty, contain the names of variables to hold
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
506 " the corresponding results.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
507 "
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
508 " Returns: string to be exec'd that sets the multiple return values.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
509
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
510 function! s:HGGetStatusVars(revisionVar, branchVar, repositoryVar)
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
511 let hgBufferCheck=s:HGCurrentBufferCheck()
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
512 if hgBufferCheck == -1
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
513 return ""
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
514 endif
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
515 let fileName=bufname(hgBufferCheck)
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
516 let realFileName = fnamemodify(s:HGResolveLink(fileName), ':t')
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
517 let oldCwd=s:HGChangeToCurrentFileDir(fileName)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
518 try
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
519 ""TODO
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
520 "if !filereadable('HG/Root')
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
521 "return ""
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
522 "endif
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
523 let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " status -mardui " . fileName
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
524 let statustext=system(hgCommand)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
525 if(v:shell_error)
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
526 return ""
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
527 endif
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
528 if match(statustext, '^[?I]') >= 0
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
529 let revision="NEW"
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
530 elseif match(statustext, '^[R]') >= 0
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
531 let revision="REMOVED"
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
532 elseif match(statustext, '^[D]') >= 0
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
533 let revision="DELETED"
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
534 elseif match(statustext, '^[A]') >= 0
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
535 let revision="ADDED"
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
536 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
537
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
538 let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " parents -b "
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
539 let statustext=system(hgCommand)
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
540 if(v:shell_error)
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
541 return ""
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
542 endif
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
543 if exists('revision')
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
544 let returnExpression = "let " . a:revisionVar . "='" . revision . "'"
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
545 else
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
546 let revision=substitute(statustext, '^changeset:\s*\(\d\+\):.*\_$\_.*$', '\1', "")
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
547 let returnExpression = "let " . a:revisionVar . "='" . revision . "'"
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
548 endif
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
549
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
550 if a:branchVar != "" && match(statustext, '^\_.*\_^branch:') >= 0
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
551 let branch=substitute(statustext, '^\_.*\_^branch:\s*\(\S\+\)\n\_.*$', '\1', "")
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
552 let returnExpression=returnExpression . " | let " . a:branchVar . "='" . branch . "'"
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
553 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
554 if a:repositoryVar != ""
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
555 let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " root "
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
556 let roottext=system(hgCommand)
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
557 let repository=substitute(roottext,'^.*/\([^/\n\r]*\)\n\_.*$','\1','')
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
558 let returnExpression=returnExpression . " | let " . a:repositoryVar . "='" . repository . "'"
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
559 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
560
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
561
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
562
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
563 return returnExpression
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
564 finally
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
565 execute 'cd' escape(oldCwd, ' ')
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
566 endtry
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
567 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
568
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
569 " Function: s:HGSetupBuffer() {{{2
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
570 " Attempts to set the b:HGBranch, b:HGRevision and b:HGRepository variables.
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
571
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
572 function! s:HGSetupBuffer()
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
573 if (exists("b:HGBufferSetup") && b:HGBufferSetup)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
574 " This buffer is already set up.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
575 return
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
576 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
577
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
578 if !s:HGGetOption("HGCommandEnableBufferSetup", 0)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
579 \ || @% == ""
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
580 \ || s:HGCommandEditFileRunning > 0
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
581 \ || exists("b:HGOrigBuffNR")
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
582 unlet! b:HGRevision
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
583 unlet! b:HGBranch
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
584 unlet! b:HGRepository
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
585 return
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
586 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
587
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
588 if !filereadable(expand("%"))
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
589 return -1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
590 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
592 let revision=""
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
593 let branch=""
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
594 let repository=""
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
595
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
596 exec s:HGGetStatusVars('revision', 'branch', 'repository')
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
597 "echomsg "DBG ".revision."#".branch."#".repository
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
598 if revision != ""
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
599 let b:HGRevision=revision
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
600 else
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
601 unlet! b:HGRevision
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
602 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
603 if branch != ""
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
604 let b:HGBranch=branch
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
605 else
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
606 unlet! b:HGBranch
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
607 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
608 if repository != ""
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
609 let b:HGRepository=repository
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
610 else
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
611 unlet! b:HGRepository
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
612 endif
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
613 silent do HGCommand User HGBufferSetup
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
614 let b:HGBufferSetup=1
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
615 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
616
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
617 " Function: s:HGMarkOrigBufferForSetup(hgbuffer) {{{2
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
618 " Resets the buffer setup state of the original buffer for a given HG buffer.
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
619 " Returns: The HG buffer number in a passthrough mode.
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
620
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
621 function! s:HGMarkOrigBufferForSetup(hgBuffer)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
622 checktime
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
623 if a:hgBuffer != -1
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
624 let origBuffer = s:HGBufferCheck(a:hgBuffer)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
625 "This should never not work, but I'm paranoid
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
626 if origBuffer != a:hgBuffer
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
627 call setbufvar(origBuffer, "HGBufferSetup", 0)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
628 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
629 endif
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
630 return a:hgBuffer
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
631 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
632
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
633 " Function: s:HGOverrideOption(option, [value]) {{{2
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
634 " Provides a temporary override for the given HG option. If no value is
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
635 " passed, the override is disabled.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
636
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
637 function! s:HGOverrideOption(option, ...)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
638 if a:0 == 0
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
639 unlet! s:{a:option}Override
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
640 else
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
641 let s:{a:option}Override = a:1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
642 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
643 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
644
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
645 " Function: s:HGWipeoutCommandBuffers() {{{2
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
646 " Clears all current HG buffers of the specified type for a given source.
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
647
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
648 function! s:HGWipeoutCommandBuffers(originalBuffer, hgCommand)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
649 let buffer = 1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
650 while buffer <= bufnr('$')
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
651 if getbufvar(buffer, 'HGOrigBuffNR') == a:originalBuffer
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
652 if getbufvar(buffer, 'HGCommand') == a:hgCommand
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
653 execute 'bw' buffer
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
654 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
655 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
656 let buffer = buffer + 1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
657 endwhile
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
658 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
659
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
660 " Section: Public functions {{{1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
661
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
662 " Function: HGGetRevision() {{{2
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
663 " Global function for retrieving the current buffer's HG revision number.
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
664 " Returns: Revision number or an empty string if an error occurs.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
665
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
666 function! HGGetRevision()
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
667 let revision=""
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
668 exec s:HGGetStatusVars('revision', '', '')
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
669 return revision
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
670 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
671
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
672 " Function: HGDisableBufferSetup() {{{2
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
673 " Global function for deactivating the buffer autovariables.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
674
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
675 function! HGDisableBufferSetup()
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
676 let g:HGCommandEnableBufferSetup=0
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
677 silent! augroup! HGCommandPlugin
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
678 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
679
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
680 " Function: HGEnableBufferSetup() {{{2
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
681 " Global function for activating the buffer autovariables.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
682
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
683 function! HGEnableBufferSetup()
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
684 let g:HGCommandEnableBufferSetup=1
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
685 augroup HGCommandPlugin
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
686 au!
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
687 au BufEnter * call s:HGSetupBuffer()
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
688 augroup END
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
689
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
690 " Only auto-load if the plugin is fully loaded. This gives other plugins a
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
691 " chance to run.
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
692 if g:loaded_hgcommand == 2
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
693 call s:HGSetupBuffer()
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
694 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
695 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
696
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
697 " Function: HGGetStatusLine() {{{2
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
698 " Default (sample) status line entry for HG files. This is only useful if
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
699 " HG-managed buffer mode is on (see the HGCommandEnableBufferSetup variable
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
700 " for how to do this).
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
701
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
702 function! HGGetStatusLine()
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
703 if exists('b:HGSourceFile')
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
704 " This is a result buffer
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
705 let value='[' . b:HGCommand . ' ' . b:HGSourceFile
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
706 if exists('b:HGStatusText')
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
707 let value=value . ' ' . b:HGStatusText
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
708 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
709 let value = value . ']'
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
710 return value
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
711 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
712
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
713 if exists('b:HGRevision')
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
714 \ && b:HGRevision != ''
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
715 \ && exists('b:HGBranch')
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
716 \ && b:HGBranch != ''
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
717 \ && exists('b:HGRepository')
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
718 \ && b:HGRepository != ''
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
719 \ && exists('g:HGCommandEnableBufferSetup')
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
720 \ && g:HGCommandEnableBufferSetup
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
721 return '[HG ' . b:HGRepository . '/' . b:HGBranch .'/' . b:HGRevision . ']'
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
722 else
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
723 return ''
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
724 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
725 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
726
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
727 " Section: HG command functions {{{1
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
728
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
729 " Function: s:HGAdd() {{{2
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
730 function! s:HGAdd()
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
731 return s:HGMarkOrigBufferForSetup(s:HGDoCommand('add', 'hgadd', ''))
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
732 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
733
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
734 " Function: s:HGAnnotate(...) {{{2
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
735 function! s:HGAnnotate(...)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
736 if a:0 == 0
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
737 if &filetype == "HGAnnotate"
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
738 " This is a HGAnnotate buffer. Perform annotation of the version
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
739 " indicated by the current line.
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
740 let revision = substitute(getline("."),'\(^[0-9]*\):.*','\1','')
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
741 if s:HGGetOption('HGCommandAnnotateParent', 0) != 0 && revision > 0
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
742 let revision = revision - 1
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
743 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
744 else
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
745 let revision=HGGetRevision()
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
746 if revision == ""
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
747 echoerr "Unable to obtain HG version information."
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
748 return -1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
749 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
750 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
751 else
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
752 let revision=a:1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
753 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
754
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
755 if revision == "NEW"
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
756 echo "No annotatation available for new file."
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
757 return -1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
758 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
759
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
760 let resultBuffer=s:HGDoCommand('annotate -ndu -r ' . revision, 'hgannotate', revision)
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
761 echomsg "DBG: ".resultBuffer
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
762 if resultBuffer != -1
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
763 set filetype=HGAnnotate
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
764 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
765
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
766 return resultBuffer
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
767 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
768
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
769 " Function: s:HGCommit() {{{2
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
770 function! s:HGCommit(...)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
771 " Handle the commit message being specified. If a message is supplied, it
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
772 " is used; if bang is supplied, an empty message is used; otherwise, the
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
773 " user is provided a buffer from which to edit the commit message.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
774 if a:2 != "" || a:1 == "!"
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
775 return s:HGMarkOrigBufferForSetup(s:HGDoCommand('commit -m "' . a:2 . '"', 'hgcommit', ''))
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
776 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
777
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
778 let hgBufferCheck=s:HGCurrentBufferCheck()
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
779 if hgBufferCheck == -1
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
780 echo "Original buffer no longer exists, aborting."
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
781 return -1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
782 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
783
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
784 " Protect against windows' backslashes in paths. They confuse exec'd
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
785 " commands.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
786
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
787 let shellSlashBak = &shellslash
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
788 try
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
789 set shellslash
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
790
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
791 let messageFileName = tempname()
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
792
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
793 let fileName=bufname(hgBufferCheck)
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
794 let realFilePath=s:HGResolveLink(fileName)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
795 let newCwd=fnamemodify(realFilePath, ':h')
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
796 if strlen(newCwd) == 0
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
797 " Account for autochdir being in effect, which will make this blank, but
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
798 " we know we'll be in the current directory for the original file.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
799 let newCwd = getcwd()
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
800 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
801
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
802 let realFileName=fnamemodify(realFilePath, ':t')
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
803
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
804 if s:HGEditFile(messageFileName, hgBufferCheck) == -1
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
805 return
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
806 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
807
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
808 " Protect against case and backslash issues in Windows.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
809 let autoPattern = '\c' . messageFileName
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
810
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
811 " Ensure existance of group
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
812 augroup HGCommit
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
813 augroup END
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
814
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
815 execute 'au HGCommit BufDelete' autoPattern 'call delete("' . messageFileName . '")'
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
816 execute 'au HGCommit BufDelete' autoPattern 'au! HGCommit * ' autoPattern
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
817
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
818 " Create a commit mapping. The mapping must clear all autocommands in case
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
819 " it is invoked when HGCommandCommitOnWrite is active, as well as to not
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
820 " invoke the buffer deletion autocommand.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
821
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
822 execute 'nnoremap <silent> <buffer> <Plug>HGCommit '.
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
823 \ ':au! HGCommit * ' . autoPattern . '<CR>'.
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
824 \ ':g/^HG:/d<CR>'.
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
825 \ ':update<CR>'.
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
826 \ ':call <SID>HGFinishCommit("' . messageFileName . '",' .
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
827 \ '"' . newCwd . '",' .
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
828 \ '"' . realFileName . '",' .
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
829 \ hgBufferCheck . ')<CR>'
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
830
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
831 silent 0put ='HG: ----------------------------------------------------------------------'
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
832 silent put =\"HG: Enter Log. Lines beginning with `HG:' are removed automatically\"
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
833 silent put ='HG: Type <leader>cc (or your own <Plug>HGCommit mapping)'
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
834
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
835 if s:HGGetOption('HGCommandCommitOnWrite', 1) == 1
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
836 execute 'au HGCommit BufWritePre' autoPattern 'g/^HG:/d'
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
837 execute 'au HGCommit BufWritePost' autoPattern 'call s:HGFinishCommit("' . messageFileName . '", "' . newCwd . '", "' . realFileName . '", ' . hgBufferCheck . ') | au! * ' autoPattern
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
838 silent put ='HG: or write this buffer'
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
839 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
840
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
841 silent put ='HG: to finish this commit operation'
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
842 silent put ='HG: ----------------------------------------------------------------------'
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
843 $
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
844 let b:HGSourceFile=fileName
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
845 let b:HGCommand='HGCommit'
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
846 set filetype=hg
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
847 finally
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
848 let &shellslash = shellSlashBak
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
849 endtry
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
850
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
851 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
852
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
853 " Function: s:HGDiff(...) {{{2
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
854 function! s:HGDiff(...)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
855 if a:0 == 1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
856 let revOptions = '-r' . a:1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
857 let caption = a:1 . ' -> current'
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
858 elseif a:0 == 2
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
859 let revOptions = '-r' . a:1 . ' -r' . a:2
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
860 let caption = a:1 . ' -> ' . a:2
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
861 else
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
862 let revOptions = ''
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
863 let caption = ''
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
864 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
865
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
866 let hgdiffopt=s:HGGetOption('HGCommandDiffOpt', 'w')
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
867
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
868 if hgdiffopt == ""
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
869 let diffoptionstring=""
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
870 else
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
871 let diffoptionstring=" -" . hgdiffopt . " "
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
872 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
873
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
874 let resultBuffer = s:HGDoCommand('diff ' . diffoptionstring . revOptions , 'hgdiff', caption)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
875 if resultBuffer != -1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
876 set filetype=diff
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
877 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
878 return resultBuffer
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
879 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
880
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
881
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
882 " Function: s:HGGotoOriginal(["!]) {{{2
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
883 function! s:HGGotoOriginal(...)
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
884 let origBuffNR = s:HGCurrentBufferCheck()
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
885 if origBuffNR > 0
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
886 let origWinNR = bufwinnr(origBuffNR)
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
887 if origWinNR == -1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
888 execute 'buffer' origBuffNR
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
889 else
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
890 execute origWinNR . 'wincmd w'
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
891 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
892 if a:0 == 1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
893 if a:1 == "!"
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
894 let buffnr = 1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
895 let buffmaxnr = bufnr("$")
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
896 while buffnr <= buffmaxnr
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
897 if getbufvar(buffnr, "HGOrigBuffNR") == origBuffNR
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
898 execute "bw" buffnr
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
899 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
900 let buffnr = buffnr + 1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
901 endwhile
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
902 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
903 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
904 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
905 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
906
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
907 " Function: s:HGFinishCommit(messageFile, targetDir, targetFile) {{{2
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
908 function! s:HGFinishCommit(messageFile, targetDir, targetFile, origBuffNR)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
909 if filereadable(a:messageFile)
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
910 let oldCwd=getcwd()
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
911 if strlen(a:targetDir) > 0
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
912 execute 'cd' escape(a:targetDir, ' ')
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
913 endif
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
914 let resultBuffer=s:HGCreateCommandBuffer('commit -F "' . a:messageFile . '" "'. a:targetFile . '"', 'hgcommit', '', a:origBuffNR)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
915 execute 'cd' escape(oldCwd, ' ')
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
916 execute 'bw' escape(a:messageFile, ' *?\')
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
917 silent execute 'call delete("' . a:messageFile . '")'
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
918 return s:HGMarkOrigBufferForSetup(resultBuffer)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
919 else
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
920 echoerr "Can't read message file; no commit is possible."
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
921 return -1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
922 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
923 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
924
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
925 " Function: s:HGLog() {{{2
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
926 function! s:HGLog(...)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
927 if a:0 == 0
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
928 let versionOption = ""
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
929 let caption = ''
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
930 else
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
931 let versionOption=" -r" . a:1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
932 let caption = a:1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
933 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
934
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
935 let resultBuffer=s:HGDoCommand('log' . versionOption, 'hglog', caption)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
936 if resultBuffer != ""
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
937 set filetype=rcslog
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
938 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
939 return resultBuffer
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
940 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
941
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
942 " Function: s:HGRevert() {{{2
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
943 function! s:HGRevert()
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
944 return s:HGMarkOrigBufferForSetup(s:HGDoCommand('revert', 'hgrevert', ''))
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
945 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
946
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
947 " Function: s:HGReview(...) {{{2
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
948 function! s:HGReview(...)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
949 if a:0 == 0
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
950 let versiontag=""
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
951 if s:HGGetOption('HGCommandInteractive', 0)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
952 let versiontag=input('Revision: ')
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
953 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
954 if versiontag == ""
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
955 let versiontag="(current)"
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
956 let versionOption=""
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
957 else
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
958 let versionOption=" -r " . versiontag . " "
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
959 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
960 else
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
961 let versiontag=a:1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
962 let versionOption=" -r " . versiontag . " "
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
963 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
964
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
965 let resultBuffer = s:HGDoCommand('cat' . versionOption, 'hgreview', versiontag)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
966 if resultBuffer > 0
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
967 let &filetype=getbufvar(b:HGOrigBuffNR, '&filetype')
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
968 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
969
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
970 return resultBuffer
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
971 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
972
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
973 " Function: s:HGStatus() {{{2
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
974 function! s:HGStatus()
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
975 return s:HGDoCommand('status', 'hgstatus', '')
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
976 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
977
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
978
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
979 " Function: s:HGUpdate() {{{2
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
980 function! s:HGUpdate()
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
981 return s:HGMarkOrigBufferForSetup(s:HGDoCommand('update', 'update', ''))
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
982 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
983
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
984 " Function: s:HGVimDiff(...) {{{2
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
985 function! s:HGVimDiff(...)
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
986 let originalBuffer = s:HGCurrentBufferCheck()
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
987 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning + 1
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
988 try
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
989 " If there's already a VimDiff'ed window, restore it.
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
990 " There may only be one HGVimDiff original window at a time.
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
991
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
992 if exists("s:vimDiffSourceBuffer") && s:vimDiffSourceBuffer != originalBuffer
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
993 " Clear the existing vimdiff setup by removing the result buffers.
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
994 call s:HGWipeoutCommandBuffers(s:vimDiffSourceBuffer, 'vimdiff')
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
995 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
996
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
997 " Split and diff
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
998 if(a:0 == 2)
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
999 " Reset the vimdiff system, as 2 explicit versions were provided.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1000 if exists('s:vimDiffSourceBuffer')
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1001 call s:HGWipeoutCommandBuffers(s:vimDiffSourceBuffer, 'vimdiff')
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1002 endif
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1003 let resultBuffer = s:HGReview(a:1)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1004 if resultBuffer < 0
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1005 echomsg "Can't open HG revision " . a:1
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1006 return resultBuffer
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1007 endif
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1008 let b:HGCommand = 'vimdiff'
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1009 diffthis
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1010 let s:vimDiffBufferCount = 1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1011 let s:vimDiffScratchList = '{'. resultBuffer . '}'
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1012 " If no split method is defined, cheat, and set it to vertical.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1013 try
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1014 call s:HGOverrideOption('HGCommandSplit', s:HGGetOption('HGCommandDiffSplit', s:HGGetOption('HGCommandSplit', 'vertical')))
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1015 let resultBuffer=s:HGReview(a:2)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1016 finally
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1017 call s:HGOverrideOption('HGCommandSplit')
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1018 endtry
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1019 if resultBuffer < 0
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1020 echomsg "Can't open HG revision " . a:1
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1021 return resultBuffer
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1022 endif
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1023 let b:HGCommand = 'vimdiff'
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1024 diffthis
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1025 let s:vimDiffBufferCount = 2
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1026 let s:vimDiffScratchList = s:vimDiffScratchList . '{'. resultBuffer . '}'
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1027 else
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1028 " Add new buffer
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1029 try
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1030 " Force splitting behavior, otherwise why use vimdiff?
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1031 call s:HGOverrideOption("HGCommandEdit", "split")
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1032 call s:HGOverrideOption("HGCommandSplit", s:HGGetOption('HGCommandDiffSplit', s:HGGetOption('HGCommandSplit', 'vertical')))
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1033 if(a:0 == 0)
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1034 let resultBuffer=s:HGReview()
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1035 else
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1036 let resultBuffer=s:HGReview(a:1)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1037 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1038 finally
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1039 call s:HGOverrideOption("HGCommandEdit")
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1040 call s:HGOverrideOption("HGCommandSplit")
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1041 endtry
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1042 if resultBuffer < 0
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1043 echomsg "Can't open current HG revision"
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1044 return resultBuffer
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1045 endif
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1046 let b:HGCommand = 'vimdiff'
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1047 diffthis
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1048
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1049 if !exists('s:vimDiffBufferCount')
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1050 " New instance of vimdiff.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1051 let s:vimDiffBufferCount = 2
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1052 let s:vimDiffScratchList = '{' . resultBuffer . '}'
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1053
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1054 " This could have been invoked on a HG result buffer, not the
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1055 " original buffer.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1056 wincmd W
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1057 execute 'buffer' originalBuffer
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1058 " Store info for later original buffer restore
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1059 let s:vimDiffRestoreCmd =
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1060 \ "call setbufvar(".originalBuffer.", \"&diff\", ".getbufvar(originalBuffer, '&diff').")"
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1061 \ . "|call setbufvar(".originalBuffer.", \"&foldcolumn\", ".getbufvar(originalBuffer, '&foldcolumn').")"
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1062 \ . "|call setbufvar(".originalBuffer.", \"&foldenable\", ".getbufvar(originalBuffer, '&foldenable').")"
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1063 \ . "|call setbufvar(".originalBuffer.", \"&foldmethod\", '".getbufvar(originalBuffer, '&foldmethod')."')"
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1064 \ . "|call setbufvar(".originalBuffer.", \"&scrollbind\", ".getbufvar(originalBuffer, '&scrollbind').")"
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1065 \ . "|call setbufvar(".originalBuffer.", \"&wrap\", ".getbufvar(originalBuffer, '&wrap').")"
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1066 \ . "|if &foldmethod=='manual'|execute 'normal zE'|endif"
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1067 diffthis
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1068 wincmd w
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1069 else
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1070 " Adding a window to an existing vimdiff
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1071 let s:vimDiffBufferCount = s:vimDiffBufferCount + 1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1072 let s:vimDiffScratchList = s:vimDiffScratchList . '{' . resultBuffer . '}'
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1073 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1074 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1075
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1076 let s:vimDiffSourceBuffer = originalBuffer
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1077
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1078 " Avoid executing the modeline in the current buffer after the autocommand.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1079
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1080 let currentBuffer = bufnr('%')
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1081 let saveModeline = getbufvar(currentBuffer, '&modeline')
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1082 try
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1083 call setbufvar(currentBuffer, '&modeline', 0)
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1084 silent do HGCommand User HGVimDiffFinish
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1085 finally
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1086 call setbufvar(currentBuffer, '&modeline', saveModeline)
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1087 endtry
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1088 return resultBuffer
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1089 finally
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1090 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning - 1
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1091 endtry
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1092 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1093
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1094 " Section: Command definitions {{{1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1095 " Section: Primary commands {{{2
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1096 com! HGAdd call s:HGAdd()
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1097 com! -nargs=? HGAnnotate call s:HGAnnotate(<f-args>)
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1098 com! -bang -nargs=? HGCommit call s:HGCommit(<q-bang>, <q-args>)
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1099 com! -nargs=* HGDiff call s:HGDiff(<f-args>)
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1100 com! -bang HGGotoOriginal call s:HGGotoOriginal(<q-bang>)
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1101 com! -nargs=? HGLog call s:HGLog(<f-args>)
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1102 com! HGRevert call s:HGRevert()
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1103 com! -nargs=? HGReview call s:HGReview(<f-args>)
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1104 com! HGStatus call s:HGStatus()
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1105 com! HGUpdate call s:HGUpdate()
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1106 com! -nargs=* HGVimDiff call s:HGVimDiff(<f-args>)
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1107
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1108 " Section: HG buffer management commands {{{2
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1109 com! HGDisableBufferSetup call HGDisableBufferSetup()
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1110 com! HGEnableBufferSetup call HGEnableBufferSetup()
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1111
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1112 " Allow reloading hgcommand.vim
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1113 com! HGReload unlet! loaded_hgcommand | runtime plugin/hgcommand.vim
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1114
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1115 " Section: Plugin command mappings {{{1
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1116 nnoremap <silent> <Plug>HGAdd :HGAdd<CR>
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1117 nnoremap <silent> <Plug>HGAnnotate :HGAnnotate<CR>
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1118 nnoremap <silent> <Plug>HGCommit :HGCommit<CR>
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1119 nnoremap <silent> <Plug>HGDiff :HGDiff<CR>
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1120 nnoremap <silent> <Plug>HGGotoOriginal :HGGotoOriginal<CR>
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1121 nnoremap <silent> <Plug>HGClearAndGotoOriginal :HGGotoOriginal!<CR>
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1122 nnoremap <silent> <Plug>HGLog :HGLog<CR>
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1123 nnoremap <silent> <Plug>HGRevert :HGRevert<CR>
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1124 nnoremap <silent> <Plug>HGReview :HGReview<CR>
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1125 nnoremap <silent> <Plug>HGStatus :HGStatus<CR>
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1126 nnoremap <silent> <Plug>HGUpdate :HGUpdate<CR>
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1127 nnoremap <silent> <Plug>HGVimDiff :HGVimDiff<CR>
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1128 nnoremap <silent> <Plug>HGWatchers :HGWatchers<CR>
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1129 nnoremap <silent> <Plug>HGWatchAdd :HGWatchAdd<CR>
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1130 nnoremap <silent> <Plug>HGWatchOn :HGWatchOn<CR>
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1131 nnoremap <silent> <Plug>HGWatchOff :HGWatchOff<CR>
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1132 nnoremap <silent> <Plug>HGWatchRemove :HGWatchRemove<CR>
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1133
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1134 " Section: Default mappings {{{1
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1135 if !hasmapto('<Plug>HGAdd')
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1136 nmap <unique> <Leader>hga <Plug>HGAdd
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1137 endif
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1138 if !hasmapto('<Plug>HGAnnotate')
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1139 nmap <unique> <Leader>hgn <Plug>HGAnnotate
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1140 endif
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1141 if !hasmapto('<Plug>HGClearAndGotoOriginal')
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1142 nmap <unique> <Leader>hgG <Plug>HGClearAndGotoOriginal
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1143 endif
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1144 if !hasmapto('<Plug>HGCommit')
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1145 nmap <unique> <Leader>hgc <Plug>HGCommit
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1146 endif
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1147 if !hasmapto('<Plug>HGDiff')
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1148 nmap <unique> <Leader>hgd <Plug>HGDiff
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1149 endif
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1150 if !hasmapto('<Plug>HGGotoOriginal')
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1151 nmap <unique> <Leader>hgg <Plug>HGGotoOriginal
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1152 endif
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1153 if !hasmapto('<Plug>HGLog')
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1154 nmap <unique> <Leader>hgl <Plug>HGLog
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1155 endif
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1156 if !hasmapto('<Plug>HGRevert')
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1157 nmap <unique> <Leader>hgq <Plug>HGRevert
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1158 endif
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1159 if !hasmapto('<Plug>HGReview')
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1160 nmap <unique> <Leader>hgr <Plug>HGReview
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1161 endif
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1162 if !hasmapto('<Plug>HGStatus')
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1163 nmap <unique> <Leader>hgs <Plug>HGStatus
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1164 endif
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1165 if !hasmapto('<Plug>HGUpdate')
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1166 nmap <unique> <Leader>hgu <Plug>HGUpdate
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1167 endif
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1168 if !hasmapto('<Plug>HGVimDiff')
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1169 nmap <unique> <Leader>hgv <Plug>HGVimDiff
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1170 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1171
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1172 " Section: Menu items {{{1
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1173 silent! aunmenu Plugin.HG
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1174 amenu <silent> &Plugin.HG.&Add <Plug>HGAdd
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1175 amenu <silent> &Plugin.HG.A&nnotate <Plug>HGAnnotate
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1176 amenu <silent> &Plugin.HG.&Commit <Plug>HGCommit
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1177 amenu <silent> &Plugin.HG.&Diff <Plug>HGDiff
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1178 amenu <silent> &Plugin.HG.&Log <Plug>HGLog
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1179 amenu <silent> &Plugin.HG.Revert <Plug>HGRevert
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1180 amenu <silent> &Plugin.HG.&Review <Plug>HGReview
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1181 amenu <silent> &Plugin.HG.&Status <Plug>HGStatus
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1182 amenu <silent> &Plugin.HG.&Update <Plug>HGUpdate
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1183 amenu <silent> &Plugin.HG.&VimDiff <Plug>HGVimDiff
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1184 amenu <silent> &Plugin.HG.&Watchers <Plug>HGWatchers
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1185 amenu <silent> &Plugin.HG.WatchAdd <Plug>HGWatchAdd
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1186 amenu <silent> &Plugin.HG.WatchOn <Plug>HGWatchOn
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1187 amenu <silent> &Plugin.HG.WatchOff <Plug>HGWatchOff
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1188 amenu <silent> &Plugin.HG.WatchRemove <Plug>HGWatchRemove
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1189
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1190 " Section: Autocommands to restore vimdiff state {{{1
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1191 function! s:HGVimDiffRestore(vimDiffBuff)
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1192 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning + 1
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1193 try
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1194 if exists("s:vimDiffSourceBuffer")
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1195 if a:vimDiffBuff == s:vimDiffSourceBuffer
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1196 " Original file is being removed.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1197 unlet! s:vimDiffSourceBuffer
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1198 unlet! s:vimDiffBufferCount
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1199 unlet! s:vimDiffRestoreCmd
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1200 unlet! s:vimDiffScratchList
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1201 elseif match(s:vimDiffScratchList, '{' . a:vimDiffBuff . '}') >= 0
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1202 let s:vimDiffScratchList = substitute(s:vimDiffScratchList, '{' . a:vimDiffBuff . '}', '', '')
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1203 let s:vimDiffBufferCount = s:vimDiffBufferCount - 1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1204 if s:vimDiffBufferCount == 1 && exists('s:vimDiffRestoreCmd')
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1205 " All scratch buffers are gone, reset the original.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1206 " Only restore if the source buffer is still in Diff mode
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1207
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1208 let sourceWinNR=bufwinnr(s:vimDiffSourceBuffer)
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1209 if sourceWinNR != -1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1210 " The buffer is visible in at least one window
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1211 let currentWinNR = winnr()
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1212 while winbufnr(sourceWinNR) != -1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1213 if winbufnr(sourceWinNR) == s:vimDiffSourceBuffer
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1214 execute sourceWinNR . 'wincmd w'
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1215 if getwinvar('', "&diff")
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1216 execute s:vimDiffRestoreCmd
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1217 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1218 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1219 let sourceWinNR = sourceWinNR + 1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1220 endwhile
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1221 execute currentWinNR . 'wincmd w'
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1222 else
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1223 " The buffer is hidden. It must be visible in order to set the
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1224 " diff option.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1225 let currentBufNR = bufnr('')
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1226 execute "hide buffer" s:vimDiffSourceBuffer
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1227 if getwinvar('', "&diff")
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1228 execute s:vimDiffRestoreCmd
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1229 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1230 execute "hide buffer" currentBufNR
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1231 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1232
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1233 unlet s:vimDiffRestoreCmd
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1234 unlet s:vimDiffSourceBuffer
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1235 unlet s:vimDiffBufferCount
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1236 unlet s:vimDiffScratchList
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1237 elseif s:vimDiffBufferCount == 0
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1238 " All buffers are gone.
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1239 unlet s:vimDiffSourceBuffer
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1240 unlet s:vimDiffBufferCount
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1241 unlet s:vimDiffScratchList
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1242 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1243 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1244 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1245 finally
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1246 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning - 1
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1247 endtry
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1248 endfunction
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1249
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1250 augroup HGVimDiffRestore
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1251 au!
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1252 au BufUnload * call s:HGVimDiffRestore(expand("<abuf>"))
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1253 augroup END
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1254
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1255 " Section: Optional activation of buffer management {{{1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1256
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1257 if s:HGGetOption('HGCommandEnableBufferSetup', 0)
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1258 call HGEnableBufferSetup()
2591
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1259 endif
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1260
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1261 " Section: Plugin completion {{{1
61f2008cd6bf Addition of CVScommand vim script as a base for HGcommand
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents:
diff changeset
1262
2592
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1263 let loaded_hgcommand=2
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1264 silent do HGCommand User HGPluginFinish
457846f400e8 Vim script: Adaptation from CVS to Mercurial
"Mathieu Clabaut <mathieu.clabaut@gmail.com>"
parents: 2591
diff changeset
1265 " vim:se expandtab sts=2 sw=2: