├── .gitattributes ├── .gitignore ├── Makefile ├── README ├── autoload └── autofmt │ ├── compat.vim │ ├── japanese.vim │ ├── uax14.vim │ └── unicode.vim ├── doc ├── autofmt.txt └── tags ├── memo.txt ├── test ├── Makefile ├── bug1.in ├── bug1.ok ├── dotest.in ├── test1.in ├── test1.ok ├── test10.in ├── test10.ok ├── test2.in ├── test2.ok ├── test3.in ├── test3.ok ├── test4.in ├── test4.ok ├── test5.in ├── test5.ok ├── test6.in ├── test6.ok ├── test7.in ├── test7.ok ├── test8.in ├── test8.ok ├── test9.in ├── test9.ok ├── todo.in ├── todo.ok ├── todo2.in ├── todo2.ok ├── todo3.in ├── todo3.ok ├── todo5.in ├── todo5.ok └── unix.vim └── tools └── unicode.vim /.gitattributes: -------------------------------------------------------------------------------- 1 | doc/tags text eol=lf 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | .*.sw? 3 | /test/*.failed 4 | /test/*.log 5 | /test/*.out 6 | /tools/LineBreak.txt 7 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | .PHONY: dist test clean 3 | 4 | all: dist 5 | 6 | dist: clean test 7 | svn export . autofmt 8 | rm -f autofmt.zip 9 | zip -r autofmt.zip autofmt 10 | rm -r autofmt 11 | 12 | test: 13 | cd test && $(MAKE) 14 | 15 | clean: 16 | cd test && $(MAKE) clean 17 | 18 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | This is a 'formatexpr' plugin. 2 | 3 | License: 4 | public domain 5 | 6 | Usage: 7 | :set runtimepath+=/path/to/autofmt/ 8 | :set formatexpr=autofmt#compat#formatexpr() 9 | 10 | Following method can be used: 11 | autofmt#compat#formatexpr(): Vim compatible 12 | autofmt#uax14#formatexpr(): Implementation of UAX #14 13 | autofmt#japanese#formatexpr(): Japanese 14 | 15 | See doc/autofmt.txt for more information. 16 | -------------------------------------------------------------------------------- /autoload/autofmt/compat.vim: -------------------------------------------------------------------------------- 1 | " Maintainer: Yukihiro Nakadaira 2 | " License: This file is placed in the public domain. 3 | " Last Change: 2012-01-25 4 | " 5 | " Options: 6 | " 7 | " None 8 | " 9 | " 10 | " Related Options: 11 | " textwidth 12 | " formatoptions 13 | " formatlistpat 14 | " joinspaces 15 | " cpoptions ('j' flag) 16 | " comments 17 | " expandtab 18 | " tabstop 19 | " ambiwidth 20 | " autoindent 21 | " copyindent 22 | " wrapmargin 23 | " foldcolumn 24 | " number 25 | " relativenumber 26 | " cindent 27 | " lispindent 28 | " smartindent 29 | " indentexpr 30 | " paste 31 | " 32 | " 33 | " Note: 34 | " This script is very slow. Only one or two paragraph (and also Insert mode 35 | " formatting) can be formatted in practical. 36 | " 37 | " Do not work when 'formatoptions' have 'a' flag. 38 | " 39 | " v:lnum can be changed when using "normal! i\" or something that uses 40 | " v:lnum. Take care to use such command in formatexpr. 41 | " 42 | " v:char is never be space or tab. When completion is used, v:char is 43 | " empty. 44 | " 45 | " Make text reformattable. Do not insert or remove spaces when it 46 | " considered unexpected. 47 | " 48 | " 49 | " TODO: 50 | " 'formatoptions': 'a' 'w' 'v' 'b' 'l' 51 | " 52 | " hoge(); /* format comment here */ 53 | " hoge(); /* format 54 | " * comment 55 | " * here 56 | " */ 57 | " 58 | " /* comment */ do_not() + format() + here(); 59 | " 60 | " How to recognize if text is list formatted? 61 | " 1 We have 62 | " 2 20 files. 63 | " Line 2 is not list but it matches 'formatlistpat'. 64 | " 65 | " Justify with padding or removing spaces. How to re-format without 66 | " breaking user typed space. 67 | " 68 | " 69 | " Reference: 70 | " UAX #14: Line Breaking Properties 71 | " http://unicode.org/reports/tr14/ 72 | " 73 | " UAX #11: East Asian Width 74 | " http://unicode.org/reports/tr11/ 75 | " 76 | " Word wrap - Wikipedia 77 | " http://en.wikipedia.org/wiki/Word_wrap 78 | 79 | let s:cpo_save = &cpo 80 | set cpo&vim 81 | 82 | function autofmt#compat#formatexpr() 83 | return s:lib.formatexpr() 84 | endfunction 85 | 86 | function autofmt#compat#import() 87 | return s:lib 88 | endfunction 89 | 90 | if exists('*strdisplaywidth') 91 | let s:strdisplaywidth = function('strdisplaywidth') 92 | else 93 | function s:strdisplaywidth(str, ...) 94 | let vcol = get(a:000, 0, 0) 95 | let w = 0 96 | for c in split(a:str, '\zs') 97 | if c == "\t" 98 | let w += &tabstop - ((vcol + w) % &tabstop) 99 | elseif c =~ '^.\%2v' " single-width char 100 | let w += 1 101 | elseif c =~ '^.\%3v' " double-width char or ctrl-code (^X) 102 | let w += 2 103 | elseif c =~ '^.\%5v' " (^X with :set display=uhex) 104 | let w += 4 105 | elseif c =~ '^.\%7v' " (e.g. U+FEFF) 106 | let w += 6 107 | endif 108 | endfor 109 | return w 110 | endfunction 111 | endif 112 | 113 | let s:lib = {} 114 | 115 | function s:lib.formatexpr() 116 | if mode() =~# '[iR]' && self.has_format_options('a') 117 | " When 'formatoptions' have "a" flag (paragraph formatting), it is 118 | " impossible to format using User Function. Paragraph is concatenated to 119 | " one line before this function is invoked and cursor is placed at end of 120 | " line. 121 | return 1 122 | elseif mode() !~# '[niR]' || (mode() =~# '[iR]' && v:count != 1) || v:char =~# '\s' 123 | echohl ErrorMsg 124 | echomsg "Assert(formatexpr): Unknown State: " mode() v:lnum v:count string(v:char) 125 | echohl None 126 | return 1 127 | endif 128 | if mode() == 'n' 129 | call self.format_normal_mode(v:lnum, v:count) 130 | else 131 | call self.format_insert_mode(v:char) 132 | endif 133 | return 0 134 | endfunction 135 | 136 | function s:lib.format_normal_mode(lnum, count) 137 | let self.textwidth = self.comp_textwidth(1) 138 | 139 | if self.textwidth == 0 140 | return 141 | endif 142 | 143 | let offset = 0 144 | let para = self.get_paragraph(getline(a:lnum, a:lnum + a:count - 1)) 145 | for [i, lines] in para 146 | let lnum = a:lnum + i + offset 147 | call setline(lnum, self.retab(getline(lnum))) 148 | 149 | let offset += self.format_lines(lnum, len(lines)) 150 | 151 | if self.is_comment_enabled() 152 | " " * */" -> " */" 153 | let lnum = a:lnum + i + (len(lines) - 1) + offset 154 | let line = getline(lnum) 155 | let [indent, com_str, mindent, text, com_flags] = self.parse_leader(line) 156 | if com_flags =~# 'm' 157 | let [s, m, e] = self.find_three_piece_comments(&comments, com_flags, com_str) 158 | if text == e[1] 159 | let line = indent . e[1] 160 | call setline(lnum, line) 161 | endif 162 | endif 163 | endif 164 | 165 | endfor 166 | 167 | " The cursor is left on the first non-blank of the last formatted line. 168 | let lnum = a:lnum + (a:count - 1) + offset 169 | execute printf('keepjumps normal! %dG', lnum) 170 | endfunction 171 | 172 | function s:lib.format_insert_mode(char) 173 | " @warning char can be "" when completion is used 174 | " @return a:char for debug 175 | 176 | let self.textwidth = self.comp_textwidth(0) 177 | 178 | let lnum = line('.') 179 | let col = col('.') - 1 180 | let vcol = (virtcol('.') - 1) + s:strdisplaywidth(a:char) 181 | let line = getline(lnum) 182 | 183 | if self.textwidth == 0 184 | \ || vcol <= self.textwidth 185 | \ || (!self.has_format_options('t') && !self.has_format_options('c')) 186 | \ || (!self.has_format_options('t') && self.has_format_options('c') 187 | \ && !self.is_comment(line)) 188 | return a:char 189 | endif 190 | 191 | " split line at the cursor and insert v:char temporarily 192 | let [line, rest] = [line[: col - 1] . a:char, line[col :]] 193 | call setline(lnum, line) 194 | 195 | let lnum += self.format_lines(lnum, 1) 196 | 197 | " remove v:char and restore actual line 198 | let line = getline(lnum) 199 | let col = len(line) - len(a:char) 200 | if a:char != "" 201 | let line = substitute(line, '.$', '', '') 202 | endif 203 | call setline(lnum, line . rest) 204 | call cursor(lnum, col + 1) 205 | 206 | return a:char 207 | endfunction 208 | 209 | function s:lib.format_lines(lnum, count) 210 | let lnum = a:lnum 211 | let prev_lines = line('$') 212 | let fo_2 = self.get_second_line_leader(getline(lnum, lnum + a:count - 1)) 213 | " If the line doesn't start with a comment leader, then don't start 214 | " one in a following broken line. (edit.c:internal_format():6063) 215 | let no_leader = !self.is_comment(getline(lnum)) 216 | let lines = getline(lnum, lnum + a:count - 1) 217 | let line = self.join_lines(lines) 218 | call setline(lnum, line) 219 | if a:count > 1 220 | execute printf('silent %ddelete _ %d', lnum + 1, a:count - 1) 221 | endif 222 | while 1 223 | let line = getline(lnum) 224 | let col = self.find_boundary(line) 225 | if col == -1 226 | break 227 | endif 228 | let line1 = substitute(line[: col - 1], '\s*$', '', '') 229 | let line2 = substitute(line[col :], '^\s*', '', '') 230 | call setline(lnum, line1) 231 | call append(lnum, line2) 232 | if fo_2 != -1 233 | let leader = fo_2 234 | else 235 | let leader = self.make_leader(lnum + 1, no_leader) 236 | endif 237 | call setline(lnum + 1, leader . line2) 238 | let lnum += 1 239 | let fo_2 = -1 240 | endwhile 241 | return line('$') - prev_lines 242 | endfunction 243 | 244 | function s:lib.find_boundary(line) 245 | let start_col = self.skip_leader(a:line) 246 | if start_col == len(a:line) 247 | return -1 248 | endif 249 | let lst = self.line2list(a:line) 250 | let break_idx = -1 251 | let i = 0 252 | while lst[i].col < start_col 253 | let i += 1 254 | endwhile 255 | let is_prev_one_letter = 0 256 | let start_idx = i 257 | let i = self.skip_word(lst, i) 258 | let i = self.skip_space(lst, i) 259 | while i < len(lst) 260 | let brk = self.check_boundary(lst, i) 261 | let next = self.skip_word(lst, i) 262 | if is_prev_one_letter && brk == "allow_break" && &fo =~ '1' 263 | " don't break a line after a one-letter word. 264 | let brk = "allow_break_before" 265 | endif 266 | if brk == "allow_break" 267 | let break_idx = i 268 | if self.textwidth < lst[next - 1].virtcol 269 | return lst[break_idx].col 270 | endif 271 | let is_prev_one_letter = (i == 0 || lst[i - 1].c =~ '\s') && 272 | \ (i + 1 == len(lst) || lst[i + 1].c =~ '\s') 273 | elseif brk == "allow_break_before" 274 | if self.textwidth < lst[next - 1].virtcol && break_idx != -1 275 | return lst[break_idx].col 276 | endif 277 | let is_prev_one_letter = (i == 0 || lst[i - 1].c =~ '\s') && 278 | \ (i + 1 == len(lst) || lst[i + 1].c =~ '\s') 279 | endif 280 | let i = self.skip_space(lst, next) 281 | endwhile 282 | return -1 283 | endfunction 284 | 285 | function s:lib.check_boundary(lst, i) 286 | " Check whether a line can be broken before lst[i]. 287 | " 288 | " @param lst line as List of Dictionary 289 | " lst[i].c character 290 | " lst[i].w width of character 291 | " lst[i].col same as col(), but 0 based 292 | " lst[i].virtcol same as virtcol(), but 0 based 293 | " @param i index of lst 294 | " @return line break status 295 | " "allow_break" Line can be broken between lst[i-1] and lst[i]. 296 | " "allow_break_before" If lst[i] is over the 'textwidth', break a line at 297 | " previous breakable point, if possible. 298 | " other Do not break. 299 | " 300 | 301 | let [lst, i] = [a:lst, a:i] 302 | 303 | if lst[i-1].c =~ '\s' 304 | return "allow_break" 305 | elseif &fo =~# 'm' 306 | let bc = char2nr(lst[i-1].c) 307 | let ac = char2nr(lst[i].c) 308 | if bc > 255 || ac > 255 309 | return "allow_break" 310 | endif 311 | endif 312 | return "allow_break_before" 313 | endfunction 314 | 315 | function s:lib.skip_word(lst, i) 316 | " @return end_of_word + 1 317 | 318 | let [lst, i] = [a:lst, a:i + 1] 319 | if lst[i - 1].c =~ '\h' 320 | while i < len(lst) && lst[i].c =~ '\w' 321 | let i += 1 322 | endwhile 323 | endif 324 | return i 325 | endfunction 326 | 327 | function s:lib.skip_space(lst, i) 328 | let [lst, i] = [a:lst, a:i] 329 | while i < len(lst) && lst[i].c =~ '\s' 330 | let i += 1 331 | endwhile 332 | return i 333 | endfunction 334 | 335 | function s:lib.skip_leader(line) 336 | let col = 0 337 | if self.is_comment_enabled() 338 | let [indent, com_str, mindent, text, com_flags] = self.parse_leader(a:line) 339 | let col += len(indent) + len(com_str) + len(mindent) 340 | else 341 | let [indent, text] = matchlist(a:line, '\v^(\s*)(.*)$')[1:2] 342 | let col += len(indent) 343 | endif 344 | if self.has_format_options('n') 345 | let listpat = matchstr(text, &formatlistpat) 346 | if listpat != "" 347 | let col += len(listpat) 348 | let col += len(matchstr(text, '\s*', len(listpat))) 349 | endif 350 | endif 351 | return col 352 | endfunction 353 | 354 | function s:lib.get_paragraph(lines) 355 | " @param lines List of String 356 | " @return List of Paragraph 357 | " [ [start_index, [line1 ,line2, ...]], ...] 358 | " For example: 359 | " lines = ["", "line2", "line3", "", "", "line6", ""] 360 | " => [ [1, ["line2", "line3"]], [5, ["line6"]] ] 361 | " 362 | " @see opt.c:same_leader() 363 | " 364 | " TODO: check for 'f' comment or 'formatlistpat'. make option? 365 | " orig vim useful? 366 | " 1: - line1 1: - line1 line2 1: - line1 367 | " 2: line2 2: line2 368 | " use indent? 369 | " 1: hoge fuga 1: hoge fuga 1: hoge fuga 370 | " 2: - list1 2: - list1 2: - list1 371 | " 3: - list2 3: - list2 hoge 3: - list2 372 | " 4: hoge fuga 4: fuga 4: hoge fuga 373 | 374 | let res = [] 375 | let pl = [] 376 | for line in a:lines 377 | call add(pl, self.parse_leader(line)) 378 | endfor 379 | let i = 0 380 | while i < len(a:lines) 381 | while i < len(a:lines) && pl[i][3] == "" 382 | let i += 1 383 | endwhile 384 | if i == len(a:lines) 385 | break 386 | endif 387 | let start = i 388 | let i += 1 389 | while i < len(a:lines) && pl[i][3] != "" 390 | if pl[start][4] =~# 'f' 391 | if pl[i][1] != '' 392 | break 393 | endif 394 | elseif pl[start][4] =~# 'e' 395 | break 396 | elseif pl[start][4] =~# 's' 397 | if pl[i][4] !~# 'm' 398 | break 399 | endif 400 | elseif pl[i-1][1] != pl[i][1] || (pl[i-1][2] != '' && pl[i][2] == '') 401 | " start/end of comment or different comment 402 | break 403 | endif 404 | if self.has_format_options('n') && pl[i][3] =~ &formatlistpat 405 | " start of list 406 | break 407 | elseif self.has_format_options('2') 408 | " separate with indent 409 | " make this behavior optional? 410 | let indent1 = s:strdisplaywidth(pl[i-1][0] . pl[i-1][1] . pl[i-1][2]) 411 | let indent2 = s:strdisplaywidth(pl[i][0] . pl[i][1] . pl[i][2]) 412 | if indent1 < indent2 413 | break 414 | endif 415 | endif 416 | let i += 1 417 | endwhile 418 | call add(res, [start, a:lines[start : i - 1]]) 419 | endwhile 420 | return res 421 | endfunction 422 | 423 | function s:lib.join_lines(lines) 424 | " :join + remove comment leader 425 | 426 | let res = a:lines[0] 427 | for line in a:lines[1:] 428 | if self.is_comment_enabled() 429 | let [indent, com_str, mindent, text, com_flags] = self.parse_leader(line) 430 | if com_flags =~# '[se]' 431 | let text = com_str . mindent . text 432 | endif 433 | else 434 | let text = substitute(line, '^\s\+', '', '') 435 | endif 436 | if res == "" 437 | let res = text 438 | elseif text != "" 439 | let res = self.join_line(substitute(res, '\s\+$', '', ''), text) 440 | endif 441 | endfor 442 | " To remove trailing space? Vim doesn't do it. 443 | " let res = substitute(res, '\s\+$', '', '') 444 | return res 445 | endfunction 446 | 447 | function s:lib.join_line(line1, line2) 448 | " Join two lines. 449 | " 450 | " Spaces at end of line1 and comment leader of line2 should be removed 451 | " before invoking. 452 | " 453 | " Make sure that broken line should be joined as original line, so that we 454 | " can re-format a paragraph without losing user typed space or adding 455 | " unexpected space. 456 | 457 | let bc = matchstr(a:line1, '.$') 458 | let ac = matchstr(a:line2, '^.') 459 | 460 | if a:line2 == "" 461 | return a:line1 462 | elseif &joinspaces && bc =~# ((&cpoptions =~# 'j') ? '[.]' : '[.?!]') 463 | return a:line1 . " " . a:line2 464 | elseif (self.has_format_options('M') && (len(bc) != 1 || len(ac) != 1)) 465 | \ || (self.has_format_options('B') && (len(bc) != 1 && len(ac) != 1)) 466 | return a:line1 . a:line2 467 | else 468 | return a:line1 . " " . a:line2 469 | endif 470 | endfunction 471 | 472 | " vim/src/options.c 473 | " Return TRUE if format option 'x' is in effect. 474 | " Take care of no formatting when 'paste' is set. 475 | function s:lib.has_format_options(x) 476 | if &paste 477 | return 0 478 | endif 479 | return stridx(&formatoptions, a:x) != -1 480 | endfunction 481 | 482 | function s:lib.is_comment_enabled() 483 | if mode() == 'n' 484 | return self.has_format_options('q') 485 | else 486 | return self.has_format_options('c') 487 | endif 488 | endfunction 489 | 490 | function s:lib.is_comment(line) 491 | let com_str = self.parse_leader(a:line)[1] 492 | return com_str != "" 493 | endfunction 494 | 495 | function s:lib.parse_leader(line) 496 | " +-------- indent 497 | " | +------ com_str 498 | " | | +---- mindent 499 | " | | | + text 500 | " v v v v 501 | " | /* xxx| 502 | " 503 | " @return [indent, com_str, mindent, text, com_flags] 504 | 505 | if a:line =~# '^\s*$' 506 | return [a:line, "", "", "", ""] 507 | endif 508 | let middle = [] 509 | for [flags, str] in self.parse_opt_comments(&comments) 510 | let mx = printf('\v^(\s*)(\V%s\v)(\s%s|$)(.*)$', escape(str, '\'), 511 | \ (flags =~# 'b') ? '+' : '*') 512 | " If we found a middle match previously, use that match when this is 513 | " not a middle or end. */ 514 | if !empty(middle) && flags !~# '[me]' 515 | break 516 | endif 517 | if a:line =~# mx 518 | let res = matchlist(a:line, mx)[1:4] + [flags] 519 | " We have found a match, stop searching unless this is a middle 520 | " comment. The middle comment can be a substring of the end 521 | " comment in which case it's better to return the length of the 522 | " end comment and its flags. Thus we keep searching with middle 523 | " and end matches and use an end match if it matches better. 524 | if flags =~# 'm' 525 | let middle = res 526 | continue 527 | elseif flags =~# 'e' 528 | if !empty(middle) && strchars(res[1]) <= strchars(middle[1]) 529 | let res = middle 530 | endif 531 | elseif flags =~# 'n' 532 | " nested comment 533 | while 1 534 | let [indent, com_str, mindent, text, com_flags] = self.parse_leader(res[3]) 535 | if com_flags !~# 'n' 536 | break 537 | endif 538 | let res = [res[0], res[1] . res[2] . com_str, mindent, text, res[4]] 539 | endwhile 540 | endif 541 | return res 542 | endif 543 | endfor 544 | if !empty(middle) 545 | return middle 546 | endif 547 | return matchlist(a:line, '\v^(\s*)()()(.*)$')[1:4] + [""] 548 | endfunction 549 | 550 | function s:lib.parse_opt_comments(comments) 551 | " @param comments 'comments' option 552 | " @return [[flags, str], ...] 553 | 554 | let res = [] 555 | for com in split(a:comments, '[^\\]\zs,') 556 | let [flags; _] = split(com, ':', 1) 557 | " str can contain ':' and ',' 558 | let str = join(_, ':') 559 | let str = substitute(str, '\\,', ',', 'g') 560 | call add(res, [flags, str]) 561 | endfor 562 | return res 563 | endfunction 564 | 565 | function s:lib.find_three_piece_comments(comments, flags, str) 566 | let coms = self.parse_opt_comments(a:comments) 567 | for i in range(len(coms)) 568 | if coms[i][0] == a:flags && coms[i][1] == a:str 569 | if a:flags =~# 's' 570 | return coms[i : i + 2] 571 | elseif a:flags =~# 'm' 572 | return coms[i - 1 : i + 1] 573 | elseif a:flags =~# 'e' 574 | return coms[i - 2 : i] 575 | endif 576 | endif 577 | endfor 578 | endfunction 579 | 580 | function s:lib.line2list(line) 581 | let res = [] 582 | let [col, virtcol] = [0, 0] 583 | for c in split(a:line, '\zs') 584 | let w = s:strdisplaywidth(c, virtcol) 585 | let virtcol += w 586 | call add(res, { 587 | \ "c": c, 588 | \ "w": w, 589 | \ "col": col, 590 | \ "virtcol": virtcol, 591 | \ }) 592 | let col += len(c) 593 | endfor 594 | return res 595 | endfunction 596 | 597 | function s:lib.list2line(lst) 598 | return join(map(copy(a:lst), 'v:val.c'), '') 599 | endfunction 600 | 601 | function s:lib.get_second_line_leader(lines) 602 | if !self.has_format_options('2') || len(a:lines) <= 1 603 | return -1 604 | endif 605 | let [indent1, com_str1, mindent1, text1, _] = self.parse_leader(a:lines[0]) 606 | let [indent2, com_str2, mindent2, text2, _] = self.parse_leader(a:lines[1]) 607 | if com_str1 == "" && com_str2 == "" && text2 != "" 608 | if s:strdisplaywidth(indent1) > s:strdisplaywidth(indent2) 609 | return indent2 610 | endif 611 | elseif com_str1 != "" && com_str2 != "" && text2 != "" 612 | if s:strdisplaywidth(indent1 . com_str1 . mindent1) > s:strdisplaywidth(indent2 . com_str2 . mindent2) 613 | return indent2 . com_str2 . mindent2 614 | endif 615 | endif 616 | return -1 617 | endfunction 618 | 619 | function s:lib.make_leader(lnum, no_leader) 620 | let prev_line = getline(a:lnum - 1) 621 | 622 | if !a:no_leader && self.is_comment_enabled() && self.is_comment(prev_line) 623 | return self.make_comment_leader(prev_line) 624 | endif 625 | 626 | let listpat = matchstr(prev_line, &formatlistpat) 627 | 628 | if self.has_format_options('n') && listpat != '' 629 | let indent = repeat(' ', s:strdisplaywidth(listpat)) 630 | else 631 | let indent = repeat(' ', self.comp_indent(a:lnum)) 632 | endif 633 | 634 | if ©indent 635 | let [indent, rest] = self.copy_indent(prev_line, indent) 636 | let indent = indent . rest 637 | else 638 | let indent = self.retab(indent) 639 | endif 640 | 641 | return indent 642 | endfunction 643 | 644 | function s:lib.make_comment_leader(line) 645 | let do_si = !&paste && &smartindent && !&cindent 646 | let [indent, com_str, mindent, text, com_flags] = self.parse_leader(a:line) 647 | let extra_space = '' 648 | let leader = indent . com_str . mindent 649 | if self.has_format_options('n') 650 | let listpat = matchstr(text, &formatlistpat) 651 | let listpat_indent = repeat(' ', s:strdisplaywidth(listpat)) 652 | else 653 | let listpat_indent = "" 654 | endif 655 | if com_str == "" 656 | if !&autoindent 657 | let indent = '' 658 | endif 659 | let [indent, com_str, mindent] = [indent, '', listpat_indent] 660 | elseif com_flags =~# 'e' 661 | let [indent, com_str, mindent] = [indent, '', ''] 662 | else 663 | let extra_space = '' 664 | if com_flags =~# 's' 665 | if !&autoindent 666 | let indent = '' 667 | endif 668 | let [s, m, e] = self.find_three_piece_comments(&comments, com_flags, com_str) 669 | let lead_repl = m[1] 670 | if leader !~ ' $' && m[0] =~# 'b' 671 | let extra_space = ' ' 672 | endif 673 | elseif com_flags =~# 'm' 674 | " pass 675 | elseif com_flags =~# 'f' 676 | let lead_repl = '' 677 | else 678 | " pass 679 | endif 680 | if exists('lead_repl') 681 | let off = matchstr(com_flags, '-\?\d\+\ze[^0-9]*') + 0 682 | let adjust = matchstr(com_flags, '\c[lr]\ze[^lr]*') 683 | if adjust ==# 'r' 684 | let newindent = s:strdisplaywidth(indent . com_str) - s:strdisplaywidth(lead_repl) 685 | if newindent < 0 686 | let newindent = 0 687 | endif 688 | else 689 | let newindent = s:strdisplaywidth(indent) 690 | let w1 = s:strdisplaywidth(com_str) 691 | let w2 = s:strdisplaywidth(lead_repl) 692 | if w1 > w2 && mindent[0] != "\t" 693 | let mindent = repeat(' ', w1 - w2) . mindent 694 | endif 695 | endif 696 | let _leader = repeat(' ', newindent) . lead_repl . mindent 697 | " Recompute the indent, it may have changed. 698 | if &autoindent || do_si 699 | let newindent = s:strdisplaywidth(matchstr(_leader, '^\s*')) 700 | endif 701 | if newindent + off < 0 702 | let off = -newindent 703 | let newindent = 0 704 | else 705 | let newindent += off 706 | endif 707 | " Correct trailing spaces for the shift, so that alignment remains equal. 708 | " Don't do it when there is a tab before the space 709 | while off > 0 && _leader != '' && _leader =~ ' $' && _leader !~ '\t' 710 | let _leader = strpart(_leader, 0, len(_leader) - 1) 711 | let off -= 1 712 | endwhile 713 | let _ = matchlist(_leader, '^\s*\(\S*\)\(\s*\)$') 714 | if _[2] != '' 715 | let extra_space = '' 716 | endif 717 | let [indent, com_str, mindent] = [repeat(' ', newindent), _[1], _[2] . extra_space . listpat_indent] 718 | else 719 | let [indent, com_str, mindent] = [indent, com_str, mindent . listpat_indent] 720 | endif 721 | endif 722 | if ©indent 723 | let [indent, rest] = self.copy_indent(a:line, indent) 724 | else 725 | let indent = self.retab(indent) 726 | let rest = '' 727 | endif 728 | let leader = indent . rest . com_str . mindent 729 | if com_str == '' 730 | let leader = self.retab(leader, len(indent)) 731 | endif 732 | return leader 733 | endfunction 734 | 735 | function s:lib.copy_indent(line1, line2) 736 | " @return [copied_indent, rest_indent . text] 737 | let indent1 = matchstr(a:line1, '^\s*') 738 | let indent2 = matchstr(a:line2, '^\s*') 739 | let text = matchstr(a:line2, '^\s*\zs.*$') 740 | let n1 = s:strdisplaywidth(indent1) 741 | let n2 = s:strdisplaywidth(indent2) 742 | let indent = matchstr(indent1, '^\s*\%<' . (n2 + 2) . 'v') 743 | if n2 > n1 744 | let text = repeat(' ', n2 - n1) . text 745 | endif 746 | return [indent, text] 747 | endfunction 748 | 749 | function s:lib.retab(line, ...) 750 | let col = get(a:000, 0, 0) 751 | let expandtab = get(a:000, 1, &expandtab) 752 | let tabstop = get(a:000, 2, &tabstop) 753 | let s2 = matchstr(a:line, '^\s*', col) 754 | if s2 == '' 755 | return a:line 756 | endif 757 | let s1 = strpart(a:line, 0, col) 758 | let t = strpart(a:line, col + len(s2)) 759 | let n1 = s:strdisplaywidth(s1) 760 | let n2 = s:strdisplaywidth(s2, n1) 761 | if expandtab 762 | let s2 = repeat(' ', n2) 763 | else 764 | if n1 != 0 && n2 >= (tabstop - (n1 % tabstop)) 765 | let n2 += n1 % tabstop 766 | endif 767 | let s2 = repeat("\t", n2 / tabstop) . repeat(' ', n2 % tabstop) 768 | endif 769 | return s1 . s2 . t 770 | endfunction 771 | 772 | function s:lib.get_opt(name) 773 | return get(w:, a:name, 774 | \ get(t:, a:name, 775 | \ get(b:, a:name, 776 | \ get(g:, a:name, 777 | \ get(self, a:name))))) 778 | endfunction 779 | 780 | " vim/src/edit.c 781 | " Find out textwidth to be used for formatting: 782 | " if 'textwidth' option is set, use it 783 | " else if 'wrapmargin' option is set, use W_WIDTH(curwin) - 'wrapmargin' 784 | " if invalid value, use 0. 785 | " Set default to window width (maximum 79) for "gq" operator. 786 | " @param ff force formatting (for "gq" command) 787 | function s:lib.comp_textwidth(ff) 788 | let textwidth = &textwidth 789 | 790 | if textwidth == 0 && &wrapmargin 791 | " The width is the window width minus 'wrapmargin' minus all the 792 | " things that add to the margin. 793 | let textwidth = winwidth(0) - &wrapmargin 794 | 795 | if self.is_cmdwin() 796 | let textwidth -= 1 797 | endif 798 | 799 | if has('folding') 800 | let textwidth -= &foldcolumn 801 | endif 802 | 803 | if has('signs') 804 | if self.has_sign() || has('netbeans_enabled') 805 | let textwidth -= 1 806 | endif 807 | endif 808 | 809 | if &number || &relativenumber 810 | let textwidth -= 8 811 | endif 812 | endif 813 | 814 | if textwidth < 0 815 | let textwidth = 0 816 | endif 817 | 818 | if a:ff && textwidth == 0 819 | let textwidth = winwidth(0) - 1 820 | if textwidth > 79 821 | let textwidth = 79 822 | endif 823 | endif 824 | 825 | return textwidth 826 | endfunction 827 | 828 | if exists('*getcmdwintype') 829 | function s:lib.is_cmdwin() 830 | return getcmdwintype() != '' 831 | endfunction 832 | else 833 | function s:lib.is_cmdwin() 834 | 835 | " workaround1 836 | "return bufname('%') == '[Command Line]' 837 | 838 | " workaround2 839 | " MEMO: In formatexpr, exception is not raised without setting 'debug'. 840 | let debug_save = &debug 841 | set debug=throw 842 | try 843 | execute winnr() . "wincmd w" 844 | " or 845 | "execute "tabnext " . tabpagenr() 846 | catch /^Vim\%((\a\+)\)\=:E11:/ 847 | " Vim(wincmd):E11: Invalid in command-line window; executes, CTRL-C quits: 2wincmd w 848 | " Vim(tabnext):E11: Invalid in command-line window; executes, CTRL-C quits: tabnext 1 849 | return 1 850 | finally 851 | let &debug = debug_save 852 | endtry 853 | return 0 854 | 855 | endfunction 856 | endif 857 | 858 | " FIXME: This may break another :redir session? 859 | " It is useful if vim provide builtin function for this. 860 | function s:lib.has_sign() 861 | redir => s 862 | execute printf('silent sign place buffer=%d', bufnr('%')) 863 | redir END 864 | let lines = split(s, '\n') 865 | " When no sign, lines == ['--- Signs ---'] 866 | return len(lines) > 1 867 | endfunction 868 | 869 | function s:lib.comp_indent(lnum) 870 | if &indentexpr != '' 871 | if &paste 872 | return 0 873 | endif 874 | let v:lnum = a:lnum 875 | return eval(&indentexpr) 876 | elseif &cindent 877 | if &paste 878 | return 0 879 | endif 880 | return cindent(a:lnum) 881 | elseif &lisp 882 | if &paste 883 | return 0 884 | endif 885 | if !&autoindent 886 | return 0 887 | endif 888 | return lispindent(a:lnum) 889 | elseif &smartindent 890 | if &paste 891 | return 0 892 | endif 893 | return self.smartindent(a:lnum) 894 | elseif &autoindent 895 | return indent(a:lnum - 1) 896 | endif 897 | return 0 898 | endfunction 899 | 900 | function s:lib.smartindent(lnum) 901 | if &paste 902 | return 0 903 | endif 904 | let prev_lnum = a:lnum - 1 905 | while prev_lnum > 1 && getline(prev_lnum) =~ '^#' 906 | let prev_lnum -= 1 907 | endwhile 908 | if prev_lnum <= 1 909 | return 0 910 | endif 911 | let prev_line = getline(prev_lnum) 912 | let firstword = matchstr(prev_line, '^\s*\zs\w\+') 913 | let cinwords = split(&cinwords, ',') 914 | if prev_line =~ '{$' || index(cinwords, firstword) != -1 915 | let n = indent(prev_lnum) + &shiftwidth 916 | if &shiftround 917 | let n = n - (n % &shiftwidth) 918 | endif 919 | return n 920 | endif 921 | return indent(prev_lnum) 922 | endfunction 923 | 924 | let &cpo = s:cpo_save 925 | 926 | -------------------------------------------------------------------------------- /autoload/autofmt/japanese.vim: -------------------------------------------------------------------------------- 1 | " Maintainer: Yukihiro Nakadaira 2 | " License: This file is placed in the public domain. 3 | " Last Change: 2011-01-11 4 | " 5 | " Options: 6 | " 7 | " autofmt_allow_over_tw number (default: 0) 8 | " 9 | " Allow character, prohibited a line break before, to over 'textwidth' 10 | " only given width. 11 | " 12 | " 13 | " autofmt_allow_over_tw_char string (default: see below) 14 | " 15 | " Character, prohibited a line break before. This variable is used with 16 | " autofmt_allow_over_tw. 17 | " 18 | 19 | scriptencoding utf-8 20 | 21 | let s:cpo_save = &cpo 22 | set cpo&vim 23 | 24 | function autofmt#japanese#formatexpr() 25 | return s:lib.formatexpr() 26 | endfunction 27 | 28 | function autofmt#japanese#import() 29 | return s:lib 30 | endfunction 31 | 32 | let s:compat = autofmt#compat#import() 33 | let s:uax14 = autofmt#uax14#import() 34 | 35 | let s:lib = {} 36 | call extend(s:lib, s:compat) 37 | 38 | let s:lib.autofmt_allow_over_tw = 0 39 | 40 | " JIS X 4051 (Formatting rules for Japanese documents) 41 | " 4.3 Handling character prohibited a line break before 42 | " These character is not allowed to position at start of line. It 43 | " should be dangled over the 'textwidth' or commited to next line with 44 | " previous character. 45 | let s:lib.autofmt_allow_over_tw_char = "" 46 | \ . ",)]}、〕〉》」』】〟’”»" 47 | \ . "ヽヾーァィゥェォッャュョヮヵヶゝゞぁぃぅぇぉっゃゅょゃゎ々" 48 | \ . "‐" 49 | \ . "?!" 50 | \ . "・:;" 51 | \ . "。." 52 | " compatible character with different width or code point 53 | let s:lib.autofmt_allow_over_tw_char .= "" 54 | \ . "°′″,.:;?!)]}…~" 55 | " not in cp932 56 | if &encoding == 'utf-8' 57 | let s:lib.autofmt_allow_over_tw_char .= "〙〗⦆ゕゖ゠–〜‼⁇⁈⁉" 58 | endif 59 | 60 | 61 | function! s:lib.check_boundary(lst, i) 62 | let [lst, i] = [a:lst, a:i] 63 | let tw = self.textwidth + self.get_opt("autofmt_allow_over_tw") 64 | let tw_char = self.get_opt("autofmt_allow_over_tw_char") 65 | if self.textwidth < lst[i].virtcol && lst[i].virtcol <= tw 66 | " Dangling wrap. Allow character, prohibited a line break before, to 67 | " over 'textwidth'. 68 | if stridx(tw_char, lst[i].c) != -1 69 | return "no_break" 70 | endif 71 | endif 72 | " use compat for single byte text 73 | if len(lst[i - 1].c) == 1 && len(lst[i].c) == 1 74 | return s:compat.check_boundary(lst, i) 75 | endif 76 | " use UAX #14 as default 77 | return s:uax14.check_boundary(lst, i) 78 | endfunction 79 | 80 | function! s:lib.join_line(line1, line2) 81 | if matchstr(a:line1, '.$') =~ '[、。]' 82 | " Don't insert space after Japanese punctuation. 83 | return a:line1 . a:line2 84 | endif 85 | return call(s:compat.join_line, [a:line1, a:line2], self) 86 | endfunction 87 | 88 | function! s:lib.get_paragraph(lines) 89 | let para = call(s:compat.get_paragraph, [a:lines], self) 90 | let i = 0 91 | while i < len(para) 92 | let [lnum, lines] = para[i] 93 | let j = 1 94 | while j < len(lines) 95 | if lines[j] =~ '^ ' || self.parse_leader(lines[j])[3] =~ '^ ' 96 | " U+3000 at start of line means new paragraph. split this paragraph. 97 | call insert(para, [para[i][0], remove(para[i][1], 0, j - 1)], i) 98 | let i += 1 99 | let para[i][0] += j 100 | let j = 1 101 | else 102 | let j += 1 103 | endif 104 | endwhile 105 | let i += 1 106 | endwhile 107 | return para 108 | endfunction 109 | 110 | let &cpo = s:cpo_save 111 | 112 | -------------------------------------------------------------------------------- /autoload/autofmt/uax14.vim: -------------------------------------------------------------------------------- 1 | " Maintainer: Yukihiro Nakadaira 2 | " License: This file is placed in the public domain. 3 | " Last Change: 2016-11-24 4 | " 5 | " Options: 6 | " 7 | " autofmt_strict_japanese_linebreak number (default: 1) 8 | " 9 | " If set to 1, line break before KATAKANA-HIRAGANA PROLONGED SOUND MARK 10 | " and small kana letters are disallowed. If set to 0, they are allowed. 11 | " 12 | 13 | let s:cpo_save = &cpo 14 | set cpo&vim 15 | 16 | function autofmt#uax14#formatexpr() 17 | return s:lib.formatexpr() 18 | endfunction 19 | 20 | function autofmt#uax14#import() 21 | return s:lib 22 | endfunction 23 | 24 | let s:compat = autofmt#compat#import() 25 | 26 | let s:lib = {} 27 | call extend(s:lib, s:compat) 28 | 29 | let s:lib.autofmt_strict_japanese_linebreak = 1 30 | let s:lib.uni = autofmt#unicode#import() 31 | 32 | function! s:lib.check_boundary(lst, i) 33 | " UAX #14: Line Breaking Properties 34 | " 7. Pair Table-Based Implementation 35 | 36 | let [lst, i] = [a:lst, a:i] 37 | 38 | let after = self.uni.prop_line_break(lst[i].c) 39 | if after == "AI" " Ambiguous (Alphabetic or Ideograph) 40 | let after = (lst[i].w == 1) ? "AL" : "ID" 41 | elseif after == "CJ" " Conditional Japanese Starter 42 | let after = self.get_opt("autofmt_strict_japanese_linebreak") ? "NS" : "ID" 43 | endif 44 | 45 | let j = i - 1 46 | while j > 0 && lst[j].c =~ '\s' 47 | let j -= 1 48 | endwhile 49 | 50 | let before = self.uni.prop_line_break(lst[j].c) 51 | if before == "AI" " Ambiguous (Alphabetic or Ideograph) 52 | let before = (lst[j].w == 1) ? "AL" : "ID" 53 | elseif before == "CJ" " Conditional Japanese Starter 54 | let before = self.get_opt("autofmt_strict_japanese_linebreak") ? "NS" : "ID" 55 | endif 56 | 57 | let brk = self.uni.uax14_pair_table(before, after) 58 | if brk == self.uni.INDIRECT_BRK 59 | if lst[i - 1].c =~ '\s' 60 | let brk = self.uni.INDIRECT_BRK 61 | else 62 | let brk = self.uni.PROHIBITED_BRK 63 | endif 64 | endif 65 | 66 | if brk == self.uni.DIRECT_BRK || brk == self.uni.INDIRECT_BRK 67 | return "allow_break" 68 | else 69 | return "allow_break_before" 70 | endif 71 | endfunction 72 | 73 | let &cpo = s:cpo_save 74 | 75 | -------------------------------------------------------------------------------- /doc/autofmt.txt: -------------------------------------------------------------------------------- 1 | *autofmt.txt* Text Formatting Plugin 2 | 3 | Maintainer: Yukihiro Nakadaira 4 | License: public domain 5 | 6 | 7 | This is a 'formatexpr' plugin. 8 | 9 | 1. Usage |autofmt-usage| 10 | 2. Language |autofmt-language| 11 | 3. Customize Unicode Line Break Property |autofmt-customize| 12 | 13 | {only works when 'encoding' is utf-8 or |+iconv| is enabled} 14 | 15 | ============================================================================== 16 | 1. Usage *autofmt-usage* 17 | > 18 | :set runtimepath+=/path/to/autofmt/ 19 | :set formatexpr=autofmt#compat#formatexpr() 20 | 21 | Following method can be used: 22 | 23 | autofmt#compat#formatexpr(): Vim compatible 24 | autofmt#uax14#formatexpr(): Implementation of UAX #14 25 | autofmt#japanese#formatexpr(): Japanese 26 | 27 | UAX #14: Line Breaking Properties: http://unicode.org/reports/tr14/. 28 | 29 | ============================================================================== 30 | 2. Language *autofmt-language* 31 | 32 | If you want to create your 'formatexpr' plugin, autofmt can be used as 33 | framework. You can define your language specific formatting easily. 34 | For example: > 35 | 36 | set formatexpr=myfmt.formatexpr() 37 | 38 | let s:compat = autofmt#compat#import() 39 | 40 | let myfmt = {} 41 | call extend(myfmt, s:compat) 42 | 43 | function! myfmt.check_boundary(lst, i) 44 | if a:lst[a:i].c == "x" 45 | " It is possible to break a line before 'x'. 46 | return "allow_break" 47 | elseif a:lst[a:i].c == "y" 48 | " It is impossible to break a line before 'y'. 49 | return "no_break" 50 | else 51 | " Use default behavior. 52 | return call(s:compat.check_boundary, [a:lst, a:i], self) 53 | endif 54 | endfunction 55 | < 56 | ============================================================================== 57 | 3. Customize Unicode Line Break Property *autofmt-customize* 58 | 59 | uax14.vim is Pair Table-Based implementation of UAX #14. It uses Unicode Line 60 | Break Property. But it is not useful for all language. You can customize it 61 | for your language. 62 | For example, line break is not allowed before LEFT DOUBLE QUOTATION MARK 63 | (U+201C) without space. To change its behavior as Open Punctuation (e.g. "(", 64 | "{", etc...): 65 | > 66 | " Use uax14 67 | set formatexpr=autofmt#uax14#formatexpr() 68 | 69 | " Customize Line Break Property 70 | let s:unicode = autofmt#unicode#import() 71 | let s:orig_prop_line_break = s:unicode.prop_line_break 72 | function! s:unicode.prop_line_break(char) 73 | if a:char == "\u201c" || a:char == "\u2018" 74 | return "OP" " Open Punctuation 75 | elseif a:char == "\u201d" || a:char == "\u2019" 76 | return "CL" " Close Punctuation 77 | endif 78 | return call(s:orig_prop_line_break, [a:char], self) 79 | endfunction 80 | < 81 | Add this code in your vimrc. 82 | 83 | See http://unicode.org/reports/tr14/ for more information. 84 | 85 | vim:tw=78:ts=8:ft=help:norl: 86 | -------------------------------------------------------------------------------- /doc/tags: -------------------------------------------------------------------------------- 1 | autofmt-customize autofmt.txt /*autofmt-customize* 2 | autofmt-language autofmt.txt /*autofmt-language* 3 | autofmt-usage autofmt.txt /*autofmt-usage* 4 | autofmt.txt autofmt.txt /*autofmt.txt* 5 | -------------------------------------------------------------------------------- /memo.txt: -------------------------------------------------------------------------------- 1 | 2 | UAX #11: East Asian Width 3 | http://unicode.org/reports/tr11/ 4 | 5 | UAX #14: Line Breaking Properties 6 | http://unicode.org/reports/tr14/ 7 | 8 | Word wrap - Wikipedia 9 | http://en.wikipedia.org/wiki/Word_wrap 10 | 11 | Requirements for Japanese Text Layout 12 | https://www.w3.org/TR/jlreq/ 13 | 日本語組版処理の要件 14 | https://www.w3.org/TR/jlreq/ja/ 15 | Mainly based on JIS X 4051 16 | 17 | JISC 日本工業標準調査会 18 | http://www.jisc.go.jp/ 19 | JIS X 4051 - Wikipedia 20 | http://ja.wikipedia.org/wiki/JIS_X_4051 21 | 22 | JIS X 4051 日本語文書の組版方法 (Formatting rules for Japanese documents) 23 | 24 | 4.3 行頭禁則処理 25 | 終わり括弧類、行頭禁止和字、ハイフン類、区切り約物、中点類及び句点類 26 | が、行頭又は割注行頭にきてはならない。 27 | 4.4 行末禁則処理 28 | 始め括弧類が行末又は割注行末にきてはならない。 29 | 4.5 分離禁止処理 30 | 4.5.1 分割禁止 31 | 分離禁止文字の組を構成する文字間では、分割してはならない。ただし、 32 | 連数字と欧文間隔以外の欧文用文字との間を分割可とするか否かは、処理 33 | 系定義とする。 34 | 4.5.2 分離禁止 35 | 延ばし処理によって行を調整する場合も、分離禁止文字の組を構成するも 36 | 時間には延ばし処理による空き量を入れてはならない。ただし、連数字と 37 | 欧文間隔以外の欧文用文字との間を延ばし可とするか否かは、処理系定義 38 | とする。 39 | 40 | (付属書1より) 文字クラス 41 | 名前 (JIS X 0213 面区点番号) 42 | (1) 始め括弧類 43 | LEFT PARENTHESIS (1-1-42) 44 | LEFT SQUARE BRACKET (1-1-46) 45 | LEFT CURLY BRACKET (1-1-48) 46 | LEFT TORTOISE SHELL BRACKET (1-1-44) 47 | LEFT ANGLE BRACKET (1-1-50) 48 | LEFT DOUBLE ANGLE BRACKET (1-1-52) 49 | LEFT CORNER BRACKET (1-1-54) 50 | LEFT WHITE CORNER BRACKET (1-1-56) 51 | LEFT BLACK LENTICULAR BRACKET (1-1-58) 52 | LEFT WHITE TORTOISE SHELL BRACKET (1-2-56) 53 | LEFT WHITE LENTICULAR BRACKET (1-2-58) 54 | REVERSED DOUBLE PRIME QUOTATION (1-13-64) 55 | LEFT SINGLE QUOTATION MARK (1-1-38) 56 | LEFT DOUBLE QUOTATION MARK (1-1-40) 57 | LEFT WHITE PARENTHESIS (1-2-54) 58 | LEFT-POINTING DOUBLE ANGLE QUOTATION MARK (1-9-8) 59 | (2) 終わり括弧類 60 | COMMA (1-1-4) 61 | RIGHT PARENTHESIS (1-1-43) 62 | RIGHT SQUARE BRACKET (1-1-47) 63 | RIGHT CURLY BRACKET (1-1-49) 64 | IDEOGRAPHIC COMMA (1-1-2) 65 | RIGHT TORTOISE SHELL BRACKET (1-1-45) 66 | RIGHT ANGLE BRACKET (1-1-51) 67 | RIGHT DOUBLE ANGLE BRACKET (1-1-53) 68 | RIGHT CORNER BRACKET (1-1-55) 69 | RIGHT WHITE CORNER BRACKET (1-1-57) 70 | RIGHT BLACK LENTICULAR BRACKET (1-1-59) 71 | RIGHT WHITE TORTOISE SHELL BRACKET (1-2-57) 72 | RIGHT WHITE LENTICULAR BRACKET (1-2-59) 73 | LOW DOUBLE PRIME QUOTATION MARK (1-13-65) 74 | RIGHT SINGLE QUOTATION MARK (1-1-39) 75 | RIGHT DOUBLE QUOTATION MARK (1-1-41) 76 | RIGHT WHITE PARENTHESIS (1-2-55) 77 | RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK (1-9-18) 78 | (3) 行頭禁則和字 79 | KATAKANA ITERATION MARK (1-1-19) 80 | KATAKANA VOICED ITERATION MARK (1-1-20) 81 | KATAKANA-HIRAGANA PROLONGED SOUND MARK (1-1-28) 82 | KATAKANA LETTER SMALL A (1-5-1) 83 | KATAKANA LETTER SMALL I (1-5-3) 84 | KATAKANA LETTER SMALL U (1-5-5) 85 | KATAKANA LETTER SMALL O (1-5-7) 86 | KATAKANA LETTER SMALL TU (1-5-35) 87 | KATAKANA LETTER SMALL YA (1-5-67) 88 | KATAKANA LETTER SMALL YU (1-5-69) 89 | KATAKANA LETTER SMALL YO (1-5-71) 90 | KATAKANA LETTER SMALL WA (1-5-78) 91 | KATAKANA LETTER SMALL WA (1-5-85) 92 | KATAKANA LETTER SMALL KE (1-5-86) 93 | HIRAGANA ITERATION MARK (1-1-21) 94 | HIRAGANA VOICED ITERATION MARK (1-1-22) 95 | HIRAGANA LETTER SMALL A (1-4-1) 96 | HIRAGANA LETTER SMALL I (1-4-3) 97 | HIRAGANA LETTER SMALL U (1-4-5) 98 | HIRAGANA LETTER SMALL E (1-4-7) 99 | HIRAGANA LETTER SMALL O (1-4-9) 100 | HIRAGANA LETTER SMALL TU (1-4-35) 101 | HIRAGANA LETTER SMALL YA (1-4-67) 102 | HIRAGANA LETTER SMALL YU (1-4-69) 103 | HIRAGANA LETTER SMALL YO (1-4-71) 104 | HIRAGANA LETTER SMALL WA (1-4-78) 105 | HIRAGANA LETTER SMALL KA (1-4-85) 106 | HIRAGANA LETTER SMALL KE (1-4-86) 107 | KATAKANA LETTER AINU K (1-6-78) [コード不明] 108 | KATAKANA LETTER AINU SI(S) (1-6-79) [コード不明] 109 | KATAKANA LETTER AINU SU(S) (1-6-80) [コード不明] 110 | KATAKANA LETTER AINU T (1-6-81) [コード不明] 111 | KATAKANA LETTER AINU N (1-6-82) [コード不明] 112 | KATAKANA LETTER AINU AX (1-6-83) [コード不明] 113 | KATAKANA LETTER AINU IX (1-6-84) [コード不明] 114 | KATAKANA LETTER AINU UX (1-6-85) [コード不明] 115 | KATAKANA LETTER AINU EX (1-6-86) [コード不明] 116 | KATAKANA LETTER AINU OX (1-6-87) [コード不明] 117 | KATAKANA LETTER AINU M (1-6-89) [コード不明] 118 | KATAKANA LETTER AINU AR (1-6-90) [コード不明] 119 | KATAKANA LETTER AINU IR (1-6-91) [コード不明] 120 | KATAKANA LETTER AINU UR (1-6-92) [コード不明] 121 | KATAKANA LETTER AINU ER (1-6-93) [コード不明] 122 | KATAKANA LETTER AINU OR (1-6-94) [コード不明] 123 | IDEOGRAPHIC ITERATION MARK (1-1-25) 124 | ITERATION MARK (1-2-22) [コード不明] 125 | (4) ハイフン類 126 | HYPHEN (1-1-30) 127 | DOUBLE HYPHEN (1-3-91) 128 | EN DASH (1-3-92) 129 | WAVE DASH (1-1-33) 130 | (5) 区切り約物 131 | QUESTION MARK (1-1-9) 132 | EXCLAMATION MARK (1-1-10) 133 | DOUBLE EXCLAMATION MARK (1-8-75) 134 | DOUBLE QUESTION MARK (1-8-76) 135 | QUESTION EXCLAMATION MARK (1-8-77) 136 | EXCLAMATION QUESTION MARK (1-8-78) 137 | (6) 中点類 138 | KATAKANA MIDDLE DOT (1-1-6) 139 | COLON (1-1-7) 140 | SEMICOLON (1-1-8) 141 | (7) 句点類 142 | IDEOGRAPHIC FULL STOP (1-1-3) 143 | FULL STOP (1-1-5) 144 | (8) 分離禁止文字 145 | EM DASH (1-1-29) 146 | HORIZONTAL ELLIPSIS (1-1-36) 147 | TWO DOT LEADER (1-1-37) 148 | VERTICAL KANA REPEAT MARK UPPER HALF (1-2-19) 149 | VERTICAL KANA REPEAT WITH VOICED SOUND MARK UPPER HALF (1-2-20) 150 | VERTICAL KANA REPEAT MARK LOWER HALF (1-2-21) 151 | (9) 前置省略記号 152 | YEN SIGN (1-1-79) 153 | POUND SIGN (1-1-82) 154 | DOLLAR SIGN (1-1-80) 155 | NUMBER SIGN (1-1-84) 156 | EURO SIGN (1-9-1) 157 | NUMERO SIGN (1-13-66) 158 | (10) 後置省略記号 159 | DEGREE SIGN (1-1-75) 160 | CENT SIGN (1-1-81) 161 | PRIME (1-1-76) 162 | DOUBLE PRIME (1-1-77) 163 | PER MILLE SIGN (1-2-83) 164 | DEGREE CELSIUS (1-1-78) 165 | SCRIPT SMALL L (1-3-63) 166 | PERCENT SIGN (1-1-83) 167 | SQUARE HP (1-3-62) 168 | (11) 和字間隔 169 | IDEOGRAPHIC SPACE (1-1-1) 170 | (12) 平仮名 171 | 1-4-2~1-4-91 (ただし、行頭禁則和字に含まれる文字を除く。) 172 | (13) (1)~(12) 以外の和字 173 | 1-1-23, 1-1-24, 1-1-26, 1-1-27, 1-1-31, 1-1-32, 1-1-34, 174 | 1-1-35, 1-1-60~1-1-74, 1-1-85~1-2-14, 1-2-23~1-2-53, 175 | 1-2-60~1-2-62, 1-2-65~1-2-81, 1-2-84~1-3-15, 1-3-26~1-3-32, 176 | 1-3-59, 1-3-93, 1-3-94, 1-5-1~1-5-94 (ただし、行頭禁則和字に含まれる文字を除く。), 177 | 1-6-25~1-6-32, 1-6-58~1-6-77, 1-6-88, 1-7-82~1-7-94, 178 | 1-8-33~1-8-62, 1-8-71~1-8-74, 1-9-6, 1-9-10, 1-9-19~1-9-21, 179 | 1-12-1~1-12-83, 1-12-93~1-13-55, 1-13-63, 1-13-67~1-13-79, 180 | 1-13-83, 1-13-88, 1-13-89, 1-13-93, 1-13-94, 1-14-2~1-15-93, 181 | 1-16-1~1-94-89, 2-1-1~2-1-94, 2-3-1~2-5-94, 2-8-1~2-8-94, 182 | 2-12-1~2-15-94, 2-78-1~2-94-86 183 | (14) 合印中の文字 184 | (15) 添え字付き親文字群中の文字 185 | (16) 熟語ルビ以外のルビ付き親文字群中の文字 186 | (17) 熟語ルビ付き親文字郡中の文字 187 | (18) 連数字中の文字 188 | 2/0 (位取りの空白) (JIS X 0201 の 2 列 0 行の空白 (SPACE)) 189 | 1-1-4 (位取りのコンマ) 190 | 1-1-5 (小数点) 191 | 1-3-16~1-3-25 (数字) 192 | (19) 単位記号中の文字 193 | 2/0 (空白) 194 | 1-1-6 (中点) 195 | 1-1-31 (斜線) (単位記号中に使用する 1-1-31 (斜線の字幅は、半角とする。) 196 | 1-1-42 (始め小括弧) 197 | 1-1-43 (終わり小括弧) 198 | 1-1-61 (負符号) 199 | 1-2-82 200 | 1-3-17~1-3-20 (数字) 201 | 1-3-33~1-3-58, 1-3-64~1-3-90, 1-6-24, 1-6-44 202 | (20) 欧文間隔 203 | 2/0 (SPACE) 204 | (21) 欧文間隔以外の欧文用文字 205 | 1-1-4, 1-1-5, 1-1-7~1-1-10, 1-1-13~1-1-18, 1-1-29, 1-1-31, 206 | 1-1-32, 1-1-34~1-1-43, 1-1-46~1-1-49, 1-1-60~1-1-77, 207 | 1-1-79~1-2-7, 1-2-10~1-2-13, 1-2-15~1-2-18, 1-2-26~1-2-53, 208 | 1-1-79~1-2-7, 1-2-10~1-2-13, 1-2-15~1-2-18, 1-2-26~1-2-53, 209 | 1-2-60~1-3-25, 1-3-31~1-3-61, 1-3-64~1-3-90, 1-3-92, 1-6-1~1-6-67, 210 | 1-6-71~1-6-75, 1-6-77, 1-7-1~1-7-33, 1-7-49~1-7-81, 211 | 1-7-86~1-7-94, 1-8-33~1-8-62, 1-8-71~1-8-74, 1-8-79~1-8-92, 212 | 1-9-1~1-12-20, 1-12-33~1-12-58, 1-12-93~1-13-20, 213 | 1-13-83, 1-13-88, 1-13-89, 1-13-93, 1-13-94 214 | (22) 割注始め括弧類 215 | LEFT PARENTHESIS (1-1-42) 216 | LEFT SQUARE BRACKET (1-1-46) 217 | LEFT TORTOISE SHELL BRACKET (1-1-44) 218 | (23) 割注終わり括弧類 219 | RIGHT PARENTHESIS (1-1-43) 220 | RIGHT SQUARE BRACKET (1-1-47) 221 | RIGHT TORTOISE SHELL BRACKET (1-1-45) 222 | 223 | -------------------------------------------------------------------------------- /test/Makefile: -------------------------------------------------------------------------------- 1 | VIMPROG = vim 2 | 3 | SCRIPTS := $(patsubst %.ok, %.out, $(wildcard *.ok)) 4 | 5 | .SUFFIXES: .in .out 6 | 7 | all: nolog $(SCRIPTS) report 8 | 9 | report: 10 | @echo 11 | @echo 'Test results:' 12 | @/bin/sh -c "if test -f test.log; \ 13 | then cat test.log; echo TEST FAILURE; exit 1; \ 14 | else echo ALL DONE; \ 15 | fi" 16 | 17 | clean: 18 | -rm -rf *.out *.failed test.log test.ok X* debug.log 19 | 20 | .in.out: 21 | -rm -rf $*.failed test.ok test.out X* 22 | cp $*.ok test.ok 23 | # Sleep a moment to avoid that the xterm title is messed up 24 | @-sleep .2 25 | -$(VIMPROG) -u unix.vim -U NONE --noplugin -s dotest.in $*.in 26 | @/bin/sh -c "if test -f test.out; then\ 27 | if diff test.out $*.ok; \ 28 | then mv -f test.out $*.out; \ 29 | else echo $* FAILED >>test.log; mv -f test.out $*.failed; \ 30 | fi \ 31 | else echo $* NO OUTPUT >>test.log; \ 32 | fi" 33 | -rm -rf X* test.ok 34 | 35 | nolog: 36 | -rm -f test.log 37 | -------------------------------------------------------------------------------- /test/bug1.in: -------------------------------------------------------------------------------- 1 | BUG: second line is not properly indented. 2 | 3 | 4 | Results of bug1: 5 | 6 | STARTTEST 7 | :set fo=cq tw=10 ai 8 | /^{/+1 9 | :set formatexpr= 10 | 3gqgq 11 | /^{/+1 12 | :set formatexpr=autofmt#compat#formatexpr() 13 | 3gqgq 14 | ENDTEST 15 | 16 | case1 17 | { 18 | aaaaa 19 | bbbbb 20 | ccccc 21 | } 22 | { 23 | aaaaa 24 | bbbbb 25 | ccccc 26 | } 27 | 28 | STARTTEST 29 | :set fo=cq tw=10 ai 30 | /^{/+1 31 | :set formatexpr= 32 | 5gqgq 33 | /^{/+1 34 | :set formatexpr=autofmt#compat#formatexpr() 35 | 5gqgq 36 | ENDTEST 37 | 38 | case2 39 | { 40 | /* 41 | * aaaaa 42 | * bbbbb 43 | * ccccc 44 | */ 45 | } 46 | { 47 | /* 48 | * aaaaa 49 | * bbbbb 50 | * ccccc 51 | */ 52 | } 53 | 54 | STARTTEST 55 | :g/^STARTTEST/.,/^ENDTEST/d 56 | :1;/^Results/,$wq! test.out 57 | ENDTEST 58 | -------------------------------------------------------------------------------- /test/bug1.ok: -------------------------------------------------------------------------------- 1 | Results of bug1: 2 | 3 | 4 | case1 5 | { 6 | aaaaa 7 | bbbbb 8 | ccccc 9 | } 10 | { 11 | aaaaa 12 | bbbbb 13 | ccccc 14 | } 15 | 16 | 17 | case2 18 | { 19 | /* 20 | * aaaaa 21 | * bbbbb 22 | * ccccc 23 | */ 24 | } 25 | { 26 | /* 27 | * aaaaa 28 | * bbbbb 29 | * ccccc 30 | */ 31 | } 32 | 33 | -------------------------------------------------------------------------------- /test/dotest.in: -------------------------------------------------------------------------------- 1 | :set cp 2 | :map clean :set all& cp :source `=g:__vimrc` 3 | :map dotest /^STARTTEST j:set ff=unix cpo-=A :.,/ENDTEST/-1w! Xdotest :set ff& cpo+=A nj0:so! Xdotest cleandotest 4 | dotest 5 | -------------------------------------------------------------------------------- /test/test1.in: -------------------------------------------------------------------------------- 1 | Test for compatible behavior. 2 | 3 | Results of test1: 4 | 5 | STARTTEST 6 | :set tw=10 fo=t 7 | /^{/+1 8 | :set formatexpr= 9 | gqgqo 10 | aaaaa 11 | /^{/+1 12 | :set formatexpr=autofmt#compat#formatexpr() 13 | gqgqo 14 | aaaaa 15 | ENDTEST 16 | 17 | 1254595097 18 | { 19 | aaaaa 20 | } 21 | { 22 | aaaaa 23 | } 24 | 25 | STARTTEST 26 | :set tw=10 fo=t 27 | /^{/+1 28 | :set formatexpr= 29 | gqgqo 30 | aaaaa bbbb 31 | /^{/+1 32 | :set formatexpr=autofmt#compat#formatexpr() 33 | gqgqo 34 | aaaaa bbbb 35 | ENDTEST 36 | 37 | 1254595115 38 | { 39 | aaaaa bbbb 40 | } 41 | { 42 | aaaaa bbbb 43 | } 44 | 45 | STARTTEST 46 | :set tw=10 fo=t 47 | /^{/+1 48 | :set formatexpr= 49 | gqgqo 50 | aaaaa bbbbb 51 | /^{/+1 52 | :set formatexpr=autofmt#compat#formatexpr() 53 | gqgqo 54 | aaaaa bbbbb 55 | ENDTEST 56 | 57 | 1254595131 58 | { 59 | aaaaa bbbbb 60 | } 61 | { 62 | aaaaa bbbbb 63 | } 64 | 65 | STARTTEST 66 | :set tw=10 fo=t 67 | /^{/+1 68 | :set formatexpr= 69 | gqgqo 70 | aaaaa bbbbb  71 | /^{/+1 72 | :set formatexpr=autofmt#compat#formatexpr() 73 | gqgqo 74 | aaaaa bbbbb  75 | ENDTEST 76 | 77 | 1254595132 78 | { 79 | aaaaa bbbbb 80 | } 81 | { 82 | aaaaa bbbbb 83 | } 84 | 85 | STARTTEST 86 | :set tw=10 fo=t 87 | /^{/+1 88 | :set formatexpr= 89 | gqgqo 90 | aaaaa bbbbb ccccc 91 | /^{/+1 92 | :set formatexpr=autofmt#compat#formatexpr() 93 | gqgqo 94 | aaaaa bbbbb ccccc 95 | ENDTEST 96 | 97 | 1254595140 98 | { 99 | aaaaa bbbbb ccccc 100 | } 101 | { 102 | aaaaa bbbbb ccccc 103 | } 104 | 105 | STARTTEST 106 | :set tw=10 fo=t 107 | /^{/+1 108 | :set formatexpr= 109 | gqgqo 110 | aaaaaaaaaabbbbbbbbbb 111 | /^{/+1 112 | :set formatexpr=autofmt#compat#formatexpr() 113 | gqgqo 114 | aaaaaaaaaabbbbbbbbbb 115 | ENDTEST 116 | 117 | 1254595141 118 | { 119 | aaaaaaaaaabbbbbbbbbb 120 | } 121 | { 122 | aaaaaaaaaabbbbbbbbbb 123 | } 124 | 125 | STARTTEST 126 | :set tw=10 fo=t 127 | /^{/+1 128 | :set formatexpr= 129 | gqgqo 130 | aaaaaaaaaabbbbbbbbbb 131 | /^{/+1 132 | :set formatexpr=autofmt#compat#formatexpr() 133 | gqgqo 134 | aaaaaaaaaabbbbbbbbbb 135 | ENDTEST 136 | 137 | 1254595143 138 | { 139 | aaaaaaaaaabbbbbbbbbb 140 | } 141 | { 142 | aaaaaaaaaabbbbbbbbbb 143 | } 144 | 145 | STARTTEST 146 | :set tw=10 fo=t 147 | /^{/+1 148 | :set formatexpr= 149 | gq/^}/ 150 | /^{/+1 151 | :set formatexpr=autofmt#compat#formatexpr() 152 | gq/^}/ 153 | ENDTEST 154 | 155 | 1254595144 156 | { 157 | aaaa 158 | bbbb 159 | cccccccccccc 160 | dddd 161 | } 162 | { 163 | aaaa 164 | bbbb 165 | cccccccccccc 166 | dddd 167 | } 168 | 169 | STARTTEST 170 | :set tw=10 fo=t 171 | /^{/+1 172 | :set formatexpr= 173 | gqgqo 174 | aaaaa bbb 175 | /^{/+1 176 | :set formatexpr=autofmt#compat#formatexpr() 177 | gqgqo 178 | aaaaa bbb 179 | ENDTEST 180 | 181 | 1254595145 182 | { 183 | aaaaa bbb 184 | } 185 | { 186 | aaaaa bbb 187 | } 188 | 189 | STARTTEST 190 | :set autoindent tw=10 fo=t 191 | /^{/+1 192 | :set formatexpr= 193 | gqgqo 194 | aaaaa bbbbb 195 | /^{/+1 196 | :set formatexpr=autofmt#compat#formatexpr() 197 | gqgqo 198 | aaaaa bbbbb 199 | ENDTEST 200 | 201 | 1254595146 202 | { 203 | aaaaa bbbbb 204 | } 205 | { 206 | aaaaa bbbbb 207 | } 208 | 209 | STARTTEST 210 | :set noautoindent tw=10 fo=t 211 | /^{/+1 212 | :set formatexpr= 213 | gqgqo 214 | aaaaa bbbbb 215 | /^{/+1 216 | :set formatexpr=autofmt#compat#formatexpr() 217 | gqgqo 218 | aaaaa bbbbb 219 | ENDTEST 220 | 221 | 1254595147 222 | { 223 | aaaaa bbbbb 224 | } 225 | { 226 | aaaaa bbbbb 227 | } 228 | 229 | STARTTEST 230 | :set tw=10 fo=2 231 | /^{/+1 232 | :set formatexpr= 233 | gq/^}/ 234 | /^{/+1 235 | :set formatexpr=autofmt#compat#formatexpr() 236 | gq/^}/ 237 | ENDTEST 238 | 239 | 1254595148 240 | { 241 | aaaaa bbbbb 242 | ccccc ddddd 243 | } 244 | { 245 | aaaaa bbbbb 246 | ccccc ddddd 247 | } 248 | 249 | STARTTEST 250 | :set tw=10 fo= 251 | /^{/+1 252 | :set formatexpr= 253 | gqgqo 254 | aaaa bbbb cccc dddd eeee ffff 255 | /^{/+1 256 | :set formatexpr=autofmt#compat#formatexpr() 257 | gqgqo 258 | aaaa bbbb cccc dddd eeee ffff 259 | ENDTEST 260 | 261 | 1254595150 262 | { 263 | aaaa bbbb cccc dddd eeee ffff 264 | } 265 | { 266 | aaaa bbbb cccc dddd eeee ffff 267 | } 268 | 269 | STARTTEST 270 | :set tw=10 fo= comments=:# 271 | /^{/+1 272 | :set formatexpr= 273 | gqgqo 274 | # aaaaa bbbbb 275 | /^{/+1 276 | :set formatexpr=autofmt#compat#formatexpr() 277 | gqgqo 278 | # aaaaa bbbbb 279 | ENDTEST 280 | 281 | 1254595151 282 | { 283 | # aaaaa bbbbb 284 | } 285 | { 286 | # aaaaa bbbbb 287 | } 288 | 289 | STARTTEST 290 | :set tw=10 fo=q comments=:# 291 | /^{/+1 292 | :set formatexpr= 293 | gqgqo 294 | # aaaaa bbbbb 295 | /^{/+1 296 | :set formatexpr=autofmt#compat#formatexpr() 297 | gqgqo 298 | # aaaaa bbbbb 299 | ENDTEST 300 | 301 | 1254595155 302 | { 303 | # aaaaa bbbbb 304 | } 305 | { 306 | # aaaaa bbbbb 307 | } 308 | 309 | STARTTEST 310 | :set tw=10 fo=c comments=:# 311 | /^{/+1 312 | gqgqo 313 | # aaaaa bbbbb 314 | /^{/+1 315 | :set formatexpr=autofmt#compat#formatexpr() 316 | gqgqo 317 | # aaaaa bbbbb 318 | ENDTEST 319 | 320 | 1254595156 321 | { 322 | # aaaaa bbbbb 323 | } 324 | { 325 | # aaaaa bbbbb 326 | } 327 | 328 | STARTTEST 329 | :set tw=10 fo=cq comments=s1:/*,mb:*,ex:*/ 330 | /^{/+1 331 | :set formatexpr= 332 | gqgqo 333 | /* aaaaa bbbbb ccccc 334 | /^{/+1 335 | :set formatexpr=autofmt#compat#formatexpr() 336 | gqgqo 337 | /* aaaaa bbbbb ccccc 338 | ENDTEST 339 | 340 | 1254595157 341 | { 342 | /* aaaaa bbbbb ccccc 343 | } 344 | { 345 | /* aaaaa bbbbb ccccc 346 | } 347 | 348 | STARTTEST 349 | :set tw=10 fo=cq comments=s1:/*,mb:*,ex:*/ 350 | /^{/+1 351 | :set formatexpr= 352 | gq/^}/ 353 | /^{/+1 354 | :set formatexpr=autofmt#compat#formatexpr() 355 | gq/^}/ 356 | ENDTEST 357 | 358 | 1254595158 359 | { 360 | /* aaa 361 | * bbb 362 | * ccc 363 | * ddd 364 | */ 365 | } 366 | { 367 | /* aaa 368 | * bbb 369 | * ccc 370 | * ddd 371 | */ 372 | } 373 | 374 | STARTTEST 375 | :set tw=10 fo=cq comments=s1:/*,mb:*,ex:*/ 376 | /^{/+1 377 | :set formatexpr= 378 | gq/^}/ 379 | /^{/+1 380 | :set formatexpr=autofmt#compat#formatexpr() 381 | gq/^}/ 382 | ENDTEST 383 | 384 | 1254595159 385 | { 386 | 387 | 388 | aaa 389 | aaa 390 | 391 | /* 392 | * bbb 393 | * bbb 394 | * 395 | * ccc 396 | */ 397 | 398 | } 399 | { 400 | 401 | 402 | aaa 403 | aaa 404 | 405 | /* 406 | * bbb 407 | * bbb 408 | * 409 | * ccc 410 | */ 411 | 412 | } 413 | 414 | STARTTEST 415 | :set tw=10 fo=cq comments=s1:/*,mb:*,ex:*/ 416 | /^{/+1 417 | :set formatexpr= 418 | gq/^}/ 419 | /^{/+1 420 | :set formatexpr=autofmt#compat#formatexpr() 421 | gq/^}/ 422 | ENDTEST 423 | 424 | 1254595160 425 | { 426 | /* aaaaa bbbbb 427 | } 428 | { 429 | /* aaaaa bbbbb 430 | } 431 | 432 | STARTTEST 433 | :set autoindent tw=10 fo=cq comments=s1:/*,mb:*,ex:*/ 434 | /^{/+1 435 | :set formatexpr= 436 | gqgqoi 437 | /* aaaaa bbbbb 438 | /^{/+1 439 | :set formatexpr=autofmt#compat#formatexpr() 440 | gqgqoi 441 | /* aaaaa bbbbb 442 | ENDTEST 443 | 444 | 1254595162 445 | { 446 | /* aaaaa bbbbb 447 | } 448 | { 449 | /* aaaaa bbbbb 450 | } 451 | 452 | STARTTEST 453 | :set noautoindent tw=10 fo=cq comments=s1:/*,mb:*,ex:*/ 454 | /^{/+1 455 | :set formatexpr= 456 | gqgqoi 457 | /* aaaaa bbbbb 458 | /^{/+1 459 | :set formatexpr=autofmt#compat#formatexpr() 460 | gqgqoi 461 | /* aaaaa bbbbb 462 | ENDTEST 463 | 464 | 1254595163 465 | { 466 | /* aaaaa bbbbb 467 | } 468 | { 469 | /* aaaaa bbbbb 470 | } 471 | 472 | STARTTEST 473 | :set tw=10 fo=cq comments=s1:/*,mb:*,ex:*/ 474 | /^{/+1 475 | :set formatexpr= 476 | gqgqjgqgqjgqgqoi 477 | /* aaaaa bbbbb 478 | i/* aaaaa bbbbb 479 | i/* aaaaa bbbbb 480 | /^{/+1 481 | :set formatexpr=autofmt#compat#formatexpr() 482 | gqgqjgqgqjgqgqoi 483 | /* aaaaa bbbbb 484 | i/* aaaaa bbbbb 485 | i/* aaaaa bbbbb 486 | ENDTEST 487 | 488 | 1254595164 489 | { 490 | /* aaaaa bbbbb 491 | /* aaaaa bbbbb 492 | /* aaaaa bbbbb 493 | } 494 | { 495 | /* aaaaa bbbbb 496 | /* aaaaa bbbbb 497 | /* aaaaa bbbbb 498 | } 499 | 500 | STARTTEST 501 | :set tw=10 fo=cq comments=s1:/*,mb:*,ex:*/ 502 | /^{/+1 503 | :set formatexpr= 504 | gqgqoi 505 | /** aaaaa bbbbb 506 | /^{/+1 507 | :set formatexpr=autofmt#compat#formatexpr() 508 | gqgqoi 509 | /** aaaaa bbbbb 510 | ENDTEST 511 | 512 | 1254596280 513 | { 514 | /** aaaaa bbbbb 515 | } 516 | { 517 | /** aaaaa bbbbb 518 | } 519 | 520 | STARTTEST 521 | :set tw=10 fo=tn formatlistpat=^\\s*\\d\\+[\\].)}\\t\ ]\\s* 522 | /^{/+1 523 | :set formatexpr= 524 | gqgqo 525 | 1. aaaaa bbbbb 526 | /^{/+1 527 | :set formatexpr=autofmt#compat#formatexpr() 528 | gqgqo 529 | 1. aaaaa bbbbb 530 | ENDTEST 531 | 532 | 1254595165 533 | { 534 | 1. aaaaa bbbbb 535 | } 536 | { 537 | 1. aaaaa bbbbb 538 | } 539 | 540 | STARTTEST 541 | :set autoindent tw=10 fo=tn formatlistpat=^\\s*\\d\\+[\\].)}\\t\ ]\\s* 542 | /^{/+1 543 | :set formatexpr= 544 | gqgqoi 545 | 1. aaa bbb ccc 546 | /^{/+1 547 | :set formatexpr=autofmt#compat#formatexpr() 548 | gqgqoi 549 | 1. aaa bbb ccc 550 | ENDTEST 551 | 552 | 1254595166 553 | { 554 | 1. aaa bbb ccc 555 | } 556 | { 557 | 1. aaa bbb ccc 558 | } 559 | 560 | STARTTEST 561 | :set noautoindent tw=10 fo=tn formatlistpat=^\\s*\\d\\+[\\].)}\\t\ ]\\s* 562 | /^{/+1 563 | :set formatexpr= 564 | gqgqoi 565 | 1. aaa bbb ccc 566 | /^{/+1 567 | :set formatexpr=autofmt#compat#formatexpr() 568 | gqgqoi 569 | 1. aaa bbb ccc 570 | ENDTEST 571 | 572 | 1254595168 573 | { 574 | 1. aaa bbb ccc 575 | } 576 | { 577 | 1. aaa bbb ccc 578 | } 579 | 580 | STARTTEST 581 | :setl tw=10 fo=tm 582 | /^{/+1 583 | :set formatexpr= 584 | gqgqo 585 | ABC 586 | /^{/+1 587 | :set formatexpr=autofmt#compat#formatexpr() 588 | gqgqo 589 | ABC 590 | ENDTEST 591 | 592 | 1254595169 593 | { 594 | ABC 595 | } 596 | { 597 | ABC 598 | } 599 | 600 | STARTTEST 601 | :setl tw=10 fo=tm 602 | /^{/+1 603 | :set formatexpr= 604 | gqgqo 605 | ABCDE 606 | /^{/+1 607 | :set formatexpr=autofmt#compat#formatexpr() 608 | gqgqo 609 | ABCDE 610 | ENDTEST 611 | 612 | 1254595170 613 | { 614 | ABCDE 615 | } 616 | { 617 | ABCDE 618 | } 619 | 620 | STARTTEST 621 | :setl tw=10 fo=tm 622 | /^{/+1 623 | :set formatexpr= 624 | gqgqo 625 | ABCDEF 626 | /^{/+1 627 | :set formatexpr=autofmt#compat#formatexpr() 628 | gqgqo 629 | ABCDEF 630 | ENDTEST 631 | 632 | 1254595171 633 | { 634 | ABCDEF 635 | } 636 | { 637 | ABCDEF 638 | } 639 | 640 | STARTTEST 641 | :setl tw=10 fo=tm 642 | /^{/+1 643 | :set formatexpr= 644 | gqgqo 645 | aaaaa bbbbA 646 | /^{/+1 647 | :set formatexpr=autofmt#compat#formatexpr() 648 | gqgqo 649 | aaaaa bbbbA 650 | ENDTEST 651 | 652 | 1254595172 653 | { 654 | aaaaa bbbbA 655 | } 656 | { 657 | aaaaa bbbbA 658 | } 659 | 660 | STARTTEST 661 | :setl tw=10 fo=tm 662 | /^{/+1 663 | :set formatexpr= 664 | gqqgjgqgqo 665 | ABCDEa 666 | ABCDabc 667 | /^{/+1 668 | :set formatexpr=autofmt#compat#formatexpr() 669 | gqgqjgqgqo 670 | ABCDEa 671 | ABCDabc 672 | ENDTEST 673 | 674 | 1254595173 675 | { 676 | ABCDEa 677 | ABCDabc 678 | } 679 | { 680 | ABCDEa 681 | ABCDabc 682 | } 683 | 684 | STARTTEST 685 | :set tw=10 fo=tm 686 | /^{/+1 687 | :set formatexpr= 688 | 4liXXX 689 | /^{/+1 690 | :set formatexpr=autofmt#compat#formatexpr() 691 | 4liXXX 692 | ENDTEST 693 | 694 | 1254595175 695 | { 696 | ABCDEFGHIJKLMNO 697 | } 698 | { 699 | ABCDEFGHIJKLMNO 700 | } 701 | 702 | STARTTEST 703 | :set autoindent noexpandtab tw=10 fo=t 704 | /^{/+1 705 | :set formatexpr= 706 | gqgqoi 707 | aaa bbb ccc 708 | /^{/+1 709 | :set formatexpr=autofmt#compat#formatexpr() 710 | gqgqoi 711 | aaa bbb ccc 712 | ENDTEST 713 | 714 | 1254595176 715 | { 716 | aaa bbb ccc 717 | } 718 | { 719 | aaa bbb ccc 720 | } 721 | 722 | STARTTEST 723 | :set autoindent expandtab tw=10 fo=t 724 | /^{/+1 725 | :set formatexpr= 726 | gqgqoi 727 |  aaa bbb ccc 728 | /^{/+1 729 | :set formatexpr=autofmt#compat#formatexpr() 730 | gqgqoi 731 |  aaa bbb ccc 732 | ENDTEST 733 | 734 | 1254595177 735 | { 736 | aaa bbb ccc 737 | } 738 | { 739 | aaa bbb ccc 740 | } 741 | 742 | STARTTEST 743 | :"MEMO: copyindent does not effect for gq operator. 744 | :set autoindent noexpandtab copyindent tw=10 fo=t 745 | /^{/+1 746 | :set formatexpr= 747 | gqgqjgqgqjgqgqoi 748 |  aaa bbb 749 | i  aaa bbb 750 | i  aaa bbb 751 | /^{/+1 752 | :set formatexpr=autofmt#compat#formatexpr() 753 | gqgqjgqgqjgqgqoi 754 |  aaa bbb 755 | i  aaa bbb 756 | i  aaa bbb 757 | ENDTEST 758 | 759 | 1254595178 760 | { 761 | aaa bbb 762 | aaa bbb 763 | aaa bbb 764 | } 765 | { 766 | aaa bbb 767 | aaa bbb 768 | aaa bbb 769 | } 770 | 771 | STARTTEST 772 | :set autoindent noexpandtab copyindent tw=10 fo=c comments=fb:- 773 | /^{/+1 774 | :set formatexpr= 775 | i  - aaa bbb 776 | /^{/+1 777 | :set formatexpr=autofmt#compat#formatexpr() 778 | i  - aaa bbb 779 | ENDTEST 780 | 781 | 1254595179 782 | { 783 | 784 | } 785 | { 786 | 787 | } 788 | 789 | STARTTEST 790 | :set autoindent tw=10 fo=c comments=fb3:- 791 | /^{/+1 792 | :set formatexpr= 793 | i- aaaaa bbbbb 794 | /^{/+1 795 | :set formatexpr=autofmt#compat#formatexpr() 796 | i- aaaaa bbbbb 797 | ENDTEST 798 | 799 | 1257457620 800 | { 801 | 802 | } 803 | { 804 | 805 | } 806 | 807 | STARTTEST 808 | :set autoindent tw=10 fo=c comments=fb-1:- 809 | /^{/+1 810 | :set formatexpr= 811 | i- aaaaa bbbbb 812 | /^{/+1 813 | :set formatexpr=autofmt#compat#formatexpr() 814 | i- aaaaa bbbbb 815 | ENDTEST 816 | 817 | 1257468164 818 | { 819 | 820 | } 821 | { 822 | 823 | } 824 | 825 | STARTTEST 826 | :set tw=10 fo=cqr comments=sr:/***,m:**,ex2:******/ 827 | /^{/+1 828 | :set formatexpr= 829 | 3gqgq 830 | /^{/+1 831 | 4gqgq 832 | /^{/+1 833 | i/*** aaa bbb 834 | / 835 | /^{/+1 836 | :set formatexpr=autofmt#compat#formatexpr() 837 | 3gqgq 838 | /^{/+1 839 | 4gqgq 840 | /^{/+1 841 | i/*** aaa bbb 842 | / 843 | ENDTEST 844 | 845 | 1257500340 846 | { 847 | /*** aaa 848 | ** bbb 849 | ******/ 850 | } 851 | { 852 | /*** 853 | ** aaa 854 | ** bbb 855 | ******/ 856 | } 857 | { 858 | 859 | } 860 | { 861 | /*** aaa 862 | ** bbb 863 | ******/ 864 | } 865 | { 866 | /*** 867 | ** aaa 868 | ** bbb 869 | ******/ 870 | } 871 | { 872 | 873 | } 874 | 875 | STARTTEST 876 | :set tw=10 fo=q comments=:# 877 | /^{/+1 878 | :set formatexpr= 879 | 2gqgq 880 | /^{/+1 881 | 2gqgq 882 | /^{/+1 883 | 2gqgq 884 | /^{/+1 885 | 2gqgq 886 | /^{/+1 887 | :set formatexpr=autofmt#compat#formatexpr() 888 | 2gqgq 889 | /^{/+1 890 | 2gqgq 891 | /^{/+1 892 | 2gqgq 893 | /^{/+1 894 | 2gqgq 895 | ENDTEST 896 | 897 | 1257516766 898 | { 899 | # aaa 900 | #bbb 901 | } 902 | { 903 | #aaa 904 | # bbb 905 | } 906 | { 907 | # aaa 908 | ## bbb 909 | } 910 | { 911 | ## aaa 912 | # bbb 913 | } 914 | { 915 | # aaa 916 | #bbb 917 | } 918 | { 919 | #aaa 920 | # bbb 921 | } 922 | { 923 | # aaa 924 | ## bbb 925 | } 926 | { 927 | ## aaa 928 | # bbb 929 | } 930 | 931 | STARTTEST 932 | :g/^STARTTEST/.,/^ENDTEST/d 933 | :1;/^Results/,$wq! test.out 934 | ENDTEST 935 | -------------------------------------------------------------------------------- /test/test1.ok: -------------------------------------------------------------------------------- 1 | Results of test1: 2 | 3 | 4 | 1254595097 5 | { 6 | aaaaa 7 | 8 | aaaaa 9 | } 10 | { 11 | aaaaa 12 | 13 | aaaaa 14 | } 15 | 16 | 17 | 1254595115 18 | { 19 | aaaaa bbbb 20 | 21 | aaaaa bbbb 22 | } 23 | { 24 | aaaaa bbbb 25 | 26 | aaaaa bbbb 27 | } 28 | 29 | 30 | 1254595131 31 | { 32 | aaaaa 33 | bbbbb 34 | 35 | aaaaa 36 | bbbbb 37 | } 38 | { 39 | aaaaa 40 | bbbbb 41 | 42 | aaaaa 43 | bbbbb 44 | } 45 | 46 | 47 | 1254595132 48 | { 49 | aaaaa 50 | bbbbb 51 | 52 | aaaaa 53 | bbbbb 54 | } 55 | { 56 | aaaaa 57 | bbbbb 58 | 59 | aaaaa 60 | bbbbb 61 | } 62 | 63 | 64 | 1254595140 65 | { 66 | aaaaa 67 | bbbbb 68 | ccccc 69 | 70 | aaaaa 71 | bbbbb 72 | ccccc 73 | } 74 | { 75 | aaaaa 76 | bbbbb 77 | ccccc 78 | 79 | aaaaa 80 | bbbbb 81 | ccccc 82 | } 83 | 84 | 85 | 1254595141 86 | { 87 | aaaaaaaaaabbbbbbbbbb 88 | 89 | aaaaaaaaaabbbbbbbbbb 90 | } 91 | { 92 | aaaaaaaaaabbbbbbbbbb 93 | 94 | aaaaaaaaaabbbbbbbbbb 95 | } 96 | 97 | 98 | 1254595143 99 | { 100 | aaaaaaaaaabbbbbbbbbb 101 | 102 | aaaaaaaaaabbbbbbbbbb 103 | } 104 | { 105 | aaaaaaaaaabbbbbbbbbb 106 | 107 | aaaaaaaaaabbbbbbbbbb 108 | } 109 | 110 | 111 | 1254595144 112 | { 113 | aaaa bbbb 114 | cccccccccccc 115 | dddd 116 | } 117 | { 118 | aaaa bbbb 119 | cccccccccccc 120 | dddd 121 | } 122 | 123 | 124 | 1254595145 125 | { 126 | aaaaa 127 | bbb 128 | 129 | aaaaa 130 | bbb 131 | } 132 | { 133 | aaaaa 134 | bbb 135 | 136 | aaaaa 137 | bbb 138 | } 139 | 140 | 141 | 1254595146 142 | { 143 | aaaaa 144 | bbbbb 145 | 146 | aaaaa 147 | bbbbb 148 | } 149 | { 150 | aaaaa 151 | bbbbb 152 | 153 | aaaaa 154 | bbbbb 155 | } 156 | 157 | 158 | 1254595147 159 | { 160 | aaaaa 161 | bbbbb 162 | 163 | aaaaa 164 | bbbbb 165 | } 166 | { 167 | aaaaa 168 | bbbbb 169 | 170 | aaaaa 171 | bbbbb 172 | } 173 | 174 | 175 | 1254595148 176 | { 177 | aaaaa 178 | bbbbb 179 | ccccc 180 | ddddd 181 | } 182 | { 183 | aaaaa 184 | bbbbb 185 | ccccc 186 | ddddd 187 | } 188 | 189 | 190 | 1254595150 191 | { 192 | aaaa bbbb 193 | cccc dddd 194 | eeee ffff 195 | 196 | aaaa bbbb cccc dddd eeee ffff 197 | } 198 | { 199 | aaaa bbbb 200 | cccc dddd 201 | eeee ffff 202 | 203 | aaaa bbbb cccc dddd eeee ffff 204 | } 205 | 206 | 207 | 1254595151 208 | { 209 | # aaaaa 210 | bbbbb 211 | 212 | # aaaaa bbbbb 213 | } 214 | { 215 | # aaaaa 216 | bbbbb 217 | 218 | # aaaaa bbbbb 219 | } 220 | 221 | 222 | 1254595155 223 | { 224 | # aaaaa 225 | # bbbbb 226 | 227 | # aaaaa bbbbb 228 | } 229 | { 230 | # aaaaa 231 | # bbbbb 232 | 233 | # aaaaa bbbbb 234 | } 235 | 236 | 237 | 1254595156 238 | { 239 | # aaaaa 240 | bbbbb 241 | 242 | # aaaaa 243 | # bbbbb 244 | } 245 | { 246 | # aaaaa 247 | bbbbb 248 | 249 | # aaaaa 250 | # bbbbb 251 | } 252 | 253 | 254 | 1254595157 255 | { 256 | /* aaaaa 257 | * bbbbb 258 | * ccccc 259 | 260 | /* aaaaa 261 | * bbbbb 262 | * ccccc 263 | } 264 | { 265 | /* aaaaa 266 | * bbbbb 267 | * ccccc 268 | 269 | /* aaaaa 270 | * bbbbb 271 | * ccccc 272 | } 273 | 274 | 275 | 1254595158 276 | { 277 | /* aaa bbb 278 | * ccc ddd 279 | */ 280 | } 281 | { 282 | /* aaa bbb 283 | * ccc ddd 284 | */ 285 | } 286 | 287 | 288 | 1254595159 289 | { 290 | 291 | 292 | aaa aaa 293 | 294 | /* 295 | * bbb bbb 296 | * 297 | * ccc 298 | */ 299 | 300 | } 301 | { 302 | 303 | 304 | aaa aaa 305 | 306 | /* 307 | * bbb bbb 308 | * 309 | * ccc 310 | */ 311 | 312 | } 313 | 314 | 315 | 1254595160 316 | { 317 | /* aaaaa 318 | * bbbbb 319 | } 320 | { 321 | /* aaaaa 322 | * bbbbb 323 | } 324 | 325 | 326 | 1254595162 327 | { 328 | /* aaaaa 329 | * bbbbb 330 | 331 | /* aaaaa 332 | * bbbbb 333 | } 334 | { 335 | /* aaaaa 336 | * bbbbb 337 | 338 | /* aaaaa 339 | * bbbbb 340 | } 341 | 342 | 343 | 1254595163 344 | { 345 | /* aaaaa 346 | * bbbbb 347 | 348 | /* aaaaa 349 | * bbbbb 350 | } 351 | { 352 | /* aaaaa 353 | * bbbbb 354 | 355 | /* aaaaa 356 | * bbbbb 357 | } 358 | 359 | 360 | 1254595164 361 | { 362 | /* aaaaa 363 | * bbbbb 364 | /* aaaaa 365 | * bbbbb 366 | /* aaaaa 367 | * bbbbb 368 | 369 | /* aaaaa 370 | * bbbbb 371 | /* aaaaa 372 | * bbbbb 373 | /* aaaaa 374 | * bbbbb 375 | } 376 | { 377 | /* aaaaa 378 | * bbbbb 379 | /* aaaaa 380 | * bbbbb 381 | /* aaaaa 382 | * bbbbb 383 | 384 | /* aaaaa 385 | * bbbbb 386 | /* aaaaa 387 | * bbbbb 388 | /* aaaaa 389 | * bbbbb 390 | } 391 | 392 | 393 | 1254596280 394 | { 395 | /** aaaaa 396 | * bbbbb 397 | 398 | /** aaaaa 399 | * bbbbb 400 | } 401 | { 402 | /** aaaaa 403 | * bbbbb 404 | 405 | /** aaaaa 406 | * bbbbb 407 | } 408 | 409 | 410 | 1254595165 411 | { 412 | 1. aaaaa 413 | bbbbb 414 | 415 | 1. aaaaa 416 | bbbbb 417 | } 418 | { 419 | 1. aaaaa 420 | bbbbb 421 | 422 | 1. aaaaa 423 | bbbbb 424 | } 425 | 426 | 427 | 1254595166 428 | { 429 | 1. aaa 430 | bbb 431 | ccc 432 | 433 | 1. aaa 434 | bbb 435 | ccc 436 | } 437 | { 438 | 1. aaa 439 | bbb 440 | ccc 441 | 442 | 1. aaa 443 | bbb 444 | ccc 445 | } 446 | 447 | 448 | 1254595168 449 | { 450 | 1. aaa 451 | bbb 452 | ccc 453 | 454 | 1. aaa 455 | bbb 456 | ccc 457 | } 458 | { 459 | 1. aaa 460 | bbb 461 | ccc 462 | 463 | 1. aaa 464 | bbb 465 | ccc 466 | } 467 | 468 | 469 | 1254595169 470 | { 471 | ABC 472 | 473 | ABC 474 | } 475 | { 476 | ABC 477 | 478 | ABC 479 | } 480 | 481 | 482 | 1254595170 483 | { 484 | ABCDE 485 | 486 | ABCDE 487 | } 488 | { 489 | ABCDE 490 | 491 | ABCDE 492 | } 493 | 494 | 495 | 1254595171 496 | { 497 | ABCDE 498 | F 499 | 500 | ABCDE 501 | F 502 | } 503 | { 504 | ABCDE 505 | F 506 | 507 | ABCDE 508 | F 509 | } 510 | 511 | 512 | 1254595172 513 | { 514 | aaaaa bbbb 515 | A 516 | 517 | aaaaa bbbb 518 | A 519 | } 520 | { 521 | aaaaa bbbb 522 | A 523 | 524 | aaaaa bbbb 525 | A 526 | } 527 | 528 | 529 | 1254595173 530 | { 531 | ABCDE 532 | a 533 | ABCD 534 | abc 535 | 536 | ABCDE 537 | a 538 | ABCD 539 | abc 540 | } 541 | { 542 | ABCDE 543 | a 544 | ABCD 545 | abc 546 | 547 | ABCDE 548 | a 549 | ABCD 550 | abc 551 | } 552 | 553 | 554 | 1254595175 555 | { 556 | ABCDX 557 | XXEFGHIJKLMNO 558 | } 559 | { 560 | ABCDX 561 | XXEFGHIJKLMNO 562 | } 563 | 564 | 565 | 1254595176 566 | { 567 | aaa 568 | bbb 569 | ccc 570 | 571 | aaa 572 | bbb 573 | ccc 574 | } 575 | { 576 | aaa 577 | bbb 578 | ccc 579 | 580 | aaa 581 | bbb 582 | ccc 583 | } 584 | 585 | 586 | 1254595177 587 | { 588 | aaa 589 | bbb 590 | ccc 591 | 592 | aaa 593 | bbb 594 | ccc 595 | } 596 | { 597 | aaa 598 | bbb 599 | ccc 600 | 601 | aaa 602 | bbb 603 | ccc 604 | } 605 | 606 | 607 | 1254595178 608 | { 609 | aaa 610 | bbb 611 | aaa 612 | bbb 613 | aaa 614 | bbb 615 | 616 | aaa 617 | bbb 618 | aaa 619 | bbb 620 | aaa 621 | bbb 622 | } 623 | { 624 | aaa 625 | bbb 626 | aaa 627 | bbb 628 | aaa 629 | bbb 630 | 631 | aaa 632 | bbb 633 | aaa 634 | bbb 635 | aaa 636 | bbb 637 | } 638 | 639 | 640 | 1254595179 641 | { 642 | - aaa 643 | bbb 644 | } 645 | { 646 | - aaa 647 | bbb 648 | } 649 | 650 | 651 | 1257457620 652 | { 653 | - aaaaa 654 | bbbbb 655 | } 656 | { 657 | - aaaaa 658 | bbbbb 659 | } 660 | 661 | 662 | 1257468164 663 | { 664 | - aaaaa 665 | bbbbb 666 | } 667 | { 668 | - aaaaa 669 | bbbbb 670 | } 671 | 672 | 673 | 1257500340 674 | { 675 | /*** aaa 676 | ** bbb 677 | ******/ 678 | } 679 | { 680 | /*** 681 | ** aaa 682 | ** bbb 683 | ******/ 684 | } 685 | { 686 | /*** aaa 687 | ** bbb 688 | ******/ 689 | } 690 | { 691 | /*** aaa 692 | ** bbb 693 | ******/ 694 | } 695 | { 696 | /*** 697 | ** aaa 698 | ** bbb 699 | ******/ 700 | } 701 | { 702 | /*** aaa 703 | ** bbb 704 | ******/ 705 | } 706 | 707 | 708 | 1257516766 709 | { 710 | # aaa 711 | #bbb 712 | } 713 | { 714 | #aaa bbb 715 | } 716 | { 717 | # aaa 718 | ## bbb 719 | } 720 | { 721 | ## aaa bbb 722 | } 723 | { 724 | # aaa 725 | #bbb 726 | } 727 | { 728 | #aaa bbb 729 | } 730 | { 731 | # aaa 732 | ## bbb 733 | } 734 | { 735 | ## aaa bbb 736 | } 737 | 738 | -------------------------------------------------------------------------------- /test/test10.in: -------------------------------------------------------------------------------- 1 | TODO: Test for comment. 2 | 3 | Results of test10: 4 | 5 | STARTTEST 6 | :set tw=80 formatoptions=tcq comments=sO:\"\ -,mO:\"\ \ ,eO:\"\",:\" 7 | /^{/+1 8 | 2gqgq 9 | /^{/+1 10 | :set formatexpr=autofmt#compat#formatexpr() 11 | 2gqgq 12 | ENDTEST 13 | 14 | case1 15 | { 16 | " hoge 17 | " fuga 18 | } 19 | { 20 | " hoge 21 | " fuga 22 | } 23 | 24 | STARTTEST 25 | :g/^STARTTEST/.,/^ENDTEST/d 26 | :1;/^Results/,$wq! test.out 27 | ENDTEST 28 | -------------------------------------------------------------------------------- /test/test10.ok: -------------------------------------------------------------------------------- 1 | Results of test10: 2 | 3 | 4 | case1 5 | { 6 | " hoge fuga 7 | } 8 | { 9 | " hoge fuga 10 | } 11 | 12 | -------------------------------------------------------------------------------- /test/test2.in: -------------------------------------------------------------------------------- 1 | Test for incompatible and/or improved behavior. 2 | 3 | Results of test2: 4 | 5 | STARTTEST 6 | :" don't split line at just after a listpat. 7 | :set tw=10 fo=tn formatlistpat=^\\s*\\d\\+[\\].)}\\t\ ]\\s* 8 | /^{/+1 9 | :set formatexpr= 10 | gqgqo 11 | 1. aaaaa bbbbb 12 | /^{/+1 13 | :set formatexpr=autofmt#compat#formatexpr() 14 | gqgqo 15 | 1. aaaaa bbbbb 16 | ENDTEST 17 | 18 | 1254595216 19 | { 20 | 1. aaaaa bbbbb 21 | } 22 | { 23 | 1. aaaaa bbbbb 24 | } 25 | 26 | STARTTEST 27 | :" allow listpat in comment. 28 | :set tw=10 fo=cqn formatlistpat=^\\s*\\d\\+[\\].)}\\t\ ]\\s* comments=:# 29 | /^{/+1 30 | :set formatexpr= 31 | gqgqo 32 | # 1. aaa bbb 33 | /^{/+1 34 | :set formatexpr=autofmt#compat#formatexpr() 35 | gqgqo 36 | # 1. aaa bbb 37 | ENDTEST 38 | 39 | 1254595217 40 | { 41 | # 1. aaa bbb 42 | } 43 | { 44 | # 1. aaa bbb 45 | } 46 | 47 | STARTTEST 48 | :" " * */" -> " */" 49 | :set tw=10 fo=cq comments=s1:/*,mb:*,ex:*/ 50 | /^{/+1 51 | :set formatexpr= 52 | gqgqo 53 | /* aaaaa bbbbb ccccc */ 54 | /^{/+1 55 | :set formatexpr=autofmt#compat#formatexpr() 56 | gqgqo 57 | /* aaaaa bbbbb ccccc */ 58 | ENDTEST 59 | 60 | 1254595219 61 | { 62 | /* aaaaa bbbbb ccccc */ 63 | } 64 | { 65 | /* aaaaa bbbbb ccccc */ 66 | } 67 | 68 | STARTTEST 69 | :g/^STARTTEST/.,/^ENDTEST/d 70 | :1;/^Results/,$wq! test.out 71 | ENDTEST 72 | -------------------------------------------------------------------------------- /test/test2.ok: -------------------------------------------------------------------------------- 1 | Results of test2: 2 | 3 | 4 | 1254595216 5 | { 6 | 1. 7 | aaaaa 8 | bbbbb 9 | 10 | 1. 11 | aaaaa 12 | bbbbb 13 | } 14 | { 15 | 1. aaaaa 16 | bbbbb 17 | 18 | 1. aaaaa 19 | bbbbb 20 | } 21 | 22 | 23 | 1254595217 24 | { 25 | # 1. aaa 26 | # bbb 27 | 28 | # 1. aaa 29 | # bbb 30 | } 31 | { 32 | # 1. aaa 33 | # bbb 34 | 35 | # 1. aaa 36 | # bbb 37 | } 38 | 39 | 40 | 1254595219 41 | { 42 | /* aaaaa 43 | * bbbbb 44 | * ccccc 45 | * */ 46 | 47 | /* aaaaa 48 | * bbbbb 49 | * ccccc 50 | * */ 51 | } 52 | { 53 | /* aaaaa 54 | * bbbbb 55 | * ccccc 56 | */ 57 | 58 | /* aaaaa 59 | * bbbbb 60 | * ccccc 61 | * */ 62 | } 63 | 64 | -------------------------------------------------------------------------------- /test/test3.in: -------------------------------------------------------------------------------- 1 | Test for Japanese. 2 | 3 | Note: In the :source! script, you can not write some multi-byte 4 | character which have 0x80 byte (e.g. U+3000 UTF8:E3 80 80). Use 5 | u3000. 0x80 is a CSI byte and it is used to represent a special 6 | key-code (e.g. ). To see how key-code and multi-byte character 7 | are stored in the memory, use -w argument. 8 | 9 | Results of test3: 10 | 11 | STARTTEST 12 | :set tw=10 fo=tm 13 | /^{/+1 14 | :set formatexpr= 15 | gqgqo 16 | あいうえおu3002かきくけこ 17 | /^{/+1 18 | :set formatexpr=autofmt#japanese#formatexpr() 19 | gqgqo 20 | あいうえおu3002かきくけこ 21 | ENDTEST 22 | 23 | 1254595249 24 | { 25 | あいうえお。かきくけこ 26 | } 27 | { 28 | あいうえお。かきくけこ 29 | } 30 | 31 | STARTTEST 32 | :set tw=10 fo=tm 33 | /^{/+1 34 | :set formatexpr= 35 | gqgqo 36 | あいうえu3002u3002かきく 37 | /^{/+1 38 | :set formatexpr=autofmt#japanese#formatexpr() 39 | gqgqo 40 | あいうえu3002u3002かきく 41 | ENDTEST 42 | 43 | 1254595243 44 | { 45 | あいうえ。。かきく 46 | } 47 | { 48 | あいうえ。。かきく 49 | } 50 | 51 | STARTTEST 52 | :set tw=2 fo=tm 53 | /^{/+1 54 | :set formatexpr= 55 | gqgqo 56 | あu3002 57 | /^{/+1 58 | :set formatexpr=autofmt#japanese#formatexpr() 59 | gqgqo 60 | あu3002 61 | ENDTEST 62 | 63 | 1254595244 64 | { 65 | あ。 66 | } 67 | { 68 | あ。 69 | } 70 | 71 | STARTTEST 72 | :set tw=10 fo=tm 73 | /^{/+1 74 | :set formatexpr= 75 | gqgqo 76 | あいうえu300cお 77 | /^{/+1 78 | :set formatexpr=autofmt#japanese#formatexpr() 79 | gqgqo 80 | あいうえu300cお 81 | ENDTEST 82 | 83 | 1254595245 84 | { 85 | あいうえ「お 86 | } 87 | { 88 | あいうえ「お 89 | } 90 | 91 | STARTTEST 92 | :set tw=10 fo=tm 93 | /^{/+1 94 | :set formatexpr= 95 | gqgqo 96 | あああああu3002いいい 97 | /^{/+1 98 | :set formatexpr=autofmt#japanese#formatexpr() 99 | :let b:autofmt_allow_over_tw = 2 100 | gqgqo 101 | あああああu3002いいい 102 | :unlet b:autofmt_allow_over_tw 103 | ENDTEST 104 | 105 | 1254595246 106 | { 107 | あああああ。いいい 108 | } 109 | { 110 | あああああ。いいい 111 | } 112 | 113 | STARTTEST 114 | :set tw=10 fo=tm 115 | /^{/+1 116 | :set formatexpr= 117 | gqgqo 118 | あああああu3002いいい 119 | /^{/+1 120 | :set formatexpr=autofmt#japanese#formatexpr() 121 | :let b:autofmt_allow_over_tw = 1 122 | gqgqo 123 | あああああu3002いいい 124 | :unlet b:autofmt_allow_over_tw 125 | ENDTEST 126 | 127 | 1254595248 128 | { 129 | あああああ。いいい 130 | } 131 | { 132 | あああああ。いいい 133 | } 134 | 135 | STARTTEST 136 | :set tw=10 fo=tm 137 | /^{/+1 138 | :set formatexpr= 139 | gqgqjgqgqo 140 | あいうえu3002abcd 141 | あいうえu3002u300d 142 | /^{/+1 143 | :set formatexpr=autofmt#japanese#formatexpr() 144 | gqgqjgqgqo 145 | あいうえu3002abcd 146 | あいうえu3002u300d 147 | ENDTEST 148 | 149 | 1295124892 150 | { 151 | あいうえ。abcd 152 | あいうえ。」 153 | } 154 | { 155 | あいうえ。abcd 156 | あいうえ。」 157 | } 158 | 159 | STARTTEST 160 | :g/^STARTTEST/.,/^ENDTEST/d 161 | :1;/^Results/,$wq! test.out 162 | ENDTEST 163 | -------------------------------------------------------------------------------- /test/test3.ok: -------------------------------------------------------------------------------- 1 | Results of test3: 2 | 3 | 4 | 1254595249 5 | { 6 | あいうえお 7 | 。かきくけ 8 | こ 9 | 10 | あいうえお 11 | 。かきくけ 12 | こ 13 | } 14 | { 15 | あいうえ 16 | お。かきく 17 | けこ 18 | 19 | あいうえ 20 | お。かきく 21 | けこ 22 | } 23 | 24 | 25 | 1254595243 26 | { 27 | あいうえ。 28 | 。かきく 29 | 30 | あいうえ。 31 | 。かきく 32 | } 33 | { 34 | あいう 35 | え。。かき 36 | く 37 | 38 | あいう 39 | え。。かき 40 | く 41 | } 42 | 43 | 44 | 1254595244 45 | { 46 | あ 47 | 。 48 | 49 | あ 50 | 。 51 | } 52 | { 53 | あ。 54 | 55 | あ。 56 | } 57 | 58 | 59 | 1254595245 60 | { 61 | あいうえ「 62 | お 63 | 64 | あいうえ「 65 | お 66 | } 67 | { 68 | あいうえ 69 | 「お 70 | 71 | あいうえ 72 | 「お 73 | } 74 | 75 | 76 | 1254595246 77 | { 78 | あああああ 79 | 。いいい 80 | 81 | あああああ 82 | 。いいい 83 | } 84 | { 85 | あああああ。 86 | いいい 87 | 88 | あああああ。 89 | いいい 90 | } 91 | 92 | 93 | 1254595248 94 | { 95 | あああああ 96 | 。いいい 97 | 98 | あああああ 99 | 。いいい 100 | } 101 | { 102 | ああああ 103 | あ。いいい 104 | 105 | ああああ 106 | あ。いいい 107 | } 108 | 109 | 110 | 1295124892 111 | { 112 | あいうえ。 113 | abcd 114 | あいうえ。 115 | 」 116 | 117 | あいうえ。 118 | abcd 119 | あいうえ。 120 | 」 121 | } 122 | { 123 | あいうえ。 124 | abcd 125 | あいう 126 | え。」 127 | 128 | あいうえ。 129 | abcd 130 | あいう 131 | え。」 132 | } 133 | 134 | -------------------------------------------------------------------------------- /test/test4.in: -------------------------------------------------------------------------------- 1 | Test for textwidth=0. 2 | 3 | This test changes 'columns'. 4 | 5 | columns 6 | wrapmargin 7 | foldcolumn 8 | number 9 | relativenumber 10 | 11 | 12 | Results of test4: 13 | 14 | STARTTEST 15 | :let g:columns = &columns 16 | :set columns=80 17 | ENDTEST 18 | 19 | STARTTEST 20 | :set fo=t 21 | /^{/+1 22 | :set formatexpr= 23 | gqgqo 24 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 25 | /^{/+1 26 | :set formatexpr=autofmt#compat#formatexpr() 27 | gqgqo 28 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 29 | ENDTEST 30 | 31 | case1 32 | { 33 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 34 | } 35 | { 36 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 37 | } 38 | 39 | STARTTEST 40 | :set columns=100 41 | :set fo=t 42 | /^{/+1 43 | :set formatexpr= 44 | gqgqo 45 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 46 | /^{/+1 47 | :set formatexpr=autofmt#compat#formatexpr() 48 | gqgqo 49 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 50 | :set columns=80 51 | ENDTEST 52 | 53 | case2 54 | { 55 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 56 | } 57 | { 58 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 59 | } 60 | 61 | STARTTEST 62 | :set columns=40 63 | :set fo=t 64 | /^{/+1 65 | :set formatexpr= 66 | gqgqo 67 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 68 | /^{/+1 69 | :set formatexpr=autofmt#compat#formatexpr() 70 | gqgqo 71 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 72 | :set columns=80 73 | ENDTEST 74 | 75 | case3 76 | { 77 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 78 | } 79 | { 80 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 81 | } 82 | 83 | STARTTEST 84 | :set fo=t wrapmargin=1 85 | /^{/+1 86 | :set formatexpr= 87 | gqgqo 88 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 89 | /^{/+1 90 | :set formatexpr=autofmt#compat#formatexpr() 91 | gqgqo 92 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 93 | ENDTEST 94 | 95 | case4 96 | { 97 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 98 | } 99 | { 100 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 101 | } 102 | 103 | STARTTEST 104 | :set columns=100 105 | :set fo=t wrapmargin=1 106 | /^{/+1 107 | :set formatexpr= 108 | gqgqo 109 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 110 | /^{/+1 111 | :set formatexpr=autofmt#compat#formatexpr() 112 | gqgqo 113 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 114 | :set columns=80 115 | ENDTEST 116 | 117 | case5 118 | { 119 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 120 | } 121 | { 122 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 123 | } 124 | 125 | STARTTEST 126 | :set columns=40 127 | :set fo=t wrapmargin=1 128 | /^{/+1 129 | :set formatexpr= 130 | gqgqo 131 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 132 | /^{/+1 133 | :set formatexpr=autofmt#compat#formatexpr() 134 | gqgqo 135 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 136 | :set columns=80 137 | ENDTEST 138 | 139 | case6 140 | { 141 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 142 | } 143 | { 144 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 145 | } 146 | 147 | STARTTEST 148 | :set fo=t wrapmargin=1 foldcolumn=1 149 | /^{/+1 150 | :set formatexpr= 151 | gqgqo 152 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 153 | /^{/+1 154 | :set formatexpr=autofmt#compat#formatexpr() 155 | gqgqo 156 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 157 | ENDTEST 158 | 159 | case7 160 | { 161 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 162 | } 163 | { 164 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 165 | } 166 | 167 | STARTTEST 168 | :set fo=t wrapmargin=1 foldcolumn=2 169 | /^{/+1 170 | :set formatexpr= 171 | gqgqo 172 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 173 | /^{/+1 174 | :set formatexpr=autofmt#compat#formatexpr() 175 | gqgqo 176 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 177 | ENDTEST 178 | 179 | case8 180 | { 181 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 182 | } 183 | { 184 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 185 | } 186 | 187 | STARTTEST 188 | :set fo=t wrapmargin=1 number 189 | /^{/+1 190 | :set formatexpr= 191 | gqgqo 192 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 193 | /^{/+1 194 | :set formatexpr=autofmt#compat#formatexpr() 195 | gqgqo 196 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 197 | ENDTEST 198 | 199 | case9 200 | { 201 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 202 | } 203 | { 204 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 205 | } 206 | 207 | STARTTEST 208 | :set fo=t wrapmargin=1 number relativenumber 209 | /^{/+1 210 | :set formatexpr= 211 | gqgqo 212 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 213 | /^{/+1 214 | :set formatexpr=autofmt#compat#formatexpr() 215 | gqgqo 216 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 217 | ENDTEST 218 | 219 | case10 220 | { 221 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 222 | } 223 | { 224 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 225 | } 226 | 227 | STARTTEST 228 | :set fo=t wrapmargin=1 number relativenumber 229 | /^{/+1 230 | :set formatexpr= 231 | gqgqo 232 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 233 | /^{/+1 234 | :set formatexpr=autofmt#compat#formatexpr() 235 | gqgqo 236 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 237 | ENDTEST 238 | 239 | case11 240 | { 241 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 242 | } 243 | { 244 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 245 | } 246 | 247 | STARTTEST 248 | :sign define sign1 text=>> 249 | :exe ':sign place 1 line=1 name=sign1 buffer=' . bufnr('%') 250 | :set fo=t wrapmargin=1 251 | /^{/+1 252 | :set formatexpr= 253 | gqgqo 254 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 255 | /^{/+1 256 | :set formatexpr=autofmt#compat#formatexpr() 257 | gqgqo 258 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 259 | :sign unplace 1 260 | :sign undefine sign1 261 | ENDTEST 262 | 263 | case12 264 | { 265 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 266 | } 267 | { 268 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 269 | } 270 | 271 | STARTTEST 272 | :sign define sign1 text=>> 273 | :exe ':sign place 1 line=1 name=sign1 buffer=' . bufnr('%') 274 | :set fo=t textwidth=80 wrapmargin=0 foldcolumn=2 number relativenumber 275 | /^{/+1 276 | :set formatexpr= 277 | gqgqo 278 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 279 | /^{/+1 280 | :set formatexpr=autofmt#compat#formatexpr() 281 | gqgqo 282 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 283 | :sign unplace 1 284 | :sign undefine sign1 285 | ENDTEST 286 | 287 | case14 288 | { 289 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 290 | } 291 | { 292 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 293 | } 294 | 295 | STARTTEST 296 | :" test for command-line window 297 | :set fo=t wrapmargin=1 298 | /^{/+1 299 | :set formatexpr= 300 | q:i1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0k2yy:q 301 | P 302 | /^{/+1 303 | :set formatexpr=autofmt#compat#formatexpr() 304 | q:i1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0k2yy:q 305 | P 306 | ENDTEST 307 | 308 | case15 309 | { 310 | } 311 | { 312 | } 313 | 314 | STARTTEST 315 | :" if "winwidth(0) - &wrapmargin - .... < 0" then same as textwidth=0. 316 | :set fo=t wrapmargin=100 317 | /^{/+1 318 | :set formatexpr= 319 | gqgqo 320 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 321 | /^{/+1 322 | :set formatexpr=autofmt#compat#formatexpr() 323 | gqgqo 324 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 325 | ENDTEST 326 | 327 | case16 328 | { 329 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 330 | } 331 | { 332 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 333 | } 334 | 335 | STARTTEST 336 | :let &columns = g:columns 337 | ENDTEST 338 | 339 | STARTTEST 340 | :g/^STARTTEST/.,/^ENDTEST/d 341 | :1;/^Results/,$wq! test.out 342 | ENDTEST 343 | -------------------------------------------------------------------------------- /test/test4.ok: -------------------------------------------------------------------------------- 1 | Results of test4: 2 | 3 | 4 | 5 | case1 6 | { 7 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 8 | 9 9 9 9 9 0 0 0 0 0 9 | 10 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 11 | } 12 | { 13 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 14 | 9 9 9 9 9 0 0 0 0 0 15 | 16 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 17 | } 18 | 19 | 20 | case2 21 | { 22 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 23 | 9 9 9 9 9 0 0 0 0 0 24 | 25 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 26 | } 27 | { 28 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 29 | 9 9 9 9 9 0 0 0 0 0 30 | 31 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 32 | } 33 | 34 | 35 | case3 36 | { 37 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 38 | 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 39 | 9 9 9 9 9 0 0 0 0 0 40 | 41 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 42 | } 43 | { 44 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 45 | 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 46 | 9 9 9 9 9 0 0 0 0 0 47 | 48 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 49 | } 50 | 51 | 52 | case4 53 | { 54 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 55 | 9 9 9 9 9 0 0 0 0 0 56 | 57 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 58 | 9 9 9 9 9 0 0 0 0 0 59 | } 60 | { 61 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 62 | 9 9 9 9 9 0 0 0 0 0 63 | 64 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 65 | 9 9 9 9 9 0 0 0 0 0 66 | } 67 | 68 | 69 | case5 70 | { 71 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 72 | 73 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 74 | } 75 | { 76 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 77 | 78 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 79 | } 80 | 81 | 82 | case6 83 | { 84 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 85 | 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 86 | 9 9 9 9 9 0 0 0 0 0 87 | 88 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 89 | 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 90 | 9 9 9 9 9 0 0 0 0 0 91 | } 92 | { 93 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 94 | 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 95 | 9 9 9 9 9 0 0 0 0 0 96 | 97 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 98 | 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 99 | 9 9 9 9 9 0 0 0 0 0 100 | } 101 | 102 | 103 | case7 104 | { 105 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 106 | 8 9 9 9 9 9 0 0 0 0 0 107 | 108 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 109 | 8 9 9 9 9 9 0 0 0 0 0 110 | } 111 | { 112 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 113 | 8 9 9 9 9 9 0 0 0 0 0 114 | 115 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 116 | 8 9 9 9 9 9 0 0 0 0 0 117 | } 118 | 119 | 120 | case8 121 | { 122 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 123 | 8 9 9 9 9 9 0 0 0 0 0 124 | 125 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 126 | 8 9 9 9 9 9 0 0 0 0 0 127 | } 128 | { 129 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 130 | 8 9 9 9 9 9 0 0 0 0 0 131 | 132 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 133 | 8 9 9 9 9 9 0 0 0 0 0 134 | } 135 | 136 | 137 | case9 138 | { 139 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 140 | 8 8 8 8 9 9 9 9 9 0 0 0 0 0 141 | 142 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 143 | 8 8 8 8 9 9 9 9 9 0 0 0 0 0 144 | } 145 | { 146 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 147 | 8 8 8 8 9 9 9 9 9 0 0 0 0 0 148 | 149 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 150 | 8 8 8 8 9 9 9 9 9 0 0 0 0 0 151 | } 152 | 153 | 154 | case10 155 | { 156 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 157 | 8 8 8 8 9 9 9 9 9 0 0 0 0 0 158 | 159 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 160 | 8 8 8 8 9 9 9 9 9 0 0 0 0 0 161 | } 162 | { 163 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 164 | 8 8 8 8 9 9 9 9 9 0 0 0 0 0 165 | 166 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 167 | 8 8 8 8 9 9 9 9 9 0 0 0 0 0 168 | } 169 | 170 | 171 | case11 172 | { 173 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 174 | 8 8 8 8 9 9 9 9 9 0 0 0 0 0 175 | 176 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 177 | 8 8 8 8 9 9 9 9 9 0 0 0 0 0 178 | } 179 | { 180 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 181 | 8 8 8 8 9 9 9 9 9 0 0 0 0 0 182 | 183 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 184 | 8 8 8 8 9 9 9 9 9 0 0 0 0 0 185 | } 186 | 187 | 188 | case12 189 | { 190 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 191 | 8 9 9 9 9 9 0 0 0 0 0 192 | 193 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 194 | 8 9 9 9 9 9 0 0 0 0 0 195 | } 196 | { 197 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 198 | 8 9 9 9 9 9 0 0 0 0 0 199 | 200 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 201 | 8 9 9 9 9 9 0 0 0 0 0 202 | } 203 | 204 | 205 | case14 206 | { 207 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 208 | 9 9 9 9 9 0 0 0 0 0 209 | 210 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 211 | 9 9 9 9 9 0 0 0 0 0 212 | } 213 | { 214 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 215 | 9 9 9 9 9 0 0 0 0 0 216 | 217 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 218 | 9 9 9 9 9 0 0 0 0 0 219 | } 220 | 221 | 222 | case15 223 | { 224 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 225 | 8 9 9 9 9 9 0 0 0 0 0 226 | } 227 | { 228 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 229 | 8 9 9 9 9 9 0 0 0 0 0 230 | } 231 | 232 | 233 | case16 234 | { 235 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 236 | 9 9 9 9 9 0 0 0 0 0 237 | 238 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 239 | } 240 | { 241 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 242 | 9 9 9 9 9 0 0 0 0 0 243 | 244 | 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0 245 | } 246 | 247 | 248 | -------------------------------------------------------------------------------- /test/test5.in: -------------------------------------------------------------------------------- 1 | Test for cursor position. 2 | 3 | Results of test5: 4 | 5 | STARTTEST 6 | :set tw=10 7 | /^{/+1 8 | :set formatexpr= 9 | V/xx 10 | gq:call setline('.', '[cursor]') 11 | /^{/+1 12 | :set formatexpr=autofmt#compat#formatexpr() 13 | V/xx 14 | gq:call setline('.', '[cursor]') 15 | ENDTEST 16 | 17 | case1 18 | { 19 | 20 | aa bb cc dd ee ff 21 | 22 | xx 23 | 24 | } 25 | { 26 | 27 | aa bb cc dd ee ff 28 | 29 | xx 30 | 31 | } 32 | 33 | STARTTEST 34 | :set tw=10 autoindent 35 | /^{/+1 36 | :set formatexpr= 37 | gqgq:call append('.', printf('col=%d', col('.'))) 38 | /^{/+1 39 | :set formatexpr=autofmt#compat#formatexpr() 40 | gqgq:call append('.', printf('col=%d', col('.'))) 41 | ENDTEST 42 | 43 | case2 44 | { 45 | aa bb cc dd ee ff 46 | } 47 | { 48 | aa bb cc dd ee ff 49 | } 50 | 51 | STARTTEST 52 | :g/^STARTTEST/.,/^ENDTEST/d 53 | :1;/^Results/,$wq! test.out 54 | ENDTEST 55 | -------------------------------------------------------------------------------- /test/test5.ok: -------------------------------------------------------------------------------- 1 | Results of test5: 2 | 3 | 4 | case1 5 | { 6 | 7 | aa bb cc 8 | dd ee ff 9 | 10 | [cursor] 11 | 12 | } 13 | { 14 | 15 | aa bb cc 16 | dd ee ff 17 | 18 | [cursor] 19 | 20 | } 21 | 22 | 23 | case2 24 | { 25 | aa bb cc 26 | dd ee ff 27 | col=3 28 | } 29 | { 30 | aa bb cc 31 | dd ee ff 32 | col=3 33 | } 34 | 35 | -------------------------------------------------------------------------------- /test/test6.in: -------------------------------------------------------------------------------- 1 | Test for join line. 2 | 3 | Results of test6: 4 | 5 | STARTTEST 6 | :set fo= tw=0 7 | /^{/+1 8 | gq} 9 | /^{/+1 10 | :set formatexpr=autofmt#compat#formatexpr() 11 | gq} 12 | ENDTEST 13 | 14 | case1 15 | { 16 | 17 | aa bb cc 18 | dd ee ff 19 | gg hh ii 20 | 21 | } 22 | { 23 | 24 | aa bb cc 25 | dd ee ff 26 | gg hh ii 27 | 28 | } 29 | 30 | STARTTEST 31 | :set fo=q tw=0 32 | /^{/+1 33 | gq} 34 | /^{/+1 35 | :set formatexpr=autofmt#compat#formatexpr() 36 | gq} 37 | ENDTEST 38 | 39 | case2 40 | { 41 | 42 | aa bb cc 43 | dd ee ff 44 | gg hh ii 45 | 46 | } 47 | { 48 | 49 | aa bb cc 50 | dd ee ff 51 | gg hh ii 52 | 53 | } 54 | 55 | STARTTEST 56 | :g/^STARTTEST/.,/^ENDTEST/d 57 | :1;/^Results/,$wq! test.out 58 | ENDTEST 59 | -------------------------------------------------------------------------------- /test/test6.ok: -------------------------------------------------------------------------------- 1 | Results of test6: 2 | 3 | 4 | case1 5 | { 6 | 7 | aa bb cc dd ee ff gg hh ii 8 | 9 | } 10 | { 11 | 12 | aa bb cc dd ee ff gg hh ii 13 | 14 | } 15 | 16 | 17 | case2 18 | { 19 | 20 | aa bb cc dd ee ff gg hh ii 21 | 22 | } 23 | { 24 | 25 | aa bb cc dd ee ff gg hh ii 26 | 27 | } 28 | 29 | -------------------------------------------------------------------------------- /test/test7.in: -------------------------------------------------------------------------------- 1 | Test for indent. 2 | 3 | autoindent 4 | cindent 5 | lispindent 6 | smartindent 7 | indentexpr 8 | 9 | 10 | Results of test7: 11 | 12 | STARTTEST 13 | :set tw=10 14 | /^{/+1 15 | :set formatexpr= 16 | gqgqjgqgqo 17 | aa bb cc dd ee ff 18 | aa bb cc dd ee ff 19 | /^{/+1 20 | :set formatexpr=autofmt#compat#formatexpr() 21 | gqgqjgqgqo 22 | aa bb cc dd ee ff 23 | aa bb cc dd ee ff 24 | ENDTEST 25 | 26 | case1 27 | { 28 | aa bb cc dd ee ff 29 | aa bb cc dd ee ff 30 | } 31 | { 32 | aa bb cc dd ee ff 33 | aa bb cc dd ee ff 34 | } 35 | 36 | STARTTEST 37 | :set tw=10 autoindent 38 | /^{/+1 39 | :set formatexpr= 40 | gqgqjgqgqo 41 | aa bb cc dd ee ff 42 | aa bb cc dd ee ff 43 | /^{/+1 44 | :set formatexpr=autofmt#compat#formatexpr() 45 | gqgqjgqgqo 46 | aa bb cc dd ee ff 47 | aa bb cc dd ee ff 48 | ENDTEST 49 | 50 | case2 51 | { 52 | aa bb cc dd ee ff 53 | aa bb cc dd ee ff 54 | } 55 | { 56 | aa bb cc dd ee ff 57 | aa bb cc dd ee ff 58 | } 59 | 60 | STARTTEST 61 | :set tw=10 cindent 62 | /^{/+1 63 | :set formatexpr= 64 | gqgqjgqgqo 65 | aa bb cc dd ee ff 66 | aa bb cc dd ee ff 67 | /^{/+1 68 | :set formatexpr=autofmt#compat#formatexpr() 69 | gqgqjgqgqo 70 | aa bb cc dd ee ff 71 | aa bb cc dd ee ff 72 | ENDTEST 73 | 74 | case3 75 | { 76 | aa bb cc dd ee ff 77 | aa bb cc dd ee ff 78 | } 79 | { 80 | aa bb cc dd ee ff 81 | aa bb cc dd ee ff 82 | } 83 | 84 | STARTTEST 85 | :set tw=10 cindent 86 | /^{/+1 87 | :set formatexpr= 88 | gqgqjgqgqo 89 | aa bb cc dd ee ff; 90 | aa bb cc dd ee ff; 91 | /^{/+1 92 | :set formatexpr=autofmt#compat#formatexpr() 93 | gqgqjgqgqo 94 | aa bb cc dd ee ff; 95 | aa bb cc dd ee ff; 96 | ENDTEST 97 | 98 | case4 99 | { 100 | aa bb cc dd ee ff; 101 | aa bb cc dd ee ff; 102 | } 103 | { 104 | aa bb cc dd ee ff; 105 | aa bb cc dd ee ff; 106 | } 107 | 108 | STARTTEST 109 | :set tw=10 lisp 110 | /^{/+1 111 | :set formatexpr= 112 | gqgqjgqgqo 113 | aa bb cc dd ee ff 114 | aa bb cc dd ee ff 115 | /^{/+1 116 | :set formatexpr=autofmt#compat#formatexpr() 117 | gqgqjgqgqo 118 | aa bb cc dd ee ff 119 | aa bb cc dd ee ff 120 | ENDTEST 121 | 122 | case5 123 | { 124 | aa bb cc dd ee ff 125 | aa bb cc dd ee ff 126 | } 127 | { 128 | aa bb cc dd ee ff 129 | aa bb cc dd ee ff 130 | } 131 | 132 | STARTTEST 133 | :set tw=10 lisp 134 | /^{/+1 135 | :set formatexpr= 136 | gqgqjgqgqo 137 | (aa bb cc dd ee ff) 138 | (aa bb cc dd ee ff) 139 | /^{/+1 140 | :set formatexpr=autofmt#compat#formatexpr() 141 | gqgqjgqgqo 142 | (aa bb cc dd ee ff) 143 | (aa bb cc dd ee ff) 144 | ENDTEST 145 | 146 | case6 147 | { 148 | (aa bb cc dd ee ff) 149 | (aa bb cc dd ee ff) 150 | } 151 | { 152 | (aa bb cc dd ee ff) 153 | (aa bb cc dd ee ff) 154 | } 155 | 156 | STARTTEST 157 | :set tw=10 lisp autoindent 158 | /^{/+1 159 | :set formatexpr= 160 | gqgqjgqgqo 161 | aa bb cc dd ee ff 162 | aa bb cc dd ee ff 163 | /^{/+1 164 | :set formatexpr=autofmt#compat#formatexpr() 165 | gqgqjgqgqo 166 | aa bb cc dd ee ff 167 | aa bb cc dd ee ff 168 | ENDTEST 169 | 170 | case7 171 | { 172 | aa bb cc dd ee ff 173 | aa bb cc dd ee ff 174 | } 175 | { 176 | aa bb cc dd ee ff 177 | aa bb cc dd ee ff 178 | } 179 | 180 | STARTTEST 181 | :set tw=10 lisp autoindent 182 | /^{/+1 183 | :set formatexpr= 184 | gqgqjgqgqo 185 | (aa bb cc dd ee ff) 186 | (aa bb cc dd ee ff) 187 | /^{/+1 188 | :set formatexpr=autofmt#compat#formatexpr() 189 | gqgqjgqgqo 190 | (aa bb cc dd ee ff) 191 | (aa bb cc dd ee ff) 192 | ENDTEST 193 | 194 | case8 195 | { 196 | (aa bb cc dd ee ff) 197 | (aa bb cc dd ee ff) 198 | } 199 | { 200 | (aa bb cc dd ee ff) 201 | (aa bb cc dd ee ff) 202 | } 203 | 204 | STARTTEST 205 | :set tw=10 smartindent 206 | /^{/+1 207 | :set formatexpr= 208 | gqgqjgqgqo 209 | aa bb cc dd ee ff 210 | aa bb cc dd ee ff 211 | /^{/+1 212 | :set formatexpr=autofmt#compat#formatexpr() 213 | gqgqjgqgqo 214 | aa bb cc dd ee ff 215 | aa bb cc dd ee ff 216 | ENDTEST 217 | 218 | case9 219 | { 220 | aa bb cc dd ee ff 221 | aa bb cc dd ee ff 222 | } 223 | { 224 | aa bb cc dd ee ff 225 | aa bb cc dd ee ff 226 | } 227 | 228 | STARTTEST 229 | :set tw=10 sw=2 smartindent 230 | /^{/+1 231 | :set formatexpr= 232 | gqgqoi 233 | if aaa 234 | do bbb 235 | while ccc 236 | #if ddd 237 | eee 238 | #endif 239 | fff 240 | { 241 | aaa 242 | { 243 | bbb 244 | } 245 | } 246 | /^{/+1 247 | :set formatexpr=autofmt#compat#formatexpr() 248 | gqgqoi 249 | if aaa 250 | do bbb 251 | while ccc 252 | #if ddd 253 | eee 254 | #endif 255 | fff 256 | { 257 | aaa 258 | { 259 | bbb 260 | } 261 | } 262 | ENDTEST 263 | 264 | case10 265 | { 266 | if aaa do bbb while ccc #if ddd #endif { aaa { bbb } } 267 | } 268 | { 269 | if aaa do bbb while ccc #if ddd #endif { aaa { bbb } } 270 | } 271 | 272 | STARTTEST 273 | :set tw=10 indentexpr=indent(v:lnum-1)+1 274 | /^{/+1 275 | :set formatexpr= 276 | gqgqjgqgqo 277 | aa bb cc dd ee ff 278 | aa bb cc dd ee ff 279 | /^{/+1 280 | :set formatexpr=autofmt#compat#formatexpr() 281 | gqgqjgqgqo 282 | aa bb cc dd ee ff 283 | aa bb cc dd ee ff 284 | ENDTEST 285 | 286 | case11 287 | { 288 | aa bb cc dd ee ff 289 | aa bb cc dd ee ff 290 | } 291 | { 292 | aa bb cc dd ee ff 293 | aa bb cc dd ee ff 294 | } 295 | 296 | STARTTEST 297 | :set tw=10 cindent 298 | /^{/+1 299 | :set formatexpr= 300 | gqgqjo{ 301 | 302 | }k aa label: 303 | /^{/+1 304 | :set formatexpr=autofmt#compat#formatexpr() 305 | gqgqjo{ 306 | 307 | }k aa label: 308 | ENDTEST 309 | 310 | case12 311 | { 312 | aa label: 313 | } 314 | { 315 | aa label: 316 | } 317 | 318 | STARTTEST 319 | :set tw=10 cindent 320 | /^{/+1 321 | :set formatexpr= 322 | gqgqjo{ 323 | 324 | }k a; label: 325 | /^{/+1 326 | :set formatexpr=autofmt#compat#formatexpr() 327 | gqgqjo{ 328 | 329 | }k a; label: 330 | ENDTEST 331 | 332 | case13 333 | { 334 | a; label: 335 | } 336 | { 337 | a; label: 338 | } 339 | 340 | STARTTEST 341 | :set tw=10 cindent 342 | /^{/+1 343 | :set formatexpr= 344 | gqgqjo{ 345 | 346 | }k a; bbbbb; 347 | /^{/+1 348 | :set formatexpr=autofmt#compat#formatexpr() 349 | gqgqjo{ 350 | 351 | }k a; bbbbb; 352 | ENDTEST 353 | 354 | case14 355 | { 356 | a; bbbbb; 357 | } 358 | { 359 | a; bbbbb; 360 | } 361 | 362 | STARTTEST 363 | :g/^STARTTEST/.,/^ENDTEST/d 364 | :1;/^Results/,$wq! test.out 365 | ENDTEST 366 | -------------------------------------------------------------------------------- /test/test7.ok: -------------------------------------------------------------------------------- 1 | Results of test7: 2 | 3 | 4 | case1 5 | { 6 | aa bb cc 7 | dd ee ff 8 | aa bb cc 9 | dd ee ff 10 | 11 | aa bb cc 12 | dd ee ff 13 | aa bb cc 14 | dd ee ff 15 | } 16 | { 17 | aa bb cc 18 | dd ee ff 19 | aa bb cc 20 | dd ee ff 21 | 22 | aa bb cc 23 | dd ee ff 24 | aa bb cc 25 | dd ee ff 26 | } 27 | 28 | 29 | case2 30 | { 31 | aa bb cc 32 | dd ee ff 33 | aa bb cc 34 | dd ee ff 35 | 36 | aa bb cc 37 | dd ee ff 38 | aa bb 39 | cc dd 40 | ee ff 41 | } 42 | { 43 | aa bb cc 44 | dd ee ff 45 | aa bb cc 46 | dd ee ff 47 | 48 | aa bb cc 49 | dd ee ff 50 | aa bb 51 | cc dd 52 | ee ff 53 | } 54 | 55 | 56 | case3 57 | { 58 | aa bb cc 59 | dd 60 | ee 61 | ff 62 | aa bb cc 63 | dd ee ff 64 | 65 | aa bb cc 66 | dd ee ff 67 | aa bb 68 | cc dd 69 | ee ff 70 | } 71 | { 72 | aa bb cc 73 | dd 74 | ee 75 | ff 76 | aa bb cc 77 | dd ee ff 78 | 79 | aa bb cc 80 | dd ee ff 81 | aa bb 82 | cc dd 83 | ee ff 84 | } 85 | 86 | 87 | case4 88 | { 89 | aa bb cc 90 | dd 91 | ee 92 | ff; 93 | aa bb cc 94 | dd 95 | ee 96 | ff; 97 | 98 | aa bb cc 99 | dd 100 | ee 101 | ff; 102 | aa bb 103 | cc 104 | dd 105 | ee 106 | ff; 107 | } 108 | { 109 | aa bb cc 110 | dd 111 | ee 112 | ff; 113 | aa bb cc 114 | dd 115 | ee 116 | ff; 117 | 118 | aa bb cc 119 | dd 120 | ee 121 | ff; 122 | aa bb 123 | cc 124 | dd 125 | ee 126 | ff; 127 | } 128 | 129 | 130 | case5 131 | { 132 | aa bb cc 133 | dd ee ff 134 | aa bb cc 135 | dd ee ff 136 | 137 | aa bb cc 138 | dd ee ff 139 | aa bb cc 140 | dd ee ff 141 | } 142 | { 143 | aa bb cc 144 | dd ee ff 145 | aa bb cc 146 | dd ee ff 147 | 148 | aa bb cc 149 | dd ee ff 150 | aa bb cc 151 | dd ee ff 152 | } 153 | 154 | 155 | case6 156 | { 157 | (aa bb cc 158 | dd ee ff) 159 | (aa bb 160 | cc dd ee 161 | ff) 162 | 163 | (aa bb cc 164 | dd ee ff) 165 | (aa bb 166 | cc dd ee 167 | ff) 168 | } 169 | { 170 | (aa bb cc 171 | dd ee ff) 172 | (aa bb 173 | cc dd ee 174 | ff) 175 | 176 | (aa bb cc 177 | dd ee ff) 178 | (aa bb 179 | cc dd ee 180 | ff) 181 | } 182 | 183 | 184 | case7 185 | { 186 | aa bb cc 187 | dd ee ff 188 | aa bb cc 189 | dd ee ff 190 | 191 | aa bb cc 192 | dd ee ff 193 | aa bb cc 194 | dd ee ff 195 | } 196 | { 197 | aa bb cc 198 | dd ee ff 199 | aa bb cc 200 | dd ee ff 201 | 202 | aa bb cc 203 | dd ee ff 204 | aa bb cc 205 | dd ee ff 206 | } 207 | 208 | 209 | case8 210 | { 211 | (aa bb cc 212 | dd ee 213 | ff) 214 | (aa bb 215 | cc 216 | dd 217 | ee 218 | ff) 219 | 220 | (aa bb cc 221 | dd ee 222 | ff) 223 | (aa bb 224 | cc 225 | dd 226 | ee 227 | ff) 228 | } 229 | { 230 | (aa bb cc 231 | dd ee 232 | ff) 233 | (aa bb 234 | cc 235 | dd 236 | ee 237 | ff) 238 | 239 | (aa bb cc 240 | dd ee 241 | ff) 242 | (aa bb 243 | cc 244 | dd 245 | ee 246 | ff) 247 | } 248 | 249 | 250 | case9 251 | { 252 | aa bb cc 253 | dd ee ff 254 | aa bb cc 255 | dd ee ff 256 | 257 | aa bb cc 258 | dd ee ff 259 | aa bb 260 | cc dd 261 | ee ff 262 | } 263 | { 264 | aa bb cc 265 | dd ee ff 266 | aa bb cc 267 | dd ee ff 268 | 269 | aa bb cc 270 | dd ee ff 271 | aa bb 272 | cc dd 273 | ee ff 274 | } 275 | 276 | 277 | case10 278 | { 279 | if aaa do 280 | bbb 281 | while 282 | ccc 283 | #if 284 | ddd 285 | #endif 286 | { aaa 287 | { bbb 288 | } } 289 | 290 | if aaa 291 | do bbb 292 | while 293 | ccc 294 | #if ddd 295 | eee 296 | #endif 297 | fff 298 | { 299 | aaa 300 | { 301 | bbb 302 | } 303 | } 304 | } 305 | { 306 | if aaa do 307 | bbb 308 | while 309 | ccc 310 | #if 311 | ddd 312 | #endif 313 | { aaa 314 | { bbb 315 | } } 316 | 317 | if aaa 318 | do bbb 319 | while 320 | ccc 321 | #if ddd 322 | eee 323 | #endif 324 | fff 325 | { 326 | aaa 327 | { 328 | bbb 329 | } 330 | } 331 | } 332 | 333 | 334 | case11 335 | { 336 | aa bb cc 337 | dd ee ff 338 | aa bb cc 339 | dd ee 340 | ff 341 | 342 | aa bb cc 343 | dd ee ff 344 | aa bb 345 | cc 346 | dd 347 | ee 348 | ff 349 | } 350 | { 351 | aa bb cc 352 | dd ee ff 353 | aa bb cc 354 | dd ee 355 | ff 356 | 357 | aa bb cc 358 | dd ee ff 359 | aa bb 360 | cc 361 | dd 362 | ee 363 | ff 364 | } 365 | 366 | 367 | case12 368 | { 369 | aa 370 | label: 371 | } 372 | { 373 | aa 374 | label: 375 | } 376 | { 377 | aa 378 | label: 379 | } 380 | { 381 | aa 382 | label: 383 | } 384 | 385 | 386 | case13 387 | { 388 | a; 389 | label: 390 | } 391 | { 392 | a; 393 | label: 394 | } 395 | { 396 | a; 397 | label: 398 | } 399 | { 400 | a; 401 | label: 402 | } 403 | 404 | 405 | case14 406 | { 407 | a; 408 | bbbbb; 409 | } 410 | { 411 | a; 412 | bbbbb; 413 | } 414 | { 415 | a; 416 | bbbbb; 417 | } 418 | { 419 | a; 420 | bbbbb; 421 | } 422 | 423 | -------------------------------------------------------------------------------- /test/test8.in: -------------------------------------------------------------------------------- 1 | Test for paste. 2 | 3 | 4 | Results of test8: 5 | 6 | STARTTEST 7 | :set paste autoindent tw=10 8 | /^{/+1 9 | gqgqo 10 | i aaaaa bbbbb 11 | /^{/+1 12 | :set formatexpr=autofmt#compat#formatexpr() 13 | gqgqo 14 | i aaaaa bbbbb 15 | ENDTEST 16 | 17 | case1 18 | { 19 | aaaaa bbbbb 20 | } 21 | { 22 | aaaaa bbbbb 23 | } 24 | 25 | STARTTEST 26 | :set paste cindent tw=10 27 | /^{/+1 28 | gqgqo 29 | i aaaaa bbbbb 30 | /^{/+1 31 | :set formatexpr=autofmt#compat#formatexpr() 32 | gqgqo 33 | i aaaaa bbbbb 34 | ENDTEST 35 | 36 | case2 37 | { 38 | aaaaa bbbbb 39 | } 40 | { 41 | aaaaa bbbbb 42 | } 43 | 44 | STARTTEST 45 | :set paste lisp autoindent tw=10 46 | /^{/+1 47 | gqgqo 48 | i(aaaaa bbbbb) 49 | /^{/+1 50 | :set formatexpr=autofmt#compat#formatexpr() 51 | gqgqo 52 | i(aaaaa bbbbb) 53 | ENDTEST 54 | 55 | case3 56 | { 57 | (aaaaa bbbbb) 58 | } 59 | { 60 | (aaaaa bbbbb) 61 | } 62 | 63 | STARTTEST 64 | :set paste smartindent tw=10 65 | /^{/+1 66 | gqgqo 67 | i if aa bbb 68 | /^{/+1 69 | :set formatexpr=autofmt#compat#formatexpr() 70 | gqgqo 71 | i if aa bbb 72 | ENDTEST 73 | 74 | case4 75 | { 76 | if aa bbb 77 | } 78 | { 79 | if aa bbb 80 | } 81 | 82 | STARTTEST 83 | :set paste indentexpr=indent(v:lnum-1)+1 tw=10 84 | /^{/+1 85 | gqgqo 86 | aa bb cc dd ee ff 87 | /^{/+1 88 | :set formatexpr=autofmt#compat#formatexpr() 89 | gqgqo 90 | aa bb cc dd ee ff 91 | ENDTEST 92 | 93 | case5 94 | { 95 | aa bb cc dd ee ff 96 | } 97 | { 98 | aa bb cc dd ee ff 99 | } 100 | 101 | STARTTEST 102 | :g/^STARTTEST/.,/^ENDTEST/d 103 | :1;/^Results/,$wq! test.out 104 | ENDTEST 105 | -------------------------------------------------------------------------------- /test/test8.ok: -------------------------------------------------------------------------------- 1 | Results of test8: 2 | 3 | 4 | case1 5 | { 6 | aaaaa 7 | bbbbb 8 | 9 | aaaaa bbbbb 10 | } 11 | { 12 | aaaaa 13 | bbbbb 14 | 15 | aaaaa bbbbb 16 | } 17 | 18 | 19 | case2 20 | { 21 | aaaaa 22 | bbbbb 23 | 24 | aaaaa bbbbb 25 | } 26 | { 27 | aaaaa 28 | bbbbb 29 | 30 | aaaaa bbbbb 31 | } 32 | 33 | 34 | case3 35 | { 36 | (aaaaa 37 | bbbbb) 38 | 39 | (aaaaa bbbbb) 40 | } 41 | { 42 | (aaaaa 43 | bbbbb) 44 | 45 | (aaaaa bbbbb) 46 | } 47 | 48 | 49 | case4 50 | { 51 | if aa 52 | bbb 53 | 54 | if aa bbb 55 | } 56 | { 57 | if aa 58 | bbb 59 | 60 | if aa bbb 61 | } 62 | 63 | 64 | case5 65 | { 66 | aa bb cc 67 | dd ee ff 68 | 69 | aa bb cc dd ee ff 70 | } 71 | { 72 | aa bb cc 73 | dd ee ff 74 | 75 | aa bb cc dd ee ff 76 | } 77 | 78 | -------------------------------------------------------------------------------- /test/test9.in: -------------------------------------------------------------------------------- 1 | Test for no_leader. 2 | 3 | edit.c: 4 | 6063 /* If the line doesn't start with a comment leader, then don't 5 | 6064 * start one in a following broken line. Avoids that a %word 6 | 6065 * moved to the start of the next line causes all following lines 7 | 6066 * to start with %. */ 8 | 6067 if (leader_len == 0) 9 | 6068 no_leader = TRUE; 10 | 11 | Results of test9: 12 | 13 | STARTTEST 14 | :set tw=4 formatoptions=tcq comments=:\" 15 | /^{/+1 16 | gqgqo 17 | innoremap "hoge" fuga puyo 18 | /^{/+1 19 | :set formatexpr=autofmt#compat#formatexpr() 20 | gqgqo 21 | innoremap "hoge" fuga puyo 22 | ENDTEST 23 | 24 | case1 25 | { 26 | nnoremap "hoge" fuga puyo 27 | } 28 | { 29 | nnoremap "hoge" fuga puyo 30 | } 31 | 32 | STARTTEST 33 | :set tw=4 formatoptions=tcq cindent comments=s1:/*,mb:*,ex:*/ 34 | /^{/+1 35 | gqgqo 36 | iint xxx /* a b c d */ 37 | /^{/+1 38 | :set formatexpr=autofmt#compat#formatexpr() 39 | gqgqo 40 | iint xxx /* a b c d */ 41 | ENDTEST 42 | 43 | case2 44 | { 45 | int xxx /* a b c d */ 46 | } 47 | { 48 | int xxx /* a b c d */ 49 | } 50 | 51 | STARTTEST 52 | :g/^STARTTEST/.,/^ENDTEST/d 53 | :1;/^Results/,$wq! test.out 54 | ENDTEST 55 | -------------------------------------------------------------------------------- /test/test9.ok: -------------------------------------------------------------------------------- 1 | Results of test9: 2 | 3 | 4 | case1 5 | { 6 | nnoremap 7 | "hoge" 8 | fuga 9 | puyo 10 | 11 | nnoremap 12 | "hoge" 13 | "fuga 14 | "puyo 15 | } 16 | { 17 | nnoremap 18 | "hoge" 19 | fuga 20 | puyo 21 | 22 | nnoremap 23 | "hoge" 24 | "fuga 25 | "puyo 26 | } 27 | 28 | 29 | case2 30 | { 31 | int 32 | xxx 33 | /* 34 | a 35 | b 36 | c 37 | d 38 | */ 39 | 40 | int 41 | xxx 42 | /* a 43 | * b 44 | * c 45 | * d 46 | * */ 47 | } 48 | { 49 | int 50 | xxx 51 | /* a 52 | b 53 | c 54 | d 55 | */ 56 | 57 | int 58 | xxx 59 | /* a 60 | * b 61 | * c 62 | * d 63 | * */ 64 | } 65 | 66 | -------------------------------------------------------------------------------- /test/todo.in: -------------------------------------------------------------------------------- 1 | Test for fo=2. 2 | 3 | 4 | Results of todo: 5 | 6 | STARTTEST 7 | :set fo=2 noai tw=10 8 | /^{/+1 9 | :set formatexpr= 10 | j2gqgq2j3gqgq 11 | /^{/+1 12 | :set formatexpr=autofmt#compat#formatexpr() 13 | j2gqgq2j3gqgq 14 | ENDTEST 15 | 16 | case1 17 | { 18 | 19 | aa bb cc 20 | dd ee ff 21 | 22 | aa bb cc 23 | dd ee ff 24 | gg hh ii 25 | 26 | } 27 | { 28 | 29 | aa bb cc 30 | dd ee ff 31 | 32 | aa bb cc 33 | dd ee ff 34 | gg hh ii 35 | 36 | } 37 | 38 | STARTTEST 39 | :set fo=2 noai tw=20 40 | /^{/+1 41 | :set formatexpr= 42 | j2gqgq2j2gqgq 43 | /^{/+1 44 | :set formatexpr=autofmt#compat#formatexpr() 45 | j2gqgq2j2gqgq 46 | ENDTEST 47 | 48 | case2 49 | { 50 | 51 | aa bb cc 52 | dd ee ff 53 | 54 | aa bb cc 55 | dd ee ff 56 | 57 | } 58 | { 59 | 60 | aa bb cc 61 | dd ee ff 62 | 63 | aa bb cc 64 | dd ee ff 65 | 66 | } 67 | 68 | STARTTEST 69 | :set fo=t2 noai tw=10 70 | /^{/+1 71 | :set formatexpr= 72 | A xx yy 73 | /^{/+1 74 | :set formatexpr=autofmt#compat#formatexpr() 75 | A xx yy 76 | ENDTEST 77 | 78 | case3 79 | { 80 | aa bb 81 | cc dd ee 82 | } 83 | { 84 | aa bb 85 | cc dd ee 86 | } 87 | 88 | STARTTEST 89 | :set fo=t2 ai tw=10 90 | /^{/+1 91 | :set formatexpr= 92 | A xx yy 93 | /^{/+1 94 | :set formatexpr=autofmt#compat#formatexpr() 95 | A xx yy 96 | ENDTEST 97 | 98 | case4 99 | { 100 | aa bb 101 | cc dd ee 102 | } 103 | { 104 | aa bb 105 | cc dd ee 106 | } 107 | 108 | STARTTEST 109 | :g/^STARTTEST/.,/^ENDTEST/d 110 | :1;/^Results/,$wq! test.out 111 | ENDTEST 112 | -------------------------------------------------------------------------------- /test/todo.ok: -------------------------------------------------------------------------------- 1 | Results of todo: 2 | 3 | 4 | case1 5 | { 6 | 7 | aa bb 8 | cc dd ee 9 | ff 10 | 11 | aa bb cc 12 | dd ee 13 | ff gg hh 14 | ii 15 | 16 | } 17 | { 18 | 19 | aa bb 20 | cc dd ee 21 | ff 22 | 23 | aa bb cc 24 | dd ee 25 | ff gg hh 26 | ii 27 | 28 | } 29 | 30 | 31 | case2 32 | { 33 | 34 | aa 35 | bb cc dd 36 | ee ff 37 | 38 | aa 39 | bb cc dd 40 | ee ff 41 | 42 | } 43 | { 44 | 45 | aa 46 | bb cc dd 47 | ee ff 48 | 49 | aa 50 | bb cc dd 51 | ee ff 52 | 53 | } 54 | 55 | 56 | case3 57 | { 58 | aa bb 59 | xx yy 60 | cc dd ee 61 | } 62 | { 63 | aa bb 64 | xx yy 65 | cc dd ee 66 | } 67 | 68 | 69 | case4 70 | { 71 | aa bb 72 | xx yy 73 | cc dd ee 74 | } 75 | { 76 | aa bb 77 | xx yy 78 | cc dd ee 79 | } 80 | 81 | -------------------------------------------------------------------------------- /test/todo2.in: -------------------------------------------------------------------------------- 1 | When using gq{motion}, we can't set cursor position to correct place. 2 | v:lnum=1 and v:count=5 for both "gq/xx" and "V/yygq". 3 | 4 | Results of todo2: 5 | 6 | STARTTEST 7 | :set tw=10 8 | /^{/+1 9 | :set formatexpr= 10 | gq/xx 11 | :call setline('.', '[cursor]') 12 | /^{/+1 13 | :set formatexpr=autofmt#compat#formatexpr() 14 | gq/xx 15 | :call setline('.', '[cursor]') 16 | ENDTEST 17 | 18 | case1 19 | { 20 | 21 | aa bb cc 22 | dd ee ff 23 | 24 | yy 25 | xx 26 | 27 | } 28 | { 29 | 30 | aa bb cc 31 | dd ee ff 32 | 33 | yy 34 | xx 35 | 36 | } 37 | 38 | STARTTEST 39 | :g/^STARTTEST/.,/^ENDTEST/d 40 | :1;/^Results/,$wq! test.out 41 | ENDTEST 42 | -------------------------------------------------------------------------------- /test/todo2.ok: -------------------------------------------------------------------------------- 1 | Results of todo2: 2 | 3 | 4 | case1 5 | { 6 | 7 | aa bb cc 8 | dd ee ff 9 | 10 | yy 11 | [cursor] 12 | 13 | } 14 | { 15 | 16 | aa bb cc 17 | dd ee ff 18 | 19 | [cursor] 20 | xx 21 | 22 | } 23 | 24 | -------------------------------------------------------------------------------- /test/todo3.in: -------------------------------------------------------------------------------- 1 | Quotation mark may require special handling. 2 | 3 | line break class 4 | QU Quotation Quotation marks Act like they are both opening and closing 5 | 6 | 1. 7 | odd: handle as opening 8 | even: handle as closing 9 | 10 | 2. 11 | ... 12 | 13 | 14 | Results of todo3: 15 | 16 | STARTTEST 17 | :set fo=tm tw=10 18 | /^{/+1 19 | :set formatexpr= 20 | gqgqjgqgqo 21 | あいうえu3002'abcd' 22 | "あいうu3002"abcd 23 | /^{/+1 24 | :set formatexpr=autofmt#japanese#formatexpr() 25 | gqgqjgqgqo 26 | あいうえu3002'abcd' 27 | "あいうu3002"abcd 28 | ENDTEST 29 | 30 | case1 31 | { 32 | あいうえ。'abcd' 33 | "あいう。"abcd 34 | } 35 | { 36 | あいうえ。'abcd' 37 | "あいう。"abcd 38 | } 39 | 40 | STARTTEST 41 | :g/^STARTTEST/.,/^ENDTEST/d 42 | :1;/^Results/,$wq! test.out 43 | ENDTEST 44 | -------------------------------------------------------------------------------- /test/todo3.ok: -------------------------------------------------------------------------------- 1 | Results of todo3: 2 | 3 | 4 | case1 5 | { 6 | あいうえ。 7 | 'abcd' 8 | "あいう。 9 | "abcd 10 | 11 | あいうえ。 12 | 'abcd' 13 | "あいう。 14 | "abcd 15 | } 16 | { 17 | あいう 18 | え。'abcd' 19 | "あい 20 | う。"abcd 21 | 22 | あいう 23 | え。'abcd' 24 | "あい 25 | う。"abcd 26 | } 27 | 28 | -------------------------------------------------------------------------------- /test/todo5.in: -------------------------------------------------------------------------------- 1 | Test for mark. 2 | 3 | Results of todo5: 4 | 5 | STARTTEST 6 | :function! GetMarks(s) 7 | : return map(split(a:s, '\zs'), 'getpos("''" . v:val)') 8 | :endfunction 9 | ENDTEST 10 | 11 | STARTTEST 12 | :set tw=10 13 | /^{/+1 14 | :set formatexpr= 15 | :normal! mawmbwmcwmdwmewmf 16 | :let before = GetMarks('abcdef') 17 | :normal! k2gqgq 18 | :let after = GetMarks('abcdef') 19 | :call append('.', [string(before), string(after), before == after ? "ok" : "ng"]) 20 | /^{/+1 21 | :set formatexpr=autofmt#compat#formatexpr() 22 | :normal! mawmbwmcwmdwmewmf 23 | :let before = GetMarks('abcdef') 24 | :normal! k2gqgq 25 | :let after = GetMarks('abcdef') 26 | :call append('.', [string(before), string(after), before == after ? "ok" : "ng"]) 27 | :delmarks! 28 | ENDTEST 29 | 30 | case1 31 | { 32 | aa bb cc 33 | dd ee ff 34 | } 35 | { 36 | aa bb cc 37 | dd ee ff 38 | } 39 | 40 | STARTTEST 41 | :set tw=10 42 | /^{/+1 43 | :set formatexpr= 44 | :normal! mawmbwmcwmdwmewmf 45 | :normal! gqgq 46 | :let marks_vim = GetMarks('abcdef') 47 | :-1,.delete 48 | :delmarks! 49 | :set formatexpr=autofmt#compat#formatexpr() 50 | :normal! mawmbwmcwmdwmewmf 51 | :normal! gqgq 52 | :let marks_autofmt = GetMarks('abcdef') 53 | :call append('.', [string(marks_vim), string(marks_autofmt), marks_vim == marks_autofmt ? 'ok' : 'ng']) 54 | :delmarks! 55 | ENDTEST 56 | 57 | case2 58 | { 59 | aa bb cc dd ee ff 60 | aa bb cc dd ee ff 61 | } 62 | 63 | STARTTEST 64 | :set tw=20 65 | /^{/+1 66 | :set formatexpr= 67 | :normal! mawmbwmcwmdwmewmf 68 | :normal! k2gqgq 69 | :let marks_vim = GetMarks('abcdef') 70 | :delete 71 | :delmarks! 72 | :set formatexpr=autofmt#compat#formatexpr() 73 | :normal! mawmbwmcwmdwmewmf 74 | :normal! k2gqgq 75 | :let marks_autofmt = GetMarks('abcdef') 76 | :call append('.', [string(marks_vim), string(marks_autofmt), marks_vim == marks_autofmt ? 'ok' : 'ng']) 77 | :delmarks! 78 | ENDTEST 79 | 80 | case3 81 | { 82 | aa bb cc 83 | dd ee ff 84 | aa bb cc 85 | dd ee ff 86 | } 87 | 88 | STARTTEST 89 | :g/^STARTTEST/.,/^ENDTEST/d 90 | :1;/^Results/,$wq! test.out 91 | ENDTEST 92 | -------------------------------------------------------------------------------- /test/todo5.ok: -------------------------------------------------------------------------------- 1 | Results of todo5: 2 | 3 | 4 | 5 | case1 6 | { 7 | aa bb cc 8 | dd ee ff 9 | [[0, 32, 1, 0], [0, 32, 4, 0], [0, 32, 7, 0], [0, 33, 1, 0], [0, 33, 4, 0], [0, 33, 7, 0]] 10 | [[0, 32, 1, 0], [0, 32, 4, 0], [0, 32, 7, 0], [0, 33, 1, 0], [0, 33, 4, 0], [0, 33, 7, 0]] 11 | ok 12 | } 13 | { 14 | aa bb cc 15 | dd ee ff 16 | [[0, 39, 1, 0], [0, 39, 4, 0], [0, 39, 7, 0], [0, 40, 1, 0], [0, 40, 4, 0], [0, 40, 7, 0]] 17 | [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] 18 | ng 19 | } 20 | 21 | 22 | case2 23 | { 24 | aa bb cc 25 | dd ee ff 26 | [[0, 65, 1, 0], [0, 65, 4, 0], [0, 65, 7, 0], [0, 66, 1, 0], [0, 66, 4, 0], [0, 66, 7, 0]] 27 | [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] 28 | ng 29 | } 30 | 31 | 32 | case3 33 | { 34 | aa bb cc dd ee ff 35 | [[0, 91, 1, 0], [0, 91, 4, 0], [0, 91, 7, 0], [0, 91, 10, 0], [0, 91, 13, 0], [0, 91, 16, 0]] 36 | [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] 37 | ng 38 | } 39 | 40 | -------------------------------------------------------------------------------- /test/unix.vim: -------------------------------------------------------------------------------- 1 | " Settings for test script execution 2 | " Always use "sh", don't use the value of "$SHELL". 3 | let g:__vimrc = expand(":p") 4 | set shell=sh 5 | set debug=msg 6 | set verbosefile=debug.log 7 | let &runtimepath = expand(":p:h:h") 8 | -------------------------------------------------------------------------------- /tools/unicode.vim: -------------------------------------------------------------------------------- 1 | 2 | function s:parse_prop(lines) 3 | " items = [[start, end, prop], ...] 4 | let items = [] 5 | 6 | " 1. parse lines 7 | for line in getline(1, '$') 8 | let line = substitute(line, '\s*#.*', '', '') 9 | if line == "" 10 | continue 11 | endif 12 | if line =~ '\.\.' 13 | "UUUU..UUUU;XX 14 | let m = matchlist(line, '\v^(\x+)\.\.(\x+);(\S+)$') 15 | call add(items, [str2nr(m[1], 16), str2nr(m[2], 16), m[3]]) 16 | else 17 | "UUUU;XX 18 | let m = matchlist(line, '\v^(\x+);(\S+)$') 19 | call add(items, [str2nr(m[1], 16), str2nr(m[1], 16), m[2]]) 20 | endif 21 | endfor 22 | 23 | " 2. reduce 24 | let i = 0 25 | while i < len(items) - 1 26 | if items[i][2] == items[i + 1][2] && items[i][1] + 1 == items[i + 1][0] 27 | let items[i][1] = items[i + 1][1] 28 | unlet items[i + 1] 29 | else 30 | let i += 1 31 | endif 32 | endwhile 33 | 34 | return items 35 | endfunction 36 | 37 | function s:prop_bsearch(ucs4, table) 38 | let [left, right] = [0, len(a:table)] 39 | while left < right 40 | let mid = (left + right) / 2 41 | let item = a:table[mid] 42 | if a:ucs4 < item[0] 43 | let right = mid 44 | elseif item[1] < a:ucs4 45 | let left = mid + 1 46 | else 47 | return item 48 | endif 49 | endwhile 50 | return [] 51 | endfunction 52 | 53 | function! s:main() 54 | if !filereadable('LineBreak.txt') 55 | edit http://www.unicode.org/Public/UNIDATA/LineBreak.txt 56 | write LineBreak.txt 57 | else 58 | edit LineBreak.txt 59 | endif 60 | let header = getline(1, 2) 61 | let linebreak = s:parse_prop(getline(1, '$')) 62 | 63 | enew 64 | 65 | if header[0] =~# '^# LineBreak-.*\.txt' 66 | $put ='\"' . header[0][1:] 67 | endif 68 | if header[1] =~# '^# Date: ' 69 | $put ='\"' . header[1][1:] 70 | endif 71 | 72 | " MEMO: line length is optimized for Vim's reading buffer size. 73 | $put ='let s:tmp = []' 74 | let n = 3 75 | for i in range(0, len(linebreak) - 1, n) 76 | let s = '' 77 | for [start, end, prop] in linebreak[i : i + n - 1] 78 | if s != '' 79 | let s .= ',' 80 | endif 81 | let s .= printf('[0x%04X,0x%04X,''%s'']', start, end, prop) 82 | endfor 83 | $put =printf('call extend(s:tmp, [%s])', s) 84 | endfor 85 | $put ='let s:lib.linebreak_table = s:tmp' 86 | $put ='unlet s:tmp' 87 | $put ='' 88 | 89 | $put ='let s:tmp = []' 90 | for x in range(0x100) 91 | let row = [] 92 | for y in range(0x100) 93 | let item = s:prop_bsearch(x * 0x100 + y, linebreak) 94 | if empty(item) 95 | let prop = 'XX' 96 | else 97 | let [start, end, prop] = item 98 | endif 99 | call add(row, prop) 100 | endfor 101 | if count(row, prop) == len(row) 102 | let row = [prop] 103 | endif 104 | let s = join(map(row, "'''' . v:val . ''''"), ',') 105 | $put =printf('call add(s:tmp, [%s])', s) 106 | endfor 107 | $put ='let s:lib.linebreak_bmp = s:tmp' 108 | $put ='unlet s:tmp' 109 | $put ='' 110 | 111 | endfunction 112 | 113 | call s:main() 114 | --------------------------------------------------------------------------------