summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcos <cos>2023-11-02 14:19:13 +0100
committercos <cos>2023-11-10 09:50:35 +0100
commit0900e3fc09c33ec5c15a42f3bffd886046be717b (patch)
treef0140f31f732c0b0869eb7efcda695e3c6cfa004
parent24d96791c318c39b4c6d7c6bdf5b66059541a4da (diff)
downloadvim-preseed-main.zip
Add support for embedded sh commandsHEADmain
-rw-r--r--doc/preseed.txt14
-rw-r--r--doc/tags1
-rw-r--r--syntax/preseed.vim69
3 files changed, 61 insertions, 23 deletions
diff --git a/doc/preseed.txt b/doc/preseed.txt
index 5603423..71903f2 100644
--- a/doc/preseed.txt
+++ b/doc/preseed.txt
@@ -6,5 +6,15 @@ some of its derivatives. As the preseed files typically either have "txt" or
simply no file extension, filetype detection relies on their first line being
`#_preseed_V1`.
- *preseed-settings*
-This plugin doesn't have any settings.
+ *preseed_add_sh_pattern* *preseed-settings*
+
+Any custom questions can be set to have their arguments set as shell, just like
+for `preseed/include_command` and friends, by setting 'preseed_add_sh_pattern'.
+
+e.g.:
+
+ let g:preseed_add_sh_pattern = '\(site_pkg/some_question\|my_pkg/a_question\)
+
+Needing to set the pattern for any widely available package is to be considered
+a bug. Please report if required to override the pattern to match a question
+expecting a shell command argument for any package included in debian.
diff --git a/doc/tags b/doc/tags
index 8233d62..8207347 100644
--- a/doc/tags
+++ b/doc/tags
@@ -1,3 +1,4 @@
ft-preseed-syntax preseed.txt /*ft-preseed-syntax*
preseed-settings preseed.txt /*preseed-settings*
preseed.txt preseed.txt /*preseed.txt*
+preseed_add_sh_pattern preseed.txt /*preseed_add_sh_pattern*
diff --git a/syntax/preseed.vim b/syntax/preseed.vim
index 4690280..5b41c74 100644
--- a/syntax/preseed.vim
+++ b/syntax/preseed.vim
@@ -1,7 +1,7 @@
" Vim syntax file
" Language: Debian preseed
" Maintainer: cos <cos>, https://www.netizen.se/#contact
-" Last Change: 2023 Nov 2
+" Last Change: 2023 Nov 10
" Remark: https://wiki.debian.org/DebianInstaller/Preseed
" quit when a syntax file was already loaded
@@ -9,6 +9,17 @@ if exists('b:current_syntax')
finish
endif
+" Allow user defined questions to have their shell script argument highlighted
+" as sh. Please see ':help preseed_add_sh_pattern' for an example.
+let s:shell_question_pattern = '\(preseed/\(early_command\|include_command\|late_command\)\|partman/early_command\)'
+let shell_pattern_start='^\s*[[:alnum:]._-]\+\s\+'
+if exists('preseed_add_sh_pattern')
+ let shell_pattern_start ..= '\(' . s:shell_question_pattern . '\|' . preseed_add_sh_pattern . '\) string'
+else
+ let shell_pattern_start ..= s:shell_question_pattern . ' string'
+endif
+let shell_pattern_end='\([^\\]$\|^$\)'
+
" The syntax of each line in a preseed file follows:
" <owner> <question name> <question type> <value>
" Lets sloppily refer to them as columns.
@@ -34,38 +45,47 @@ endif
syntax cluster preseedSecond contains=preseedQuestion,preseedOwnerLC
syntax cluster preseedThird contains=preseedBooleanType,preseedStrLikeType,preseedMultiSelType,preseedNote,preseedSelectType,preseedQuestionLC
+" Highlight shell syntax for include_command and friends. This is not fully
+" correct for multi-line arguments, as line continuations are flattened prior
+" to the argument being given to the shell as one single line. Reusing sh.vim
+" gets close enough to be useful though. Any patches with improvements are
+" welcome.
+syntax include @Sh syntax/sh.vim
" Define the highlighting. Doesn't map perfectly to the group's intents, but
" arguably close enough?
" First column, <owner>
-hi! def link preseedOwner Label
+hi! def link preseedOwner Label
+hi! def link preseedShellOwner Label
" Second column, <question name>
-hi! def link preseedQuestion Identifier
+hi! def link preseedQuestion Identifier
+hi! def link preseedShellQuestion Special
+hi! def link preseedShellStr Type
" Third column, <question type>
-hi! def link preseedBooleanType Type
-hi! def link preseedMultiSelType Type
-hi! def link preseedNote Type
-hi! def link preseedSelectType Type
-hi! def link preseedStrLikeType Type
+hi! def link preseedBooleanType Type
+hi! def link preseedMultiSelType Type
+hi! def link preseedNote Type
+hi! def link preseedSelectType Type
+hi! def link preseedStrLikeType Type
" Fourth column, <value>
-hi! def link preseedBooleanVal Special
-hi! def link preseedMultiSelVal Special
-hi! def link preseedStrLikeVal String
-hi! def link preseedVal String
-hi! def link preseedSelectVal Special
-hi! def link preseedMultiSelSep Operator
-hi! def link preseedComment Comment
+hi! def link preseedBooleanVal Special
+hi! def link preseedMultiSelVal Special
+hi! def link preseedStrLikeVal String
+hi! def link preseedVal String
+hi! def link preseedSelectVal Special
+hi! def link preseedMultiSelSep Operator
+hi! def link preseedComment Comment
" Line Continuation
-hi! def link preseedOwnerLC Operator
-hi! def link preseedQuestionLC Operator
-hi! def link preseedBooleanLC Operator
-hi! def link preseedMultiSelLC Operator
-hi! def link preseedStrLikeLC Operator
+hi! def link preseedOwnerLC Operator
+hi! def link preseedQuestionLC Operator
+hi! def link preseedBooleanLC Operator
+hi! def link preseedMultiSelLC Operator
+hi! def link preseedStrLikeLC Operator
" Add the syntax matching rules.
@@ -95,7 +115,7 @@ sy match preseedStrLikeVal contained /.*/me=e
sy match preseedStrLikeVal contained /.*\\/me=e-1 nextgroup=preseedStrLikeLC
-" Line continuation needs to be down here override everything other syntax.
+" Line continuation needs to be down here override other syntax.
sy match preseedBooleanLC contained /\s*\\$/ nextgroup=preseedBooleanVal,preseedBooleanLC skipnl
sy match preseedMultiSelLC contained /\\$/ nextgroup=preseedMultiSelVal skipnl
sy match preseedOwnerLC contained /\s*\\$/ nextgroup=@preseedSecond skipnl
@@ -103,5 +123,12 @@ sy match preseedQuestionLC contained /\s*\\$/ nextgroup=@preseedThird skipnl
sy match preseedSelectLC contained /\s*\\$/ nextgroup=preseedSelectVal,preseedSelectLC skipnl
sy match preseedStrLikeLC contained /\\$/ nextgroup=preseedStrLikeVal skipnl
+" Argument to some questions is embedded shell script code.
+execute 'syn region preseedShell start="' . shell_pattern_start . '"' . ' end="' . shell_pattern_end . '" contains=preseedShellOwner,@Sh'
+syn region notShell start="whatever" end='\([^\x5c]\$\|^$\)' contains=preseedShellOwner,@Sh
+sy match preseedShellOwner contained /^\s*[[:alnum:]._-]\+\(\s\|$\)/ nextgroup=preseedShellQuestion
+sy match preseedShellQuestion contained "\s*\([[:alnum:]._-]\+/\)\+[[:alnum:]._-]\+\(\s\|$\)" nextgroup=preseedShellStr
+sy match preseedShellStr contained /string/
+
" And comments must override everything else.
sy match preseedComment /^\s*#.*/