File: table_autoformat.vader

package info (click to toggle)
vim-vimwiki 2024.01.24-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,692 kB
  • sloc: sh: 313; makefile: 2
file content (240 lines) | stat: -rw-r--r-- 5,017 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# Table autoformating
# Very configurable: read doc/design_notes.md

# Do not consider \| {{{1
##########################

Given vimwiki (Table with \| #281):
  | Head1 | Head2 |
  | ---  | --- |
  | l1_1 | l1_2 |
  | l2_1 \| with escaped pipe | l2_2 |

Execute (Rename file wiki_test.md for table expand):
  file wiki_test.md
  call SetSyntax('markdown')

Do (A to trigger insertLeave #281):
  A

Expect(Table aligned with \| in cells):
  | Head1                     | Head2 |
  | ---                       | ---   |
  | l1_1                      | l1_2  |
  | l2_1 \| with escaped pipe | l2_2  |


# Do not alter config {{{1
##########################

Given vimwiki (Table Head \#891):
  | foo | bar |

Execute (set tw=71):
  set tw=71
  AssertEqual &tw, 71

Do (A<Cr>):
  A\<Cr>\<Esc>

Expect (Table Head \#891):
  | foo | bar |
  |     |     |

Execute (Assert tw=71):
  AssertEqual &tw, 71

# Autoformat {{{1
#################

Given vimwiki (Unaligned table):
  | title1 | title2 |
  | - | - |
  | a1 | b1 |
  | a2 | |

Execute (Rename file wiki_test.md for table expand):
  file wiki_test.md

Do (A to trigger insertLeave):
  A

Expect (Table autoformat):
  | title1 | title2 |
  | -      | -      |
  | a1     | b1     |
  | a2     |        |

Do (gqq to reformats table after making changes.):
  gqq

Expect (Table autoformat):
  | title1 | title2 |
  | -      | -      |
  | a1     | b1     |
  | a2     |        |

Execute (Option table_reduce_last_col = 1):
  let g:vimwiki_global_vars['table_reduce_last_col'] = 1

Do (A to trigger insertLeave):
  A

Expect (Last column not expanded):
  | title1 | title2 |
  | -      | - |
  | a1     | b1 |
  | a2     |   |

Execute (Option table_reduce_last_col = 0 [restore]):
  let g:vimwiki_global_vars['table_reduce_last_col'] = 0

Execute (Option table_auto_fmt = 0):
  let g:vimwiki_global_vars['table_auto_fmt'] = 0

Expect (Same as input):
  | title1 | title2 |
  | - | - |
  | a1 | b1 |
  | a2 | |

Execute (Option table_auto_fmt = 1 [restore]):
  let g:vimwiki_global_vars['table_auto_fmt'] = 1



# Move and edit cells {{{1
##########################

Do (Use <Tab> in insert mode):
  GI
  \<Tab>
  this_is_16_chars
  \<Tab>
  this_is_16_chars
  \<Esc>

Expect (Table autoformated with more content):
  | title1             | title2           |
  | -                  | -                |
  | a1                 | b1               |
  | this_is_16_charsa2 | this_is_16_chars |

Do (VimwikiTableMoveColumnRight):
  gg:VimwikiTableMoveColumnRight\<CR>

Expect (Column inverted):
  | title2 | title1 |
  | -      | -      |
  | b1     | a1     |
  |        | a2     |

Do (CR must insert new row):
  GI\<Cr>a3

Expect (Table with new row starting by a3):
  | title1 | title2 |
  | -      | -      |
  | a1     | b1     |
  | a2     |        |
  | a3     |        |




# VimwikiTable Command {{{1
###########################

Given (Nothing):

Execute (VimwikiTable):
  VimwikiTable

Expect (Table 5 x 2):

  |   |   |   |   |   |
  |---|---|---|---|---|
  |   |   |   |   |   |

Execute (VimwikiTable 8 3):
  VimwikiTable 8 3

Expect (Table 8 x 3):

  |   |   |   |   |   |   |   |   |
  |---|---|---|---|---|---|---|---|
  |   |   |   |   |   |   |   |   |
  |   |   |   |   |   |   |   |   |


Given vimwiki (Table 5 x (1+3)):
  | h1  | h2  | h3  | h4  | h5  |
  |-----|-----|-----|-----|-----|
  | l11 | l12 | l13 | l14 | l15 |
  | l21 | l22 | l23 | l24 | l25 |
  | l31 | l32 | l33 | l34 | l35 |

Execute (VimwikiTableMoveColumnRight):
  VimwikiTableMoveColumnRight

Expect (Col: 1 -> 2):
  | h2  | h1  | h3  | h4  | h5  |
  |-----|-----|-----|-----|-----|
  | l12 | l11 | l13 | l14 | l15 |
  | l22 | l21 | l23 | l24 | l25 |
  | l32 | l31 | l33 | l34 | l35 |

Execute (VimwikiTableMoveColumnLeft):
  call cursor(5, 16)
  VimwikiTableMoveColumnLeft

Expect (Col: 3 -> 2):
  | h1  | h3  | h2  | h4  | h5  |
  |-----|-----|-----|-----|-----|
  | l11 | l13 | l12 | l14 | l15 |
  | l21 | l23 | l22 | l24 | l25 |
  | l31 | l33 | l32 | l34 | l35 |

# Justify Cell Content {{{1
###########################


Given vimwiki (To be justified from help file [Coffe price]):
  | Date       |  Item  |   Price |
  |------------|:------:|--------:|
  | yest       |Coffee |$15.00 |
  | 2017-02-13 |Tea   |$2.10 |
  | 2017-03-14 |Cake  |$143.12 |

Execute (Rename file wiki_test.md for table expand):
  file wiki_test.md

Do (A to trigger insertLeave):
  A

Expect (Text justified):
  | Date       |  Item  |   Price |
  |------------|:------:|--------:|
  | yest       | Coffee |  $15.00 |
  | 2017-02-13 |  Tea   |   $2.10 |
  | 2017-03-14 |  Cake  | $143.12 |

Given vimwiki (To be left aligned):
  | Date       |  Item  |
  |:------------|------:|
  |yest|Coffee |
  | 2017-02-13|  Tea|
  |2017-03-14        |Cake  |

Do (A to trigger insertLeave):
  A

Expect (Left justified and :--- -> ----):
  | Date       |   Item |
  |------------|-------:|
  | yest       | Coffee |
  | 2017-02-13 |    Tea |
  | 2017-03-14 |   Cake |


# vim: foldmethod=marker foldlevel=30