diff --git a/README.markdown b/README.markdown index bbe723c..3756d67 100644 --- a/README.markdown +++ b/README.markdown @@ -453,9 +453,10 @@ excerpt showing the configuration for the ‘markdown’ file type: let g:pencil#autoformat_config = { \ 'markdown': { \ 'black': [ - \ 'markdown(Code|H[0-9]|Url|IdDeclaration|Link|Rule|Highlight[A-Za-z0-9]+)', \ 'htmlH[0-9]', + \ 'markdown(Code|H[0-9]|Url|IdDeclaration|Link|Rule|Highlight[A-Za-z0-9]+)', \ 'markdown(FencedCodeBlock|InlineCode)', + \ 'mkd(Code|Rule|Delimiter|Link|ListItem|IndentCode)', \ 'mmdTable[A-Za-z0-9]*', \ ], \ 'white': [ @@ -468,12 +469,12 @@ excerpt showing the configuration for the ‘markdown’ file type: For example, if editing a file of type ‘markdown’ and you enter Insert mode from inside a `markdownFencedCodeBlock` highlight group, then Vim’s -autoformat will _not_ be enabled. +autoformat will _not_ be activated. -The whitelist can override the blacklist and allow Vim’s autoformat to be -enabled if text that would normally be blacklisted doesn’t dominate the -entire line. This allows autoformat to work with `inline` snippets of -code or links. +The whitelist will override the blacklist and allow Vim’s autoformat to +be activated if text that would normally be blacklisted doesn’t dominate +the entire line. This allows autoformat to work with `inline` code and +links. ### Auto-detecting wrap mode diff --git a/autoload/pencil.vim b/autoload/pencil.vim index b50b3ed..6c20340 100644 --- a/autoload/pencil.vim +++ b/autoload/pencil.vim @@ -56,7 +56,8 @@ fun! s:maybe_enable_autoformat() abort " don't enable autoformat if in a blacklisted code block or table, " allowing for reprieve via whitelist in certain cases - let l:af_cfg = get(g:pencil#autoformat_config, &ft, {}) + let l:ft = get(g:pencil#autoformat_aliases, &ft, &ft) + let l:af_cfg = get(g:pencil#autoformat_config, l:ft, {}) let l:black = get(l:af_cfg, 'black', []) let l:white = get(l:af_cfg, 'white', []) let l:has_black_re = len(l:black) > 0 diff --git a/plugin/pencil.vim b/plugin/pencil.vim index fa866e0..8f01cf2 100644 --- a/plugin/pencil.vim +++ b/plugin/pencil.vim @@ -62,8 +62,8 @@ if !exists('g:pencil#autoformat') en if !exists('g:pencil#autoformat_config') - " do not engage autoformat if cursor is inside any of - " the following syntax groups + " Do not activate autoformat if entering Insert mode when + " the cursor is inside any of the following syntax groups. " " markdown* (tpope/vim-markdown) " mkd*, htmlH[0-9] (plasticboy/vim-markdown) @@ -74,29 +74,16 @@ if !exists('g:pencil#autoformat_config') let g:pencil#autoformat_config = { \ 'markdown': { \ 'black': [ - \ 'markdown(Code|H[0-9]|Url|IdDeclaration|Link|Rule|Highlight[A-Za-z0-9]+)', \ 'htmlH[0-9]', + \ 'markdown(Code|H[0-9]|Url|IdDeclaration|Link|Rule|Highlight[A-Za-z0-9]+)', \ 'markdown(FencedCodeBlock|InlineCode)', + \ 'mkd(Code|Rule|Delimiter|Link|ListItem|IndentCode)', \ 'mmdTable[A-Za-z0-9]*', \ ], \ 'white': [ \ 'markdown(Code|Link)', \ ], \ }, - \ 'mkd': { - \ 'black': [ - \ 'mkd(Code|Rule|Delimiter|Link|ListItem|IndentCode)', - \ 'htmlH[0-9]', - \ 'mmdTable[A-Za-z0-9]*', - \ ], - \ }, - \ 'tex': { - \ 'black': [ - \ 'tex(BeginEndName|Delimiter|DocType|InputFile|Math|RefZone|Title)', - \ 'texSection$', - \ ], - \ 'enforce-previous-line': 1, - \ }, \ 'asciidoc': { \ 'black': [ \ 'asciidoc(AttributeList|AttributeEntry|ListLabel|Literal|SideBar|Source|Sect[0-9])', @@ -112,6 +99,13 @@ if !exists('g:pencil#autoformat_config') \ 'rst(CodeBlock|Directive|LiteralBlock|Sections)', \ ], \ }, + \ 'tex': { + \ 'black': [ + \ 'tex(BeginEndName|Delimiter|DocType|InputFile|Math|RefZone|Title)', + \ 'texSection$', + \ ], + \ 'enforce-previous-line': 1, + \ }, \ 'textile': { \ 'black': [ \ 'txtCode', @@ -119,6 +113,14 @@ if !exists('g:pencil#autoformat_config') \ }, \ } en +if !exists('g:pencil#autoformat_aliases') + " Aliases used exclusively for autoformat config. + " Pencil will NOT modify the filetype setting. + let g:pencil#autoformat_aliases = { + \ 'md': 'markdown', + \ 'mkd': 'markdown', + \ } +en if !exists('g:pencil#joinspaces') " by default, only one space after full stop (.)