Additional changes for #33, file type specific autoformat config

This commit is contained in:
Reed Esau
2015-09-07 12:18:19 -06:00
parent f89a3ac998
commit dd8321a2d5
3 changed files with 28 additions and 24 deletions

View File

@@ -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 Vims
autoformat will _not_ be enabled.
autoformat will _not_ be activated.
The whitelist can override the blacklist and allow Vims autoformat to be
enabled if text that would normally be blacklisted doesnt dominate the
entire line. This allows autoformat to work with `inline` snippets of
code or links.
The whitelist will override the blacklist and allow Vims autoformat to
be activated if text that would normally be blacklisted doesnt dominate
the entire line. This allows autoformat to work with `inline` code and
links.
### Auto-detecting wrap mode

View File

@@ -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

View File

@@ -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 (.)