annotate plugin/lawrencium.vim @ 23:84bceffbb19c

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