Skip to content

Commit dd8321a

Browse files
author
Reed Esau
committed
Additional changes for #33, file type specific autoformat config
1 parent f89a3ac commit dd8321a

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

README.markdown

+7-6
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,10 @@ excerpt showing the configuration for the ‘markdown’ file type:
453453
let g:pencil#autoformat_config = {
454454
\ 'markdown': {
455455
\ 'black': [
456-
\ 'markdown(Code|H[0-9]|Url|IdDeclaration|Link|Rule|Highlight[A-Za-z0-9]+)',
457456
\ 'htmlH[0-9]',
457+
\ 'markdown(Code|H[0-9]|Url|IdDeclaration|Link|Rule|Highlight[A-Za-z0-9]+)',
458458
\ 'markdown(FencedCodeBlock|InlineCode)',
459+
\ 'mkd(Code|Rule|Delimiter|Link|ListItem|IndentCode)',
459460
\ 'mmdTable[A-Za-z0-9]*',
460461
\ ],
461462
\ 'white': [
@@ -468,12 +469,12 @@ excerpt showing the configuration for the ‘markdown’ file type:
468469

469470
For example, if editing a file of type ‘markdown’ and you enter Insert
470471
mode from inside a `markdownFencedCodeBlock` highlight group, then Vim’s
471-
autoformat will _not_ be enabled.
472+
autoformat will _not_ be activated.
472473

473-
The whitelist can override the blacklist and allow Vim’s autoformat to be
474-
enabled if text that would normally be blacklisted doesn’t dominate the
475-
entire line. This allows autoformat to work with `inline` snippets of
476-
code or links.
474+
The whitelist will override the blacklist and allow Vim’s autoformat to
475+
be activated if text that would normally be blacklisted doesn’t dominate
476+
the entire line. This allows autoformat to work with `inline` code and
477+
links.
477478

478479
### Auto-detecting wrap mode
479480

autoload/pencil.vim

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ fun! s:maybe_enable_autoformat() abort
5656
" don't enable autoformat if in a blacklisted code block or table,
5757
" allowing for reprieve via whitelist in certain cases
5858

59-
let l:af_cfg = get(g:pencil#autoformat_config, &ft, {})
59+
let l:ft = get(g:pencil#autoformat_aliases, &ft, &ft)
60+
let l:af_cfg = get(g:pencil#autoformat_config, l:ft, {})
6061
let l:black = get(l:af_cfg, 'black', [])
6162
let l:white = get(l:af_cfg, 'white', [])
6263
let l:has_black_re = len(l:black) > 0

plugin/pencil.vim

+19-17
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ if !exists('g:pencil#autoformat')
6262
en
6363

6464
if !exists('g:pencil#autoformat_config')
65-
" do not engage autoformat if cursor is inside any of
66-
" the following syntax groups
65+
" Do not activate autoformat if entering Insert mode when
66+
" the cursor is inside any of the following syntax groups.
6767
"
6868
" markdown* (tpope/vim-markdown)
6969
" mkd*, htmlH[0-9] (plasticboy/vim-markdown)
@@ -74,29 +74,16 @@ if !exists('g:pencil#autoformat_config')
7474
let g:pencil#autoformat_config = {
7575
\ 'markdown': {
7676
\ 'black': [
77-
\ 'markdown(Code|H[0-9]|Url|IdDeclaration|Link|Rule|Highlight[A-Za-z0-9]+)',
7877
\ 'htmlH[0-9]',
78+
\ 'markdown(Code|H[0-9]|Url|IdDeclaration|Link|Rule|Highlight[A-Za-z0-9]+)',
7979
\ 'markdown(FencedCodeBlock|InlineCode)',
80+
\ 'mkd(Code|Rule|Delimiter|Link|ListItem|IndentCode)',
8081
\ 'mmdTable[A-Za-z0-9]*',
8182
\ ],
8283
\ 'white': [
8384
\ 'markdown(Code|Link)',
8485
\ ],
8586
\ },
86-
\ 'mkd': {
87-
\ 'black': [
88-
\ 'mkd(Code|Rule|Delimiter|Link|ListItem|IndentCode)',
89-
\ 'htmlH[0-9]',
90-
\ 'mmdTable[A-Za-z0-9]*',
91-
\ ],
92-
\ },
93-
\ 'tex': {
94-
\ 'black': [
95-
\ 'tex(BeginEndName|Delimiter|DocType|InputFile|Math|RefZone|Title)',
96-
\ 'texSection$',
97-
\ ],
98-
\ 'enforce-previous-line': 1,
99-
\ },
10087
\ 'asciidoc': {
10188
\ 'black': [
10289
\ 'asciidoc(AttributeList|AttributeEntry|ListLabel|Literal|SideBar|Source|Sect[0-9])',
@@ -112,13 +99,28 @@ if !exists('g:pencil#autoformat_config')
11299
\ 'rst(CodeBlock|Directive|LiteralBlock|Sections)',
113100
\ ],
114101
\ },
102+
\ 'tex': {
103+
\ 'black': [
104+
\ 'tex(BeginEndName|Delimiter|DocType|InputFile|Math|RefZone|Title)',
105+
\ 'texSection$',
106+
\ ],
107+
\ 'enforce-previous-line': 1,
108+
\ },
115109
\ 'textile': {
116110
\ 'black': [
117111
\ 'txtCode',
118112
\ ],
119113
\ },
120114
\ }
121115
en
116+
if !exists('g:pencil#autoformat_aliases')
117+
" Aliases used exclusively for autoformat config.
118+
" Pencil will NOT modify the filetype setting.
119+
let g:pencil#autoformat_aliases = {
120+
\ 'md': 'markdown',
121+
\ 'mkd': 'markdown',
122+
\ }
123+
en
122124

123125
if !exists('g:pencil#joinspaces')
124126
" by default, only one space after full stop (.)

0 commit comments

Comments
 (0)