diff options
| author | Mehmet Samet Duman <yongdohyun@projecttick.org> | 2026-04-02 18:44:22 +0300 |
|---|---|---|
| committer | Mehmet Samet Duman <yongdohyun@projecttick.org> | 2026-04-02 18:44:22 +0300 |
| commit | 934382c8a1ce738589dee9ee0f14e1cec812770e (patch) | |
| tree | f13715762efd06518f8aec3a2bf39ac8a615987f /uvim/runtime/indent/make.vim | |
| parent | 0b24459ac12b6cf9fd5a401d647796ca254a8fa8 (diff) | |
| parent | 7088926316d8d4a7572a242d0765e99adfc8b083 (diff) | |
| download | Project-Tick-934382c8a1ce738589dee9ee0f14e1cec812770e.tar.gz Project-Tick-934382c8a1ce738589dee9ee0f14e1cec812770e.zip | |
Add 'uvim/' from commit '7088926316d8d4a7572a242d0765e99adfc8b083'
git-subtree-dir: uvim
git-subtree-mainline: 0b24459ac12b6cf9fd5a401d647796ca254a8fa8
git-subtree-split: 7088926316d8d4a7572a242d0765e99adfc8b083
Diffstat (limited to 'uvim/runtime/indent/make.vim')
| -rw-r--r-- | uvim/runtime/indent/make.vim | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/uvim/runtime/indent/make.vim b/uvim/runtime/indent/make.vim new file mode 100644 index 0000000000..aeea4de741 --- /dev/null +++ b/uvim/runtime/indent/make.vim @@ -0,0 +1,122 @@ +" Vim indent file +" Language: Makefile +" Maintainer: Doug Kearns <dougkearns@gmail.com> +" Previous Maintainer: Nikolai Weibull <now@bitwi.se> +" Last Change: 2022 Apr 06 +" 2025 Apr 22 by Vim Project: do not indent after special targets #17183 + +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +setlocal indentexpr=GetMakeIndent() +setlocal indentkeys=!^F,o,O,<:>,=else,=endif +setlocal nosmartindent + +let b:undo_indent = "setl inde< indk< si<" + +if exists("*GetMakeIndent") + finish +endif + +let s:comment_rx = '^\s*#' +let s:rule_rx = '^[^ \t#:][^#:]*:\{1,2}\%([^=:]\|$\)' +" .PHONY, .DELETE_ON_ERROR, etc +let s:rule_special = '^\.[A-Z_]\+\s*:' +let s:continued_rule_rx = '^[^#:]*:\{1,2}\%([^=:]\|$\)' +let s:continuation_rx = '\\$' +let s:assignment_rx = '^\s*\h\w*\s*[+:?]\==\s*\zs.*\\$' +let s:folded_assignment_rx = '^\s*\h\w*\s*[+:?]\==' +" TODO: This needs to be a lot more restrictive in what it matches. +let s:just_inserted_rule_rx = '^\s*[^#:]\+:\{1,2}$' +let s:conditional_directive_rx = '^ *\%(ifn\=\%(eq\|def\)\|else\)\>' +let s:end_conditional_directive_rx = '^\s*\%(else\|endif\)\>' + +function s:remove_continuation(line) + return substitute(a:line, s:continuation_rx, "", "") +endfunction + +function GetMakeIndent() + " TODO: Should this perhaps be v:lnum -1? +" let prev_lnum = prevnonblank(v:lnum - 1) + let prev_lnum = v:lnum - 1 + if prev_lnum == 0 + return 0 + endif + let prev_line = getline(prev_lnum) + + let prev_prev_lnum = prev_lnum - 1 + let prev_prev_line = prev_prev_lnum != 0 ? getline(prev_prev_lnum) : "" + + " TODO: Deal with comments. In comments, continuations aren't interesting. + if prev_line =~ s:continuation_rx + if prev_prev_line =~ s:continuation_rx + return indent(prev_lnum) + elseif prev_line =~ s:rule_rx && prev_line !~ s:rule_special + return shiftwidth() + elseif prev_line =~ s:assignment_rx + call cursor(prev_lnum, 1) + if search(s:assignment_rx, 'W') != 0 + return virtcol('.') - 1 + else + " TODO: ? + return shiftwidth() + endif + else + " TODO: OK, this might be a continued shell command, so perhaps indent + " properly here? Leave this out for now, but in the next release this + " should be using indent/sh.vim somehow. + "if prev_line =~ '^\t' " s:rule_command_rx + " if prev_line =~ '^\s\+[@-]\%(if\)\>' + " return indent(prev_lnum) + 2 + " endif + "endif + return indent(prev_lnum) + shiftwidth() + endif + elseif prev_prev_line =~ s:continuation_rx + let folded_line = s:remove_continuation(prev_prev_line) . ' ' . s:remove_continuation(prev_line) + let lnum = prev_prev_lnum - 1 + let line = getline(lnum) + while line =~ s:continuation_rx + let folded_line = s:remove_continuation(line) . ' ' . folded_line + let lnum -= 1 + let line = getline(lnum) + endwhile + let folded_lnum = lnum + 1 + if folded_line =~ s:rule_rx && prev_line !~ s:rule_special + if getline(v:lnum) =~ s:rule_rx && prev_line !~ s:rule_special + return 0 + else + return &ts + endif + else +" elseif folded_line =~ s:folded_assignment_rx + if getline(v:lnum) =~ s:rule_rx && prev_line !~ s:rule_special + return 0 + else + return indent(folded_lnum) + endif +" else +" " TODO: ? +" return indent(prev_lnum) + endif + elseif prev_line =~ s:rule_rx && prev_line !~ s:rule_special + if getline(v:lnum) =~ s:rule_rx && prev_line !~ s:rule_special + return 0 + else + return &ts + endif + elseif prev_line =~ s:conditional_directive_rx + return shiftwidth() + else + let line = getline(v:lnum) + if line =~ s:just_inserted_rule_rx + return 0 + elseif line =~ s:end_conditional_directive_rx + return v:lnum - 1 == 0 ? 0 : indent(v:lnum - 1) - shiftwidth() + else + return v:lnum - 1 == 0 ? 0 : indent(v:lnum - 1) + endif + endif +endfunction |
