annotate runtime/indent/fish.vim @ 32029:23e8d0371e35 v9.0.1346

patch 9.0.1346: Starlark files are not recognized Commit: https://github.com/vim/vim/commit/ca06b30073de22dc120b532e90fbee2a10ef9772 Author: Amaan Qureshi <amaanq12@gmail.com> Date: Thu Feb 23 15:38:49 2023 +0000 patch 9.0.1346: Starlark files are not recognized Problem: Starlark files are not recognized. Solution: Add patterns for Starlark files. (Amaan Qureshi, closes https://github.com/vim/vim/issues/12049)
author Bram Moolenaar <Bram@vim.org>
date Thu, 23 Feb 2023 16:45:03 +0100
parents a9b5ffbc0428
children 5c220cf30f1f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32004
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 " Vim indent file
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 " Language: fish
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 " Maintainer: Nicholas Boyle (github.com/nickeb96)
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 " Repository: https://github.com/nickeb96/fish.vim
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 " Last Change: February 4, 2023
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 if exists("b:did_indent")
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 finish
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9 endif
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 let b:did_indent = 1
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 setlocal indentexpr=GetFishIndent(v:lnum)
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 setlocal indentkeys+==end,=else,=case
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 function s:PrevCmdStart(linenum)
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 let l:linenum = a:linenum
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 " look for the first line that isn't a line continuation
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 while l:linenum > 1 && getline(l:linenum - 1) =~# '\\$'
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 let l:linenum = l:linenum - 1
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 endwhile
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 return l:linenum
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 endfunction
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 function GetFishIndent(lnum)
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 let l:shiftwidth = shiftwidth()
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 let l:prevlnum = prevnonblank(a:lnum - 1)
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 if l:prevlnum ==# 0
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 return 0
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 endif
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 " if the previous line ended with a line continuation
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 if getline(a:lnum - 1) =~# '\\$'
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 if a:lnum ==# 0 || getline(a:lnum - 2) !~# '\\$'
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 " this is the first line continuation in a chain, so indent it
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 return indent(a:lnum - 1) + l:shiftwidth
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 else
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 " use the same indentation as the previous continued line
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 return indent(a:lnum - 1)
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 endif
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 endif
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 let l:prevlnum = s:PrevCmdStart(l:prevlnum)
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 let l:prevline = getline(l:prevlnum)
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 if l:prevline =~# '^\s*\(begin\|if\|else\|while\|for\|function\|case\|switch\)\>'
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 let l:indent = l:shiftwidth
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 else
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 let l:indent = 0
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 endif
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 let l:line = getline(a:lnum)
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 if l:line =~# '^\s*end\>'
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 " find end's matching start
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 let l:depth = 1
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 let l:currentlnum = a:lnum
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 while l:depth > 0 && l:currentlnum > 0
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 let l:currentlnum = s:PrevCmdStart(prevnonblank(l:currentlnum - 1))
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 let l:currentline = getline(l:currentlnum)
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 if l:currentline =~# '^\s*end\>'
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 let l:depth = l:depth + 1
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 elseif l:currentline =~# '^\s*\(begin\|if\|while\|for\|function\|switch\)\>'
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 let l:depth = l:depth - 1
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 endif
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 endwhile
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 if l:currentline =~# '^\s*switch\>'
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 return indent(l:currentlnum)
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 else
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 return indent(l:prevlnum) + l:indent - l:shiftwidth
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 endif
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 elseif l:line =~# '^\s*else\>'
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 return indent(l:prevlnum) + l:indent - l:shiftwidth
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 elseif l:line =~# '^\s*case\>'
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 if getline(l:prevlnum) =~# '^\s*switch\>'
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 return indent(l:prevlnum) + l:indent
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 else
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 return indent(l:prevlnum) + l:indent - l:shiftwidth
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 endif
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 else
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 return indent(l:prevlnum) + l:indent
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 endif
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 endfunction