vim highlighting WIP

This commit is contained in:
anon 2025-01-23 13:33:36 +01:00
parent b61f6c64c8
commit 190a65fa35
5 changed files with 84 additions and 0 deletions

1
.vim/ftdetect/vimdir.vim Normal file
View File

@ -0,0 +1 @@
au BufRead,BufNewFile *.vimdir set filetype=vimdir

25
.vim/syntax/vimdir.vim Normal file
View File

@ -0,0 +1,25 @@
" Vim syntax file
" Language: Vimdir entry file
" Current Maintainer: Anon
" Last Change: 2025
let b:current_syntax = "vimdir"
syn match vdId "^\d\+"
syn match vdSeparator ":"
syn match vdPermissions "[-dcbpls][-rwx]\{9}"
syn match vdDirectory "[^\t]\+/"
" NOTE: tabs are used for field separation,
" however it is possible that the user has expandtab on.
" this would confuse the lexer, leading to unexpected results.
" therefor, it is a good idea to warn the user.
" that said, spaces are valid inside file names.
syn match vdSpace " "
hi link vdId Number
hi link vdSeparator Statement
hi link vdPermissions Special
hi link vdSpace Error
hi link vdDirectory Directory
" #placeholder<ls_colors> COLLAPSED

View File

@ -11,6 +11,16 @@ ${OUT}: ${SOURCE}
test:
cmdtest --fast
ls_colors:
tclsh script/gen_syntax_from_ls_colors.tcl > object/ls_colors.vimdir
plug -g -e ls_colors object/ls_colors.vimdir .vim/syntax/vimdir.vim
bundle:
tar -c .vim/ -f vimdir.tar
install: bundle
tar -x -f vimdir.tar --dereference -C ~/
clean:
-rm ${OUT}

0
object/.gitkeep Normal file
View File

View File

@ -0,0 +1,48 @@
#!/usr/bin/tclsh
if {[info exists env(LS_COLORS)] == 0} {
puts stderr "Error: LS_COLORS environment variable is not set."
exit 1
}
set rules {}
set lscolors $env(LS_COLORS)
foreach pair [split $lscolors :] {
set color [lindex [split $pair =] 1]
set pattern [lindex [split $pair =] 0]
lappend rules [list $pattern $color]
}
proc to_clean_name {string} {
set r $string
set r [regsub -all {[^a-zA-Z0-9]} $r ""]
return $r
}
proc rewrite_regex {string} {
set r $string
set r [string map {"*" ".\*"} $r]
return $r
}
proc match_rule {rule} {
set template "syn match vd%s \"%s\""
set name [to_clean_name [lindex $rule 0]]
set pattern [rewrite_regex [lindex $rule 0]]
return [format $template $name $pattern]
}
proc def_rule {rule} {
set template "hi def vd%s ctermfg=%s"
set name [to_clean_name [lindex $rule 0]]
set color [lindex $rule 1]
return [format $template $name $color]
}
foreach rule $rules {
puts [match_rule $rule]
}
foreach rule $rules {
puts [def_rule $rule]
}