annotate runtime/indent/nginx.vim @ 31653:ec76f9d2319e v9.0.1159

patch 9.0.1159: extends argument for class not implemented yet Commit: https://github.com/vim/vim/commit/8367716a6e9589d61a771e6c329da05c9b55e61a Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 8 19:54:10 2023 +0000 patch 9.0.1159: extends argument for class not implemented yet Problem: Extends argument for class not implemented yet. Solution: Basic implementation of "extends".
author Bram Moolenaar <Bram@vim.org>
date Sun, 08 Jan 2023 21:00:05 +0100
parents 7d68a90cbf5c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25880
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 " Vim indent file
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 " Language: nginx.conf
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 " Maintainer: Chris Aumann <me@chr4.org>
31579
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
4 " Last Change: 2022 Dec 01
25880
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5
31579
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
6 " Only load this indent file when no other was loaded.
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
7 if exists('b:did_indent')
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
8 finish
25880
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9 endif
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 let b:did_indent = 1
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11
31579
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
12 setlocal indentexpr=GetNginxIndent()
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
13
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
14 setlocal indentkeys=0{,0},0#,!^F,o,O
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
15
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
16 let b:undo_indent = 'setl inde< indk<'
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
17
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
18 " Only define the function once.
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
19 if exists('*GetNginxIndent')
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
20 finish
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
21 endif
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
22
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
23 function GetNginxIndent() abort
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
24 let plnum = s:PrevNotAsBlank(v:lnum - 1)
25880
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25
31579
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
26 " Hit the start of the file, use zero indent.
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
27 if plnum == 0
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
28 return 0
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
29 endif
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
30
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
31 let ind = indent(plnum)
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
32
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
33 " Add a 'shiftwidth' after '{'
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
34 if s:AsEndWith(getline(plnum), '{')
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
35 let ind = ind + shiftwidth()
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
36 end
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
37
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
38 " Subtract a 'shiftwidth' on '}'
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
39 " This is the part that requires 'indentkeys'.
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
40 if getline(v:lnum) =~ '^\s*}'
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
41 let ind = ind - shiftwidth()
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
42 endif
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
43
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
44 let pplnum = s:PrevNotAsBlank(plnum - 1)
25880
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45
31579
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
46 if s:IsLineContinuation(plnum)
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
47 if !s:IsLineContinuation(pplnum)
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
48 let ind = ind + shiftwidth()
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
49 end
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
50 else
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
51 if s:IsLineContinuation(pplnum)
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
52 let ind = ind - shiftwidth()
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
53 end
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
54 endif
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
55
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
56 return ind
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
57 endfunction
28379
6dd88e45d47d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25880
diff changeset
58
31579
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
59 " Find the first line at or above {lnum} that is non-blank and not a comment.
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
60 function s:PrevNotAsBlank(lnum) abort
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
61 let lnum = prevnonblank(a:lnum)
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
62 while lnum > 0
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
63 if getline(lnum) !~ '^\s*#'
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
64 break
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
65 endif
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
66 let lnum = prevnonblank(lnum - 1)
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
67 endwhile
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
68 return lnum
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
69 endfunction
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
70
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
71 " Check whether {line} ends with {pat}, ignoring trailing comments.
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
72 function s:AsEndWith(line, pat) abort
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
73 return a:line =~ a:pat . '\m\s*\%(#.*\)\?$'
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
74 endfunction
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
75
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
76 function s:IsLineContinuation(lnum) abort
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
77 return a:lnum > 0 && !s:AsEndWith(getline(a:lnum), '[;{}]')
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 28379
diff changeset
78 endfunction