From 287955cfb401df4e43bd22c10fa29ff234ffdef6 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sun, 13 Apr 2025 18:42:39 +0200 Subject: [PATCH] vim-patch:9.1.1299: filetype: mbsyncrc files are not recognized Problem: filetype: mbsyncrc files are not recognized Solution: detect isyncrc and "*.mbsyncrc" files as mbsync filetype, include filetype and syntax plugin (Pierrick Guillaume) mbsync is a command line application which synchronizes mailboxes; currently Maildir and IMAP4 mailboxes are supported. New messages, message deletions and flag changes can be propagated both ways; the operation set can be selected in a fine-grained manner. References: mbsync syntax overview: mbsync manual (isync v1.4.4) https://isync.sourceforge.io/mbsync.html Upstream support for the mbsync filetype. Original plugin: https://github.com/Fymyte/mbsync.vim closes: vim/vim#17103 https://github.com/vim/vim/commit/836b87d6998a1f18783afdc41c90ae1f38c9c3e9 Co-authored-by: Pierrick Guillaume --- runtime/doc/syntax.txt | 6 + runtime/ftplugin/mbsync.vim | 13 ++ runtime/lua/vim/filetype.lua | 3 +- runtime/syntax/mbsync.vim | 218 +++++++++++++++++++++++++++++ test/old/testdir/test_filetype.vim | 3 +- 5 files changed, 241 insertions(+), 2 deletions(-) create mode 100644 runtime/ftplugin/mbsync.vim create mode 100644 runtime/syntax/mbsync.vim diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt index 93a385359d..317961c12b 100644 --- a/runtime/doc/syntax.txt +++ b/runtime/doc/syntax.txt @@ -1972,6 +1972,12 @@ have the following in your vimrc: > let filetype_m = "mma" +MBSYNC *mbsync.vim* *ft-mbsync-syntax* + +The mbsync application uses a configuration file to setup mailboxes names, +user and password. All files ending with `.mbsyncrc` or with the name +`isyncrc` will be recognized as mbsync configuration files. + MEDIAWIKI *ft-mediawiki-syntax* By default, syntax highlighting includes basic HTML tags like style and diff --git a/runtime/ftplugin/mbsync.vim b/runtime/ftplugin/mbsync.vim new file mode 100644 index 0000000000..f2d13effb4 --- /dev/null +++ b/runtime/ftplugin/mbsync.vim @@ -0,0 +1,13 @@ +" Vim filetype plugin file +" Language: mbsync configuration file +" Maintainer: Pierrick Guillaume +" Last Change: 2025 Apr 13 + +if (exists('b:did_ftplugin')) + finish +endif +let b:did_ftplugin = 1 + +let b:undo_ftplugin = "setlocal commentstring<" + +setlocal commentstring=#\ %s diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua index 8d3f205d0d..426102b353 100644 --- a/runtime/lua/vim/filetype.lua +++ b/runtime/lua/vim/filetype.lua @@ -762,6 +762,7 @@ local extension = { dm3 = 'maxima', dmt = 'maxima', wxm = 'maxima', + mbsyncrc = 'mbsync', mw = 'mediawiki', wiki = 'mediawiki', mel = 'mel', @@ -1502,7 +1503,6 @@ local filename = { ['.chktexrc'] = 'conf', ['.ripgreprc'] = 'conf', ripgreprc = 'conf', - ['.mbsyncrc'] = 'conf', ['configure.in'] = 'config', ['configure.ac'] = 'config', crontab = 'crontab', @@ -1705,6 +1705,7 @@ local filename = { ['/etc/man.conf'] = 'manconf', ['man.config'] = 'manconf', ['maxima-init.mac'] = 'maxima', + isyncrc = 'mbsync', ['meson.build'] = 'meson', ['meson.options'] = 'meson', ['meson_options.txt'] = 'meson', diff --git a/runtime/syntax/mbsync.vim b/runtime/syntax/mbsync.vim new file mode 100644 index 0000000000..f1df4719ca --- /dev/null +++ b/runtime/syntax/mbsync.vim @@ -0,0 +1,218 @@ +" Vim syntax file +" Language: mbsyncrc +" Maintainer: Pierrick Guillaume +" Last Change: 2025 Apr 13 +" +" Syntax support for mbsync config file + +" This file is based on the mbsync manual (isync v1.4.4) +" https://isync.sourceforge.io/mbsync.html + +if exists('b:current_syntax') + finish +endif + +let b:current_syntax = 'mbsync' + +let s:cpo_save = &cpo +set cpo&vim + +syn match mbsError '.*' + +syn match mbsCommentL '^#.*$' + +" Properties {{{ + +syn match mbsNumber '[0-9]\+' display contained +syn match mbsPath '\%([A-Za-z0-9/._+#$%~=\\{}\[\]:@!-]\|\\.\)\+' display contained +syn match mbsPath '"\%([A-Za-z0-9/._+#$%~=\\{}\[\]:@! -]\|\\.\)\+"' display contained +syn match mbsName '\%([A-Za-z0-9/._+#$%~=\\{}\[\]:@!-]\|\\.\)\+' display contained +syn match mbsName '"\%([A-Za-z0-9/._+#$%~=\\{}\[\]:@! -]\|\\.\)\+"' display contained +syn match mbsCommand '+\?.*$' display contained contains=mbsCommandPrompt +syn match mbsCommandPrompt '+' display contained +syn region mbsString start=+"+ skip=+\\"+ end=+"+ display contained +syn match mbsSizeUnit '[kKmMbB]' display contained +syn match mbsSize '[0-9]\+' display contained contains=mbsNumber nextgroup=mbsSizeUnit +syn keyword mbsBool yes no contained + +" }}} + + +" Stores {{{ +" Global Store Config Items +syn match mbsGlobConfPath '^Path\s\+\ze.*$' contains=mbsGlobConfItemK contained nextgroup=mbsPath transparent +syn match mbsGlobConfMaxSize '^MaxSize\s\+\ze.*$' contains=mbsGlobConfItemK contained nextgroup=mbsSize transparent +syn match mbsGlobConfMapInbox '^MapInbox\s\+\ze.*$' contains=mbsGlobConfItemK contained nextgroup=mbsPath transparent +syn match mbsGlobConfFlatten '^Flatten\s\+\ze.*$' contains=mbsGlobConfItemK contained nextgroup=mbsPath transparent +syn match mbsGlobConfTrash '^Trash\s\+\ze.*$' contains=mbsGlobConfItemK contained nextgroup=mbsPath transparent +syn match mbsGlobConfTrashNO '^TrashNewOnly\s\+\ze.*$' contains=mbsGlobConfItemK contained nextgroup=mbsBool transparent +syn match mbsGlobConfTrashRN '^TrashRemoteNew\s\+\ze.*$' contains=mbsGlobConfItemK contained nextgroup=mbsBool transparent +syn keyword mbsGlobConfItemK Path MaxSize MapInbox Flatten Trash TrashNewOnly TrashRemoteNew contained + +syn cluster mbsGlobConfItem contains=mbsGlobConfPath,mbsGlobConfMaxSize,mbsGlobConfMapInbox,mbsGlobConfFlatten,mbsCommentL,mbsGlobConfTrash.* + + +" MaildirStore +syn match mbsMdSConfStMaildirStore '^MaildirStore\s\+\ze.*$' contains=mbsMdSConfItemK contained nextgroup=mbsName transparent +syn match mbsMdSConfStAltMap '^AltMap\s\+\ze.*$' contains=mbsMdSConfItemK contained nextgroup=mbsBool transparent +syn match mbsMdsConfStInbox '^Inbox\s\+\ze.*$' contains=mbsMdSConfItemK contained nextgroup=mbsPath transparent +syn match mbsMdsConfStInfoDelimiter '^InfoDelimiter\s\+\ze.*$' contains=mbsMdSConfItemK contained nextgroup=mbsPath transparent +syn keyword mbsMdSConfSubFoldersOpt Verbatim Legacy contained +syn match mbsMdSConfSubFoldersOpt 'Maildir++' display contained +syn match mbsMdsConfStSubFolders '^SubFolders\s\+\ze.*$' contains=mbsMdSConfItemK contained nextgroup=mbsMdSConfSubFoldersOpt transparent + +syn cluster mbsMdSConfItem contains=mbsMdSConfSt.* + +syn keyword mbsMdSConfItemK MaildirStore AltMap Inbox InfoDelimiter SubFolders contained + +syn region mbsMaildirStore start="^MaildirStore" end="^$" end='\%$' contains=@mbsGlobConfItem,mbsCommentL,@mbsMdSConfItem,mbsError transparent + + +" IMAP4Accounts +syn match mbsIAConfStIMAPAccount '^IMAPAccount\s\+\ze.*$' contains=mbsIAConfItemK contained nextgroup=mbsName transparent +syn match mbsIAConfStHost '^Host\s\+\ze.*$' contains=mbsIAConfItemK contained nextgroup=mbsPath transparent +syn match mbsIAConfStPort '^Port\s\+\ze.*$' contains=mbsIAConfItemK contained nextgroup=mbsNumber transparent +syn match mbsIAConfStTimeout '^Timeout\s\+\ze.*$' contains=mbsIAConfItemK contained nextgroup=mbsNumber transparent +syn match mbsIAConfStUser '^User\s\+\ze.*$' contains=mbsIAConfItemK contained nextgroup=mbsPath transparent +syn match mbsIAConfStUserCmd '^UserCmd\s\+\ze.*$' contains=mbsIAConfItemK contained nextgroup=mbsCommand transparent +syn match mbsIAConfStPass '^Pass\s\+\ze.*$' contains=mbsIAConfItemK contained nextgroup=mbsPath transparent +syn match mbsIAConfStPassCmd '^PassCmd\s\+\ze.*$' contains=mbsIAConfItemK contained nextgroup=mbsCommand transparent +syn match mbsIAConfStUseKeychain '^UseKeychain\s\+\ze.*$' contains=mbsIAConfItemK contained nextgroup=mbsBool transparent +syn match mbsIAConfStTunnel '^Tunnel\s\+\ze.*$' contains=mbsIAConfItemK contained nextgroup=mbsCommand transparent +syn match mbsIAConfStAuthMechs '^AuthMechs\s\+\ze.*$' contains=mbsIAConfItemK contained nextgroup=mbsPath transparent +syn keyword mbsIAConfSSLTypeOpt None STARTTLS IMAPS contained +syn match mbsIAConfStSSLType '^SSLType\s\+\ze.*$' contains=mbsIAConfItemK contained nextgroup=mbsIAConfSSLTypeOpt transparent +syn match mbsIAConfSSLVersionsOpt '\%(SSLv3\|TLSv1\%(.[123]\)\?\)\%(\s\+\%(SSLv3\|TLSv1\%(.[123]\)\?\)\)*' contained +syn match mbsIAConfStSSLVersions '^SSLVersions\s\+\ze.*$' contains=mbsIAConfItemK contained nextgroup=mbsIAConfSSLVersionsOpt transparent +syn match mbsIAConfStSystemCertificates '^SystemCertificates\s\+\ze.*$' contains=mbsIAConfItemK contained nextgroup=mbsBool transparent +syn match mbsIAConfStCertificateFile '^CertificateFile\s\+\ze.*$' contains=mbsIAConfItemK contained nextgroup=mbsPath transparent +syn match mbsIAConfStClientCertificate '^ClientCertificate\s\+\ze.*$' contains=mbsIAConfItemK contained nextgroup=mbsPath transparent +syn match mbsIAConfStClientKey '^ClientKey\s\+\ze.*$' contains=mbsIAConfItemK contained nextgroup=mbsPath transparent +syn match mbsIAConfStCipherString '^CipherString\s\+\ze.*$' contains=mbsIAConfItemK contained nextgroup=mbsString transparent +syn match mbsIAConfStPipelineDepth '^PipelineDepth\s\+\ze.*$' contains=mbsIAConfItemK contained nextgroup=mbsNumber transparent +syn match mbsIAConfStDisableExtensions '^DisableExtensions\?\s\+\ze.*$' contains=mbsIAConfItemK contained nextgroup=mbsPath transparent + +syn cluster mbsIAConfItem contains=mbsIAConfSt.* + +syn keyword mbsIAConfItemK + \ IMAPAccount Host Port Timeout User UserCmd Pass PassCmd UseKeychain Tunnel + \ AuthMechs SSLType SSLVersions SystemCertificates CertificateFile ClientCertificate + \ ClientKey CipherString PipelineDepth DisableExtension[s] contained + +syn region mbsIMAP4AccontsStore start="^IMAPAccount" end="^$" end="\%$" contains=@mbsGlobConfItem,mbsCommentL,@mbsIAConfItem,mbsError transparent + + +" IMAPStores +syn match mbsISConfStIMAPStore '^IMAPStore\s\+\ze.*$' contains=mbsISConfItemK contained nextgroup=mbsName transparent +syn match mbsISConfStAccount '^Account\s\+\ze.*$' contains=mbsISConfItemK contained nextgroup=mbsName transparent +syn match mbsISConfStUseNamespace '^UseNamespace\s\+\ze.*$' contains=mbsISConfItemK contained nextgroup=mbsBool transparent +syn match mbsISConfStPathDelimiter '^PathDelimiter\s\+\ze.*$' contains=mbsISConfItemK contained nextgroup=mbsPath transparent +syn match mbsISConfStSubscribedOnly '^SubscribedOnly\s\+\ze.*$' contains=mbsISConfItemK contained nextgroup=mbsBool transparent + +syn cluster mbsISConfItem contains=mbsISConfSt.* + +syn keyword mbsISConfItemK IMAPStore Account UseNamespace PathDelimiter SubscribedOnly contained + +syn region mbsIMAPStore start="^IMAPStore" end="^$" end="\%$" contains=@mbsGlobConfItem,mbsCommentL,@mbsISConfItem,mbsError transparent + +" }}} + +" Channels {{{ + +syn match mbsCConfStChannel '^Channel\s\+\ze.*$' contains=mbsCConfItemK contained nextgroup=mbsName transparent +syn region mbsCConfProxOpt matchgroup=mbsCConfProxOptOp start=':' matchgroup=mbsCConfProxOptOp end=':' contained contains=mbsName nextgroup=mbsPath keepend +syn match mbsCConfStFar '^Far\s\+\ze.*$' contains=mbsCConfItemK contained nextgroup=mbsCConfProxOpt transparent +syn match mbsCConfStNear '^Near\s\+\ze.*$' contains=mbsCConfItemK contained nextgroup=mbsCConfProxOpt transparent +syn match mbsCConfPatternOptOp '[*%!]' display contained +syn match mbsCConfPatternOpt '.*$' display contained contains=mbsCConfPatternOptOp +syn match mbsCConfStPattern '^Patterns\?\s\+\ze.*$' contains=mbsCConfItemK contained nextgroup=mbsCConfPatternOpt transparent +syn match mbsCConfStMaxSize '^MaxSize\s\+\ze.*$' contains=mbsCConfItemK contained nextgroup=mbsSize transparent +syn match mbsCConfStMaxMessages '^MaxMessages\s\+\ze.*$' contains=mbsCConfItemK contained nextgroup=mbsNumber transparent +syn match mbsCConfStExpireUnread '^ExpireUnread\s\+\ze.*$' contains=mbsCConfItemK contained nextgroup=mbsBool transparent +syn match mbsCConfSyncOpt 'None\|All\|\%(\s\+\%(Pull\|Push\|New\|ReNew\|Delete\|Flags\)\)\+' display contained +syn match mbsCConfStSync '^Sync\s\+\ze.*$' contains=mbsCConfItemK contained nextgroup=mbsCConfSyncOpt transparent +syn keyword mbsCConfManipOpt None Far Near Both contained +syn match mbsCConfStCreate '^Create\s\+\ze.*$' contains=mbsCConfItemK contained nextgroup=mbsCConfManipOpt transparent +syn match mbsCConfStRemove '^Remove\s\+\ze.*$' contains=mbsCConfItemK contained nextgroup=mbsCConfManipOpt transparent +syn match mbsCConfStExpunge '^Expunge\s\+\ze.*$' contains=mbsCConfItemK contained nextgroup=mbsCConfManipOpt transparent +syn match mbsCConfStCopyArrivalDate '^CopyArrivalDate\s\+\ze.*$' contains=mbsCConfItemK contained nextgroup=mbsBool transparent +syn match mbsCConfSyncStateOpt '\*\|.*$' display contained contains=mbsCConfSyncStateOptOp,mbsPath transparent +syn match mbsCConfSyncStateOptOp '\*' display contained +syn match mbsCConfStSyncState '^SyncState\s\+\ze.*$' contains=mbsCConfItemK contained nextgroup=mbsCConfSyncStateOpt transparent + +syn cluster mbsCConfItem contains=mbsCConfSt.* + +syn keyword mbsCConfItemK + \ Channel Far Near Pattern[s] MaxSize MaxMessages ExpireUnread Sync Create + \ Remove Expunge CopyArrivalDate SyncState contained + +syn region mbsChannel start="^Channel" end="^$" end="\%$" contains=@mbsCConfItem,mbsCommentL,mbsError transparent + +" }}} + +" Groups {{{ + +syn match mbsGConfGroupOpt '\%([A-Za-z0-9/._+#$%~=\\{}\[\]:@!-]\|\\.\)\+' display contained contains=mbsName nextgroup=mbsGConfChannelOpt +syn match mbsGConfStGroup '^Group\s\+\ze.*$' contains=mbsGConfItemK contained nextgroup=mbsGConfGroupOpt transparent +syn match mbsGConfChannelOpt '.*$' display contained +syn match mbsGConfStChannel '^Channels\?\s\+\ze.*$' contains=mbsGConfItemK contained nextgroup=mbsGConfChannelOpt transparent + +syn cluster mbsGConfItem contains=mbsGConfSt.* + +syn keyword mbsGConfItemK Group Channel[s] contained + +syn region mbsGroup start="^Group" end="^$" end="\%$" contains=@mbsGConfItem,mbsError transparent + +" }}} + +" Global Options {{{ + +syn match mbsFSync '^FSync\s\+\ze.*$' contains=mbsGlobOptItemK nextgroup=mbsBool transparent +syn match mbsFieldDelimiter '^FieldDelimiter\s\+\ze.*$' contains=mbsGlobOptItemK nextgroup=mbsPath transparent +syn match mbsBufferLimit '^BufferLimit\s\+\ze.*$' contains=mbsGlobOptItemK nextgroup=mbsSize transparent + +syn keyword mbsGlobOptItemK FSync FieldDelimiter BufferLimit contained +" }}} + +" Highlights {{{ + +hi def link mbsError Error + +hi def link mbsCommentL Comment + +hi def link mbsNumber Number +hi def link mbsSizeUnit Type +hi def link mbsPath String +hi def link mbsString String +hi def link mbsCommand String +hi def link mbsCommandPrompt Operator +hi def link mbsName Constant +hi def link mbsBool Boolean + +hi def link mbsGlobConfItemK Statement + +hi def link mbsMdSConfItemK Statement +hi def link mbsMdSConfSubFoldersOpt Keyword + +hi def link mbsIAConfItemK Statement +hi def link mbsIAConfSSLTypeOpt Keyword +hi def link mbsIAConfSSLVersionsOpt Keyword + +hi def link mbsISConfItemK Statement + +hi def link mbsCConfItemK Statement +hi def link mbsCConfProxOptOp Operator +hi def link mbsCConfPatternOpt String +hi def link mbsCConfPatternOptOp Operator +hi def link mbsCConfSyncOpt Keyword +hi def link mbsCConfManipOpt Keyword +hi def link mbsCConfSyncStateOptOp Operator + +hi def link mbsGConfItemK Statement +hi def link mbsGConfChannelOpt String + +hi def link mbsGlobOptItemK Statement +" }}} + +let &cpo = s:cpo_save +unlet s:cpo_save diff --git a/test/old/testdir/test_filetype.vim b/test/old/testdir/test_filetype.vim index 1667bd0935..ec15fadf28 100644 --- a/test/old/testdir/test_filetype.vim +++ b/test/old/testdir/test_filetype.vim @@ -181,7 +181,7 @@ func s:GetFilenameChecks() abort \ 'cobol': ['file.cbl', 'file.cob'], \ 'coco': ['file.atg'], \ 'conaryrecipe': ['file.recipe'], - \ 'conf': ['auto.master', 'file.conf', 'texdoc.cnf', '.x11vncrc', '.chktexrc', '.ripgreprc', 'ripgreprc', 'file.ctags', '.mbsyncrc'], + \ 'conf': ['auto.master', 'file.conf', 'texdoc.cnf', '.x11vncrc', '.chktexrc', '.ripgreprc', 'ripgreprc', 'file.ctags'], \ 'config': ['configure.in', 'configure.ac', '/etc/hostname.file', 'any/etc/hostname.file'], \ 'confini': ['pacman.conf', 'paru.conf', 'mpv.conf', 'any/.aws/config', 'any/.aws/credentials', 'file.nmconnection'], \ 'context': ['tex/context/any/file.tex', 'file.mkii', 'file.mkiv', 'file.mkvi', 'file.mkxl', 'file.mklx'], @@ -469,6 +469,7 @@ func s:GetFilenameChecks() abort \ 'matlab': ['file.m'], \ 'maxima': ['file.demo', 'file.dmt', 'file.dm1', 'file.dm2', 'file.dm3', \ 'file.wxm', 'maxima-init.mac'], + \ 'mbsync': ['.mbsyncrc', 'file.mbsyncrc', 'isyncrc'], \ 'mediawiki': ['file.mw', 'file.wiki'], \ 'mel': ['file.mel'], \ 'mermaid': ['file.mmd', 'file.mmdc', 'file.mermaid'],