@@ -69,7 +69,7 @@ let s:cpo_save = &cpo
69
69
set cpo &vim
70
70
71
71
let s: plug_source = ' https://raw.github.com/junegunn/vim-plug/master/plug.vim'
72
- let s: plug_buf = -1
72
+ let s: plug_buf = get ( s: , ' plug_buf ' , -1 )
73
73
let s: mac_gui = has (' gui_macvim' ) && has (' gui_running' )
74
74
let s: is_win = has (' win32' ) || has (' win64' )
75
75
let s: me = expand (' <sfile>:p' )
@@ -468,6 +468,7 @@ function! s:prepare()
468
468
else
469
469
execute winnr . ' wincmd w'
470
470
endif
471
+ setlocal modifiable
471
472
silent % d _
472
473
else
473
474
vertical topleft new
@@ -483,7 +484,8 @@ function! s:prepare()
483
484
endif
484
485
silent ! unmap <buffer> <cr>
485
486
silent ! unmap <buffer> L
486
- setlocal buftype = nofile bufhidden = wipe nobuflisted noswapfile nowrap cursorline
487
+ silent ! unmap <buffer> X
488
+ setlocal buftype = nofile bufhidden = wipe nobuflisted noswapfile nowrap cursorline modifiable
487
489
setf vim - plug
488
490
call s: syntax ()
489
491
endfunction
@@ -1112,6 +1114,7 @@ function! s:status()
1112
1114
endfor
1113
1115
call setline (1 , ' Finished. ' .ecnt.' error(s).' )
1114
1116
normal ! gg
1117
+ setlocal nomodifiable
1115
1118
if unloaded
1116
1119
echo " Press 'L' on each line to load plugin"
1117
1120
nnoremap <silent> <buffer> L :call <SID> status_load(line('.'))<cr>
@@ -1125,7 +1128,9 @@ function! s:status_load(lnum)
1125
1128
if ! empty (matches)
1126
1129
let name = matches[1 ]
1127
1130
call plug#load (name)
1131
+ setlocal modifiable
1128
1132
call setline (a: lnum , substitute (line , ' (not loaded)$' , ' ' , ' ' ))
1133
+ setlocal nomodifiable
1129
1134
endif
1130
1135
endfunction
1131
1136
@@ -1138,34 +1143,43 @@ function! s:is_preview_window_open()
1138
1143
return 0
1139
1144
endfunction
1140
1145
1146
+ function ! s: find_name (lnum)
1147
+ for lnum in reverse (range (1 , a: lnum ))
1148
+ let line = getline (lnum)
1149
+ if empty (line )
1150
+ return ' '
1151
+ endif
1152
+ let name = matchstr (line , ' \(^- \)\@<=[^:]\+' )
1153
+ if ! empty (name)
1154
+ return name
1155
+ endif
1156
+ endfor
1157
+ return ' '
1158
+ endfunction
1159
+
1141
1160
function ! s: preview_commit ()
1142
1161
if b: plug_preview < 0
1143
1162
let b: plug_preview = ! s: is_preview_window_open ()
1144
1163
endif
1145
1164
1146
1165
let sha = matchstr (getline (' .' ), ' \(^ \)\@<=[0-9a-z]\{7}' )
1147
- if ! empty (sha)
1148
- let lnum = line (' .' )
1149
- while lnum > 1
1150
- let lnum -= 1
1151
- let line = getline (lnum)
1152
- let name = matchstr (line , ' \(^- \)\@<=[^:]\+' )
1153
- if ! empty (name)
1154
- let dir = g: plugs [name].dir
1155
- if isdirectory (dir )
1156
- execute ' cd ' .s: esc (dir )
1157
- execute ' pedit ' .sha
1158
- wincmd P
1159
- setlocal filetype = git buftype = nofile nobuflisted
1160
- execute ' silent read !git show ' .sha
1161
- normal ! ggdd
1162
- wincmd p
1163
- cd -
1164
- endif
1165
- break
1166
- endif
1167
- endwhile
1166
+ if empty (sha)
1167
+ return
1168
1168
endif
1169
+
1170
+ let name = s: find_name (line (' .' ))
1171
+ if empty (name) || ! has_key (g: plugs , name) || ! isdirectory (g: plugs [name].dir )
1172
+ return
1173
+ endif
1174
+
1175
+ execute ' cd ' .s: esc (g: plugs [name].dir )
1176
+ execute ' pedit ' .sha
1177
+ wincmd P
1178
+ setlocal filetype = git buftype = nofile nobuflisted
1179
+ execute ' silent read !git show ' .sha
1180
+ normal ! ggdd
1181
+ wincmd p
1182
+ cd -
1169
1183
endfunction
1170
1184
1171
1185
function ! s: section (flags)
@@ -1199,7 +1213,28 @@ function! s:diff()
1199
1213
1200
1214
call setline (1 , cnt == 0 ? ' No updates.' : ' Last update:' )
1201
1215
nnoremap <silent> <buffer> <cr> :silent! call <SID> preview_commit()<cr>
1216
+ nnoremap <silent> <buffer> X :call <SID> revert()<cr>
1202
1217
normal ! gg
1218
+ setlocal nomodifiable
1219
+ if cnt > 0
1220
+ echo " Press 'X' on each block to revert the update"
1221
+ endif
1222
+ endfunction
1223
+
1224
+ function ! s: revert ()
1225
+ let name = s: find_name (line (' .' ))
1226
+ if empty (name) || ! has_key (g: plugs , name) ||
1227
+ \ input (printf (' Revert the update of %s? (Y/N) ' , name)) !~? ' ^y'
1228
+ return
1229
+ endif
1230
+
1231
+ execute ' cd ' .s: esc (g: plugs [name].dir )
1232
+ call system (' git reset --hard HEAD@{1} && git checkout ' .s: esc (g: plugs [name].branch))
1233
+ cd -
1234
+ setlocal modifiable
1235
+ normal ! dap
1236
+ setlocal nomodifiable
1237
+ echo ' Reverted.'
1203
1238
endfunction
1204
1239
1205
1240
let s: first_rtp = s: esc (get (split (&rtp , ' ,' ), 0 , ' ' ))
0 commit comments