Skip to content

Commit a68fdf1

Browse files
committed
Fix syntax extensions being lost on syntax reload
Reapplying syntax settings with for example "syntax on" results in loss of linux kernel extensions because they are applied only on loading the file. Fix this by splitting syntax configuration into a separate function, modifying LinuxConfigure() to allow performing selective configuration, and creating after/syntax/c.vim snippet to load syntax extensions as part of regular syntax handling. Autocmd will only apply non-syntax settings, such as adjusting text width and prohibiting tab expansion. Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 35962fd commit a68fdf1

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

after/syntax/c.vim

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
" Extend C syntax settings with Linux Kernel-specific extensions.
2+
3+
call g:LinuxConfigure("syntax_only")

plugin/linuxsty.vim

+21-16
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ set wildignore+=*.ko,*.mod.c,*.order,modules.builtin
3939
augroup linuxsty
4040
autocmd!
4141

42-
autocmd FileType c,cpp call s:LinuxConfigure()
42+
autocmd FileType c,cpp call g:LinuxConfigure("settings_only")
4343
autocmd FileType diff setlocal ts=8
4444
autocmd FileType rst setlocal ts=8 sw=8 sts=8 noet
4545
autocmd FileType kconfig setlocal ts=8 sw=8 sts=8 noet
4646
autocmd FileType dts setlocal ts=8 sw=8 sts=8 noet
4747
autocmd FileType make setlocal ts=8 sw=8 sts=8 noet
4848
augroup END
4949

50-
function s:LinuxConfigure()
50+
function g:LinuxConfigure(what)
5151
let apply_style = 0
5252

5353
if exists("g:linuxsty_patterns")
@@ -63,17 +63,22 @@ function s:LinuxConfigure()
6363
endif
6464

6565
if apply_style
66-
call s:LinuxCodingStyle()
66+
call s:LinuxCodingStyle(a:what)
6767
endif
6868
endfunction
6969

70-
command! LinuxCodingStyle call s:LinuxCodingStyle()
70+
command! LinuxCodingStyle call s:LinuxCodingStyle("all")
7171

72-
function! s:LinuxCodingStyle()
73-
call s:LinuxFormatting()
74-
call s:LinuxKeywords()
75-
call s:LinuxHighlighting()
76-
call s:LinuxSavePath()
72+
function! s:LinuxCodingStyle(what)
73+
if a:what != "settings_only"
74+
call s:LinuxSyntax()
75+
endif
76+
77+
if a:what != "syntax_only"
78+
call s:LinuxFormatting()
79+
call s:LinuxHighlighting()
80+
call s:LinuxSavePath()
81+
endif
7782
endfunction
7883

7984
function s:LinuxFormatting()
@@ -87,7 +92,7 @@ function s:LinuxFormatting()
8792
setlocal cinoptions=:0,l1,t0,g0,(0
8893
endfunction
8994

90-
function s:LinuxKeywords()
95+
function s:LinuxSyntax()
9196
syn keyword cStatement fallthrough return_ptr
9297
syn keyword cStorageClass noinline __always_inline __must_check
9398
syn keyword cStorageClass __pure __weak __noclone
@@ -98,11 +103,6 @@ function s:LinuxKeywords()
98103
syn keyword cType __u8 __u16 __u32 __u64 __s8 __s16 __s32 __s64
99104
syn keyword cType __le16 __le32 __le64 __be16 __be32 __be64
100105
syn keyword LinuxGuard guard scoped_guard scoped_cond_guard
101-
endfunction
102-
103-
function s:LinuxHighlighting()
104-
highlight default link LinuxError ErrorMsg
105-
highlight default link LinuxGuard cConditional
106106

107107
syn match LinuxError / \+\ze\t/ " spaces before tab
108108
syn match LinuxError /\%>100v[^()\{\}\[\]<>]\+/ " virtual column 101 and more
@@ -114,6 +114,11 @@ function s:LinuxHighlighting()
114114
" highlight various for_each() variants
115115
syn match cRepeat /\v^\s*\zs((h)?list_|device_)?for_each(_\w+)?(\()@=/
116116

117+
highlight default link LinuxError ErrorMsg
118+
highlight default link LinuxGuard cConditional
119+
endfunction
120+
121+
function s:LinuxHighlighting()
117122
" Highlight trailing whitespace, unless we're in insert mode and the
118123
" cursor's placed right after the whitespace. This prevents us from having
119124
" to put up with whitespace being highlighted in the middle of typing
@@ -151,7 +156,7 @@ endfunction
151156

152157
if g:linuxsty_save_path
153158
if s:PathExistInCacheFile(s:path_cache_file, s:path)
154-
call s:LinuxCodingStyle()
159+
call s:LinuxCodingStyle("all")
155160
endif
156161
endif
157162

0 commit comments

Comments
 (0)