mirror of
https://github.com/preservim/vim-pencil.git
synced 2025-11-12 03:43:46 -05:00
Better behavior for #31, autoformat lists in Markdown
For tpope's markdown syntax, restored standard autoformat behavior for unordered lists, which is generally pretty good. Ordered lists had annoying behavior for autoformat, so simply disabling autoformat if detected when insert is entered. This isn't ideal, but it's not clear what else can be done now. Fixed bug for PFormatToggle, where it wasn't properly disabling Vim's autoformat. Provided help in README for mapping key to toggle autoformat.
This commit is contained in:
@@ -258,6 +258,13 @@ augroup END
|
|||||||
...where by default, files of type `text` will use hard line endings, but
|
...where by default, files of type `text` will use hard line endings, but
|
||||||
with autoformat disabled.
|
with autoformat disabled.
|
||||||
|
|
||||||
|
Optionally, you can map a toggle to control autoformat in your `.vimrc`:
|
||||||
|
|
||||||
|
```vim
|
||||||
|
noremap <buffer> <silent> <F7> :<C-u>PFormatToggle<cr>
|
||||||
|
inoremap <buffer> <silent> <F7> <C-o>:PFormatToggle<cr>
|
||||||
|
```
|
||||||
|
|
||||||
## Manual formatting
|
## Manual formatting
|
||||||
|
|
||||||
Note that you need not rely on Vim’s autoformat exclusively and can
|
Note that you need not rely on Vim’s autoformat exclusively and can
|
||||||
@@ -432,46 +439,18 @@ _not_ in the blacklist. The current blacklist is:
|
|||||||
|
|
||||||
```vim
|
```vim
|
||||||
let g:pencil#autoformat_blacklist = [
|
let g:pencil#autoformat_blacklist = [
|
||||||
\ 'markdownCode',
|
\ 'markdown(Code|H[0-9]|Url|IdDeclaration|Link|Rule|Highlight[A-Za-z0-9]+)',
|
||||||
\ 'markdownH[0-9]',
|
\ 'markdownOrderedListMarker',
|
||||||
\ 'markdownUrl',
|
\ 'mkd(Code|Rule|Delimiter|Link|ListItem|IndentCode)',
|
||||||
\ 'markdownIdDeclaration',
|
|
||||||
\ 'markdownLink',
|
|
||||||
\ 'markdownRule',
|
|
||||||
\ 'markdownHighlight[A-Za-z0-9]+',
|
|
||||||
\ 'markdownListMarker',
|
|
||||||
\ 'mkdCode',
|
|
||||||
\ 'mkdRule',
|
|
||||||
\ 'mkdDelimiter',
|
|
||||||
\ 'mkdLink',
|
|
||||||
\ 'mkdListItem',
|
|
||||||
\ 'mkdIndentCode',
|
|
||||||
\ 'htmlH[0-9]',
|
\ 'htmlH[0-9]',
|
||||||
\ 'markdownFencedCodeBlock',
|
\ 'markdown(FencedCodeBlock|InlineCode)',
|
||||||
\ 'markdownInlineCode',
|
|
||||||
\ 'mmdTable[A-Za-z0-9]*',
|
\ 'mmdTable[A-Za-z0-9]*',
|
||||||
\ 'txtCode',
|
\ 'txtCode',
|
||||||
\ 'rstCodeBlock',
|
\ 'rst(CodeBlock|Directive|LiteralBlock|Sections)',
|
||||||
\ 'rstDirective',
|
\ 'tex(BeginEndName|Delimiter|DocType|InputFile|Math|RefZone|Title)',
|
||||||
\ 'rstLiteralBlock',
|
|
||||||
\ 'rstSections',
|
|
||||||
\ 'texBeginEndName',
|
|
||||||
\ 'texDelimiter',
|
|
||||||
\ 'texDocType',
|
|
||||||
\ 'texInputFile',
|
|
||||||
\ 'texMath',
|
|
||||||
\ 'texRefZone',
|
|
||||||
\ 'texSection$',
|
\ 'texSection$',
|
||||||
\ 'texTitle',
|
\ 'asciidoc(AttributeList|ListLabel|Literal|SideBar|Source|Sect[0-9])',
|
||||||
\ 'asciidocAttributeList',
|
\ 'asciidoc[A-Za-z]*(Block|Macro|Title)',
|
||||||
\ 'asciidocListLabel',
|
|
||||||
\ 'asciidocLiteral',
|
|
||||||
\ 'asciidocSidebar',
|
|
||||||
\ 'asciidocSource',
|
|
||||||
\ 'asciidocSect[0-9]',
|
|
||||||
\ 'asciidoc[A-Za-z]*Block',
|
|
||||||
\ 'asciidoc[A-Za-z]*Macro',
|
|
||||||
\ 'asciidoc[A-Za-z]*Title',
|
|
||||||
\ ]
|
\ ]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -121,8 +121,10 @@ fun! s:maybe_enable_autoformat() abort
|
|||||||
endfo
|
endfo
|
||||||
en
|
en
|
||||||
en
|
en
|
||||||
" disallow enable if start of previous line is in blacklist
|
" disallow enable if start of previous line is in blacklist,
|
||||||
if l:line > 1
|
" (To avoid problem of autowrap screwing up adding a new item
|
||||||
|
" to a list.)
|
||||||
|
if l:okay_to_enable && l:line > 1
|
||||||
let l:prev_stack = synstack(l:line - 1, 1)
|
let l:prev_stack = synstack(l:line - 1, 1)
|
||||||
for l:sid in l:prev_stack
|
for l:sid in l:prev_stack
|
||||||
if len(l:sid) > 0 &&
|
if len(l:sid) > 0 &&
|
||||||
@@ -152,7 +154,6 @@ fun! pencil#setAutoFormat(af) abort
|
|||||||
au InsertEnter <buffer> call s:maybe_enable_autoformat()
|
au InsertEnter <buffer> call s:maybe_enable_autoformat()
|
||||||
au InsertLeave <buffer> set formatoptions-=a
|
au InsertLeave <buffer> set formatoptions-=a
|
||||||
aug END
|
aug END
|
||||||
let b:last_autoformat = l:nu_af
|
|
||||||
el
|
el
|
||||||
sil! au! pencil_autoformat * <buffer>
|
sil! au! pencil_autoformat * <buffer>
|
||||||
if l:nu_af && !l:is_hard
|
if l:nu_af && !l:is_hard
|
||||||
@@ -162,6 +163,7 @@ fun! pencil#setAutoFormat(af) abort
|
|||||||
return
|
return
|
||||||
en
|
en
|
||||||
en
|
en
|
||||||
|
let b:last_autoformat = l:nu_af
|
||||||
endf
|
endf
|
||||||
|
|
||||||
" Create mappings for word processing
|
" Create mappings for word processing
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ if !exists('g:pencil#autoformat')
|
|||||||
en
|
en
|
||||||
|
|
||||||
if !exists('g:pencil#autoformat_blacklist')
|
if !exists('g:pencil#autoformat_blacklist')
|
||||||
" by default, pencil does NOT start autoformat if inside any of
|
" do not engage autoformat if cursor is inside any of
|
||||||
" the following syntax groups
|
" the following syntax groups
|
||||||
"
|
"
|
||||||
" markdown* (tpope/vim-markdown)
|
" markdown* (tpope/vim-markdown)
|
||||||
@@ -68,46 +68,18 @@ if !exists('g:pencil#autoformat_blacklist')
|
|||||||
" txtCode (timcharper/textile.vim)
|
" txtCode (timcharper/textile.vim)
|
||||||
" rst*,tex*,asciidoc* (syntax file shipped with vim)
|
" rst*,tex*,asciidoc* (syntax file shipped with vim)
|
||||||
let g:pencil#autoformat_blacklist = [
|
let g:pencil#autoformat_blacklist = [
|
||||||
\ 'markdownCode',
|
\ 'markdown(Code|H[0-9]|Url|IdDeclaration|Link|Rule|Highlight[A-Za-z0-9]+)',
|
||||||
\ 'markdownH[0-9]',
|
\ 'markdownOrderedListMarker',
|
||||||
\ 'markdownUrl',
|
\ 'mkd(Code|Rule|Delimiter|Link|ListItem|IndentCode)',
|
||||||
\ 'markdownIdDeclaration',
|
|
||||||
\ 'markdownLink',
|
|
||||||
\ 'markdownRule',
|
|
||||||
\ 'markdownHighlight[A-Za-z0-9]+',
|
|
||||||
\ 'markdownListMarker',
|
|
||||||
\ 'mkdCode',
|
|
||||||
\ 'mkdRule',
|
|
||||||
\ 'mkdDelimiter',
|
|
||||||
\ 'mkdLink',
|
|
||||||
\ 'mkdListItem',
|
|
||||||
\ 'mkdIndentCode',
|
|
||||||
\ 'htmlH[0-9]',
|
\ 'htmlH[0-9]',
|
||||||
\ 'markdownFencedCodeBlock',
|
\ 'markdown(FencedCodeBlock|InlineCode)',
|
||||||
\ 'markdownInlineCode',
|
|
||||||
\ 'mmdTable[A-Za-z0-9]*',
|
\ 'mmdTable[A-Za-z0-9]*',
|
||||||
\ 'txtCode',
|
\ 'txtCode',
|
||||||
\ 'rstCodeBlock',
|
\ 'rst(CodeBlock|Directive|LiteralBlock|Sections)',
|
||||||
\ 'rstDirective',
|
\ 'tex(BeginEndName|Delimiter|DocType|InputFile|Math|RefZone|Title)',
|
||||||
\ 'rstLiteralBlock',
|
|
||||||
\ 'rstSections',
|
|
||||||
\ 'texBeginEndName',
|
|
||||||
\ 'texDelimiter',
|
|
||||||
\ 'texDocType',
|
|
||||||
\ 'texInputFile',
|
|
||||||
\ 'texMath',
|
|
||||||
\ 'texRefZone',
|
|
||||||
\ 'texSection$',
|
\ 'texSection$',
|
||||||
\ 'texTitle',
|
\ 'asciidoc(AttributeList|ListLabel|Literal|SideBar|Source|Sect[0-9])',
|
||||||
\ 'asciidocAttributeList',
|
\ 'asciidoc[A-Za-z]*(Block|Macro|Title)',
|
||||||
\ 'asciidocListLabel',
|
|
||||||
\ 'asciidocLiteral',
|
|
||||||
\ 'asciidocSidebar',
|
|
||||||
\ 'asciidocSource',
|
|
||||||
\ 'asciidocSect[0-9]',
|
|
||||||
\ 'asciidoc[A-Za-z]*Block',
|
|
||||||
\ 'asciidoc[A-Za-z]*Macro',
|
|
||||||
\ 'asciidoc[A-Za-z]*Title',
|
|
||||||
\ ]
|
\ ]
|
||||||
en
|
en
|
||||||
let g:pencil#autoformat_blacklist_re =
|
let g:pencil#autoformat_blacklist_re =
|
||||||
@@ -119,10 +91,8 @@ if !exists('g:pencil#autoformat_inline_whitelist')
|
|||||||
"
|
"
|
||||||
"'markdownCode' (tpope/vim-markdown)
|
"'markdownCode' (tpope/vim-markdown)
|
||||||
let g:pencil#autoformat_inline_whitelist = [
|
let g:pencil#autoformat_inline_whitelist = [
|
||||||
\ 'markdownCode',
|
\ 'markdown(Code|Link)',
|
||||||
\ 'markdownLink',
|
\ 'asciidoc(AttributeRef|Macro)',
|
||||||
\ 'asciidocAttributeRef',
|
|
||||||
\ 'asciidocMacro',
|
|
||||||
\ ]
|
\ ]
|
||||||
en
|
en
|
||||||
let g:pencil#autoformat_inline_whitelist_re =
|
let g:pencil#autoformat_inline_whitelist_re =
|
||||||
|
|||||||
Reference in New Issue
Block a user