runtime(lf): improve syntax script, add filetype plugin

- Greatly improve detection and highlighting of command/shell regions,
  input-device key labels, escape sequences (@joelim-work)
- Add ftplugin for formatoptions, toggling comment areas
  (@andis-sprinkis)
- Add a few missing lf option keywords, rm. old non-working code, misc.
  formatting (@andis-sprinkis)

closes: #17078

Signed-off-by: Andis Spriņķis <andis@sprinkis.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Andis Spriņķis
2025-04-08 20:34:14 +02:00
committed by Christian Brabandt
parent b71f1309a2
commit 7517a8cadf
3 changed files with 219 additions and 203 deletions

1
.github/MAINTAINERS vendored
View File

@ -222,6 +222,7 @@ runtime/ftplugin/ldapconf.vim @ribru17
runtime/ftplugin/leo.vim @ribru17
runtime/ftplugin/less.vim @genoma
runtime/ftplugin/lex.vim @ribru17
runtime/ftplugin/lf.vim @andis-sprinkis
runtime/ftplugin/liquid.vim @tpope
runtime/ftplugin/lua.vim @dkearns
runtime/ftplugin/lc.vim @ribru17

22
runtime/ftplugin/lf.vim Normal file
View File

@ -0,0 +1,22 @@
" Vim filetype plugin file
" Language: lf file manager configuration file (lfrc)
" Maintainer: Andis Sprinkis <andis@sprinkis.com>
" URL: https://github.com/andis-sprinkis/lf-vim
" Last Change: 6 Apr 2025
if exists("b:did_ftplugin") | finish | endif
let b:did_ftplugin = 1
let s:cpo = &cpo
set cpo&vim
let b:undo_ftplugin = "setlocal comments< commentstring< formatoptions<"
setlocal comments=:#
setlocal commentstring=#\ %s
setlocal formatoptions-=t formatoptions+=rol
let &cpo = s:cpo
unlet s:cpo

View File

@ -3,15 +3,13 @@
" Maintainer: Andis Sprinkis <andis@sprinkis.com>
" Former Maintainer: Cameron Wright
" URL: https://github.com/andis-sprinkis/lf-vim
" Last Change: 28 March 2025
" 29 Mar 2025 by Vim Project (save and restore 'cpo' setting)
" Last Change: 5 Apr 2025
"
" The shell syntax highlighting is configurable. See $VIMRUNTIME/doc/syntax.txt
" lf version: 34
if exists("b:current_syntax")
finish
endif
if exists("b:current_syntax") | finish | endif
let s:cpo = &cpo
set cpo&vim
@ -23,11 +21,7 @@ syn match lfComment '#.*$'
"{{{ String Matching
syn match lfString "'.*'"
syn match lfString '".*"' contains=lfVar,lfSpecial
"}}}
"{{{ Match lf Variables
syn match lfVar '\$f\|\$fx\|\$fs\|\$id'
syn match lfString '".*"' contains=lfSpecial
"}}}
"{{{ Keywords
@ -45,6 +39,7 @@ syn keyword lfOptions
\ cleaner
\ clear
\ clearmaps
\ cmaps
\ cmd-capitalize-word
\ cmd-complete
\ cmd-delete
@ -73,6 +68,7 @@ syn keyword lfOptions
\ cmd-word
\ cmd-word-back
\ cmd-yank
\ cmds
\ copy
\ copyfmt
\ cursoractivefmt
@ -86,6 +82,7 @@ syn keyword lfOptions
\ dirfirst
\ dironly
\ dirpreviews
\ doc
\ down
\ draw
\ drawbox
@ -127,6 +124,7 @@ syn keyword lfOptions
\ load
\ locale
\ low
\ maps
\ mark-load
\ mark-remove
\ mark-save
@ -207,38 +205,33 @@ syn keyword lfOptions
"}}}
"{{{ Special Matching
syn match lfSpecial '<.*>\|\\.'
syn match lfSpecial '\v\<[^>]+\>'
syn match lfSpecial '\v\\(["\\abfnrtv]|\o+)'
"}}}
"{{{ Shell Script Matching for cmd
let s:shell_syntax = get(g:, 'lf_shell_syntax', "syntax/sh.vim")
let s:shell_syntax = get(b:, 'lf_shell_syntax', s:shell_syntax)
unlet b:current_syntax
exe 'syn include @Shell '.s:shell_syntax
let b:current_syntax = "lf"
syn region lfIgnore start=".{{\n" end="^}}"
\ keepend contains=lfExternalShell,lfExternalPatch
syn match lfShell '\$[a-zA-Z].*$
\\|:[a-zA-Z].*$
\\|%[a-zA-Z].*$
\\|![a-zA-Z].*$
\\|&[a-zA-Z].*$'
\ transparent contains=@Shell,lfExternalPatch
syn match lfExternalShell "^.*$" transparent contained contains=@Shell
syn match lfExternalPatch "^\s*cmd\ .*\ .{{$\|^}}$" contained
syn region lfCommand matchgroup=lfCommandMarker start=' \zs:\ze' end='$' keepend transparent
syn region lfCommand matchgroup=lfCommandMarker start=' \zs:{{\ze' end='}}' keepend transparent
syn region lfShell matchgroup=lfShellMarker start=' \zs[$!%&]\ze' end='$' keepend contains=@Shell
syn region lfShell matchgroup=lfShellMarker start=' \zs[$!%&]{{\ze' end='}}' keepend contains=@Shell
"}}}
"{{{ Link Highlighting
hi def link lfComment Comment
hi def link lfVar Type
hi def link lfSpecial Special
hi def link lfSpecial SpecialChar
hi def link lfString String
hi def link lfKeyword Statement
hi def link lfOptions Constant
hi def link lfConstant Constant
hi def link lfExternalShell Normal
hi def link lfExternalPatch Special
hi def link lfIgnore Special
hi def link lfCommandMarker Special
hi def link lfShellMarker Special
"}}}
let &cpo = s:cpo
unlet s:cpo