annotate plugin/lawrencium.vim @ 47:edc43c59b3b8

avoid conflicts with plugins like minibufexplorer that might open a buffer when a new one is created
author Sylvain Soliman <Sylvain.Soliman@m4x.org>
date Sun, 04 Nov 2012 16:13:23 +0100
parents ea0ae8f6af81
children 85e39bdd7089
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
43
fc20a265551d Added auto cd'ing into the repo root for `:Hg`.
Ludovic Chabant <ludovic@chabant.com>
parents: 41
diff changeset
23 if !exists('g:lawrencium_auto_cd')
fc20a265551d Added auto cd'ing into the repo root for `:Hg`.
Ludovic Chabant <ludovic@chabant.com>
parents: 41
diff changeset
24 let g:lawrencium_auto_cd = 1
fc20a265551d Added auto cd'ing into the repo root for `:Hg`.
Ludovic Chabant <ludovic@chabant.com>
parents: 41
diff changeset
25 endif
fc20a265551d Added auto cd'ing into the repo root for `:Hg`.
Ludovic Chabant <ludovic@chabant.com>
parents: 41
diff changeset
26
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
27 if !exists('g:lawrencium_trace')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
28 let g:lawrencium_trace = 0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
29 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
30
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
31 if !exists('g:lawrencium_define_mappings')
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
32 let g:lawrencium_define_mappings = 1
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
33 endif
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
34
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35 " }}}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37 " Utility {{{
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
38
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
39 " Strips the ending slash in a path.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
40 function! s:stripslash(path)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
41 return fnamemodify(a:path, ':s?[/\\]$??')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
42 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
43
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
44 " Normalizes the slashes in a path.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
45 function! s:normalizepath(path)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
46 if exists('+shellslash') && &shellslash
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
47 return substitute(a:path, '\\', '/', '')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
48 elseif has('win32')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
49 return substitute(a:path, '/', '\\', '')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
50 else
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
51 return a:path
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
52 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
53 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
54
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
55 " 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
56 function! s:tempname(name, ...)
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
57 let l:path = tempname()
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
58 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
59 if a:0 > 0
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
60 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
61 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
62 return l:result
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
63 endfunction
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
64
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
65 " Delete a temporary file if it exists.
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
66 function! s:clean_tempfile(path)
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
67 if filewritable(a:path)
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
68 call s:trace("Cleaning up temporary file: " . a:path)
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
69 call delete(a:path)
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
70 endif
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
71 endfunction
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
72
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
73 " Prints a message if debug tracing is enabled.
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
74 function! s:trace(message, ...)
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
75 if g:lawrencium_trace || (a:0 && a:1)
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
76 let l:message = "lawrencium: " . a:message
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
77 echom l:message
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
78 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
79 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
80
18
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
81 " 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
82 function! s:error(message)
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
83 echom "lawrencium error: " . a:message
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
84 endfunction
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
85
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
86 " Throw a Lawrencium exception message.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
87 function! s:throw(message)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
88 let v:errmsg = "lawrencium: " . a:message
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
89 throw v:errmsg
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
90 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
91
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
92 " Finds the repository root given a path inside that repository.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
93 " Throw an error if not repository is found.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
94 function! s:find_repo_root(path)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
95 let l:path = s:stripslash(a:path)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
96 let l:previous_path = ""
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
97 while l:path != l:previous_path
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
98 if isdirectory(l:path . '/.hg/store')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
99 return simplify(fnamemodify(l:path, ':p'))
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
100 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
101 let l:previous_path = l:path
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
102 let l:path = fnamemodify(l:path, ':h')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
103 endwhile
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
104 call s:throw("No Mercurial repository found above: " . a:path)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
105 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
106
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
107 " Given a Lawrencium path (e.g: 'lawrencium:///repo/root_dir@foo/bar/file.py//34'), extract
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
108 " the repository root, relative file path and revision number/changeset ID.
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
109 function! s:parse_lawrencium_path(lawrencium_path)
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
110 let l:repo_path = a:lawrencium_path
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
111 if l:repo_path =~? '^lawrencium://'
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
112 let l:repo_path = strpart(l:repo_path, strlen('lawrencium://'))
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
113 endif
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
114
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
115 let l:root_dir = ''
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
116 let l:at_idx = stridx(l:repo_path, '@')
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
117 if l:at_idx >= 0
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
118 let l:root_dir = strpart(l:repo_path, 0, l:at_idx)
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
119 let l:repo_path = strpart(l:repo_path, l:at_idx + 1)
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
120 endif
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
121
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
122 let l:rev = matchstr(l:repo_path, '\v//[0-9a-f]+$')
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
123 if l:rev !=? ''
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
124 let l:repo_path = strpart(l:repo_path, 0, strlen(l:repo_path) - strlen(l:rev))
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
125 let l:rev = strpart(l:rev, 2)
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
126 endif
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
127
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
128 let l:result = { 'root': l:root_dir, 'path': l:repo_path, 'rev': l:rev }
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
129 return l:result
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
130 endfunction
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
131
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
132 " }}}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
133
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
134 " Mercurial Repository {{{
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
135
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
136 " Let's define a Mercurial repo 'class' using prototype-based object-oriented
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
137 " programming.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
138 "
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
139 " The prototype dictionary.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
140 let s:HgRepo = {}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
141
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
142 " Constructor.
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
143 function! s:HgRepo.New(path) abort
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
144 let l:newRepo = copy(self)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
145 let l:newRepo.root_dir = s:find_repo_root(a:path)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
146 call s:trace("Built new Mercurial repository object at : " . l:newRepo.root_dir)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
147 return l:newRepo
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
148 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
149
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
150 " Gets a full path given a repo-relative path.
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
151 function! s:HgRepo.GetFullPath(path) abort
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
152 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
153 if a:path =~# '\v^[/\\]'
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
154 let l:root_dir = s:stripslash(l:root_dir)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
155 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
156 return l:root_dir . a:path
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
157 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
158
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
159 " Gets a list of files matching a root-relative pattern.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
160 " 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
161 " directories.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
162 function! s:HgRepo.Glob(pattern, ...) abort
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
163 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
164 if (a:pattern =~# '\v^[/\\]')
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
165 let l:root_dir = s:stripslash(l:root_dir)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
166 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
167 let l:matches = split(glob(l:root_dir . a:pattern), '\n')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
168 if a:0 && a:1
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
169 for l:idx in range(len(l:matches))
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
170 if !filereadable(l:matches[l:idx])
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
171 let l:matches[l:idx] = l:matches[l:idx] . '/'
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
172 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
173 endfor
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
174 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
175 let l:strip_len = len(l:root_dir)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
176 call map(l:matches, 'v:val[l:strip_len : -1]')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
177 return l:matches
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
178 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
179
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
180 " Gets a full Mercurial command.
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
181 function! s:HgRepo.GetCommand(command, ...) abort
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
182 " If there's only one argument, and it's a list, then use that as the
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
183 " argument list.
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
184 let l:arg_list = a:000
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
185 if a:0 == 1 && type(a:1) == type([])
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
186 let l:arg_list = a:1
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
187 endif
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
188 let l:hg_command = g:lawrencium_hg_executable . ' --repository ' . shellescape(s:stripslash(self.root_dir))
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
189 let l:hg_command = l:hg_command . ' ' . a:command . ' ' . join(l:arg_list, ' ')
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
190 return l:hg_command
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
191 endfunction
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
192
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
193 " Runs a Mercurial command in the repo.
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
194 function! s:HgRepo.RunCommand(command, ...) abort
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
195 let l:all_args = [a:command] + a:000
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
196 let l:hg_command = call(self['GetCommand'], l:all_args, self)
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
197 call s:trace("Running Mercurial command: " . l:hg_command)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
198 return system(l:hg_command)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
199 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
200
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
201 " Repo cache map.
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
202 let s:buffer_repos = {}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
203
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
204 " Get a cached repo.
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
205 function! s:hg_repo(...) abort
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
206 " Use the given path, or the mercurial directory of the current buffer.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
207 if a:0 == 0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
208 if exists('b:mercurial_dir')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
209 let l:path = b:mercurial_dir
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
210 else
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
211 let l:path = s:find_repo_root(expand('%:p'))
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
212 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
213 else
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
214 let l:path = a:1
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
215 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
216 " Find a cache repo instance, or make a new one.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
217 if has_key(s:buffer_repos, l:path)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
218 return get(s:buffer_repos, l:path)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
219 else
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
220 let l:repo = s:HgRepo.New(l:path)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
221 let s:buffer_repos[l:path] = l:repo
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
222 return l:repo
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
223 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
224 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
225
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
226 " 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
227 " If the file is not in a Mercurial repo, just exit silently.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
228 function! s:setup_buffer_commands() abort
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
229 call s:trace("Scanning buffer '" . bufname('%') . "' for Lawrencium setup...")
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
230 let l:do_setup = 1
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
231 if exists('b:mercurial_dir')
11
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
232 if b:mercurial_dir =~# '\v^\s*$'
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
233 unlet b:mercurial_dir
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
234 else
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
235 let l:do_setup = 0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
236 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
237 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
238 try
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
239 let l:repo = s:hg_repo()
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
240 catch /^lawrencium\:/
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
241 return
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
242 endtry
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
243 let b:mercurial_dir = l:repo.root_dir
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
244 if exists('b:mercurial_dir') && l:do_setup
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
245 call s:trace("Setting Mercurial commands for buffer '" . bufname('%'))
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
246 call s:trace(" with repo : " . expand(b:mercurial_dir))
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
247 silent doautocmd User Lawrencium
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
248 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
249 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
250
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
251 augroup lawrencium_detect
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
252 autocmd!
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
253 autocmd BufNewFile,BufReadPost * call s:setup_buffer_commands()
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
254 autocmd VimEnter * if expand('<amatch>')==''|call s:setup_buffer_commands()|endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
255 augroup end
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
256
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
257 " }}}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
258
14
eab2680e6818 Better fold sections.
Ludovic Chabant <ludovic@chabant.com>
parents: 12
diff changeset
259 " Buffer Commands Management {{{
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
260
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
261 " 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
262 " batch when we need to.
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
263 let s:main_commands = []
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
264
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
265 function! s:AddMainCommand(command) abort
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
266 let s:main_commands += [a:command]
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
267 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
268
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
269 function! s:DefineMainCommands()
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
270 for l:command in s:main_commands
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
271 execute 'command! -buffer ' . l:command
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
272 endfor
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
273 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
274
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
275 augroup lawrencium_main
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
276 autocmd!
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
277 autocmd User Lawrencium call s:DefineMainCommands()
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
278 augroup end
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
279
14
eab2680e6818 Better fold sections.
Ludovic Chabant <ludovic@chabant.com>
parents: 12
diff changeset
280 " }}}
eab2680e6818 Better fold sections.
Ludovic Chabant <ludovic@chabant.com>
parents: 12
diff changeset
281
eab2680e6818 Better fold sections.
Ludovic Chabant <ludovic@chabant.com>
parents: 12
diff changeset
282 " Commands Auto-Complete {{{
eab2680e6818 Better fold sections.
Ludovic Chabant <ludovic@chabant.com>
parents: 12
diff changeset
283
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
284 " 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
285 function! s:ListRepoFiles(ArgLead, CmdLine, CursorPos) abort
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
286 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
287 call map(l:matches, 's:normalizepath(v:val)')
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
288 return l:matches
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
289 endfunction
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
290
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
291 " 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
292 function! s:ListRepoDirs(ArgLead, CmdLine, CursorPos) abort
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
293 let l:matches = s:hg_repo().Glob(a:ArgLead . '*/')
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
294 call map(l:matches, 's:normalizepath(v:val)')
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
295 return l:matches
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
296 endfunction
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
297
14
eab2680e6818 Better fold sections.
Ludovic Chabant <ludovic@chabant.com>
parents: 12
diff changeset
298 " }}}
eab2680e6818 Better fold sections.
Ludovic Chabant <ludovic@chabant.com>
parents: 12
diff changeset
299
4
b6e4446ed292 HgStatus now outputs to the location window.
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
300 " Hg {{{
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
301
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
302 function! s:Hg(bang, ...) abort
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
303 let l:repo = s:hg_repo()
44
95f8e7cb5ca2 Stop fucking with my brain, Python.
Ludovic Chabant <ludovic@chabant.com>
parents: 43
diff changeset
304 if g:lawrencium_auto_cd
43
fc20a265551d Added auto cd'ing into the repo root for `:Hg`.
Ludovic Chabant <ludovic@chabant.com>
parents: 41
diff changeset
305 " Temporary set the current directory to the root of the repo
fc20a265551d Added auto cd'ing into the repo root for `:Hg`.
Ludovic Chabant <ludovic@chabant.com>
parents: 41
diff changeset
306 " to make auto-completed paths work magically.
fc20a265551d Added auto cd'ing into the repo root for `:Hg`.
Ludovic Chabant <ludovic@chabant.com>
parents: 41
diff changeset
307 execute 'cd! ' . l:repo.root_dir
fc20a265551d Added auto cd'ing into the repo root for `:Hg`.
Ludovic Chabant <ludovic@chabant.com>
parents: 41
diff changeset
308 endif
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
309 let l:output = call(l:repo.RunCommand, a:000, l:repo)
44
95f8e7cb5ca2 Stop fucking with my brain, Python.
Ludovic Chabant <ludovic@chabant.com>
parents: 43
diff changeset
310 if g:lawrencium_auto_cd
43
fc20a265551d Added auto cd'ing into the repo root for `:Hg`.
Ludovic Chabant <ludovic@chabant.com>
parents: 41
diff changeset
311 execute 'cd! -'
fc20a265551d Added auto cd'ing into the repo root for `:Hg`.
Ludovic Chabant <ludovic@chabant.com>
parents: 41
diff changeset
312 endif
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
313 if a:bang
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
314 " 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
315 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
316 execute 'pedit ' . l:temp_file
47
edc43c59b3b8 avoid conflicts with plugins like minibufexplorer that might open a buffer when a new one is created
Sylvain Soliman <Sylvain.Soliman@m4x.org>
parents: 45
diff changeset
317 wincmd P
21
d0acefc1ec9a Fixed multi-line output of `:Hg`.
Ludovic Chabant <ludovic@chabant.com>
parents: 18
diff changeset
318 call append(0, split(l:output, '\n'))
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
319 else
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
320 " Just print out the output of the command.
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
321 echo l:output
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
322 endif
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
323 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
324
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
325 " 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
326 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
327 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
328 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
329 else
18
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
330 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
331 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
332
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
333 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
334 " 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
335 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
336 return []
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
337 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
338
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
339 " 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
340 " Gotta find out why...
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
341 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
342 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
343 let l:arglead = '-'
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
344 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
345
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
346 " 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
347 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
348 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
349 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
350
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
351 " 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
352 " the command name).
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
353 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
354 echom " - matched command"
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
355 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
356 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
357
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
358 " 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
359 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
360 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
361 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
362 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
363 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
364 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
365 " 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
366 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
367 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
368 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
369 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
370 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
371
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
372 " 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
373 if l:arglead[0] ==# '-'
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
374 return []
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
375 else
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
376 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
377 endfunction
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
378
26
de588a4bca10 Fixed completely wrong code that somehow almost ran completely fine.
Ludovic Chabant <ludovic@chabant.com>
parents: 25
diff changeset
379 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
380
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
381 " }}}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
382
4
b6e4446ed292 HgStatus now outputs to the location window.
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
383 " Hgstatus {{{
b6e4446ed292 HgStatus now outputs to the location window.
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
384
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
385 function! s:HgStatus() abort
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
386 " 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
387 let l:repo = s:hg_repo()
b6e4446ed292 HgStatus now outputs to the location window.
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
388 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
389 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
390 echo "Nothing modified."
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
391 endif
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
392
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
393 " 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
394 " 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
395 let l:temp_file = s:tempname('hg-status-', '.txt')
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
396 let l:preview_height = &previewheight
11
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
397 let l:status_lines = split(l:status_text, '\n')
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
398 execute "setlocal previewheight=" . (len(l:status_lines) + 1)
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
399 execute "pedit " . l:temp_file
47
edc43c59b3b8 avoid conflicts with plugins like minibufexplorer that might open a buffer when a new one is created
Sylvain Soliman <Sylvain.Soliman@m4x.org>
parents: 45
diff changeset
400 wincmd P
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
401 call append(0, l:status_lines)
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
402 call cursor(1, 1)
11
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
403 " Make it a nice size.
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
404 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
405 " 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
406 setlocal bufhidden=delete
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
407
7
adc267e2f0f4 Added syntax highlighting for hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 6
diff changeset
408 " 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
409 " to it.
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
410 let b:mercurial_dir = l:repo.root_dir
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
411 setlocal buftype=nofile
7
adc267e2f0f4 Added syntax highlighting for hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 6
diff changeset
412 setlocal syntax=hgstatus
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
413
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
414 " Make commands available.
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
415 call s:DefineMainCommands()
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
416
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
417 " Add some nice commands.
33
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
418 command! -buffer Hgstatusedit :call s:HgStatus_FileEdit()
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
419 command! -buffer Hgstatusdiff :call s:HgStatus_Diff(0)
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
420 command! -buffer Hgstatusvdiff :call s:HgStatus_Diff(1)
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
421 command! -buffer Hgstatusrefresh :call s:HgStatus_Refresh()
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
422 command! -buffer -range Hgstatusaddremove :call s:HgStatus_AddRemove(<line1>, <line2>)
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
423 command! -buffer -range=% -bang Hgstatuscommit :call s:HgStatus_Commit(<line1>, <line2>, <bang>0, 0)
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
424 command! -buffer -range=% -bang Hgstatusvcommit :call s:HgStatus_Commit(<line1>, <line2>, <bang>0, 1)
40
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
425 command! -buffer -range=% -nargs=+ Hgstatusqnew :call s:HgStatus_QNew(<line1>, <line2>, <f-args>)
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
426 command! -buffer -range=% Hgstatusqrefresh :call s:HgStatus_QRefresh(<line1>, <line2>)
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
427
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
428 " Add some handy mappings.
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
429 if g:lawrencium_define_mappings
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
430 nnoremap <buffer> <silent> <cr> :Hgstatusedit<cr>
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
431 nnoremap <buffer> <silent> <C-N> :call search('^[MARC\!\?I ]\s.', 'We')<cr>
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
432 nnoremap <buffer> <silent> <C-P> :call search('^[MARC\!\?I ]\s.', 'Wbe')<cr>
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
433 nnoremap <buffer> <silent> <C-D> :Hgstatusdiff<cr>
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
434 nnoremap <buffer> <silent> <C-V> :Hgstatusvdiff<cr>
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
435 nnoremap <buffer> <silent> <C-A> :Hgstatusaddremove<cr>
33
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
436 nnoremap <buffer> <silent> <C-S> :Hgstatuscommit<cr>
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
437 nnoremap <buffer> <silent> <C-R> :Hgstatusrefresh<cr>
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
438 nnoremap <buffer> <silent> q :bdelete!<cr>
33
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
439
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
440 vnoremap <buffer> <silent> <C-A> :Hgstatusaddremove<cr>
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
441 vnoremap <buffer> <silent> <C-S> :Hgstatuscommit<cr>
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
442 endif
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
443
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
444 " Make sure the file is deleted with the buffer.
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
445 autocmd BufDelete <buffer> call s:clean_tempfile(expand('<afile>:p'))
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
446 endfunction
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
447
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
448 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
449 " 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
450 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
451 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
452
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
453 " 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
454 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
455 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
456 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
457 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
458 edit
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
459 endfunction
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
460
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
461 function! s:HgStatus_FileEdit() abort
9
82a49134a85c Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 8
diff changeset
462 " Get the path of the file the cursor is on.
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
463 let l:filename = s:HgStatus_GetSelectedFile()
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
464
21a879a09f20 Trying to keep the cursor line when open an already opened file in `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents: 23
diff changeset
465 " 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
466 " 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
467 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
468 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
469 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
470 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
471 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
472 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
473 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
474 endfor
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
475 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
476 execute 'edit ' . l:filename
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
477 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
478
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
479 function! s:HgStatus_AddRemove(linestart, lineend) abort
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
480 " Get the selected filenames.
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
481 let l:filenames = s:HgStatus_GetSelectedFiles(a:linestart, a:lineend, ['!', '?'])
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
482 if len(l:filenames) == 0
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
483 call s:error("No files to add or remove in selection or current line.")
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
484 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
485
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
486 " Run `addremove` on those paths.
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
487 let l:repo = s:hg_repo()
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
488 call l:repo.RunCommand('addremove', l:filenames)
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
489
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
490 " Refresh the status window.
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
491 call s:HgStatus_Refresh()
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
492 endfunction
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
493
33
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
494 function! s:HgStatus_Commit(linestart, lineend, bang, vertical) abort
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
495 " Get the selected filenames.
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
496 let l:filenames = s:HgStatus_GetSelectedFiles(a:linestart, a:lineend, ['M', 'A', 'R'])
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
497 if len(l:filenames) == 0
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
498 call s:error("No files to commit in selection or file.")
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
499 endif
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
500
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
501 " Run `Hgcommit` on those paths.
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
502 call s:HgCommit(a:bang, a:vertical, l:filenames)
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
503 endfunction
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
504
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
505 function! s:HgStatus_Diff(vertical) abort
25
0e952b7c79d7 Fixed a bug with opening a diff from `Hgstatus`
Ludovic Chabant <ludovic@chabant.com>
parents: 24
diff changeset
506 " 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
507 call s:HgStatus_FileEdit()
0e952b7c79d7 Fixed a bug with opening a diff from `Hgstatus`
Ludovic Chabant <ludovic@chabant.com>
parents: 24
diff changeset
508 call s:HgDiff('%:p', a:vertical)
9
82a49134a85c Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 8
diff changeset
509 endfunction
82a49134a85c Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 8
diff changeset
510
40
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
511 function! s:HgStatus_QNew(linestart, lineend, patchname, ...) abort
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
512 " Get the selected filenames.
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
513 let l:filenames = s:HgStatus_GetSelectedFiles(a:linestart, a:lineend, ['M', 'A', 'R'])
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
514 if len(l:filenames) == 0
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
515 call s:error("No files in selection or file to create patch.")
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
516 endif
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
517
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
518 " Run `Hg qnew` on those paths.
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
519 let l:repo = s:hg_repo()
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
520 call insert(l:filenames, a:patchname, 0)
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
521 if a:0 > 0
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
522 call insert(l:filenames, '-m', 0)
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
523 let l:message = '"' . join(a:000, ' ') . '"'
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
524 call insert(l:filenames, l:message, 1)
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
525 endif
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
526 call l:repo.RunCommand('qnew', l:filenames)
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
527 endfunction
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
528
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
529 function! s:HgStatus_QRefresh(linestart, lineend) abort
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
530 " Get the selected filenames.
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
531 let l:filenames = s:HgStatus_GetSelectedFiles(a:linestart, a:lineend, ['M', 'A', 'R'])
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
532 if len(l:filenames) == 0
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
533 call s:error("No files in selection or file to refresh the patch.")
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
534 endif
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
535
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
536 " Run `Hg qrefresh` on those paths.
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
537 let l:repo = s:hg_repo()
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
538 call insert(l:filenames, '-s', 0)
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
539 call l:repo.RunCommand('qrefresh', l:filenames)
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
540 endfunction
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
541
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
542
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
543 function! s:HgStatus_GetSelectedFile() abort
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
544 let l:filenames = s:HgStatus_GetSelectedFiles()
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
545 return l:filenames[0]
9
82a49134a85c Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 8
diff changeset
546 endfunction
82a49134a85c Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 8
diff changeset
547
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
548 function! s:HgStatus_GetSelectedFiles(...) abort
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
549 if a:0 >= 2
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
550 let l:lines = getline(a:1, a:2)
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
551 else
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
552 let l:lines = []
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
553 call add(l:lines, getline('.'))
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
554 endif
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
555 let l:filenames = []
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
556 let l:repo = s:hg_repo()
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
557 for line in l:lines
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
558 if a:0 >= 3
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
559 let l:status = s:HgStatus_GetFileStatus(line)
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
560 if index(a:3, l:status) < 0
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
561 continue
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
562 endif
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
563 endif
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
564 " Yay, awesome, Vim's regex syntax is fucked up like shit, especially for
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
565 " look-aheads and look-behinds. See for yourself:
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
566 let l:filename = matchstr(l:line, '\v(^[MARC\!\?I ]\s)@<=.*')
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
567 let l:filename = l:repo.GetFullPath(l:filename)
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
568 call add(l:filenames, l:filename)
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
569 endfor
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
570 return l:filenames
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
571 endfunction
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
572
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
573 function! s:HgStatus_GetFileStatus(...) abort
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
574 let l:line = a:0 ? a:1 : getline('.')
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
575 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
576 endfunction
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
577
26
de588a4bca10 Fixed completely wrong code that somehow almost ran completely fine.
Ludovic Chabant <ludovic@chabant.com>
parents: 25
diff changeset
578 call s:AddMainCommand("Hgstatus :call s:HgStatus()")
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
579
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
580 " }}}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
581
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
582 " Hgcd, Hglcd {{{
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
583
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
584 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
585 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
586
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
587 " }}}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
588
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
589 " Hgedit {{{
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
590
27
09115be355e2 Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents: 26
diff changeset
591 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
592 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
593 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
594 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
595 else
09115be355e2 Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents: 26
diff changeset
596 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
597 endif
09115be355e2 Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents: 26
diff changeset
598 endfunction
09115be355e2 Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents: 26
diff changeset
599
09115be355e2 Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents: 26
diff changeset
600 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
601
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
602 " }}}
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
603
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
604 " Hgdiff {{{
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
605
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
606 function! s:HgDiff(filename, vertical, ...) abort
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
607 " Default revisions to diff: the working directory (special Lawrencium
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
608 " 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
609 " Mercurial's revsets syntax).
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
610 let l:rev1 = 'lawrencium#_wdir_'
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
611 let l:rev2 = 'p1()'
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
612 if a:0 == 1
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
613 let l:rev2 = a:1
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
614 elseif a:0 == 2
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
615 let l:rev1 = a:1
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
616 let l:rev2 = a:2
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
617 endif
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
618
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
619 " 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
620 " fancy filename modifiers.
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
621 let l:repo = s:hg_repo()
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
622 let l:path = expand(a:filename)
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
623 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
624
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
625 " 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
626 " others' 'diff' flag is turned off.
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
627 let l:diff_buffers = []
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
628
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
629 " Get the first file and open it.
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
630 if l:rev1 == 'lawrencium#_wdir_'
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
631 if bufexists(l:path)
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
632 execute 'buffer ' . fnameescape(l:path)
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
633 else
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
634 execute 'edit ' . fnameescape(l:path)
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
635 endif
11
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
636 " 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
637 call s:HgDiff_DiffThis()
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
638 else
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
639 let l:temp_file = tempname()
41
decbefcf74db Fixed problems with spaces in paths (thanks to @lllama).
Ludovic Chabant <ludovic@chabant.com>
parents: 40
diff changeset
640 call l:repo.RunCommand('cat', '-r', '"'.l:rev1.'"', '-o', '"'.l:temp_file.'"', '"'.l:path.'"')
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
641 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
642 " 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
643 call s:HgDiff_DiffThis()
11
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
644 " Remember the repo it belongs to.
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
645 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
646 " 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
647 setlocal bufhidden=delete
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
648 " Make commands available.
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
649 call s:DefineMainCommands()
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
650 endif
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
651
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
652 " Get the second file and open it too.
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
653 let l:diffsplit = 'diffsplit'
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
654 if a:vertical
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
655 let l:diffsplit = 'vertical diffsplit'
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
656 endif
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
657 if l:rev2 == 'lawrencium#_wdir_'
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
658 execute l:diffsplit . ' ' . fnameescape(l:path)
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
659 else
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
660 let l:temp_file = tempname()
41
decbefcf74db Fixed problems with spaces in paths (thanks to @lllama).
Ludovic Chabant <ludovic@chabant.com>
parents: 40
diff changeset
661 call l:repo.RunCommand('cat', '-r', '"'.l:rev2.'"', '-o', '"'.l:temp_file.'"', '"'.l:path.'"')
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
662 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
663 " Remember the repo it belongs to.
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
664 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
665 " 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
666 setlocal bufhidden=delete
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
667 " Make commands available.
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
668 call s:DefineMainCommands()
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
669 endif
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
670 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
671
23
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
672 function! s:HgDiff_DiffThis() abort
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
673 " 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
674 " 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
675 " 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
676 if !&diff
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
677 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
678 let w:lawrencium_diffoff = {}
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
679 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
680 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
681 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
682 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
683 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
684 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
685 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
686 diffthis
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
687 endif
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
688 endfunction
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
689
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
690 function! s:HgDiff_DiffOff(...) abort
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
691 " 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
692 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
693
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
694 " 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
695 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
696 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
697 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
698 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
699 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
700 endfor
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
701 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
702 else
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
703 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
704 diffoff
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
705 endif
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
706 endfunction
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
707
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
708 function! s:HgDiff_GetDiffWindows() abort
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
709 let l:result = []
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
710 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
711 if getwinvar(nr, '&diff')
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
712 call add(l:result, nr)
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
713 endif
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
714 endfor
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
715 return l:result
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
716 endfunction
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
717
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
718 function! s:HgDiff_CleanUp() abort
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
719 " 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
720 if !&diff
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
721 return
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
722 endif
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
723
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
724 " 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
725 " turn off diff everywhere.
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
726 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
727 if len(l:nrs) <= 2
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
728 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
729 for nr in l:nrs
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
730 if getwinvar(nr, '&diff')
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
731 call s:HgDiff_DiffOff(nr)
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
732 endif
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
733 endfor
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
734 else
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
735 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
736 endif
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
737 endfunction
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
738
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
739 augroup lawrencium_diff
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
740 autocmd!
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
741 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
742 augroup end
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
743
26
de588a4bca10 Fixed completely wrong code that somehow almost ran completely fine.
Ludovic Chabant <ludovic@chabant.com>
parents: 25
diff changeset
744 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
745 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
746
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
747 " }}}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
748
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
749 " Hgcommit {{{
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
750
33
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
751 function! s:HgCommit(bang, vertical, ...) abort
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
752 " 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
753 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
754
33
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
755 " Get the list of files to commit.
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
756 " It can either be several files passed as extra parameters, or an
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
757 " actual list passed as the first extra parameter.
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
758 let l:filenames = []
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
759 if a:0
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
760 let l:filenames = a:000
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
761 if a:0 == 1 && type(a:1) == type([])
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
762 let l:filenames = a:1
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
763 endif
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
764 endif
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
765
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
766 " 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
767 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
768 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
769 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
770 call append(0, ['', ''])
33
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
771 call append(2, split(s:HgCommit_GenerateMessage(l:repo, l:filenames), '\n'))
28
0cdfdab43907 `Hgcommit` now puts the cursor at the beginning of the commit message.
Ludovic Chabant <ludovic@chabant.com>
parents: 27
diff changeset
772 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
773
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
774 " 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
775 " 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
776 let b:mercurial_dir = l:repo.root_dir
33
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
777 let b:lawrencium_commit_files = l:filenames
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
778 setlocal bufhidden=delete
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
779 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
780 if a:bang
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
781 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
782 else
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
783 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
784 endif
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
785 " Make commands available.
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
786 call s:DefineMainCommands()
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
787 endfunction
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
788
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
789 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
790 \'M': 'modified',
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
791 \'A': 'added',
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
792 \'R': 'removed',
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
793 \'C': 'clean',
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
794 \'!': 'missing',
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
795 \'?': 'not tracked',
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
796 \'I': 'ignored',
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
797 \' ': '',
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
798 \}
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
799
33
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
800 function! s:HgCommit_GenerateMessage(repo, filenames) abort
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
801 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
802 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
803 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
804 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
805 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
806 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
807
33
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
808 if len(a:filenames)
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
809 let l:status_lines = split(a:repo.RunCommand('status', a:filenames), "\n")
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
810 else
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
811 let l:status_lines = split(a:repo.RunCommand('status'), "\n")
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
812 endif
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
813 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
814 if l:line ==# ''
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
815 continue
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
816 endif
11
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
817 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
818 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
819 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
820 endfor
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
821
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
822 return l:msg
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
823 endfunction
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
824
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
825 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
826 " 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
827 if !filereadable(a:log_file)
18
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
828 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
829 return
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
830 endif
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
831
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
832 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
833
18
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
834 " 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
835 " 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
836 " 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
837 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
838 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
839 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
840 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
841 return
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
842 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
843 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
844
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
845 " 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
846 let l:repo = s:hg_repo()
33
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
847 let l:hg_args = ['-l', a:log_file]
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
848 call extend(l:hg_args, b:lawrencium_commit_files)
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
849 let l:output = l:repo.RunCommand('commit', l:hg_args)
16
724f6db3baa2 Don't show `hg commit` output if there's nothing to show.
Ludovic Chabant <ludovic@chabant.com>
parents: 15
diff changeset
850 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
851 call s:trace("Output from hg commit:", 1)
17
5c6c605d0660 Better output for `hg commit`.
Ludovic Chabant <ludovic@chabant.com>
parents: 16
diff changeset
852 for l:output_line in split(l:output, '\n')
5c6c605d0660 Better output for `hg commit`.
Ludovic Chabant <ludovic@chabant.com>
parents: 16
diff changeset
853 echom l:output_line
5c6c605d0660 Better output for `hg commit`.
Ludovic Chabant <ludovic@chabant.com>
parents: 16
diff changeset
854 endfor
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
855 endif
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
856 endfunction
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
857
33
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
858 call s:AddMainCommand("-bang -nargs=* -complete=customlist,s:ListRepoFiles Hgcommit :call s:HgCommit(<bang>0, 0, <f-args>)")
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
859 call s:AddMainCommand("-bang -nargs=* -complete=customlist,s:ListRepoFiles Hgvcommit :call s:HgCommit(<bang>0, 1, <f-args>)")
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
860
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
861 " }}}
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
862
37
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
863 " Hgrevert {{{
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
864
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
865 function! s:HgRevert(bang, ...) abort
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
866 " Get the files to revert.
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
867 let l:filenames = a:000
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
868 if a:0 == 0
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
869 let l:filenames = [ expand('%:p') ]
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
870 endif
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
871 if a:bang
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
872 call insert(l:filenames, '--no-backup', 0)
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
873 endif
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
874
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
875 " Get the repo and run the command.
37
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
876 let l:repo = s:hg_repo()
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
877 call l:repo.RunCommand('revert', l:filenames)
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
878 endfunction
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
879
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
880 call s:AddMainCommand("-bang -nargs=* -complete=customlist,s:ListRepoFiles Hgrevert :call s:HgRevert(<bang>0, <f-args>)")
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
881
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
882 " }}}
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
883
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
884 " Hglog {{{
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
885
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
886 function! s:HgLog(...) abort
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
887 let l:filepath = expand('%:p')
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
888 if a:0 == 1
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
889 let l:filepath = a:1
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
890 endif
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
891
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
892 " Get the repo and get the command.
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
893 let l:repo = s:hg_repo()
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
894 let l:log_command = l:repo.GetCommand('log', l:filepath, '--template', '"{rev}\t{desc|firstline}\n"')
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
895
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
896 " Open a new temp buffer in the preview window, jump to it,
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
897 " and paste the `hg log` output in there.
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
898 let l:temp_file = s:tempname('hg-log-', '.txt')
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
899 execute "pedit " . l:temp_file
47
edc43c59b3b8 avoid conflicts with plugins like minibufexplorer that might open a buffer when a new one is created
Sylvain Soliman <Sylvain.Soliman@m4x.org>
parents: 45
diff changeset
900 wincmd P
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
901 execute "read !" . escape(l:log_command, '%#\')
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
902
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
903 " Setup the buffer correctly: readonly, and with the correct repo linked
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
904 " to it, and deleted on close.
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
905 let b:mercurial_dir = l:repo.root_dir
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
906 let b:mercurial_logged_file = l:filepath
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
907 setlocal bufhidden=delete
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
908 setlocal buftype=nofile
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
909 setlocal syntax=hglog
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
910
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
911 " Make commands available.
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
912 call s:DefineMainCommands()
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
913
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
914 " Add some other nice commands and mappings.
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
915 command! -buffer -nargs=? Hglogrevedit :call s:HgLog_FileRevEdit(<f-args>)
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
916 if g:lawrencium_define_mappings
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
917 nnoremap <buffer> <silent> <cr> :Hglogrevedit<cr>
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
918 nnoremap <buffer> <silent> q :bdelete!<cr>
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
919 endif
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
920
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
921 " Make sure the file is deleted with the buffer.
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
922 autocmd BufDelete <buffer> call s:clean_tempfile(expand('<afile>:p'))
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
923 endfunction
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
924
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
925 function! s:HgLog_FileRevEdit(...)
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
926 if a:0 > 0
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
927 " Revision was given manually.
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
928 let l:rev = a:1
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
929 else
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
930 " Revision should be parsed from the current line in the log.
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
931 let l:rev = s:HgLog_GetSelectedRev()
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
932 endif
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
933 let l:path = 'lawrencium://' . b:mercurial_dir . '@' . b:mercurial_logged_file . '//' . l:rev
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
934 execute 'edit ' . l:path
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
935 endfunction
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
936
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
937 function! s:HgLog_GetSelectedRev() abort
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
938 let l:line = getline('.')
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
939 " Behold, Vim's look-ahead regex syntax again! WTF.
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
940 let l:rev = matchstr(l:line, '\v^(\d+)(\s)@=')
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
941 if l:rev == ''
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
942 call s:throw("Can't parse revision number from line: " . l:line)
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
943 endif
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
944 return l:rev
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
945 endfunction
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
946
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
947 call s:AddMainCommand("-nargs=? -complete=customlist,s:ListRepoFiles Hglog :call s:HgLog(<f-args>)")
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
948
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
949 " }}}
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
950
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
951 " Lawrencium files {{{
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
952
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
953 function! s:ReadFileRevision(path) abort
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
954 let l:comps = s:parse_lawrencium_path(a:path)
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
955 if l:comps['root'] == ''
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
956 call s:throw("Can't get repository root from: " . a:path)
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
957 endif
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
958 let l:repo = s:HgRepo.New(l:comps['root'])
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
959 if l:comps['rev'] == ''
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
960 execute 'read !' . escape(l:repo.GetCommand('cat', l:comps['path']), '%#\')
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
961 else
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
962 execute 'read !' . escape(l:repo.GetCommand('cat', '-r', l:comps['rev'], l:comps['path']), '%#\')
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
963 endif
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
964 return ''
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
965 endfunction
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
966
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
967 augroup lawrencium_files
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
968 autocmd!
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
969 autocmd BufReadCmd lawrencium://**//[0-9a-f][0-9a-f]* exe s:ReadFileRevision(expand('<amatch>'))
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
970 augroup END
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
971
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
972 " }}}
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
973
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
974 " Autoload Functions {{{
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
975
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
976 " Prints a summary of the current repo (if any) that's appropriate for
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
977 " displaying on the status line.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
978 function! lawrencium#statusline(...)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
979 if !exists('b:mercurial_dir')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
980 return ''
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
981 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
982 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
983 let l:suffix = (a:0 > 1 ? a:2 : '')
30
35d097b9513c Fixed a bug with the status line indicator.
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
984 let l:branch = 'default'
5
3a4f9f41a7e2 Use a hackish shortcut to get the current branch faster for the statusline.
Ludovic Chabant <ludovic@chabant.com>
parents: 4
diff changeset
985 let l:branch_file = s:hg_repo().GetFullPath('.hg/branch')
30
35d097b9513c Fixed a bug with the status line indicator.
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
986 if filereadable(l:branch_file)
35d097b9513c Fixed a bug with the status line indicator.
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
987 let l:branch = readfile(l:branch_file)[0]
35d097b9513c Fixed a bug with the status line indicator.
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
988 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
989 return l:prefix . l:branch . l:suffix
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
990 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
991
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
992 " Rescans the current buffer for setting up Mercurial commands.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
993 " Passing '1' as the parameter enables debug traces temporarily.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
994 function! lawrencium#rescan(...)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
995 if exists('b:mercurial_dir')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
996 unlet b:mercurial_dir
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
997 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
998 if a:0 && a:1
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
999 let l:trace_backup = g:lawrencium_trace
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1000 let g:lawrencium_trace = 1
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1001 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1002 call s:setup_buffer_commands()
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1003 if a:0 && a:1
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1004 let g:lawrencium_trace = l:trace_backup
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1005 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1006 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1007
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1008 " Enables/disables the debug trace.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1009 function! lawrencium#debugtrace(...)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1010 let g:lawrencium_trace = (a:0 == 0 || (a:0 && a:1))
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1011 echom "Lawrencium debug trace is now " . (g:lawrencium_trace ? "enabled." : "disabled.")
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1012 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1013
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1014 " }}}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1015