Mercurial > vim-lawrencium
comparison autoload/lawrencium/record.vim @ 140:652a6f5df0f3
Fixed for broken things after the reorganization.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Mon, 13 Jun 2016 21:55:40 -0700 |
parents | 065625e1bb31 |
children | 4d5f4233b04e |
comparison
equal
deleted
inserted
replaced
139:065625e1bb31 | 140:652a6f5df0f3 |
---|---|
9 let l:orig_buf = lawrencium#buffer_obj() | 9 let l:orig_buf = lawrencium#buffer_obj() |
10 let l:tmp_path = l:orig_buf.GetName(':p') . '~record' | 10 let l:tmp_path = l:orig_buf.GetName(':p') . '~record' |
11 let l:diff_id = localtime() | 11 let l:diff_id = localtime() |
12 | 12 |
13 " Start diffing on the current file, enable some commands. | 13 " Start diffing on the current file, enable some commands. |
14 call l:orig_buf.DefineCommand('Hgrecordabort', ':call s:HgRecord_Abort()') | 14 call l:orig_buf.DefineCommand('Hgrecordabort', ':call lawrencium#record#HgRecord_Abort()') |
15 call l:orig_buf.DefineCommand('Hgrecordcommit', ':call s:HgRecord_Execute()') | 15 call l:orig_buf.DefineCommand('Hgrecordcommit', ':call lawrencium#record#HgRecord_Execute()') |
16 call lawrencium#diff#HgDiffThis(l:diff_id) | 16 call lawrencium#diff#HgDiffThis(l:diff_id) |
17 setlocal foldmethod=diff | 17 setlocal foldmethod=diff |
18 | 18 |
19 " Split the window and open the parent revision in the right or bottom | 19 " Split the window and open the parent revision in the right or bottom |
20 " window. Keep the current buffer in the left or top window... we're going | 20 " window. Keep the current buffer in the left or top window... we're going |
41 call setbufvar(l:orig_buf.nr, 'lawrencium_record_for', '%') | 41 call setbufvar(l:orig_buf.nr, 'lawrencium_record_for', '%') |
42 call setbufvar(l:orig_buf.nr, 'lawrencium_record_other_nr', bufnr('%')) | 42 call setbufvar(l:orig_buf.nr, 'lawrencium_record_other_nr', bufnr('%')) |
43 | 43 |
44 " Hookup the commit and abort commands. | 44 " Hookup the commit and abort commands. |
45 let l:rec_buf = lawrencium#buffer_obj() | 45 let l:rec_buf = lawrencium#buffer_obj() |
46 call l:rec_buf.OnDelete('call s:HgRecord_Execute()') | 46 call l:rec_buf.OnDelete('call lawrencium#record#HgRecord_Execute()') |
47 call l:rec_buf.DefineCommand('Hgrecordcommit', ':quit') | 47 call l:rec_buf.DefineCommand('Hgrecordcommit', ':quit') |
48 call l:rec_buf.DefineCommand('Hgrecordabort', ':call s:HgRecord_Abort()') | 48 call l:rec_buf.DefineCommand('Hgrecordabort', ':call lawrencium#record#HgRecord_Abort()') |
49 call lawrencium#define_commands() | 49 call lawrencium#define_commands() |
50 | 50 |
51 " Make it the other part of the diff. | 51 " Make it the other part of the diff. |
52 call lawrencium#diff#HgDiffThis(l:diff_id) | 52 call lawrencium#diff#HgDiffThis(l:diff_id) |
53 setlocal foldmethod=diff | 53 setlocal foldmethod=diff |
57 if g:lawrencium_record_start_in_working_buffer | 57 if g:lawrencium_record_start_in_working_buffer |
58 wincmd p | 58 wincmd p |
59 endif | 59 endif |
60 endfunction | 60 endfunction |
61 | 61 |
62 function! s:HgRecord_Execute() abort | 62 function! lawrencium#record#HgRecord_Execute() abort |
63 if exists('b:lawrencium_record_abort') | 63 if exists('b:lawrencium_record_abort') |
64 " Abort flag is set, let's just cleanup. | 64 " Abort flag is set, let's just cleanup. |
65 let l:buf_nr = b:lawrencium_record_for == '%' ? bufnr('%') : | 65 let l:buf_nr = b:lawrencium_record_for == '%' ? bufnr('%') : |
66 \b:lawrencium_record_other_nr | 66 \b:lawrencium_record_other_nr |
67 call s:HgRecord_CleanUp(l:buf_nr) | 67 call lawrencium#record#HgRecord_CleanUp(l:buf_nr) |
68 call lawrencium#error("abort: User requested aborting the record operation.") | 68 call lawrencium#error("abort: User requested aborting the record operation.") |
69 return | 69 return |
70 endif | 70 endif |
71 | 71 |
72 if !exists('b:lawrencium_record_for') | 72 if !exists('b:lawrencium_record_for') |
82 let l:split = b:lawrencium_record_commit_split | 82 let l:split = b:lawrencium_record_commit_split |
83 let l:working_bufnr = b:lawrencium_record_other_nr | 83 let l:working_bufnr = b:lawrencium_record_other_nr |
84 let l:working_path = fnameescape(b:lawrencium_record_for) | 84 let l:working_path = fnameescape(b:lawrencium_record_for) |
85 let l:record_path = fnameescape(expand('%:p')) | 85 let l:record_path = fnameescape(expand('%:p')) |
86 let l:callbacks = [ | 86 let l:callbacks = [ |
87 \'call s:HgRecord_PostExecutePre('.l:working_bufnr.', "'. | 87 \'call lawrencium#record#HgRecord_PostExecutePre('.l:working_bufnr.', "'. |
88 \escape(l:working_path, '\').'", "'. | 88 \escape(l:working_path, '\').'", "'. |
89 \escape(l:record_path, '\').'")', | 89 \escape(l:record_path, '\').'")', |
90 \'call s:HgRecord_PostExecutePost('.l:working_bufnr.', "'. | 90 \'call lawrencium#record#HgRecord_PostExecutePost('.l:working_bufnr.', "'. |
91 \escape(l:working_path, '\').'")', | 91 \escape(l:working_path, '\').'")', |
92 \'call s:HgRecord_PostExecuteAbort('.l:working_bufnr.', "'. | 92 \'call lawrencium#record#HgRecord_PostExecuteAbort('.l:working_bufnr.', "'. |
93 \escape(l:record_path, '\').'")' | 93 \escape(l:record_path, '\').'")' |
94 \] | 94 \] |
95 call lawrencium#trace("Starting commit flow with callbacks: ".string(l:callbacks)) | 95 call lawrencium#trace("Starting commit flow with callbacks: ".string(l:callbacks)) |
96 call lawrencium#commit#HgCommit(0, l:split, l:callbacks, b:lawrencium_record_for) | 96 call lawrencium#commit#HgCommit(0, l:split, l:callbacks, b:lawrencium_record_for) |
97 endfunction | 97 endfunction |
98 | 98 |
99 function! s:HgRecord_PostExecutePre(working_bufnr, working_path, record_path) abort | 99 function! lawrencium#record#HgRecord_PostExecutePre(working_bufnr, working_path, record_path) abort |
100 " Just before committing, we switch the original file with the record | 100 " Just before committing, we switch the original file with the record |
101 " file... we'll restore things in the post-callback below. | 101 " file... we'll restore things in the post-callback below. |
102 " We also switch on 'autoread' temporarily on the working buffer so that | 102 " We also switch on 'autoread' temporarily on the working buffer so that |
103 " we don't have an annoying popup in gVim. | 103 " we don't have an annoying popup in gVim. |
104 if has('dialog_gui') | 104 if has('dialog_gui') |
109 call lawrencium#trace("Committing recorded changes using: ".a:record_path) | 109 call lawrencium#trace("Committing recorded changes using: ".a:record_path) |
110 silent call rename(a:record_path, a:working_path) | 110 silent call rename(a:record_path, a:working_path) |
111 sleep 200m | 111 sleep 200m |
112 endfunction | 112 endfunction |
113 | 113 |
114 function! s:HgRecord_PostExecutePost(working_bufnr, working_path) abort | 114 function! lawrencium#record#HgRecord_PostExecutePost(working_bufnr, working_path) abort |
115 " Recover the back-up file from underneath the buffer. | 115 " Recover the back-up file from underneath the buffer. |
116 call lawrencium#trace("Recovering original file: ".a:working_path) | 116 call lawrencium#trace("Recovering original file: ".a:working_path) |
117 silent call rename(a:working_path.'~working', a:working_path) | 117 silent call rename(a:working_path.'~working', a:working_path) |
118 | 118 |
119 " Clean up! | 119 " Clean up! |
120 call s:HgRecord_CleanUp(a:working_bufnr) | 120 call lawrencium#record#HgRecord_CleanUp(a:working_bufnr) |
121 | 121 |
122 " Restore default 'autoread'. | 122 " Restore default 'autoread'. |
123 if has('dialog_gui') | 123 if has('dialog_gui') |
124 set autoread< | 124 set autoread< |
125 endif | 125 endif |
126 endfunction | 126 endfunction |
127 | 127 |
128 function! s:HgRecord_PostExecuteAbort(working_bufnr, record_path) abort | 128 function! lawrencium#record#HgRecord_PostExecuteAbort(working_bufnr, record_path) abort |
129 call s:HgRecord_CleanUp(a:working_bufnr) | 129 call lawrencium#record#HgRecord_CleanUp(a:working_bufnr) |
130 call lawrencium#trace("Delete discarded record file: ".a:record_path) | 130 call lawrencium#trace("Delete discarded record file: ".a:record_path) |
131 silent call delete(a:record_path) | 131 silent call delete(a:record_path) |
132 endfunction | 132 endfunction |
133 | 133 |
134 function! s:HgRecord_Abort() abort | 134 function! lawrencium#record#HgRecord_Abort() abort |
135 if b:lawrencium_record_for == '%' | 135 if b:lawrencium_record_for == '%' |
136 " We're in the working directory buffer. Switch to the 'recording' | 136 " We're in the working directory buffer. Switch to the 'recording' |
137 " buffer and quit. | 137 " buffer and quit. |
138 let l:buf_obj = lawrencium#buffer_obj(b:lawrencium_record_other_nr) | 138 let l:buf_obj = lawrencium#buffer_obj(b:lawrencium_record_other_nr) |
139 call l:buf_obj.MoveToFirstWindow() | 139 call l:buf_obj.MoveToFirstWindow() |
142 " which will run the execution (it will early out and clean things up). | 142 " which will run the execution (it will early out and clean things up). |
143 let b:lawrencium_record_abort = 1 | 143 let b:lawrencium_record_abort = 1 |
144 quit! | 144 quit! |
145 endfunction | 145 endfunction |
146 | 146 |
147 function! s:HgRecord_CleanUp(buf_nr) abort | 147 function! lawrencium#record#HgRecord_CleanUp(buf_nr) abort |
148 " Get in the original buffer and clean the local commands/variables. | 148 " Get in the original buffer and clean the local commands/variables. |
149 let l:buf_obj = lawrencium#buffer_obj(a:buf_nr) | 149 let l:buf_obj = lawrencium#buffer_obj(a:buf_nr) |
150 call l:buf_obj.MoveToFirstWindow() | 150 call l:buf_obj.MoveToFirstWindow() |
151 if !exists('b:lawrencium_record_for') || b:lawrencium_record_for != '%' | 151 if !exists('b:lawrencium_record_for') || b:lawrencium_record_for != '%' |
152 call lawrencium#throw("Cleaning up something else than the original buffer ". | 152 call lawrencium#throw("Cleaning up something else than the original buffer ". |