annotate runtime/indent/fish.vim @ 34493:1fa23ccd6d9a v9.1.0153

patch 9.1.0153: Text properties corrupted with fo+=aw and backspace Commit: https://github.com/vim/vim/commit/7ac1145fbebb66dfee325dc5265309877d941c4e Author: zeertzjq <zeertzjq@outlook.com> Date: Wed Mar 6 20:54:22 2024 +0100 patch 9.1.0153: Text properties corrupted with fo+=aw and backspace Problem: Text properties corrupted with fo+=aw and backspace Solution: Allocate line and move text properties (zeertzjq) closes: #14147 Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Wed, 06 Mar 2024 21:00:11 +0100
parents 5c220cf30f1f
children
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
33052
5c220cf30f1f runtime: Set b:undo_indent where missing (#12944)
Christian Brabandt <cb@256bit.org>
parents: 32004
diff changeset
6 " 2023 Aug 28 by Vim Project (undo_indent)
32004
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 if exists("b:did_indent")
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9 finish
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 endif
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 let b:did_indent = 1
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 setlocal indentexpr=GetFishIndent(v:lnum)
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 setlocal indentkeys+==end,=else,=case
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15
33052
5c220cf30f1f runtime: Set b:undo_indent where missing (#12944)
Christian Brabandt <cb@256bit.org>
parents: 32004
diff changeset
16 let b:undo_indent = "setlocal indentexpr< indentkeys<"
5c220cf30f1f runtime: Set b:undo_indent where missing (#12944)
Christian Brabandt <cb@256bit.org>
parents: 32004
diff changeset
17
32004
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 function s:PrevCmdStart(linenum)
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 let l:linenum = a:linenum
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 " look for the first line that isn't a line continuation
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 while l:linenum > 1 && getline(l:linenum - 1) =~# '\\$'
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 let l:linenum = l:linenum - 1
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 endwhile
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 return l:linenum
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 endfunction
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 function GetFishIndent(lnum)
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 let l:shiftwidth = shiftwidth()
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 let l:prevlnum = prevnonblank(a:lnum - 1)
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 if l:prevlnum ==# 0
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 return 0
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 endif
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 " if the previous line ended with a line continuation
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 if getline(a:lnum - 1) =~# '\\$'
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 if a:lnum ==# 0 || getline(a:lnum - 2) !~# '\\$'
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 " this is the first line continuation in a chain, so indent it
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 return indent(a:lnum - 1) + l:shiftwidth
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 else
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 " use the same indentation as the previous continued line
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 return indent(a:lnum - 1)
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 endif
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 endif
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 let l:prevlnum = s:PrevCmdStart(l:prevlnum)
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 let l:prevline = getline(l:prevlnum)
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 if l:prevline =~# '^\s*\(begin\|if\|else\|while\|for\|function\|case\|switch\)\>'
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 let l:indent = l:shiftwidth
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 else
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 let l:indent = 0
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 endif
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 let l:line = getline(a:lnum)
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 if l:line =~# '^\s*end\>'
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 " find end's matching start
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 let l:depth = 1
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 let l:currentlnum = a:lnum
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 while l:depth > 0 && l:currentlnum > 0
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 let l:currentlnum = s:PrevCmdStart(prevnonblank(l:currentlnum - 1))
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 let l:currentline = getline(l:currentlnum)
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 if l:currentline =~# '^\s*end\>'
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 let l:depth = l:depth + 1
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 elseif l:currentline =~# '^\s*\(begin\|if\|while\|for\|function\|switch\)\>'
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 let l:depth = l:depth - 1
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 endif
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 endwhile
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 if l:currentline =~# '^\s*switch\>'
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 return indent(l:currentlnum)
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 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 endif
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 elseif l:line =~# '^\s*else\>'
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 return indent(l:prevlnum) + l:indent - l:shiftwidth
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 elseif l:line =~# '^\s*case\>'
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 if getline(l:prevlnum) =~# '^\s*switch\>'
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 return indent(l:prevlnum) + l:indent
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 - l:shiftwidth
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 else
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 return indent(l:prevlnum) + l:indent
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 endif
a9b5ffbc0428 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 endfunction