annotate vendor/vim-packs/ctrlp.vim/autoload/ctrlp/undo.vim @ 719:bcdf320dabf4

Rewrite the ed2k again in php Getting openssl to hash md4 is a pain.
author nanaya <me@nanaya.net>
date Sun, 10 Dec 2023 00:35:22 +0900
parents 4576f1471f53
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
707
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
1 " =============================================================================
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
2 " File: autoload/ctrlp/undo.vim
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
3 " Description: Undo extension
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
4 " Author: Kien Nguyen <github.com/kien>
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
5 " =============================================================================
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
6
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
7 " Init {{{1
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
8 if ( exists('g:loaded_ctrlp_undo') && g:loaded_ctrlp_undo )
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
9 fini
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
10 en
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
11 let g:loaded_ctrlp_undo = 1
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
12
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
13 cal add(g:ctrlp_ext_vars, {
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
14 \ 'init': 'ctrlp#undo#init()',
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
15 \ 'accept': 'ctrlp#undo#accept',
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
16 \ 'lname': 'undo',
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
17 \ 'sname': 'udo',
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
18 \ 'enter': 'ctrlp#undo#enter()',
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
19 \ 'exit': 'ctrlp#undo#exit()',
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
20 \ 'type': 'line',
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
21 \ 'sort': 0,
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
22 \ 'nolim': 1,
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
23 \ })
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
24
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
25 let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
26
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
27 let s:text = map(['second', 'seconds', 'minutes', 'hours', 'days', 'weeks',
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
28 \ 'months', 'years'], '" ".v:val." ago"')
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
29 " Utilities {{{1
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
30 fu! s:getundo()
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
31 if exists('*undotree')
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
32 \ && ( v:version > 703 || ( v:version == 703 && has('patch005') ) )
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
33 retu [1, undotree()]
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
34 el
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
35 redi => result
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
36 sil! undol
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
37 redi END
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
38 retu [0, split(result, "\n")[1:]]
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
39 en
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
40 endf
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
41
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
42 fu! s:flatten(tree, cur)
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
43 let flatdict = {}
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
44 for each in a:tree
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
45 let saved = has_key(each, 'save') ? 'saved' : ''
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
46 let current = each['seq'] == a:cur ? 'current' : ''
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
47 cal extend(flatdict, { each['seq'] : [each['time'], saved, current] })
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
48 if has_key(each, 'alt')
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
49 cal extend(flatdict, s:flatten(each['alt'], a:cur))
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
50 en
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
51 endfo
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
52 retu flatdict
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
53 endf
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
54
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
55 fu! s:elapsed(nr)
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
56 let [text, time] = [s:text, localtime() - a:nr]
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
57 let mins = time / 60
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
58 let hrs = time / 3600
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
59 let days = time / 86400
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
60 let wks = time / 604800
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
61 let mons = time / 2592000
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
62 let yrs = time / 31536000
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
63 if yrs > 1
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
64 retu yrs.text[7]
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
65 elsei mons > 1
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
66 retu mons.text[6]
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
67 elsei wks > 1
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
68 retu wks.text[5]
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
69 elsei days > 1
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
70 retu days.text[4]
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
71 elsei hrs > 1
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
72 retu hrs.text[3]
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
73 elsei mins > 1
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
74 retu mins.text[2]
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
75 elsei time == 1
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
76 retu time.text[0]
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
77 elsei time < 120
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
78 retu time.text[1]
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
79 en
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
80 endf
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
81
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
82 fu! s:syntax()
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
83 if ctrlp#nosy() | retu | en
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
84 for [ke, va] in items({'T': 'Directory', 'Br': 'Comment', 'Nr': 'String',
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
85 \ 'Sv': 'Comment', 'Po': 'Title'})
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
86 cal ctrlp#hicheck('CtrlPUndo'.ke, va)
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
87 endfo
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
88 sy match CtrlPUndoT '\v\d+ \zs[^ ]+\ze|\d+:\d+:\d+'
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
89 sy match CtrlPUndoBr '\[\|\]'
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
90 sy match CtrlPUndoNr '\[\d\+\]' contains=CtrlPUndoBr
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
91 sy match CtrlPUndoSv 'saved'
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
92 sy match CtrlPUndoPo 'current'
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
93 endf
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
94
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
95 fu! s:dict2list(dict)
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
96 for ke in keys(a:dict)
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
97 let a:dict[ke][0] = s:elapsed(a:dict[ke][0])
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
98 endfo
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
99 retu map(keys(a:dict), 'eval(''[v:val, a:dict[v:val]]'')')
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
100 endf
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
101
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
102 fu! s:compval(...)
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
103 retu a:2[0] - a:1[0]
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
104 endf
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
105
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
106 fu! s:format(...)
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
107 let saved = !empty(a:1[1][1]) ? ' '.a:1[1][1] : ''
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
108 let current = !empty(a:1[1][2]) ? ' '.a:1[1][2] : ''
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
109 retu a:1[1][0].' ['.a:1[0].']'.saved.current
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
110 endf
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
111
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
112 fu! s:formatul(...)
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
113 let parts = matchlist(a:1,
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
114 \ '\v^\s+(\d+)\s+\d+\s+([^ ]+\s?[^ ]+|\d+\s\w+\s\w+)(\s*\d*)$')
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
115 retu parts == [] ? '----'
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
116 \ : parts[2].' ['.parts[1].']'.( parts[3] != '' ? ' saved' : '' )
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
117 endf
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
118 " Public {{{1
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
119 fu! ctrlp#undo#init()
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
120 let entries = s:undos[0] ? s:undos[1]['entries'] : s:undos[1]
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
121 if empty(entries) | retu [] | en
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
122 if !exists('s:lines')
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
123 if s:undos[0]
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
124 let entries = s:dict2list(s:flatten(entries, s:undos[1]['seq_cur']))
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
125 let s:lines = map(sort(entries, 's:compval'), 's:format(v:val)')
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
126 el
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
127 let s:lines = map(reverse(entries), 's:formatul(v:val)')
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
128 en
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
129 en
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
130 cal s:syntax()
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
131 retu s:lines
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
132 endf
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
133
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
134 fu! ctrlp#undo#accept(mode, str)
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
135 let undon = matchstr(a:str, '\[\zs\d\+\ze\]')
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
136 if empty(undon) | retu | en
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
137 cal ctrlp#exit()
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
138 exe 'u' undon
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
139 endf
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
140
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
141 fu! ctrlp#undo#id()
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
142 retu s:id
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
143 endf
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
144
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
145 fu! ctrlp#undo#enter()
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
146 let s:undos = s:getundo()
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
147 endf
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
148
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
149 fu! ctrlp#undo#exit()
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
150 unl! s:lines
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
151 endf
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
152 "}}}
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
153
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
154 " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2