patch 9.1.0354: runtime(uci): No support for uci file types

Commit: 
https://github.com/vim/vim/commit/4b3fab14dbde971f15d8783e9ef125b19fdbc829
Author: Colin Caine <complai...@cmcaine.co.uk>
Date:   Thu Apr 18 23:53:02 2024 +0200

    patch 9.1.0354: runtime(uci): No support for uci file types
    
    Problem:  runtime(uci): No support for uci file types
              (Wu, Zhenyu)
    Solution: include basic uci ftplugin and syntax plugins
              (Colin Caine)
    
    closes: #14575
    
    Co-authored-by: Wu, Zhenyu <wuzhe...@ustc.edu>
    Signed-off-by: Colin Caine <complai...@cmcaine.co.uk>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/runtime/autoload/dist/ft.vim b/runtime/autoload/dist/ft.vim
index 05f1611b2..4e7d51793 100644
--- a/runtime/autoload/dist/ft.vim
+++ b/runtime/autoload/dist/ft.vim
@@ -1298,5 +1298,21 @@ export def FTvba()
   endif
 enddef
 
+export def Detect_UCI_statements(): bool
+  # Match a config or package statement at the start of the line.
+  const config_or_package_statement = 
'^\s*\(\(c\|config\)\|\(p\|package\)\)\s\+\S'
+  # Match a line that is either all blank or blank followed by a comment
+  const comment_or_blank = '^\s*\(#.*\)\?$'
+
+  # Return true iff the file has a config or package statement near the
+  # top of the file and all preceding lines were comments or blank.
+  return getline(1) =~# config_or_package_statement
+  \   || getline(1) =~# comment_or_blank
+  \      && (   getline(2) =~# config_or_package_statement
+  \          || getline(2) =~# comment_or_blank
+  \             && getline(3) =~# config_or_package_statement
+  \         )
+enddef
+
 # Uncomment this line to check for compilation errors early
 # defcompile
diff --git a/runtime/filetype.vim b/runtime/filetype.vim
index 4a877f7f8..c7fc33196 100644
--- a/runtime/filetype.vim
+++ b/runtime/filetype.vim
@@ -3030,6 +3030,12 @@ au BufNewFile,BufRead {.,}tmux*.conf*            setf 
tmux
 " Universal Scene Description
 au BufNewFile,BufRead *.usda,*.usd             setf usd
 
+" UCI
+" UCI files are normally in /etc/config, but that might be mounted over sshfs 
or similar, so we match more loosely.
+" There was some concern[1] that this pattern would match too much, so now we 
check the file content as well.
+" [1]: https://github.com/vim/vim/pull/14385#discussion_r1558878741
+au BufNewFile,BufRead */etc/config/*           if 
dist#ft#Detect_UCI_statements() | call s:StarSetf('uci') | endif
+
 " VHDL
 au BufNewFile,BufRead *.vhdl_[0-9]*            call s:StarSetf('vhdl')
 
diff --git a/runtime/ftplugin/uci.vim b/runtime/ftplugin/uci.vim
new file mode 100644
index 000000000..984dab6c5
--- /dev/null
+++ b/runtime/ftplugin/uci.vim
@@ -0,0 +1,21 @@
+" Vim ftplugin file
+" Language:    OpenWrt Unified Configuration Interface
+" Maintainer:  Colin Caine <complai...@cmcaine.co.uk>
+" Upstream:    https://github.com/cmcaine/vim-uci
+" Last Change: 2024 Apr 17
+"
+" For more information on uci, see 
https://openwrt.org/docs/guide-user/base-system/uci
+
+if exists("b:did_ftplugin")
+  finish
+endif
+let b:did_ftplugin = 1
+
+" UCI files are indented with tabs.
+setl noexpandtab
+setl shiftwidth=0
+setl softtabstop=0
+
+setl commentstring=#\ %s
+
+let b:undo_ftplugin = "setlocal et< cms< sts< sw<"
diff --git a/runtime/syntax/uci.vim b/runtime/syntax/uci.vim
new file mode 100644
index 000000000..fdf5bfd9b
--- /dev/null
+++ b/runtime/syntax/uci.vim
@@ -0,0 +1,33 @@
+" Vim syntax file
+" Language:    OpenWrt Unified Configuration Interface
+" Maintainer:  Colin Caine <complai...@cmcaine.co.uk>
+" Upstream:    https://github.com/cmcaine/vim-uci
+" Last Change: 2021 Sep 19
+"
+" For more information on uci, see 
https://openwrt.org/docs/guide-user/base-system/uci
+
+if exists("b:current_syntax")
+    finish
+endif
+
+" Fancy zero-width non-capturing look-behind to see what the last word was.
+" Would be really nice if there was some less obscure or more efficient way to
+" do this.
+syntax match uciOptionName '\%(\%(option\|list\)\s\+\)\@<=\S*'
+syntax match uciConfigName '\%(\%(package\|config\)\s\+\)\@<=\S*'
+syntax keyword uciConfigDec package config nextgroup=uciConfigName skipwhite
+syntax keyword uciOptionType option list nextgroup=uciOptionName skipwhite
+
+" Standard matches.
+syntax match uciComment "#.*$"
+syntax region uciString start=+"+ end=+"+ skip=+\"+
+syntax region uciString start=+'+ end=+'+ skip=+\'+
+
+highlight default link uciConfigName Identifier
+highlight default link uciOptionName Constant
+highlight default link uciConfigDec Statement
+highlight default link uciOptionType Type
+highlight default link uciComment Comment
+highlight default link uciString Normal
+
+let b:current_syntax = "uci"
diff --git a/src/testdir/test_filetype.vim b/src/testdir/test_filetype.vim
index e2098667e..02a6e2d1c 100644
--- a/src/testdir/test_filetype.vim
+++ b/src/testdir/test_filetype.vim
@@ -2441,4 +2441,26 @@ func Test_def_file()
   filetype off
 endfunc
 
+func Test_uci_file()
+  filetype on
+
+  call mkdir('any/etc/config', 'pR')
+  call writefile(['config firewall'], 'any/etc/config/firewall', 'D')
+  split any/etc/config/firewall
+  call assert_equal('uci', &filetype)
+  bwipe!
+
+  call writefile(['# config for nginx here'], 'any/etc/config/firewall', 'D')
+  split any/etc/config/firewall
+  call assert_notequal('uci', &filetype)
+  bwipe!
+
+  call writefile(['# Copyright Cool Cats 1997', 'config firewall'], 
'any/etc/config/firewall', 'D')
+  split any/etc/config/firewall
+  call assert_equal('uci', &filetype)
+  bwipe!
+
+  filetype off
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index 7458026de..23d2c803d 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    354,
 /**/
     353,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1rxZnX-0012U2-AO%40256bit.org.

Raspunde prin e-mail lui