mirror of
https://github.com/preservim/vim-pencil.git
synced 2025-11-11 03:13:47 -05:00
Additional changes for #33, file type specific autoformat config
This commit is contained in:
@@ -453,9 +453,10 @@ excerpt showing the configuration for the ‘markdown’ file type:
|
|||||||
let g:pencil#autoformat_config = {
|
let g:pencil#autoformat_config = {
|
||||||
\ 'markdown': {
|
\ 'markdown': {
|
||||||
\ 'black': [
|
\ 'black': [
|
||||||
\ 'markdown(Code|H[0-9]|Url|IdDeclaration|Link|Rule|Highlight[A-Za-z0-9]+)',
|
|
||||||
\ 'htmlH[0-9]',
|
\ 'htmlH[0-9]',
|
||||||
|
\ 'markdown(Code|H[0-9]|Url|IdDeclaration|Link|Rule|Highlight[A-Za-z0-9]+)',
|
||||||
\ 'markdown(FencedCodeBlock|InlineCode)',
|
\ 'markdown(FencedCodeBlock|InlineCode)',
|
||||||
|
\ 'mkd(Code|Rule|Delimiter|Link|ListItem|IndentCode)',
|
||||||
\ 'mmdTable[A-Za-z0-9]*',
|
\ 'mmdTable[A-Za-z0-9]*',
|
||||||
\ ],
|
\ ],
|
||||||
\ 'white': [
|
\ '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
|
For example, if editing a file of type ‘markdown’ and you enter Insert
|
||||||
mode from inside a `markdownFencedCodeBlock` highlight group, then Vim’s
|
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
|
The whitelist will override the blacklist and allow Vim’s autoformat to
|
||||||
enabled if text that would normally be blacklisted doesn’t dominate the
|
be activated if text that would normally be blacklisted doesn’t dominate
|
||||||
entire line. This allows autoformat to work with `inline` snippets of
|
the entire line. This allows autoformat to work with `inline` code and
|
||||||
code or links.
|
links.
|
||||||
|
|
||||||
### Auto-detecting wrap mode
|
### Auto-detecting wrap mode
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,8 @@ fun! s:maybe_enable_autoformat() abort
|
|||||||
" don't enable autoformat if in a blacklisted code block or table,
|
" don't enable autoformat if in a blacklisted code block or table,
|
||||||
" allowing for reprieve via whitelist in certain cases
|
" 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:black = get(l:af_cfg, 'black', [])
|
||||||
let l:white = get(l:af_cfg, 'white', [])
|
let l:white = get(l:af_cfg, 'white', [])
|
||||||
let l:has_black_re = len(l:black) > 0
|
let l:has_black_re = len(l:black) > 0
|
||||||
|
|||||||
@@ -62,8 +62,8 @@ if !exists('g:pencil#autoformat')
|
|||||||
en
|
en
|
||||||
|
|
||||||
if !exists('g:pencil#autoformat_config')
|
if !exists('g:pencil#autoformat_config')
|
||||||
" do not engage autoformat if cursor is inside any of
|
" Do not activate autoformat if entering Insert mode when
|
||||||
" the following syntax groups
|
" the cursor is inside any of the following syntax groups.
|
||||||
"
|
"
|
||||||
" markdown* (tpope/vim-markdown)
|
" markdown* (tpope/vim-markdown)
|
||||||
" mkd*, htmlH[0-9] (plasticboy/vim-markdown)
|
" mkd*, htmlH[0-9] (plasticboy/vim-markdown)
|
||||||
@@ -74,29 +74,16 @@ if !exists('g:pencil#autoformat_config')
|
|||||||
let g:pencil#autoformat_config = {
|
let g:pencil#autoformat_config = {
|
||||||
\ 'markdown': {
|
\ 'markdown': {
|
||||||
\ 'black': [
|
\ 'black': [
|
||||||
\ 'markdown(Code|H[0-9]|Url|IdDeclaration|Link|Rule|Highlight[A-Za-z0-9]+)',
|
|
||||||
\ 'htmlH[0-9]',
|
\ 'htmlH[0-9]',
|
||||||
|
\ 'markdown(Code|H[0-9]|Url|IdDeclaration|Link|Rule|Highlight[A-Za-z0-9]+)',
|
||||||
\ 'markdown(FencedCodeBlock|InlineCode)',
|
\ 'markdown(FencedCodeBlock|InlineCode)',
|
||||||
|
\ 'mkd(Code|Rule|Delimiter|Link|ListItem|IndentCode)',
|
||||||
\ 'mmdTable[A-Za-z0-9]*',
|
\ 'mmdTable[A-Za-z0-9]*',
|
||||||
\ ],
|
\ ],
|
||||||
\ 'white': [
|
\ 'white': [
|
||||||
\ 'markdown(Code|Link)',
|
\ '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': {
|
\ 'asciidoc': {
|
||||||
\ 'black': [
|
\ 'black': [
|
||||||
\ 'asciidoc(AttributeList|AttributeEntry|ListLabel|Literal|SideBar|Source|Sect[0-9])',
|
\ '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)',
|
\ 'rst(CodeBlock|Directive|LiteralBlock|Sections)',
|
||||||
\ ],
|
\ ],
|
||||||
\ },
|
\ },
|
||||||
|
\ 'tex': {
|
||||||
|
\ 'black': [
|
||||||
|
\ 'tex(BeginEndName|Delimiter|DocType|InputFile|Math|RefZone|Title)',
|
||||||
|
\ 'texSection$',
|
||||||
|
\ ],
|
||||||
|
\ 'enforce-previous-line': 1,
|
||||||
|
\ },
|
||||||
\ 'textile': {
|
\ 'textile': {
|
||||||
\ 'black': [
|
\ 'black': [
|
||||||
\ 'txtCode',
|
\ 'txtCode',
|
||||||
@@ -119,6 +113,14 @@ if !exists('g:pencil#autoformat_config')
|
|||||||
\ },
|
\ },
|
||||||
\ }
|
\ }
|
||||||
en
|
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')
|
if !exists('g:pencil#joinspaces')
|
||||||
" by default, only one space after full stop (.)
|
" by default, only one space after full stop (.)
|
||||||
|
|||||||
Reference in New Issue
Block a user