Skip to content

Commit

Permalink
Additional changes for #33, file type specific autoformat config
Browse files Browse the repository at this point in the history
  • Loading branch information
Reed Esau committed Sep 7, 2015
1 parent f89a3ac commit dd8321a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
13 changes: 7 additions & 6 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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': [
Expand All @@ -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

Expand Down
3 changes: 2 additions & 1 deletion autoload/pencil.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 19 additions & 17 deletions plugin/pencil.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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])',
Expand All @@ -112,13 +99,28 @@ 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',
\ ],
\ },
\ }
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 (.)
Expand Down

0 comments on commit dd8321a

Please sign in to comment.