annotate runtime/autoload/rustfmt.vim @ 34273:f4ae2a159bde v9.1.0075

patch 9.1.0075: insert completion not correct when adding new leader Commit: https://github.com/vim/vim/commit/cbb46b439888e10f87baaca504eafd191723c44b Author: glepnir <glephunter@gmail.com> Date: Sat Feb 3 18:11:13 2024 +0100 patch 9.1.0075: insert completion not correct when adding new leader Problem: insert completion not correct when adding new leader Solution: Reset compl_curr_match to compl_shown_match (glepnir) closes: #13957 Co-authored-by: glepnir <glephunter@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Sat, 03 Feb 2024 18:30:03 +0100
parents d6dde6229b36
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Author: Stephen Sugden <stephen@stephensugden.com>
33255
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
2 " Last Modified: 2023-09-11
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 "
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 " Adapted from https://github.com/fatih/vim-go
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 " For bugs, patches and license go to https://github.com/rust-lang/rust.vim
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 if !exists("g:rustfmt_autosave")
33255
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
8 let g:rustfmt_autosave = 0
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 endif
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 if !exists("g:rustfmt_command")
33255
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
12 let g:rustfmt_command = "rustfmt"
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 endif
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 if !exists("g:rustfmt_options")
33255
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
16 let g:rustfmt_options = ""
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 endif
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 if !exists("g:rustfmt_fail_silently")
33255
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
20 let g:rustfmt_fail_silently = 0
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
21 endif
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
22
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
23 function! rustfmt#DetectVersion()
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
24 " Save rustfmt '--help' for feature inspection
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
25 silent let s:rustfmt_help = system(g:rustfmt_command . " --help")
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
26 let s:rustfmt_unstable_features = s:rustfmt_help =~# "--unstable-features"
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
27
33577
d6dde6229b36 runtime: Fix more typos (#13354)
Christian Brabandt <cb@256bit.org>
parents: 33255
diff changeset
28 " Build a comparable rustfmt version variable out of its `--version` output:
33255
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
29 silent let l:rustfmt_version_full = system(g:rustfmt_command . " --version")
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
30 let l:rustfmt_version_list = matchlist(l:rustfmt_version_full,
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
31 \ '\vrustfmt ([0-9]+[.][0-9]+[.][0-9]+)')
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
32 if len(l:rustfmt_version_list) < 3
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
33 let s:rustfmt_version = "0"
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
34 else
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
35 let s:rustfmt_version = l:rustfmt_version_list[1]
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
36 endif
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
37 return s:rustfmt_version
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
38 endfunction
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
39
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
40 call rustfmt#DetectVersion()
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
41
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
42 if !exists("g:rustfmt_emit_files")
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
43 let g:rustfmt_emit_files = s:rustfmt_version >= "0.8.2"
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
44 endif
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
45
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
46 if !exists("g:rustfmt_file_lines")
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
47 let g:rustfmt_file_lines = s:rustfmt_help =~# "--file-lines JSON"
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 endif
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 let s:got_fmt_error = 0
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51
33255
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
52 function! rustfmt#Load()
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
53 " Utility call to get this script loaded, for debugging
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
54 endfunction
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
55
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
56 function! s:RustfmtWriteMode()
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
57 if g:rustfmt_emit_files
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
58 return "--emit=files"
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
59 else
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
60 return "--write-mode=overwrite"
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
61 endif
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
62 endfunction
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
63
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
64 function! s:RustfmtConfigOptions()
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
65 let l:rustfmt_toml = findfile('rustfmt.toml', expand('%:p:h') . ';')
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
66 if l:rustfmt_toml !=# ''
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
67 return '--config-path '.shellescape(fnamemodify(l:rustfmt_toml, ":p"))
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
68 endif
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
69
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
70 let l:_rustfmt_toml = findfile('.rustfmt.toml', expand('%:p:h') . ';')
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
71 if l:_rustfmt_toml !=# ''
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
72 return '--config-path '.shellescape(fnamemodify(l:_rustfmt_toml, ":p"))
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
73 endif
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
74
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
75 " Default to edition 2018 in case no rustfmt.toml was found.
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
76 return '--edition 2018'
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
77 endfunction
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78
33255
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
79 function! s:RustfmtCommandRange(filename, line1, line2)
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
80 if g:rustfmt_file_lines == 0
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
81 echo "--file-lines is not supported in the installed `rustfmt` executable"
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
82 return
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
83 endif
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
84
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
85 let l:arg = {"file": shellescape(a:filename), "range": [a:line1, a:line2]}
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
86 let l:write_mode = s:RustfmtWriteMode()
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
87 let l:rustfmt_config = s:RustfmtConfigOptions()
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
88
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
89 " FIXME: When --file-lines gets to be stable, add version range checking
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
90 " accordingly.
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
91 let l:unstable_features = s:rustfmt_unstable_features ? '--unstable-features' : ''
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
92
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
93 let l:cmd = printf("%s %s %s %s %s --file-lines '[%s]' %s", g:rustfmt_command,
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
94 \ l:write_mode, g:rustfmt_options,
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
95 \ l:unstable_features, l:rustfmt_config,
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
96 \ json_encode(l:arg), shellescape(a:filename))
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
97 return l:cmd
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
98 endfunction
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
99
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
100 function! s:RustfmtCommand()
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
101 let write_mode = g:rustfmt_emit_files ? '--emit=stdout' : '--write-mode=display'
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
102 let config = s:RustfmtConfigOptions()
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
103 return join([g:rustfmt_command, write_mode, config, g:rustfmt_options])
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
104 endfunction
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
105
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
106 function! s:DeleteLines(start, end) abort
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
107 silent! execute a:start . ',' . a:end . 'delete _'
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
108 endfunction
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
109
33255
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
110 function! s:RunRustfmt(command, tmpname, from_writepre)
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
111 let l:view = winsaveview()
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
112
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
113 let l:stderr_tmpname = tempname()
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
114 call writefile([], l:stderr_tmpname)
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
115
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
116 let l:command = a:command . ' 2> ' . l:stderr_tmpname
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
117
33255
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
118 if a:tmpname ==# ''
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
119 " Rustfmt in stdin/stdout mode
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
120
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
121 " chdir to the directory of the file
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
122 let l:has_lcd = haslocaldir()
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
123 let l:prev_cd = getcwd()
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
124 execute 'lchdir! '.expand('%:h')
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
125
33255
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
126 let l:buffer = getline(1, '$')
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
127 if exists("*systemlist")
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
128 silent let out = systemlist(l:command, l:buffer)
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
129 else
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
130 silent let out = split(system(l:command,
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
131 \ join(l:buffer, "\n")), '\r\?\n')
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
132 endif
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
133 else
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
134 if exists("*systemlist")
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
135 silent let out = systemlist(l:command)
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
136 else
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
137 silent let out = split(system(l:command), '\r\?\n')
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
138 endif
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
139 endif
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
140
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
141 let l:stderr = readfile(l:stderr_tmpname)
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
142
33255
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
143 call delete(l:stderr_tmpname)
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
144
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
145 let l:open_lwindow = 0
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
146 if v:shell_error == 0
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
147 if a:from_writepre
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
148 " remove undo point caused via BufWritePre
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
149 try | silent undojoin | catch | endtry
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
150 endif
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
151
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
152 if a:tmpname ==# ''
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
153 let l:content = l:out
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
154 else
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
155 " take the tmpfile's content, this is better than rename
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
156 " because it preserves file modes.
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
157 let l:content = readfile(a:tmpname)
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
158 endif
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
159
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
160 call s:DeleteLines(len(l:content), line('$'))
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
161 call setline(1, l:content)
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
162
33255
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
163 " only clear location list if it was previously filled to prevent
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
164 " clobbering other additions
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
165 if s:got_fmt_error
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
166 let s:got_fmt_error = 0
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
167 call setloclist(0, [])
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
168 let l:open_lwindow = 1
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
169 endif
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
170 elseif g:rustfmt_fail_silently == 0 && !a:from_writepre
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
171 " otherwise get the errors and put them in the location list
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
172 let l:errors = []
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
173
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
174 let l:prev_line = ""
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
175 for l:line in l:stderr
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
176 " error: expected one of `;` or `as`, found `extern`
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
177 " --> src/main.rs:2:1
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
178 let tokens = matchlist(l:line, '^\s\+-->\s\(.\{-}\):\(\d\+\):\(\d\+\)$')
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
179 if !empty(tokens)
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
180 call add(l:errors, {"filename": @%,
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
181 \"lnum": tokens[2],
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
182 \"col": tokens[3],
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
183 \"text": l:prev_line})
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
184 endif
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
185 let l:prev_line = l:line
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
186 endfor
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
187
33255
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
188 if !empty(l:errors)
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
189 call setloclist(0, l:errors, 'r')
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
190 echohl Error | echomsg "rustfmt returned error" | echohl None
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
191 else
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
192 echo "rust.vim: was not able to parse rustfmt messages. Here is the raw output:"
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
193 echo "\n"
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
194 for l:line in l:stderr
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
195 echo l:line
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
196 endfor
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
197 endif
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
198
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
199 let s:got_fmt_error = 1
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
200 let l:open_lwindow = 1
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
201 endif
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
202
33255
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
203 " Restore the current directory if needed
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
204 if a:tmpname ==# ''
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
205 if l:has_lcd
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
206 execute 'lchdir! '.l:prev_cd
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
207 else
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
208 execute 'chdir! '.l:prev_cd
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
209 endif
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
210 endif
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
211
33255
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
212 " Open lwindow after we have changed back to the previous directory
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
213 if l:open_lwindow == 1
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
214 lwindow
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
215 endif
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
216
33255
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
217 call winrestview(l:view)
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
218 endfunction
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
219
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
220 function! rustfmt#FormatRange(line1, line2)
33255
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
221 let l:tmpname = tempname()
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
222 call writefile(getline(1, '$'), l:tmpname)
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
223 let command = s:RustfmtCommandRange(l:tmpname, a:line1, a:line2)
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
224 call s:RunRustfmt(command, l:tmpname, v:false)
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
225 call delete(l:tmpname)
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
226 endfunction
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
227
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
228 function! rustfmt#Format()
33255
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
229 call s:RunRustfmt(s:RustfmtCommand(), '', v:false)
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
230 endfunction
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
231
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
232 function! rustfmt#Cmd()
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
233 " Mainly for debugging
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
234 return s:RustfmtCommand()
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
235 endfunction
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
236
33255
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
237 function! rustfmt#PreWrite()
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
238 if !filereadable(expand("%@"))
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
239 return
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
240 endif
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
241 if rust#GetConfigVar('rustfmt_autosave_if_config_present', 0)
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
242 if findfile('rustfmt.toml', '.;') !=# '' || findfile('.rustfmt.toml', '.;') !=# ''
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
243 let b:rustfmt_autosave = 1
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
244 let b:_rustfmt_autosave_because_of_config = 1
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
245 endif
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
246 else
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
247 if has_key(b:, '_rustfmt_autosave_because_of_config')
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
248 unlet b:_rustfmt_autosave_because_of_config
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
249 unlet b:rustfmt_autosave
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
250 endif
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
251 endif
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
252
33255
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
253 if !rust#GetConfigVar("rustfmt_autosave", 0)
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
254 return
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
255 endif
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
256
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
257 call s:RunRustfmt(s:RustfmtCommand(), '', v:true)
11229
146a1e213b60 Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
258 endfunction
33255
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
259
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
260
555fede66c30 runtime(rust): sync rust runtime files with upstream (#13075)
Christian Brabandt <cb@256bit.org>
parents: 11229
diff changeset
261 " vim: set et sw=4 sts=4 ts=8: