Mercurial > vim
comparison runtime/indent/html.vim @ 11518:63b0b7b79b25
Update runtime files.
commit https://github.com/vim/vim/commit/3ec574f2b549f456f664f689d6da36dc5719aeb9
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jun 13 18:12:01 2017 +0200
Update runtime files.
Includes changing &sw to shiftwidth() for all indent scripts.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 13 Jun 2017 18:15:04 +0200 |
parents | 523cd59d6db0 |
children | 02b3f719eacb |
comparison
equal
deleted
inserted
replaced
11517:01330ca5f7f8 | 11518:63b0b7b79b25 |
---|---|
1 " Vim indent script for HTML | 1 " Vim indent script for HTML |
2 " Header: "{{{ | 2 " Header: "{{{ |
3 " Maintainer: Bram Moolenaar | 3 " Maintainer: Bram Moolenaar |
4 " Original Author: Andy Wokula <anwoku@yahoo.de> | 4 " Original Author: Andy Wokula <anwoku@yahoo.de> |
5 " Last Change: 2017 Jan 17 | 5 " Last Change: 2017 Jun 13 |
6 " Version: 1.0 | 6 " Version: 1.0 |
7 " Description: HTML indent script with cached state for faster indenting on a | 7 " Description: HTML indent script with cached state for faster indenting on a |
8 " range of lines. | 8 " range of lines. |
9 " Supports template systems through hooks. | 9 " Supports template systems through hooks. |
10 " Supports Closure stylesheets. | 10 " Supports Closure stylesheets. |
49 if exists("*HtmlIndent") && !exists('g:force_reload_html') | 49 if exists("*HtmlIndent") && !exists('g:force_reload_html') |
50 call HtmlIndent_CheckUserSettings() | 50 call HtmlIndent_CheckUserSettings() |
51 finish | 51 finish |
52 endif | 52 endif |
53 | 53 |
54 " shiftwidth() exists since patch 7.3.694 | |
55 if exists('*shiftwidth') | |
56 let s:ShiftWidth = function('shiftwidth') | |
57 else | |
58 func! s:ShiftWidth() | |
59 return &shiftwidth | |
60 endfunc | |
61 endif | |
62 | |
63 " Allow for line continuation below. | 54 " Allow for line continuation below. |
64 let s:cpo_save = &cpo | 55 let s:cpo_save = &cpo |
65 set cpo-=C | 56 set cpo-=C |
66 "}}} | 57 "}}} |
67 | 58 |
121 endfor | 112 endfor |
122 endif | 113 endif |
123 | 114 |
124 let indone = {"zero": 0 | 115 let indone = {"zero": 0 |
125 \,"auto": "indent(prevnonblank(v:lnum-1))" | 116 \,"auto": "indent(prevnonblank(v:lnum-1))" |
126 \,"inc": "b:hi_indent.blocktagind + s:ShiftWidth()"} | 117 \,"inc": "b:hi_indent.blocktagind + shiftwidth()"} |
127 | 118 |
128 let script1 = '' | 119 let script1 = '' |
129 if exists("b:html_indent_script1") | 120 if exists("b:html_indent_script1") |
130 let script1 = b:html_indent_script1 | 121 let script1 = b:html_indent_script1 |
131 elseif exists("g:html_indent_script1") | 122 elseif exists("g:html_indent_script1") |
356 if s:countonly | 347 if s:countonly |
357 return "" | 348 return "" |
358 endif | 349 endif |
359 let b:hi_newstate.blocklnr = v:lnum | 350 let b:hi_newstate.blocklnr = v:lnum |
360 " save allover indent for the endtag | 351 " save allover indent for the endtag |
361 let b:hi_newstate.blocktagind = b:hi_indent.baseindent + (s:nextrel + s:curind) * s:ShiftWidth() | 352 let b:hi_newstate.blocktagind = b:hi_indent.baseindent + (s:nextrel + s:curind) * shiftwidth() |
362 if a:ind == 3 | 353 if a:ind == 3 |
363 return "SCRIPT" " all except this must be lowercase | 354 return "SCRIPT" " all except this must be lowercase |
364 " line is to be checked again for the type attribute | 355 " line is to be checked again for the type attribute |
365 endif | 356 endif |
366 else | 357 else |
478 let state.scripttype = s:GetScriptType(matchstr(tagline, '\>[^>]*', stopcol)) | 469 let state.scripttype = s:GetScriptType(matchstr(tagline, '\>[^>]*', stopcol)) |
479 endif | 470 endif |
480 let state.blocklnr = stopline | 471 let state.blocklnr = stopline |
481 " check preceding tags in the line: | 472 " check preceding tags in the line: |
482 call s:CountITags(tagline[: stopcol-2]) | 473 call s:CountITags(tagline[: stopcol-2]) |
483 let state.blocktagind = indent(stopline) + (s:curind + s:nextrel) * s:ShiftWidth() | 474 let state.blocktagind = indent(stopline) + (s:curind + s:nextrel) * shiftwidth() |
484 return state | 475 return state |
485 elseif stopline == state.lnum | 476 elseif stopline == state.lnum |
486 " handle special case: previous line (= state.lnum) contains a | 477 " handle special case: previous line (= state.lnum) contains a |
487 " closing blocktag which is preceded by line-noise; | 478 " closing blocktag which is preceded by line-noise; |
488 " blocktag == "/..." | 479 " blocktag == "/..." |
489 let swendtag = match(tagline, '^\s*</') >= 0 | 480 let swendtag = match(tagline, '^\s*</') >= 0 |
490 if !swendtag | 481 if !swendtag |
491 let [bline, bcol] = searchpos('<'.blocktag[1:].'\>', "bnW") | 482 let [bline, bcol] = searchpos('<'.blocktag[1:].'\>', "bnW") |
492 call s:CountITags(tolower(getline(bline)[: bcol-2])) | 483 call s:CountITags(tolower(getline(bline)[: bcol-2])) |
493 let state.baseindent = indent(bline) + (s:curind + s:nextrel) * s:ShiftWidth() | 484 let state.baseindent = indent(bline) + (s:curind + s:nextrel) * shiftwidth() |
494 return state | 485 return state |
495 endif | 486 endif |
496 endif | 487 endif |
497 endif | 488 endif |
498 if stopline > stopline2 | 489 if stopline > stopline2 |
509 " check preceding tags in the line: | 500 " check preceding tags in the line: |
510 call s:CountITags(tolower(getline(comlnum)[: comcol-2])) | 501 call s:CountITags(tolower(getline(comlnum)[: comcol-2])) |
511 if found == 2 | 502 if found == 2 |
512 let state.baseindent = b:hi_indent.baseindent | 503 let state.baseindent = b:hi_indent.baseindent |
513 endif | 504 endif |
514 let state.blocktagind = indent(comlnum) + (s:curind + s:nextrel) * s:ShiftWidth() | 505 let state.blocktagind = indent(comlnum) + (s:curind + s:nextrel) * shiftwidth() |
515 return state | 506 return state |
516 endif | 507 endif |
517 | 508 |
518 " else within usual HTML | 509 " else within usual HTML |
519 let text = tolower(getline(state.lnum)) | 510 let text = tolower(getline(state.lnum)) |
528 let text = text[: comcol-2] | 519 let text = text[: comcol-2] |
529 else | 520 else |
530 let text = tolower(getline(comlnum)[: comcol-2]) | 521 let text = tolower(getline(comlnum)[: comcol-2]) |
531 endif | 522 endif |
532 call s:CountITags(text) | 523 call s:CountITags(text) |
533 let state.baseindent = indent(comlnum) + (s:curind + s:nextrel) * s:ShiftWidth() | 524 let state.baseindent = indent(comlnum) + (s:curind + s:nextrel) * shiftwidth() |
534 " TODO check tags that follow "-->" | 525 " TODO check tags that follow "-->" |
535 return state | 526 return state |
536 endif | 527 endif |
537 | 528 |
538 " Check if the previous line starts with end tag. | 529 " Check if the previous line starts with end tag. |
548 if col('.') > 2 | 539 if col('.') > 2 |
549 " check for tags before the matching opening tag. | 540 " check for tags before the matching opening tag. |
550 let text = getline(start_lnum) | 541 let text = getline(start_lnum) |
551 let swendtag = match(text, '^\s*</') >= 0 | 542 let swendtag = match(text, '^\s*</') >= 0 |
552 call s:CountITags(text[: col('.') - 2]) | 543 call s:CountITags(text[: col('.') - 2]) |
553 let state.baseindent += s:nextrel * s:ShiftWidth() | 544 let state.baseindent += s:nextrel * shiftwidth() |
554 if !swendtag | 545 if !swendtag |
555 let state.baseindent += s:curind * s:ShiftWidth() | 546 let state.baseindent += s:curind * shiftwidth() |
556 endif | 547 endif |
557 endif | 548 endif |
558 return state | 549 return state |
559 endif | 550 endif |
560 endif | 551 endif |
563 let [state.lnum, found] = HtmlIndent_FindTagStart(state.lnum) | 554 let [state.lnum, found] = HtmlIndent_FindTagStart(state.lnum) |
564 " Check if that line starts with end tag. | 555 " Check if that line starts with end tag. |
565 let text = getline(state.lnum) | 556 let text = getline(state.lnum) |
566 let swendtag = match(text, '^\s*</') >= 0 | 557 let swendtag = match(text, '^\s*</') >= 0 |
567 call s:CountITags(tolower(text)) | 558 call s:CountITags(tolower(text)) |
568 let state.baseindent = indent(state.lnum) + s:nextrel * s:ShiftWidth() | 559 let state.baseindent = indent(state.lnum) + s:nextrel * shiftwidth() |
569 if !swendtag | 560 if !swendtag |
570 let state.baseindent += s:curind * s:ShiftWidth() | 561 let state.baseindent += s:curind * shiftwidth() |
571 endif | 562 endif |
572 return state | 563 return state |
573 endfunc "}}} | 564 endfunc "}}} |
574 | 565 |
575 " Indent inside a <pre> block: Keep indent as-is. | 566 " Indent inside a <pre> block: Keep indent as-is. |
644 endtry | 635 endtry |
645 endif | 636 endif |
646 | 637 |
647 " add indent after { | 638 " add indent after { |
648 let brace_counts = HtmlIndent_CountBraces(prev_lnum) | 639 let brace_counts = HtmlIndent_CountBraces(prev_lnum) |
649 let extra = brace_counts.c_open * s:ShiftWidth() | 640 let extra = brace_counts.c_open * shiftwidth() |
650 | 641 |
651 let prev_text = getline(prev_lnum) | 642 let prev_text = getline(prev_lnum) |
652 let below_end_brace = prev_text =~ '}\s*$' | 643 let below_end_brace = prev_text =~ '}\s*$' |
653 | 644 |
654 " Search back to align with the first line that's unfinished. | 645 " Search back to align with the first line that's unfinished. |
661 let prev_special = prev_text =~ '^\s*\(/\*\|@\)' | 652 let prev_special = prev_text =~ '^\s*\(/\*\|@\)' |
662 if curtext =~ '^\s*\(/\*\|@\)' | 653 if curtext =~ '^\s*\(/\*\|@\)' |
663 " if the current line is not a comment or starts with @ (used by template | 654 " if the current line is not a comment or starts with @ (used by template |
664 " systems) reduce indent if previous line is a continuation line | 655 " systems) reduce indent if previous line is a continuation line |
665 if !prev_hasfield && !prev_special | 656 if !prev_hasfield && !prev_special |
666 let extra = -s:ShiftWidth() | 657 let extra = -shiftwidth() |
667 endif | 658 endif |
668 else | 659 else |
669 let cur_hasfield = curtext =~ '^\s*[a-zA-Z0-9-]\+:' | 660 let cur_hasfield = curtext =~ '^\s*[a-zA-Z0-9-]\+:' |
670 let prev_unfinished = s:CssUnfinished(prev_text) | 661 let prev_unfinished = s:CssUnfinished(prev_text) |
671 if !cur_hasfield && (prev_hasfield || prev_unfinished) | 662 if !cur_hasfield && (prev_hasfield || prev_unfinished) |
672 " Continuation line has extra indent if the previous line was not a | 663 " Continuation line has extra indent if the previous line was not a |
673 " continuation line. | 664 " continuation line. |
674 let extra = s:ShiftWidth() | 665 let extra = shiftwidth() |
675 " Align with @if | 666 " Align with @if |
676 if prev_text =~ '^\s*@if ' | 667 if prev_text =~ '^\s*@if ' |
677 let extra = 4 | 668 let extra = 4 |
678 endif | 669 endif |
679 elseif cur_hasfield && !prev_hasfield && !prev_special | 670 elseif cur_hasfield && !prev_hasfield && !prev_special |
680 " less indent below a continuation line | 671 " less indent below a continuation line |
681 let extra = -s:ShiftWidth() | 672 let extra = -shiftwidth() |
682 endif | 673 endif |
683 endif | 674 endif |
684 endif | 675 endif |
685 | 676 |
686 if below_end_brace | 677 if below_end_brace |
697 let special = 0 | 688 let special = 0 |
698 endtry | 689 endtry |
699 if special | 690 if special |
700 " do not reduce indent below @{ ... } | 691 " do not reduce indent below @{ ... } |
701 if extra < 0 | 692 if extra < 0 |
702 let extra += s:ShiftWidth() | 693 let extra += shiftwidth() |
703 endif | 694 endif |
704 else | 695 else |
705 let extra -= (brace_counts.c_close - (prev_text =~ '^\s*}')) * s:ShiftWidth() | 696 let extra -= (brace_counts.c_close - (prev_text =~ '^\s*}')) * shiftwidth() |
706 endif | 697 endif |
707 endif | 698 endif |
708 | 699 |
709 " if no extra indent yet... | 700 " if no extra indent yet... |
710 if extra == 0 | 701 if extra == 0 |
711 if brace_counts.p_open > brace_counts.p_close | 702 if brace_counts.p_open > brace_counts.p_close |
712 " previous line has more ( than ): add a shiftwidth | 703 " previous line has more ( than ): add a shiftwidth |
713 let extra = s:ShiftWidth() | 704 let extra = shiftwidth() |
714 elseif brace_counts.p_open < brace_counts.p_close | 705 elseif brace_counts.p_open < brace_counts.p_close |
715 " previous line has more ) than (: subtract a shiftwidth | 706 " previous line has more ) than (: subtract a shiftwidth |
716 let extra = -s:ShiftWidth() | 707 let extra = -shiftwidth() |
717 endif | 708 endif |
718 endif | 709 endif |
719 | 710 |
720 return indent(align_lnum) + extra | 711 return indent(align_lnum) + extra |
721 endfunc "}}} | 712 endfunc "}}} |
814 let prevlnum = prevnonblank(v:lnum - 1) | 805 let prevlnum = prevnonblank(v:lnum - 1) |
815 let prevtext = getline(prevlnum) | 806 let prevtext = getline(prevlnum) |
816 let idx = match(prevtext, '^\s*\zs<!--') | 807 let idx = match(prevtext, '^\s*\zs<!--') |
817 if idx >= 0 | 808 if idx >= 0 |
818 " just below comment start, add a shiftwidth | 809 " just below comment start, add a shiftwidth |
819 return idx + s:ShiftWidth() | 810 return idx + shiftwidth() |
820 endif | 811 endif |
821 | 812 |
822 " Some files add 4 spaces just below a TODO line. It's difficult to detect | 813 " Some files add 4 spaces just below a TODO line. It's difficult to detect |
823 " the end of the TODO, so let's not do that. | 814 " the end of the TODO, so let's not do that. |
824 | 815 |
835 let lnum = search('<!--', 'bn') | 826 let lnum = search('<!--', 'bn') |
836 if lnum > 0 | 827 if lnum > 0 |
837 return indent(lnum) | 828 return indent(lnum) |
838 endif | 829 endif |
839 endif | 830 endif |
840 return b:hi_indent.baseindent + s:ShiftWidth() | 831 return b:hi_indent.baseindent + shiftwidth() |
841 endfunc "}}} | 832 endfunc "}}} |
842 | 833 |
843 " When the "lnum" line ends in ">" find the line containing the matching "<". | 834 " When the "lnum" line ends in ">" find the line containing the matching "<". |
844 func! HtmlIndent_FindTagStart(lnum) | 835 func! HtmlIndent_FindTagStart(lnum) |
845 "{{{ | 836 "{{{ |
945 " First non-blank line has no indent. | 936 " First non-blank line has no indent. |
946 return 0 | 937 return 0 |
947 endif | 938 endif |
948 | 939 |
949 let curtext = tolower(getline(v:lnum)) | 940 let curtext = tolower(getline(v:lnum)) |
950 let indentunit = s:ShiftWidth() | 941 let indentunit = shiftwidth() |
951 | 942 |
952 let b:hi_newstate = {} | 943 let b:hi_newstate = {} |
953 let b:hi_newstate.lnum = v:lnum | 944 let b:hi_newstate.lnum = v:lnum |
954 | 945 |
955 " When syntax HL is enabled, detect we are inside a tag. Indenting inside | 946 " When syntax HL is enabled, detect we are inside a tag. Indenting inside |
1028 | 1019 |
1029 let indent = indent(start_lnum) | 1020 let indent = indent(start_lnum) |
1030 if col('.') > 2 | 1021 if col('.') > 2 |
1031 let swendtag = match(text, '^\s*</') >= 0 | 1022 let swendtag = match(text, '^\s*</') >= 0 |
1032 call s:CountITags(text[: col('.') - 2]) | 1023 call s:CountITags(text[: col('.') - 2]) |
1033 let indent += s:nextrel * s:ShiftWidth() | 1024 let indent += s:nextrel * shiftwidth() |
1034 if !swendtag | 1025 if !swendtag |
1035 let indent += s:curind * s:ShiftWidth() | 1026 let indent += s:curind * shiftwidth() |
1036 endif | 1027 endif |
1037 endif | 1028 endif |
1038 else | 1029 else |
1039 " not sure what to do | 1030 " not sure what to do |
1040 let indent = b:hi_indent.baseindent | 1031 let indent = b:hi_indent.baseindent |