diff options
author | cos <cos> | 2023-10-13 16:28:31 +0200 |
---|---|---|
committer | cos <cos> | 2023-10-13 16:28:31 +0200 |
commit | 3db59dd0a0f7c40ae866df608e9ea133c52f94e4 (patch) | |
tree | b454e70276fac7d790103e87e15b4382769a30f5 | |
download | vim-preseed-3db59dd0a0f7c40ae866df608e9ea133c52f94e4.zip |
Initial commit
-rw-r--r-- | LICENSE | 18 | ||||
-rw-r--r-- | README.md | 16 | ||||
-rw-r--r-- | ftplugin/preseed.vim | 107 | ||||
-rw-r--r-- | scripts.vim | 16 |
4 files changed, 157 insertions, 0 deletions
@@ -0,0 +1,18 @@ +MIT No Attribution + +Copyright 2023 cos, https://www.netizen.se/#contact + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..97a368f --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +A filetype plugin for [vim][] to add syntax highlighting to Debian [preseed][] +files. + +This plugin seems to work for me. Yet this is my first attempt at publishing a +vim plugin. I am fully aware the pattern matching should be possible to do more +cleanly. One could also imagine wishing to use the WarningMsg group, and place +known broken syntax (such as leading spaces in values) in it. It is unlikely to +be any further feature development on this by me, but my aim is to maintain the +code. Patches are welcome, as is positive and constructive feedback. + +Provided under MIT No Attribution License. Relicensing will be immediately done +on request, if needed for inclusion in the vim official source tree or as part +of its debian package. + +[vim]: https://www.vim.org/ +[preseed]: https://wiki.debian.org/DebianInstaller/Preseed diff --git a/ftplugin/preseed.vim b/ftplugin/preseed.vim new file mode 100644 index 0000000..7b4e1ed --- /dev/null +++ b/ftplugin/preseed.vim @@ -0,0 +1,107 @@ +" Vim syntax file +" Language: Debian preseed +" Maintainer: cos <cos>, https://www.netizen.se/#contact +" Last Change: 2023 Oct 13 +" Remark: https://wiki.debian.org/DebianInstaller/Preseed + +" quit when a syntax file was already loaded +if exists('b:current_syntax') + finish +endif + + +" The syntax of each line in a preseed file follows: +" <owner> <question name> <question type> <value> + +" Create clusters for two of these four parts of a preseed line. +syntax cluster preseedSecond contains=preseedQuestion,preseedOwnerLC +syntax cluster preseedThird contains=preseedBooleanType, + \ preseedStrLikeType, + \ preseedMultiSelType, + \ preseedNote, + \ preseedSelectType, + \ preseedQuestionLC + + +" Define the highlighting. Doesn't map perfectly to the group's intents, but +" arguably close enough? + +" First, <owner> +hi! def link preseedOwner Label + +" Second, <question name> +hi! def link preseedQuestion Identifier + +" Third, <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 + +" Fourth, <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 + +" 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 + + +" Add the syntax matching rules. + +" First, <owner> +sy match preseedOwner /^\s*[[:alnum:]_-]\+\(\s\|$\)/ + \ nextgroup=@preseedSecond,preseedOwnerLC + +" Second, <question name> +sy match preseedQuestion contained + \ "\s*\([[:alnum:]_-]\+/\)\+[[:alnum:]_-]\+\(\s\|$\)" + \ nextgroup=@preseedThird,preseedQuestionLC + +" Third, <question type> +" (boolean, multiselect, note, password, select, string) +sy match preseedBooleanType contained /\s*boolean\(\s\|$\)/ + \ nextgroup=preseedBooleanVal,preseedBooleanLC +sy match preseedMultiSelType contained /\s*multiselect\(\s\|$\)/ + \ nextgroup=preseedMultiSelVal,preseedMultiSelLC +sy match preseedNote contained /\s*note$/ +sy match preseedSelectType contained /\s*select\(\s\|$\)/ + \ nextgroup=preseedSelectVal,preseedSelectLC +sy match preseedStrLikeType contained /\s*\(password\|string\)\(\s\|$\)/ + \ nextgroup=preseedStrLikeVal,preseedStrLikeLC + + +" Fourth, <value> +sy match preseedBooleanVal contained /\s*\(false\|true\)/ +sy match preseedMultiSelVal contained /.*/me=e + \ contains=preseedMultiSelSep +sy match preseedMultiSelVal contained /.*\\/me=e-1 + \ contains=preseedMultiSelSep nextgroup=preseedMultiSelLC +sy match preseedMultiSelSep contained /,/ +sy match preseedSelectVal contained /.*/ +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. +sy match preseedBooleanLC contained /\s*\\$/ + \ nextgroup=preseedBooleanVal,preseedBooleanLC skipnl +sy match preseedMultiSelLC contained /\\$/ nextgroup=preseedMultiSelVal skipnl +sy match preseedOwnerLC contained /\s*\\$/ nextgroup=@preseedSecond skipnl +sy match preseedQuestionLC contained /\s*\\$/ nextgroup=@preseedThird skipnl +sy match preseedSelectLC contained /\s*\\$/ + \ nextgroup=preseedSelectVal,preseedSelectLC skipnl +sy match preseedStrLikeLC contained /\\$/ nextgroup=preseedStrLikeVal skipnl + +" And comments must override everything else. +sy match preseedComment /^\s*#.*/ diff --git a/scripts.vim b/scripts.vim new file mode 100644 index 0000000..5c3e739 --- /dev/null +++ b/scripts.vim @@ -0,0 +1,16 @@ +" This detects the presence of the preseed file magic string on the first line +" of a file whenever vim opens it. +" +" I found the vim `:help` a bit thin on how to do it, and thus had to consult +" the following two stackoverflow threads to get it working: +" +" https://stackoverflow.com/q/54207515/using-a-file-type-plugin-file +" https://stackoverflow.com/q/5774824/set-filetype-for-none-extension + +if did_filetype() " filetype already set.. + finish " ..don't do these checks +endif +if getline(1) =~? '^#_preseed_V1' + setfiletype preseed + set filetype=preseed +endif |