Mercurial > vim
annotate plugins/hghelp/hghelp.vim @ 18:203279635445 default tip
Adding in the voice note ability. It's not perfect but it is working.
| author | Luka Sitas <lsitas@avatarasoftware.com> |
|---|---|
| date | Tue, 16 Dec 2025 11:03:27 -0500 |
| parents | 412c33afd395 |
| children |
| rev | line source |
|---|---|
|
6
3017fd33ad8b
Better support for db tables.
Luka Sitas <lsitas@avatarasoftware.com>
parents:
diff
changeset
|
1 let g:hg_format_command = "" |
|
3017fd33ad8b
Better support for db tables.
Luka Sitas <lsitas@avatarasoftware.com>
parents:
diff
changeset
|
2 |
|
3017fd33ad8b
Better support for db tables.
Luka Sitas <lsitas@avatarasoftware.com>
parents:
diff
changeset
|
3 |
|
3017fd33ad8b
Better support for db tables.
Luka Sitas <lsitas@avatarasoftware.com>
parents:
diff
changeset
|
4 function! s:CommitWithFormat() |
|
3017fd33ad8b
Better support for db tables.
Luka Sitas <lsitas@avatarasoftware.com>
parents:
diff
changeset
|
5 wa |
|
3017fd33ad8b
Better support for db tables.
Luka Sitas <lsitas@avatarasoftware.com>
parents:
diff
changeset
|
6 if exists("g:hg_format_command") && !empty(g:hg_format_command) |
|
3017fd33ad8b
Better support for db tables.
Luka Sitas <lsitas@avatarasoftware.com>
parents:
diff
changeset
|
7 execute '!'.g:hg_format_command |
|
3017fd33ad8b
Better support for db tables.
Luka Sitas <lsitas@avatarasoftware.com>
parents:
diff
changeset
|
8 endif |
|
8
9c80955f0c6e
I think I got popups working on the commit
Luka Sitas <lsitas@avatarasoftware.com>
parents:
7
diff
changeset
|
9 execute |
|
18
203279635445
Adding in the voice note ability. It's not perfect but it is working.
Luka Sitas <lsitas@avatarasoftware.com>
parents:
17
diff
changeset
|
10 call ExecuteCommand('hg addremove') |
|
8
9c80955f0c6e
I think I got popups working on the commit
Luka Sitas <lsitas@avatarasoftware.com>
parents:
7
diff
changeset
|
11 call PopupCommand('hg commit') |
|
6
3017fd33ad8b
Better support for db tables.
Luka Sitas <lsitas@avatarasoftware.com>
parents:
diff
changeset
|
12 endfunction |
|
3017fd33ad8b
Better support for db tables.
Luka Sitas <lsitas@avatarasoftware.com>
parents:
diff
changeset
|
13 |
|
17
412c33afd395
Update for core and some minor fixes
Luka Sitas <lsitas@avatarasoftware.com>
parents:
15
diff
changeset
|
14 |
|
6
3017fd33ad8b
Better support for db tables.
Luka Sitas <lsitas@avatarasoftware.com>
parents:
diff
changeset
|
15 function! s:OpenHgDiff(file) |
|
3017fd33ad8b
Better support for db tables.
Luka Sitas <lsitas@avatarasoftware.com>
parents:
diff
changeset
|
16 let l:current_file = a:file !=# '' ? a:file : expand('%') |
|
3017fd33ad8b
Better support for db tables.
Luka Sitas <lsitas@avatarasoftware.com>
parents:
diff
changeset
|
17 let l:filetype = &filetype |
|
3017fd33ad8b
Better support for db tables.
Luka Sitas <lsitas@avatarasoftware.com>
parents:
diff
changeset
|
18 let l:temp_file = tempname() |
|
7
34930197e9d4
Updating hg diff tool.
Luka Sitas <lsitas@avatarasoftware.com>
parents:
6
diff
changeset
|
19 let l:command = 'hg cat -r . ' . l:current_file . ' > ' . l:temp_file |
|
8
9c80955f0c6e
I think I got popups working on the commit
Luka Sitas <lsitas@avatarasoftware.com>
parents:
7
diff
changeset
|
20 call ExecuteCommand(l:command) |
|
7
34930197e9d4
Updating hg diff tool.
Luka Sitas <lsitas@avatarasoftware.com>
parents:
6
diff
changeset
|
21 execute 'tabe ' . l:temp_file |
|
6
3017fd33ad8b
Better support for db tables.
Luka Sitas <lsitas@avatarasoftware.com>
parents:
diff
changeset
|
22 execute 'setfiletype' l:filetype |
|
3017fd33ad8b
Better support for db tables.
Luka Sitas <lsitas@avatarasoftware.com>
parents:
diff
changeset
|
23 setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile |
|
3017fd33ad8b
Better support for db tables.
Luka Sitas <lsitas@avatarasoftware.com>
parents:
diff
changeset
|
24 execute 'vert diffsplit' l:current_file |
|
3017fd33ad8b
Better support for db tables.
Luka Sitas <lsitas@avatarasoftware.com>
parents:
diff
changeset
|
25 endfunction |
|
3017fd33ad8b
Better support for db tables.
Luka Sitas <lsitas@avatarasoftware.com>
parents:
diff
changeset
|
26 |
|
3017fd33ad8b
Better support for db tables.
Luka Sitas <lsitas@avatarasoftware.com>
parents:
diff
changeset
|
27 command HGDiff call s:OpenHgDiff(expand('%')) |
| 13 | 28 command! HGCommit call <SID>HgCommitUI() |
| 29 " command Commit call s:CommitWithFormat() | |
| 30 " map <C-k> :Commit<CR> | |
| 31 " | |
| 32 | |
| 33 nnoremap <Leader>df :HGDiff<CR> | |
| 34 nnoremap <C-k> :HGCommit<CR> | |
| 35 | |
| 36 | |
| 37 | |
| 38 " HG UI | |
| 39 function! s:HgCommitUI() | |
| 40 " Save current window to go back if needed | |
| 41 let l:save_winid = win_getid() | |
| 42 | |
| 43 " Get hg status | |
| 44 let l:status = ExecuteCommand('hg status -T"[ ] {status} {path}\n"') | |
| 45 if v:shell_error != 0 | |
| 46 echohl ErrorMsg | |
| 47 echom "hg status failed:" | |
| 48 echom l:status | |
| 49 echohl None | |
| 50 return | |
| 51 endif | |
| 52 let l:lines = split(l:status, "\n") | |
| 53 if empty(l:lines) | |
| 54 echo "No changes to commit." | |
| 55 return | |
| 56 endif | |
| 57 | |
| 58 " Open a new tab for this commit UI | |
| 59 tabnew | |
| 60 " Top window for file selection | |
| 61 enew | |
| 62 let b:hgcommit_type = 'filelist' | |
|
15
7edd5f6fe136
This is another test of commiting with the message this time
Luka Sitas <lsitas@avatarasoftware.com>
parents:
14
diff
changeset
|
63 call setline(1, l:lines) |
| 13 | 64 setlocal buftype=acwrite bufhidden=wipe nobuflisted noswapfile |
| 65 setlocal nomodifiable | |
| 66 setlocal cursorline | |
| 67 nnoremap <silent> <buffer> <CR> :call <SID>ToggleHgFileSelection()<CR> | |
| 68 nnoremap <silent> <buffer> <leader>aa :call <SID>ToggleHgSelectAll()<CR> | |
| 69 | |
| 70 " Split for commit message | |
| 71 belowright split | |
| 72 resize 10 | |
| 73 enew | |
| 74 let b:hgcommit_type = 'message' | |
| 75 setlocal buftype=acwrite bufhidden=wipe nobuflisted noswapfile | |
| 76 " Optional: initial comment | |
| 77 call setline(1, ['# Enter commit message above. Lines starting with # are ignored.']) | |
| 78 " Map to commit | |
|
15
7edd5f6fe136
This is another test of commiting with the message this time
Luka Sitas <lsitas@avatarasoftware.com>
parents:
14
diff
changeset
|
79 nnoremap <silent> <buffer> <leader>c :call <SID>DoHgCommit()<CR> |
| 13 | 80 |
| 81 " Go back to top window to start there | |
| 82 wincmd k | |
| 83 endfunction | |
| 84 | |
| 85 function! s:FormatHgStatusLines(lines) abort | |
| 86 let l:out = [] | |
| 87 for l in a:lines | |
| 88 if empty(l) | |
| 89 continue | |
| 90 endif | |
| 91 " Typical hg status line: "M path/to/file" | |
| 92 " We keep status char and the rest of line, but prepend [ ] | |
| 93 call add(l:out, l) | |
| 94 endfor | |
| 95 return l:out | |
| 96 endfunction | |
| 97 | |
| 98 function! s:ToggleHgFileSelection() abort | |
| 99 if get(b:, 'hgcommit_type', '') !=# 'filelist' | |
| 100 return | |
| 101 endif | |
| 102 setlocal modifiable | |
| 103 let l:lnum = line('.') | |
| 104 let l:line = getline(l:lnum) | |
| 105 if l:line =~# '^\[ \]' | |
| 106 " select | |
| 107 let l:line = substitute(l:line, '^\[ \]', '[x]', '') | |
| 108 elseif l:line =~# '^\[x\]' | |
| 109 " unselect | |
| 110 let l:line = substitute(l:line, '^\[x\]', '[ ]', '') | |
| 111 endif | |
| 112 call setline(l:lnum, l:line) | |
| 113 setlocal nomodifiable | |
| 114 endfunction | |
| 115 | |
| 116 | |
| 117 function! s:ToggleHgSelectAll() abort | |
| 118 if get(b:, 'hgcommit_type', '') !=# 'filelist' | |
| 119 return | |
| 120 endif | |
| 121 setlocal modifiable | |
| 122 let l:lines = getline(1, '$') | |
| 123 | |
| 124 " Decide if we're selecting all or deselecting all: | |
| 125 let l:any_unselected = 0 | |
| 126 for l:l in l:lines | |
| 127 if l:l =~# '^\[ \]' | |
| 128 let l:any_unselected = 1 | |
| 129 break | |
| 130 endif | |
| 131 endfor | |
|
6
3017fd33ad8b
Better support for db tables.
Luka Sitas <lsitas@avatarasoftware.com>
parents:
diff
changeset
|
132 |
| 13 | 133 let l:new = [] |
| 134 if l:any_unselected | |
| 135 " select all | |
| 136 for l:l in l:lines | |
| 137 if l:l =~# '^\[ \]' | |
| 138 call add(l:new, substitute(l:l, '^\[ \]', '[x]', '')) | |
| 139 else | |
| 140 call add(l:new, l:l) | |
| 141 endif | |
| 142 endfor | |
| 143 else | |
| 144 " deselect all | |
| 145 for l:l in l:lines | |
| 146 if l:l =~# '^\[x\]' | |
| 147 call add(l:new, substitute(l:l, '^\[x\]', '[ ]', '')) | |
| 148 else | |
| 149 call add(l:new, l:l) | |
| 150 endif | |
| 151 endfor | |
| 152 endif | |
| 153 | |
| 154 call setline(1, l:new) | |
| 155 setlocal nomodifiable | |
| 156 endfunction | |
| 157 | |
| 158 | |
| 159 function! s:GetSelectedHgFiles() abort | |
| 160 " Find the filelist buffer in this tab | |
| 161 let l:files = [] | |
| 162 for l:w in range(1, winnr('$')) | |
| 163 execute l:w . 'wincmd w' | |
| 164 if get(b:, 'hgcommit_type', '') ==# 'filelist' | |
| 165 let l:lines = getline(1, '$') | |
| 166 for l:L in l:lines | |
| 167 if l:L =~# '^\[x\] ' | |
| 168 " Format: "[x] X path/to/file" | |
| 169 " Strip "[x] " | |
| 170 let l:rest = substitute(l:L, '^\[x\] ', '', '') | |
| 171 " First char is hg status, then space, then filename | |
| 172 if len(l:rest) >= 3 | |
| 173 let l:file = strpart(l:rest, 2) | |
| 174 call add(l:files, l:file) | |
| 175 endif | |
| 176 endif | |
| 177 endfor | |
| 178 break | |
| 179 endif | |
| 180 endfor | |
| 181 " Go back to original window (optional; this simple version just leaves you where you end) | |
| 182 return l:files | |
| 183 endfunction | |
| 184 | |
|
15
7edd5f6fe136
This is another test of commiting with the message this time
Luka Sitas <lsitas@avatarasoftware.com>
parents:
14
diff
changeset
|
185 function! s:GetHgCommitMessage() abort |
|
7edd5f6fe136
This is another test of commiting with the message this time
Luka Sitas <lsitas@avatarasoftware.com>
parents:
14
diff
changeset
|
186 let l:msg_lines = [] |
|
7edd5f6fe136
This is another test of commiting with the message this time
Luka Sitas <lsitas@avatarasoftware.com>
parents:
14
diff
changeset
|
187 for l:w in range(1, winnr('$')) |
|
7edd5f6fe136
This is another test of commiting with the message this time
Luka Sitas <lsitas@avatarasoftware.com>
parents:
14
diff
changeset
|
188 execute l:w . 'wincmd w' |
|
7edd5f6fe136
This is another test of commiting with the message this time
Luka Sitas <lsitas@avatarasoftware.com>
parents:
14
diff
changeset
|
189 if get(b:, 'hgcommit_type', '') ==# 'message' |
|
7edd5f6fe136
This is another test of commiting with the message this time
Luka Sitas <lsitas@avatarasoftware.com>
parents:
14
diff
changeset
|
190 " Get commit message lines, ignoring leading '#' lines |
|
7edd5f6fe136
This is another test of commiting with the message this time
Luka Sitas <lsitas@avatarasoftware.com>
parents:
14
diff
changeset
|
191 let l:all_lines = getline(1, '$') |
|
7edd5f6fe136
This is another test of commiting with the message this time
Luka Sitas <lsitas@avatarasoftware.com>
parents:
14
diff
changeset
|
192 let l:msg_lines = [] |
|
7edd5f6fe136
This is another test of commiting with the message this time
Luka Sitas <lsitas@avatarasoftware.com>
parents:
14
diff
changeset
|
193 for l:L in l:all_lines |
|
7edd5f6fe136
This is another test of commiting with the message this time
Luka Sitas <lsitas@avatarasoftware.com>
parents:
14
diff
changeset
|
194 if l:L =~# '^#' |
|
7edd5f6fe136
This is another test of commiting with the message this time
Luka Sitas <lsitas@avatarasoftware.com>
parents:
14
diff
changeset
|
195 continue |
|
7edd5f6fe136
This is another test of commiting with the message this time
Luka Sitas <lsitas@avatarasoftware.com>
parents:
14
diff
changeset
|
196 endif |
|
7edd5f6fe136
This is another test of commiting with the message this time
Luka Sitas <lsitas@avatarasoftware.com>
parents:
14
diff
changeset
|
197 call add(l:msg_lines, l:L) |
|
7edd5f6fe136
This is another test of commiting with the message this time
Luka Sitas <lsitas@avatarasoftware.com>
parents:
14
diff
changeset
|
198 endfor |
|
7edd5f6fe136
This is another test of commiting with the message this time
Luka Sitas <lsitas@avatarasoftware.com>
parents:
14
diff
changeset
|
199 endif |
|
7edd5f6fe136
This is another test of commiting with the message this time
Luka Sitas <lsitas@avatarasoftware.com>
parents:
14
diff
changeset
|
200 endfor |
|
7edd5f6fe136
This is another test of commiting with the message this time
Luka Sitas <lsitas@avatarasoftware.com>
parents:
14
diff
changeset
|
201 return l:msg_lines |
|
7edd5f6fe136
This is another test of commiting with the message this time
Luka Sitas <lsitas@avatarasoftware.com>
parents:
14
diff
changeset
|
202 endfunction |
| 13 | 203 |
| 204 function! s:DoHgCommit() abort | |
| 205 if get(b:, 'hgcommit_type', '') !=# 'message' | |
| 206 return | |
| 207 endif | |
| 208 | |
| 209 " Get selected files | |
| 210 let l:files = s:GetSelectedHgFiles() | |
| 211 if empty(l:files) | |
| 212 echohl ErrorMsg | |
| 213 echom "No files selected for commit." | |
| 214 echohl None | |
| 215 return | |
| 216 endif | |
| 217 | |
| 218 | |
|
15
7edd5f6fe136
This is another test of commiting with the message this time
Luka Sitas <lsitas@avatarasoftware.com>
parents:
14
diff
changeset
|
219 let l:msg_lines = s:GetHgCommitMessage() |
| 13 | 220 let l:msg = join(l:msg_lines, "\n") |
| 221 if empty(l:msg) | |
| 222 echohl ErrorMsg | |
| 223 echom "Commit message is empty." | |
| 224 echohl None | |
| 225 return | |
| 226 endif | |
| 227 | |
| 228 " Write commit message to temp file | |
| 229 let l:tmpfile = tempname() | |
| 230 call writefile(l:msg_lines, l:tmpfile) | |
| 231 | |
| 232 " Build command: hg commit -l tmpfile file1 file2 ... | |
| 233 let l:cmd = 'hg commit -l ' . shellescape(l:tmpfile) | |
| 234 for l:f in l:files | |
| 235 let l:cmd .= ' ' . shellescape(l:f) | |
| 236 endfor | |
| 237 | |
| 238 " Run it | |
| 239 let l:out = ExecuteCommand(l:cmd) | |
| 240 let l:status = v:shell_error | |
| 241 | |
| 242 " Clean up temp file | |
| 243 call delete(l:tmpfile) | |
| 244 | |
| 245 if l:status != 0 | |
| 246 echohl ErrorMsg | |
| 247 echom "hg commit failed:" | |
| 248 echom l:out | |
| 249 echohl None | |
|
14
6ee7fce1cba8
[x] M plugins/hghelp/hghelp.vim
Luka Sitas <lsitas@avatarasoftware.com>
parents:
13
diff
changeset
|
250 return |
| 13 | 251 endif |
| 252 | |
|
14
6ee7fce1cba8
[x] M plugins/hghelp/hghelp.vim
Luka Sitas <lsitas@avatarasoftware.com>
parents:
13
diff
changeset
|
253 echom "hg commit succeeded." |
|
6ee7fce1cba8
[x] M plugins/hghelp/hghelp.vim
Luka Sitas <lsitas@avatarasoftware.com>
parents:
13
diff
changeset
|
254 |
|
6ee7fce1cba8
[x] M plugins/hghelp/hghelp.vim
Luka Sitas <lsitas@avatarasoftware.com>
parents:
13
diff
changeset
|
255 " Close only the commit UI buffers in this tab |
|
6ee7fce1cba8
[x] M plugins/hghelp/hghelp.vim
Luka Sitas <lsitas@avatarasoftware.com>
parents:
13
diff
changeset
|
256 try |
|
6ee7fce1cba8
[x] M plugins/hghelp/hghelp.vim
Luka Sitas <lsitas@avatarasoftware.com>
parents:
13
diff
changeset
|
257 for l:w in range(1, winnr('$')) |
|
6ee7fce1cba8
[x] M plugins/hghelp/hghelp.vim
Luka Sitas <lsitas@avatarasoftware.com>
parents:
13
diff
changeset
|
258 execute l:w . 'wincmd w' |
|
6ee7fce1cba8
[x] M plugins/hghelp/hghelp.vim
Luka Sitas <lsitas@avatarasoftware.com>
parents:
13
diff
changeset
|
259 if get(b:, 'hgcommit_type', '') ==# 'filelist' |
|
6ee7fce1cba8
[x] M plugins/hghelp/hghelp.vim
Luka Sitas <lsitas@avatarasoftware.com>
parents:
13
diff
changeset
|
260 bwipeout! |
|
6ee7fce1cba8
[x] M plugins/hghelp/hghelp.vim
Luka Sitas <lsitas@avatarasoftware.com>
parents:
13
diff
changeset
|
261 elseif get(b:, 'hgcommit_type', '') ==# 'message' |
|
6ee7fce1cba8
[x] M plugins/hghelp/hghelp.vim
Luka Sitas <lsitas@avatarasoftware.com>
parents:
13
diff
changeset
|
262 bwipeout! |
|
6ee7fce1cba8
[x] M plugins/hghelp/hghelp.vim
Luka Sitas <lsitas@avatarasoftware.com>
parents:
13
diff
changeset
|
263 endif |
|
6ee7fce1cba8
[x] M plugins/hghelp/hghelp.vim
Luka Sitas <lsitas@avatarasoftware.com>
parents:
13
diff
changeset
|
264 endfor |
|
6ee7fce1cba8
[x] M plugins/hghelp/hghelp.vim
Luka Sitas <lsitas@avatarasoftware.com>
parents:
13
diff
changeset
|
265 catch /^Vim\%((\a\+)\)\=:E/ |
|
6ee7fce1cba8
[x] M plugins/hghelp/hghelp.vim
Luka Sitas <lsitas@avatarasoftware.com>
parents:
13
diff
changeset
|
266 endtry |
| 13 | 267 endfunction |
