annotate plugin/lawrencium.vim @ 28:0cdfdab43907

`Hgcommit` now puts the cursor at the beginning of the commit message.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 20 Dec 2011 16:15:11 -0800
parents 09115be355e2
children 35d097b9513c 3a0f7bb6ea64
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 " lawrencium.vim - A Mercurial wrapper
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2 " Maintainer: Ludovic Chabant <http://ludovic.chabant.com>
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 " Version: 0.1
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5 " Globals {{{
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 if !exists('g:lawrencium_debug')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8 let g:lawrencium_debug = 0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 if (exists('g:loaded_lawrencium') || &cp) && !g:lawrencium_debug
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12 finish
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 endif
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
14 if (exists('g:loaded_lawrencium') && g:lawrencium_debug)
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
15 echom "Reloaded Lawrencium."
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
16 endif
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 let g:loaded_lawrencium = 1
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19 if !exists('g:lawrencium_hg_executable')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20 let g:lawrencium_hg_executable = 'hg'
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
23 if !exists('g:lawrencium_trace')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
24 let g:lawrencium_trace = 0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
25 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
26
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
27 " }}}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
28
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
29 " Utility {{{
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
30
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
31 " Strips the ending slash in a path.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
32 function! s:stripslash(path)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
33 return fnamemodify(a:path, ':s?[/\\]$??')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
34 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36 " Normalizes the slashes in a path.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37 function! s:normalizepath(path)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
38 if exists('+shellslash') && &shellslash
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
39 return substitute(a:path, '\\', '/', '')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
40 elseif has('win32')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
41 return substitute(a:path, '/', '\\', '')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
42 else
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
43 return a:path
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
44 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
45 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
46
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
47 " Like tempname() but with some control over the filename.
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
48 function! s:tempname(name, ...)
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
49 let l:path = tempname()
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
50 let l:result = fnamemodify(l:path, ':h') . '/' . a:name . fnamemodify(l:path, ':t')
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
51 if a:0 > 0
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
52 let l:result = l:result . a:1
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
53 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
54 return l:result
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
55 endfunction
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
56
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
57 " Prints a message if debug tracing is enabled.
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
58 function! s:trace(message, ...)
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
59 if g:lawrencium_trace || (a:0 && a:1)
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
60 let l:message = "lawrencium: " . a:message
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
61 echom l:message
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
62 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
63 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
64
18
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
65 " Prints an error message with 'lawrencium error' prefixed to it.
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
66 function! s:error(message)
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
67 echom "lawrencium error: " . a:message
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
68 endfunction
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
69
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
70 " Throw a Lawrencium exception message.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
71 function! s:throw(message)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
72 let v:errmsg = "lawrencium: " . a:message
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
73 throw v:errmsg
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
74 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
75
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
76 " Finds the repository root given a path inside that repository.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
77 " Throw an error if not repository is found.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
78 function! s:find_repo_root(path)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
79 let l:path = s:stripslash(a:path)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
80 let l:previous_path = ""
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
81 while l:path != l:previous_path
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
82 if isdirectory(l:path . '/.hg/store')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
83 return simplify(fnamemodify(l:path, ':p'))
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
84 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
85 let l:previous_path = l:path
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
86 let l:path = fnamemodify(l:path, ':h')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
87 endwhile
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
88 call s:throw("No Mercurial repository found above: " . a:path)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
89 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
90
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
91 " }}}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
92
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
93 " Mercurial Repository {{{
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
94
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
95 " Let's define a Mercurial repo 'class' using prototype-based object-oriented
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
96 " programming.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
97 "
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
98 " The prototype dictionary.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
99 let s:HgRepo = {}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
100
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
101 " Constructor
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
102 function! s:HgRepo.New(path) abort
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
103 let l:newRepo = copy(self)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
104 let l:newRepo.root_dir = s:find_repo_root(a:path)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
105 call s:trace("Built new Mercurial repository object at : " . l:newRepo.root_dir)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
106 return l:newRepo
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
107 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
108
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
109 " Gets a full path given a repo-relative path
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
110 function! s:HgRepo.GetFullPath(path) abort
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
111 let l:root_dir = self.root_dir
11
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
112 if a:path =~# '\v^[/\\]'
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
113 let l:root_dir = s:stripslash(l:root_dir)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
114 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
115 return l:root_dir . a:path
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
116 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
117
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
118 " Gets a list of files matching a root-relative pattern.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
119 " If a flag is passed and is TRUE, a slash will be appended to all
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
120 " directories.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
121 function! s:HgRepo.Glob(pattern, ...) abort
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
122 let l:root_dir = self.root_dir
11
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
123 if (a:pattern =~# '\v^[/\\]')
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
124 let l:root_dir = s:stripslash(l:root_dir)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
125 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
126 let l:matches = split(glob(l:root_dir . a:pattern), '\n')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
127 if a:0 && a:1
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
128 for l:idx in range(len(l:matches))
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
129 if !filereadable(l:matches[l:idx])
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
130 let l:matches[l:idx] = l:matches[l:idx] . '/'
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
131 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
132 endfor
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
133 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
134 let l:strip_len = len(l:root_dir)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
135 call map(l:matches, 'v:val[l:strip_len : -1]')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
136 return l:matches
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
137 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
138
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
139 " Runs a Mercurial command in the repo
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
140 function! s:HgRepo.RunCommand(command, ...) abort
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
141 let l:hg_command = g:lawrencium_hg_executable . ' --repository ' . shellescape(s:stripslash(self.root_dir))
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
142 let l:hg_command = l:hg_command . ' ' . a:command . ' ' . join(a:000, ' ')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
143 call s:trace("Running Mercurial command: " . l:hg_command)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
144 return system(l:hg_command)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
145 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
146
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
147 " Repo cache map
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
148 let s:buffer_repos = {}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
149
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
150 " Get a cached repo
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
151 function! s:hg_repo(...) abort
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
152 " Use the given path, or the mercurial directory of the current buffer.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
153 if a:0 == 0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
154 if exists('b:mercurial_dir')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
155 let l:path = b:mercurial_dir
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
156 else
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
157 let l:path = s:find_repo_root(expand('%:p'))
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
158 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
159 else
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
160 let l:path = a:1
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
161 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
162 " Find a cache repo instance, or make a new one.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
163 if has_key(s:buffer_repos, l:path)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
164 return get(s:buffer_repos, l:path)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
165 else
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
166 let l:repo = s:HgRepo.New(l:path)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
167 let s:buffer_repos[l:path] = l:repo
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
168 return l:repo
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
169 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
170 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
171
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
172 " Sets up the current buffer with Lawrencium commands if it contains a file from a Mercurial repo.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
173 " If the file is not in a Mercurial repo, just exit silently.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
174 function! s:setup_buffer_commands() abort
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
175 call s:trace("Scanning buffer '" . bufname('%') . "' for Lawrencium setup...")
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
176 let l:do_setup = 1
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
177 if exists('b:mercurial_dir')
11
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
178 if b:mercurial_dir =~# '\v^\s*$'
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
179 unlet b:mercurial_dir
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
180 else
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
181 let l:do_setup = 0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
182 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
183 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
184 try
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
185 let l:repo = s:hg_repo()
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
186 catch /^lawrencium\:/
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
187 return
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
188 endtry
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
189 let b:mercurial_dir = l:repo.root_dir
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
190 if exists('b:mercurial_dir') && l:do_setup
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
191 call s:trace("Setting Mercurial commands for buffer '" . bufname('%'))
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
192 call s:trace(" with repo : " . expand(b:mercurial_dir))
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
193 silent doautocmd User Lawrencium
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
194 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
195 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
196
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
197 augroup lawrencium_detect
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
198 autocmd!
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
199 autocmd BufNewFile,BufReadPost * call s:setup_buffer_commands()
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
200 autocmd VimEnter * if expand('<amatch>')==''|call s:setup_buffer_commands()|endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
201 augroup end
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
202
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
203 " }}}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
204
14
eab2680e6818 Better fold sections.
Ludovic Chabant <ludovic@chabant.com>
parents: 12
diff changeset
205 " Buffer Commands Management {{{
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
206
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
207 " Store the commands for Lawrencium-enabled buffers so that we can add them in
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
208 " batch when we need to.
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
209 let s:main_commands = []
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
210
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
211 function! s:AddMainCommand(command) abort
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
212 let s:main_commands += [a:command]
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
213 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
214
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
215 function! s:DefineMainCommands()
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
216 for l:command in s:main_commands
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
217 execute 'command! -buffer ' . l:command
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
218 endfor
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
219 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
220
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
221 augroup lawrencium_main
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
222 autocmd!
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
223 autocmd User Lawrencium call s:DefineMainCommands()
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
224 augroup end
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
225
14
eab2680e6818 Better fold sections.
Ludovic Chabant <ludovic@chabant.com>
parents: 12
diff changeset
226 " }}}
eab2680e6818 Better fold sections.
Ludovic Chabant <ludovic@chabant.com>
parents: 12
diff changeset
227
eab2680e6818 Better fold sections.
Ludovic Chabant <ludovic@chabant.com>
parents: 12
diff changeset
228 " Commands Auto-Complete {{{
eab2680e6818 Better fold sections.
Ludovic Chabant <ludovic@chabant.com>
parents: 12
diff changeset
229
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
230 " Auto-complete function for commands that take repo-relative file paths.
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
231 function! s:ListRepoFiles(ArgLead, CmdLine, CursorPos) abort
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
232 let l:matches = s:hg_repo().Glob(a:ArgLead . '*', 1)
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
233 call map(l:matches, 's:normalizepath(v:val)')
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
234 return l:matches
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
235 endfunction
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
236
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
237 " Auto-complete function for commands that take repo-relative directory paths.
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
238 function! s:ListRepoDirs(ArgLead, CmdLine, CursorPos) abort
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
239 let l:matches = s:hg_repo().Glob(a:ArgLead . '*/')
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
240 call map(l:matches, 's:normalizepath(v:val)')
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
241 return l:matches
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
242 endfunction
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
243
14
eab2680e6818 Better fold sections.
Ludovic Chabant <ludovic@chabant.com>
parents: 12
diff changeset
244 " }}}
eab2680e6818 Better fold sections.
Ludovic Chabant <ludovic@chabant.com>
parents: 12
diff changeset
245
4
b6e4446ed292 HgStatus now outputs to the location window.
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
246 " Hg {{{
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
247
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
248 function! s:Hg(bang, ...) abort
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
249 let l:repo = s:hg_repo()
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
250 let l:output = call(l:repo.RunCommand, a:000, l:repo)
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
251 if a:bang
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
252 " Open the output of the command in a temp file.
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
253 let l:temp_file = s:tempname('hg-output-', '.txt')
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
254 execute 'pedit ' . l:temp_file
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
255 wincmd p
21
d0acefc1ec9a Fixed multi-line output of `:Hg`.
Ludovic Chabant <ludovic@chabant.com>
parents: 18
diff changeset
256 call append(0, split(l:output, '\n'))
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
257 else
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
258 " Just print out the output of the command.
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
259 echo l:output
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
260 endif
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
261 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
262
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
263 " Include the generated HG usage file.
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
264 let s:usage_file = expand("<sfile>:h:h") . "/resources/hg_usage.vim"
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
265 if filereadable(s:usage_file)
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
266 execute "source " . s:usage_file
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
267 else
18
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
268 call s:error("Can't find the Mercurial usage file. Auto-completion will be disabled in Lawrencium.")
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
269 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
270
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
271 function! s:CompleteHg(ArgLead, CmdLine, CursorPos)
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
272 " Don't do anything if the usage file was not sourced.
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
273 if !exists('g:lawrencium_hg_commands') || !exists('g:lawrencium_hg_options')
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
274 return []
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
275 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
276
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
277 " a:ArgLead seems to be the number 0 when completing a minus '-'.
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
278 " Gotta find out why...
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
279 let l:arglead = a:ArgLead
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
280 if type(a:ArgLead) == type(0)
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
281 let l:arglead = '-'
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
282 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
283
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
284 " Try completing a global option, before any command name.
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
285 if a:CmdLine =~# '\v^Hg(\s+\-[a-zA-Z0-9\-_]*)+$'
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
286 return filter(copy(g:lawrencium_hg_options), "v:val[0:strlen(l:arglead)-1] ==# l:arglead")
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
287 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
288
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
289 " Try completing a command (note that there could be global options before
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
290 " the command name).
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
291 if a:CmdLine =~# '\v^Hg\s+(\-[a-zA-Z0-9\-_]+\s+)*[a-zA-Z]+$'
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
292 echom " - matched command"
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
293 return filter(keys(g:lawrencium_hg_commands), "v:val[0:strlen(l:arglead)-1] ==# l:arglead")
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
294 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
295
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
296 " Try completing a command's options.
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
297 let l:cmd = matchstr(a:CmdLine, '\v(^Hg\s+(\-[a-zA-Z0-9\-_]+\s+)*)@<=[a-zA-Z]+')
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
298 if strlen(l:cmd) > 0
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
299 echom " - matched command option for " . l:cmd . " with : " . l:arglead
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
300 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
301 if strlen(l:cmd) > 0 && l:arglead[0] ==# '-'
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
302 if has_key(g:lawrencium_hg_commands, l:cmd)
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
303 " Return both command options and global options together.
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
304 let l:copts = filter(copy(g:lawrencium_hg_commands[l:cmd]), "v:val[0:strlen(l:arglead)-1] ==# l:arglead")
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
305 let l:gopts = filter(copy(g:lawrencium_hg_options), "v:val[0:strlen(l:arglead)-1] ==# l:arglead")
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
306 return l:copts + l:gopts
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
307 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
308 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
309
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
310 " Just auto-complete with filenames unless it's an option.
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
311 if l:arglead[0] ==# '-'
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
312 return []
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
313 else
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
314 return s:ListRepoFiles(a:ArgLead, a:CmdLine, a:CursorPos)
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
315 endfunction
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
316
26
de588a4bca10 Fixed completely wrong code that somehow almost ran completely fine.
Ludovic Chabant <ludovic@chabant.com>
parents: 25
diff changeset
317 call s:AddMainCommand("-bang -complete=customlist,s:CompleteHg -nargs=* Hg :call s:Hg(<bang>0, <f-args>)")
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
318
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
319 " }}}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
320
4
b6e4446ed292 HgStatus now outputs to the location window.
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
321 " Hgstatus {{{
b6e4446ed292 HgStatus now outputs to the location window.
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
322
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
323 function! s:HgStatus() abort
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
324 " Get the repo and the `hg status` output.
4
b6e4446ed292 HgStatus now outputs to the location window.
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
325 let l:repo = s:hg_repo()
b6e4446ed292 HgStatus now outputs to the location window.
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
326 let l:status_text = l:repo.RunCommand('status')
16
724f6db3baa2 Don't show `hg commit` output if there's nothing to show.
Ludovic Chabant <ludovic@chabant.com>
parents: 15
diff changeset
327 if l:status_text ==# '\v%^\s*%$'
11
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
328 echo "Nothing modified."
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
329 endif
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
330
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
331 " Open a new temp buffer in the preview window, jump to it,
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
332 " and paste the `hg status` output in there.
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
333 let l:temp_file = s:tempname('hg-status-', '.txt')
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
334 let l:preview_height = &previewheight
11
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
335 let l:status_lines = split(l:status_text, '\n')
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
336 execute "setlocal previewheight=" . (len(l:status_lines) + 1)
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
337 execute "pedit " . l:temp_file
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
338 wincmd p
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
339 call append(0, l:status_lines)
11
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
340 " Make it a nice size.
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
341 execute "setlocal previewheight=" . l:preview_height
11
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
342 " Make sure it's deleted when we exit the window.
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
343 setlocal bufhidden=delete
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
344
7
adc267e2f0f4 Added syntax highlighting for hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 6
diff changeset
345 " Setup the buffer correctly: readonly, and with the correct repo linked
adc267e2f0f4 Added syntax highlighting for hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 6
diff changeset
346 " to it.
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
347 let b:mercurial_dir = l:repo.root_dir
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
348 setlocal buftype=nofile
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
349 setlocal nomodified
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
350 setlocal nomodifiable
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
351 setlocal readonly
7
adc267e2f0f4 Added syntax highlighting for hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 6
diff changeset
352 setlocal syntax=hgstatus
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
353
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
354 " Add some handy mappings.
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
355 nnoremap <buffer> <silent> <C-N> :call search('^[MARC\!\?I ]\s.', 'We')<cr>
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
356 nnoremap <buffer> <silent> <C-P> :call search('^[MARC\!\?I ]\s.','Wbe')<cr>
26
de588a4bca10 Fixed completely wrong code that somehow almost ran completely fine.
Ludovic Chabant <ludovic@chabant.com>
parents: 25
diff changeset
357 nnoremap <buffer> <silent> <cr> :call <SID>HgStatus_FileEdit()<cr>
de588a4bca10 Fixed completely wrong code that somehow almost ran completely fine.
Ludovic Chabant <ludovic@chabant.com>
parents: 25
diff changeset
358 nnoremap <buffer> <silent> <C-D> :call <SID>HgStatus_FileDiff(0)<cr>
de588a4bca10 Fixed completely wrong code that somehow almost ran completely fine.
Ludovic Chabant <ludovic@chabant.com>
parents: 25
diff changeset
359 nnoremap <buffer> <silent> <C-V> :call <SID>HgStatus_FileDiff(1)<cr>
de588a4bca10 Fixed completely wrong code that somehow almost ran completely fine.
Ludovic Chabant <ludovic@chabant.com>
parents: 25
diff changeset
360 nnoremap <buffer> <silent> <C-A> :call <SID>HgStatus_FileAdd()<cr>
de588a4bca10 Fixed completely wrong code that somehow almost ran completely fine.
Ludovic Chabant <ludovic@chabant.com>
parents: 25
diff changeset
361 nnoremap <buffer> <silent> <C-R> :call <SID>HgStatus_Refresh()<cr>
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
362 nnoremap <buffer> <silent> q :bdelete<cr>
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
363
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
364 " Make sure the file is deleted with the buffer.
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
365 autocmd BufDelete <buffer> call s:HgStatus_CleanUp(expand('<afile>:p'))
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
366 endfunction
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
367
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
368 function! s:HgStatus_CleanUp(path) abort
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
369 " If the `hg status` output has been saved to disk (e.g. because of a
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
370 " refresh we did), let's delete it.
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
371 if filewritable(a:path)
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
372 call s:trace("Cleaning up status log: " . a:path)
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
373 call delete(a:path)
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
374 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
375 endfunction
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
376
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
377 function! s:HgStatus_Refresh() abort
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
378 " Get the repo and the `hg status` output.
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
379 let l:repo = s:hg_repo()
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
380 let l:status_text = l:repo.RunCommand('status')
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
381
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
382 " Replace the contents of the current buffer with it, and refresh.
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
383 echo "Writing to " . expand('%:p')
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
384 let l:path = expand('%:p')
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
385 let l:status_lines = split(l:status_text, '\n')
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
386 call writefile(l:status_lines, l:path)
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
387 edit
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
388 endfunction
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
389
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
390 function! s:HgStatus_FileEdit() abort
9
82a49134a85c Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 8
diff changeset
391 " Get the path of the file the cursor is on.
82a49134a85c Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 8
diff changeset
392 let l:filename = s:HgStatus_GetSelectedPath()
24
21a879a09f20 Trying to keep the cursor line when open an already opened file in `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents: 23
diff changeset
393
21a879a09f20 Trying to keep the cursor line when open an already opened file in `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents: 23
diff changeset
394 " If the file is already open in a window, jump to that window.
21a879a09f20 Trying to keep the cursor line when open an already opened file in `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents: 23
diff changeset
395 " Otherwise, jump to the previous window and open it there.
21a879a09f20 Trying to keep the cursor line when open an already opened file in `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents: 23
diff changeset
396 for nr in range(1, winnr('$'))
21a879a09f20 Trying to keep the cursor line when open an already opened file in `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents: 23
diff changeset
397 let l:br = winbufnr(nr)
21a879a09f20 Trying to keep the cursor line when open an already opened file in `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents: 23
diff changeset
398 let l:bpath = fnamemodify(bufname(l:br), ':p')
21a879a09f20 Trying to keep the cursor line when open an already opened file in `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents: 23
diff changeset
399 if l:bpath ==# l:filename
21a879a09f20 Trying to keep the cursor line when open an already opened file in `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents: 23
diff changeset
400 execute nr . 'wincmd w'
21a879a09f20 Trying to keep the cursor line when open an already opened file in `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents: 23
diff changeset
401 return
21a879a09f20 Trying to keep the cursor line when open an already opened file in `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents: 23
diff changeset
402 endif
21a879a09f20 Trying to keep the cursor line when open an already opened file in `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents: 23
diff changeset
403 endfor
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
404 wincmd p
24
21a879a09f20 Trying to keep the cursor line when open an already opened file in `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents: 23
diff changeset
405 execute 'edit ' . l:filename
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
406 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
407
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
408 function! s:HgStatus_FileAdd() abort
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
409 " Get the path of the file the cursor is on, and its status.
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
410 let l:filename = s:HgStatus_GetSelectedPath()
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
411 let l:status = s:HgStatus_GetSelectedStatus()
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
412 if l:status !=# '?'
18
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
413 call s:error("Not an untracked file: " . l:filename)
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
414 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
415
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
416 " Add the file.
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
417 let l:repo = s:hg_repo()
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
418 call l:repo.RunCommand('add', l:filename)
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
419
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
420 " Refresh the status window.
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
421 call s:HgStatus_Refresh()
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
422 endfunction
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
423
9
82a49134a85c Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 8
diff changeset
424 function! s:HgStatus_FileDiff(vertical) abort
25
0e952b7c79d7 Fixed a bug with opening a diff from `Hgstatus`
Ludovic Chabant <ludovic@chabant.com>
parents: 24
diff changeset
425 " Open the file and run `Hgdiff` on it.
0e952b7c79d7 Fixed a bug with opening a diff from `Hgstatus`
Ludovic Chabant <ludovic@chabant.com>
parents: 24
diff changeset
426 call s:HgStatus_FileEdit()
0e952b7c79d7 Fixed a bug with opening a diff from `Hgstatus`
Ludovic Chabant <ludovic@chabant.com>
parents: 24
diff changeset
427 call s:HgDiff('%:p', a:vertical)
9
82a49134a85c Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 8
diff changeset
428 endfunction
82a49134a85c Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 8
diff changeset
429
82a49134a85c Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 8
diff changeset
430 function! s:HgStatus_GetSelectedPath() abort
82a49134a85c Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 8
diff changeset
431 let l:repo = s:hg_repo()
82a49134a85c Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 8
diff changeset
432 let l:line = getline('.')
82a49134a85c Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 8
diff changeset
433 " Yay, awesome, Vim's regex syntax is fucked up like shit, especially for
82a49134a85c Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 8
diff changeset
434 " look-aheads and look-behinds. See for yourself:
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
435 let l:filename = matchstr(l:line, '\v(^[MARC\!\?I ]\s)@<=.*')
9
82a49134a85c Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 8
diff changeset
436 let l:filename = l:repo.GetFullPath(l:filename)
82a49134a85c Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 8
diff changeset
437 return l:filename
82a49134a85c Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 8
diff changeset
438 endfunction
82a49134a85c Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 8
diff changeset
439
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
440 function! s:HgStatus_GetSelectedStatus() abort
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
441 let l:line = getline('.')
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
442 return matchstr(l:line, '\v^[MARC\!\?I ]')
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
443 endfunction
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
444
26
de588a4bca10 Fixed completely wrong code that somehow almost ran completely fine.
Ludovic Chabant <ludovic@chabant.com>
parents: 25
diff changeset
445 call s:AddMainCommand("Hgstatus :call s:HgStatus()")
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
446
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
447 " }}}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
448
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
449 " Hgcd, Hglcd {{{
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
450
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
451 call s:AddMainCommand("-bang -nargs=? -complete=customlist,s:ListRepoDirs Hgcd :cd<bang> `=s:hg_repo().GetFullPath(<q-args>)`")
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
452 call s:AddMainCommand("-bang -nargs=? -complete=customlist,s:ListRepoDirs Hglcd :lcd<bang> `=s:hg_repo().GetFullPath(<q-args>)`")
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
453
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
454 " }}}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
455
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
456 " Hgedit {{{
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
457
27
09115be355e2 Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents: 26
diff changeset
458 function! s:HgEdit(bang, filename) abort
09115be355e2 Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents: 26
diff changeset
459 let l:full_path = s:hg_repo().GetFullPath(a:filename)
09115be355e2 Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents: 26
diff changeset
460 if a:bang
09115be355e2 Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents: 26
diff changeset
461 execute "edit! " . l:full_path
09115be355e2 Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents: 26
diff changeset
462 else
09115be355e2 Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents: 26
diff changeset
463 execute "edit " . l:full_path
09115be355e2 Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents: 26
diff changeset
464 endif
09115be355e2 Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents: 26
diff changeset
465 endfunction
09115be355e2 Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents: 26
diff changeset
466
09115be355e2 Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents: 26
diff changeset
467 call s:AddMainCommand("-bang -nargs=? -complete=customlist,s:ListRepoFiles Hgedit :call s:HgEdit(<bang>0, <f-args>)")
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
468
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
469 " }}}
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
470
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
471 " Hgdiff {{{
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
472
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
473 function! s:HgDiff(filename, vertical, ...) abort
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
474 " Default revisions to diff: the working directory (special Lawrencium
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
475 " hard-coded syntax) and the parent of the working directory (using
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
476 " Mercurial's revsets syntax).
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
477 let l:rev1 = 'lawrencium#_wdir_'
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
478 let l:rev2 = 'p1()'
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
479 if a:0 == 1
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
480 let l:rev2 = a:1
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
481 elseif a:0 == 2
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
482 let l:rev1 = a:1
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
483 let l:rev2 = a:2
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
484 endif
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
485
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
486 " Get the current repo, and expand the given filename in case it contains
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
487 " fancy filename modifiers.
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
488 let l:repo = s:hg_repo()
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
489 let l:path = expand(a:filename)
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
490 call s:trace("Diff'ing '".l:rev1."' and '".l:rev2."' on file: ".l:path)
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
491
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
492 " We'll keep a list of buffers in this diff, so when one exits, the
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
493 " others' 'diff' flag is turned off.
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
494 let l:diff_buffers = []
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
495
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
496 " Get the first file and open it.
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
497 if l:rev1 == 'lawrencium#_wdir_'
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
498 if bufexists(l:path)
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
499 execute 'buffer ' . fnameescape(l:path)
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
500 else
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
501 execute 'edit ' . fnameescape(l:path)
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
502 endif
11
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
503 " Make it part of the diff group.
23
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
504 call s:HgDiff_DiffThis()
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
505 else
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
506 let l:temp_file = tempname()
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
507 call l:repo.RunCommand('cat', '-r', '"'.l:rev1.'"', '-o', l:temp_file, l:path)
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
508 execute 'edit ' . fnameescape(l:temp_file)
11
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
509 " Make it part of the diff group.
23
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
510 call s:HgDiff_DiffThis()
11
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
511 " Remember the repo it belongs to.
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
512 let b:mercurial_dir = l:repo.root_dir
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
513 " Make sure it's deleted when we move away from it.
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
514 setlocal bufhidden=delete
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
515 endif
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
516
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
517 " Get the second file and open it too.
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
518 let l:diffsplit = 'diffsplit'
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
519 if a:vertical
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
520 let l:diffsplit = 'vertical diffsplit'
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
521 endif
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
522 if l:rev2 == 'lawrencium#_wdir_'
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
523 execute l:diffsplit . ' ' . fnameescape(l:path)
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
524 else
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
525 let l:temp_file = tempname()
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
526 call l:repo.RunCommand('cat', '-r', '"'.l:rev2.'"', '-o', l:temp_file, l:path)
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
527 execute l:diffsplit . ' ' . fnameescape(l:temp_file)
11
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
528 " Remember the repo it belongs to.
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
529 let b:mercurial_dir = l:repo.root_dir
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
530 " Make sure it's deleted when we move away from it.
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
531 setlocal bufhidden=delete
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
532 endif
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
533 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
534
23
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
535 function! s:HgDiff_DiffThis() abort
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
536 " Store some commands to run when we exit diff mode.
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
537 " It's needed because `diffoff` reverts those settings to their default
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
538 " values, instead of their previous ones.
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
539 if !&diff
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
540 call s:trace('Enabling diff mode on ' . bufname('%'))
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
541 let w:lawrencium_diffoff = {}
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
542 let w:lawrencium_diffoff['&diff'] = 0
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
543 let w:lawrencium_diffoff['&wrap'] = &l:wrap
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
544 let w:lawrencium_diffoff['&scrollopt'] = &l:scrollopt
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
545 let w:lawrencium_diffoff['&scrollbind'] = &l:scrollbind
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
546 let w:lawrencium_diffoff['&cursorbind'] = &l:cursorbind
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
547 let w:lawrencium_diffoff['&foldmethod'] = &l:foldmethod
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
548 let w:lawrencium_diffoff['&foldcolumn'] = &l:foldcolumn
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
549 diffthis
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
550 endif
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
551 endfunction
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
552
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
553 function! s:HgDiff_DiffOff(...) abort
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
554 " Get the window name (given as a paramter, or current window).
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
555 let l:nr = a:0 ? a:1 : winnr()
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
556
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
557 " Run the commands we saved in `HgDiff_DiffThis`, or just run `diffoff`.
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
558 let l:backup = getwinvar(l:nr, 'lawrencium_diffoff')
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
559 if type(l:backup) == type({}) && len(l:backup) > 0
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
560 call s:trace('Disabling diff mode on ' . l:nr)
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
561 for key in keys(l:backup)
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
562 call setwinvar(l:nr, key, l:backup[key])
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
563 endfor
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
564 call setwinvar(l:nr, 'lawrencium_diffoff', {})
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
565 else
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
566 call s:trace('Disabling diff mode on ' . l:nr . ' (but no true restore)')
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
567 diffoff
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
568 endif
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
569 endfunction
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
570
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
571 function! s:HgDiff_GetDiffWindows() abort
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
572 let l:result = []
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
573 for nr in range(1, winnr('$'))
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
574 if getwinvar(nr, '&diff')
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
575 call add(l:result, nr)
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
576 endif
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
577 endfor
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
578 return l:result
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
579 endfunction
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
580
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
581 function! s:HgDiff_CleanUp() abort
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
582 " If we're not leaving a diff window, do nothing.
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
583 if !&diff
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
584 return
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
585 endif
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
586
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
587 " If there will be only one diff window left (plus the one we're leaving),
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
588 " turn off diff everywhere.
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
589 let l:nrs = s:HgDiff_GetDiffWindows()
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
590 if len(l:nrs) <= 2
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
591 call s:trace('Disabling diff mode in ' . len(l:nrs) . ' windows.')
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
592 for nr in l:nrs
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
593 if getwinvar(nr, '&diff')
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
594 call s:HgDiff_DiffOff(nr)
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
595 endif
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
596 endfor
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
597 else
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
598 call s:trace('Still ' . len(l:nrs) . ' diff windows open.')
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
599 endif
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
600 endfunction
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
601
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
602 augroup lawrencium_diff
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
603 autocmd!
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
604 autocmd BufWinLeave * call s:HgDiff_CleanUp()
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
605 augroup end
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
606
26
de588a4bca10 Fixed completely wrong code that somehow almost ran completely fine.
Ludovic Chabant <ludovic@chabant.com>
parents: 25
diff changeset
607 call s:AddMainCommand("-nargs=* -complete=customlist,s:ListRepoFiles Hgdiff :call s:HgDiff('%:p', 0, <f-args>)")
de588a4bca10 Fixed completely wrong code that somehow almost ran completely fine.
Ludovic Chabant <ludovic@chabant.com>
parents: 25
diff changeset
608 call s:AddMainCommand("-nargs=* -complete=customlist,s:ListRepoFiles Hgvdiff :call s:HgDiff('%:p', 1, <f-args>)")
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
609
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
610 " }}}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
611
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
612 " Hgcommit {{{
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
613
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
614 function! s:HgCommit(bang, vertical) abort
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
615 " Get the repo we'll be committing into.
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
616 let l:repo = s:hg_repo()
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
617
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
618 " Open a commit message file.
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
619 let l:commit_path = s:tempname('hg-editor-', '.txt')
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
620 let l:split = a:vertical ? 'vsplit' : 'split'
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
621 execute l:split . ' ' . l:commit_path
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
622 call append(0, ['', ''])
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
623 call append(2, split(s:HgCommit_GenerateMessage(l:repo), '\n'))
28
0cdfdab43907 `Hgcommit` now puts the cursor at the beginning of the commit message.
Ludovic Chabant <ludovic@chabant.com>
parents: 27
diff changeset
624 call cursor(1, 1)
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
625
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
626 " Setup the auto-command that will actually commit on write/exit,
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
627 " and make the buffer delete itself on exit.
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
628 let b:mercurial_dir = l:repo.root_dir
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
629 setlocal bufhidden=delete
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
630 setlocal syntax=hgcommit
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
631 if a:bang
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
632 autocmd BufDelete <buffer> call s:HgCommit_Execute(expand('<afile>:p'), 0)
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
633 else
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
634 autocmd BufDelete <buffer> call s:HgCommit_Execute(expand('<afile>:p'), 1)
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
635 endif
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
636 endfunction
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
637
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
638 let s:hg_status_messages = {
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
639 \'M': 'modified',
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
640 \'A': 'added',
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
641 \'R': 'removed',
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
642 \'C': 'clean',
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
643 \'!': 'missing',
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
644 \'?': 'not tracked',
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
645 \'I': 'ignored',
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
646 \' ': '',
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
647 \}
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
648
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
649 function! s:HgCommit_GenerateMessage(repo) abort
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
650 let l:msg = "HG: Enter commit message. Lines beginning with 'HG:' are removed.\n"
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
651 let l:msg .= "HG: Leave message empty to abort commit.\n"
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
652 let l:msg .= "HG: Write and quit buffer to proceed.\n"
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
653 let l:msg .= "HG: --\n"
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
654 let l:msg .= "HG: user: " . split(a:repo.RunCommand('showconfig ui.username'), '\n')[0] . "\n"
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
655 let l:msg .= "HG: branch '" . split(a:repo.RunCommand('branch'), '\n')[0] . "'\n"
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
656
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
657 let l:status_lines = split(a:repo.RunCommand('status'), "\n")
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
658 for l:line in l:status_lines
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
659 if l:line ==# ''
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
660 continue
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
661 endif
11
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
662 let l:type = matchstr(l:line, '\v^[MARC\!\?I ]')
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
663 let l:path = l:line[2:]
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
664 let l:msg .= "HG: " . s:hg_status_messages[l:type] . ' ' . l:path . "\n"
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
665 endfor
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
666
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
667 return l:msg
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
668 endfunction
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
669
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
670 function! s:HgCommit_Execute(log_file, show_output) abort
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
671 " Check if the user actually saved a commit message.
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
672 if !filereadable(a:log_file)
18
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
673 call s:error("abort: Commit message not saved")
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
674 return
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
675 endif
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
676
12
a7bf37a97a1b Clean the 'HG:' lines from the commit message (apparently 'hg commit' doesn't do it with -o).
Ludovic Chabant <ludovic@chabant.com>
parents: 11
diff changeset
677 call s:trace("Committing with log file: " . a:log_file)
a7bf37a97a1b Clean the 'HG:' lines from the commit message (apparently 'hg commit' doesn't do it with -o).
Ludovic Chabant <ludovic@chabant.com>
parents: 11
diff changeset
678
18
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
679 " Clean up all the 'HG:' lines from the commit message, and see if there's
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
680 " any message left (Mercurial does this automatically, usually, but
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
681 " apparently not when you feed it a log file...).
12
a7bf37a97a1b Clean the 'HG:' lines from the commit message (apparently 'hg commit' doesn't do it with -o).
Ludovic Chabant <ludovic@chabant.com>
parents: 11
diff changeset
682 let l:lines = readfile(a:log_file)
a7bf37a97a1b Clean the 'HG:' lines from the commit message (apparently 'hg commit' doesn't do it with -o).
Ludovic Chabant <ludovic@chabant.com>
parents: 11
diff changeset
683 call filter(l:lines, "v:val !~# '\\v^HG:'")
18
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
684 if len(filter(copy(l:lines), "v:val !~# '\\v^\\s*$'")) == 0
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
685 call s:error("abort: Empty commit message")
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
686 return
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
687 endif
12
a7bf37a97a1b Clean the 'HG:' lines from the commit message (apparently 'hg commit' doesn't do it with -o).
Ludovic Chabant <ludovic@chabant.com>
parents: 11
diff changeset
688 call writefile(l:lines, a:log_file)
a7bf37a97a1b Clean the 'HG:' lines from the commit message (apparently 'hg commit' doesn't do it with -o).
Ludovic Chabant <ludovic@chabant.com>
parents: 11
diff changeset
689
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
690 " Get the repo and commit with the given message.
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
691 let l:repo = s:hg_repo()
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
692 let l:output = l:repo.RunCommand('commit', '-l', a:log_file)
16
724f6db3baa2 Don't show `hg commit` output if there's nothing to show.
Ludovic Chabant <ludovic@chabant.com>
parents: 15
diff changeset
693 if a:show_output && l:output !~# '\v%^\s*%$'
724f6db3baa2 Don't show `hg commit` output if there's nothing to show.
Ludovic Chabant <ludovic@chabant.com>
parents: 15
diff changeset
694 call s:trace("Output from hg commit:", 1)
17
5c6c605d0660 Better output for `hg commit`.
Ludovic Chabant <ludovic@chabant.com>
parents: 16
diff changeset
695 for l:output_line in split(l:output, '\n')
5c6c605d0660 Better output for `hg commit`.
Ludovic Chabant <ludovic@chabant.com>
parents: 16
diff changeset
696 echom l:output_line
5c6c605d0660 Better output for `hg commit`.
Ludovic Chabant <ludovic@chabant.com>
parents: 16
diff changeset
697 endfor
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
698 endif
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
699 endfunction
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
700
26
de588a4bca10 Fixed completely wrong code that somehow almost ran completely fine.
Ludovic Chabant <ludovic@chabant.com>
parents: 25
diff changeset
701 call s:AddMainCommand("-bang Hgcommit :call s:HgCommit(<bang>0, 0)")
de588a4bca10 Fixed completely wrong code that somehow almost ran completely fine.
Ludovic Chabant <ludovic@chabant.com>
parents: 25
diff changeset
702 call s:AddMainCommand("-bang Hgvcommit :call s:HgCommit(<bang>0, 1)")
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
703
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
704 " }}}
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
705
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
706 " Autoload Functions {{{
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
707
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
708 " Prints a summary of the current repo (if any) that's appropriate for
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
709 " displaying on the status line.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
710 function! lawrencium#statusline(...)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
711 if !exists('b:mercurial_dir')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
712 return ''
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
713 endif
5
3a4f9f41a7e2 Use a hackish shortcut to get the current branch faster for the statusline.
Ludovic Chabant <ludovic@chabant.com>
parents: 4
diff changeset
714 let l:prefix = (a:0 > 0 ? a:1 : '')
3a4f9f41a7e2 Use a hackish shortcut to get the current branch faster for the statusline.
Ludovic Chabant <ludovic@chabant.com>
parents: 4
diff changeset
715 let l:suffix = (a:0 > 1 ? a:2 : '')
3a4f9f41a7e2 Use a hackish shortcut to get the current branch faster for the statusline.
Ludovic Chabant <ludovic@chabant.com>
parents: 4
diff changeset
716 let l:branch_file = s:hg_repo().GetFullPath('.hg/branch')
3a4f9f41a7e2 Use a hackish shortcut to get the current branch faster for the statusline.
Ludovic Chabant <ludovic@chabant.com>
parents: 4
diff changeset
717 let l:branch = readfile(l:branch_file)[0]
3a4f9f41a7e2 Use a hackish shortcut to get the current branch faster for the statusline.
Ludovic Chabant <ludovic@chabant.com>
parents: 4
diff changeset
718 return l:prefix . l:branch . l:suffix
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
719 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
720
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
721 " Rescans the current buffer for setting up Mercurial commands.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
722 " Passing '1' as the parameter enables debug traces temporarily.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
723 function! lawrencium#rescan(...)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
724 if exists('b:mercurial_dir')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
725 unlet b:mercurial_dir
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
726 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
727 if a:0 && a:1
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
728 let l:trace_backup = g:lawrencium_trace
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
729 let g:lawrencium_trace = 1
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
730 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
731 call s:setup_buffer_commands()
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
732 if a:0 && a:1
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
733 let g:lawrencium_trace = l:trace_backup
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
734 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
735 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
736
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
737 " Enables/disables the debug trace.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
738 function! lawrencium#debugtrace(...)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
739 let g:lawrencium_trace = (a:0 == 0 || (a:0 && a:1))
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
740 echom "Lawrencium debug trace is now " . (g:lawrencium_trace ? "enabled." : "disabled.")
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
741 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
742
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
743 " }}}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
744