mirror of
https://github.com/preservim/vim-pencil.git
synced 2025-11-11 19:33:48 -05:00
various naming/reliability
Added breakat chars to preserve footnote and email addresses. Rename 'exclude' global to 'blacklist' Removed formatoptions that were interfering with syntax module.
This commit is contained in:
@@ -24,7 +24,7 @@ smooth the path to writing prose.
|
|||||||
* Buffer-scoped configuration (with a few minor exceptions, _pencil_
|
* Buffer-scoped configuration (with a few minor exceptions, _pencil_
|
||||||
preserves your global settings)
|
preserves your global settings)
|
||||||
* Support for Vim’s Conceal feature to hide markup defined by Syntax
|
* Support for Vim’s Conceal feature to hide markup defined by Syntax
|
||||||
plugins (e.g., `_` and `*` markup for styled text in \_*Markdown\_*)
|
plugins (e.g., `_` and `*` markup for styled text in \_*Markdown*\_)
|
||||||
* Pure Vimscript with no dependencies
|
* Pure Vimscript with no dependencies
|
||||||
|
|
||||||
Need spell-check and other features? Vim is about customization. To
|
Need spell-check and other features? Vim is about customization. To
|
||||||
@@ -159,8 +159,8 @@ 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.
|
||||||
|
|
||||||
(*) Advanced users will want to check out `g:pencil#autoformat_exclude` to set
|
(\*) Advanced users will want to check out `g:pencil#autoformat_blacklist`
|
||||||
highlight groups for which autoformat will not be enabled.
|
to set highlight groups for which autoformat will not be enabled.
|
||||||
|
|
||||||
### Manual formatting
|
### Manual formatting
|
||||||
|
|
||||||
@@ -233,7 +233,7 @@ For more details on Vim’s Conceal feature, see:
|
|||||||
#### Concealing styled text in Markdown
|
#### Concealing styled text in Markdown
|
||||||
|
|
||||||
Syntax plugins such as [tpope/vim-markdown][tm] support concealing the
|
Syntax plugins such as [tpope/vim-markdown][tm] support concealing the
|
||||||
`_` and `*` characters when displaying \_*italic*\_, \*\*__bold__\*\*, and
|
markup characters when displaying \_*italic*\_, \*\*__bold__\*\*, and
|
||||||
\*\*\*___bold italic___\*\*\* styled text.
|
\*\*\*___bold italic___\*\*\* styled text.
|
||||||
|
|
||||||
To use Vim’s Conceal feature with Markdown, you will need to install:
|
To use Vim’s Conceal feature with Markdown, you will need to install:
|
||||||
@@ -258,7 +258,7 @@ terminal to support **bold** and _italic_ styles.
|
|||||||
|
|
||||||
## Auto-detecting wrap mode
|
## Auto-detecting wrap mode
|
||||||
|
|
||||||
(For advanced users looking to tweak _pencil's_ behavior.)
|
**(For advanced users looking to tweak _pencil's_ behavior.)**
|
||||||
|
|
||||||
If you didn't explicitly specify a wrap mode during initialization,
|
If you didn't explicitly specify a wrap mode during initialization,
|
||||||
_pencil_ will attempt to detect it.
|
_pencil_ will attempt to detect it.
|
||||||
@@ -273,7 +273,7 @@ chances by giving _pencil_ an explicit hint.
|
|||||||
|
|
||||||
At the bottom of this document is a odd-looking code:
|
At the bottom of this document is a odd-looking code:
|
||||||
|
|
||||||
```
|
```html
|
||||||
<!-- vim: set tw=74 :-->
|
<!-- vim: set tw=74 :-->
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -289,7 +289,7 @@ not soft line wrap is the default editing mode for files of type ‘markdown’.
|
|||||||
|
|
||||||
You explicitly specify soft wrap mode by specifying a textwidth of `0`:
|
You explicitly specify soft wrap mode by specifying a textwidth of `0`:
|
||||||
|
|
||||||
```
|
```html
|
||||||
<!-- vim: set tw=0 :-->
|
<!-- vim: set tw=0 :-->
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -53,24 +53,18 @@ fun! s:imap(preserve_completion, key, icmd)
|
|||||||
en
|
en
|
||||||
endf
|
endf
|
||||||
|
|
||||||
fun! s:enable_autoformat(mode)
|
fun! s:enable_autoformat()
|
||||||
" mode=1 InsertEnter
|
" don't enable autoformat if in a code block (TODO or table)
|
||||||
" mode=0 InsertLeave
|
let l:okay_to_enable = 1
|
||||||
if a:mode
|
for l:sid in synstack(line('.'), col('.'))
|
||||||
" don't enable autoformat if in a code block (or table)
|
if match(synIDattr(l:sid, 'name'),
|
||||||
let l:okay_to_enable = 1
|
\ g:pencil#autoformat_blacklist_re) >= 0
|
||||||
for l:sid in synstack(line('.'), col('.'))
|
let l:okay_to_enable = 0
|
||||||
if match(synIDattr(l:sid, 'name'),
|
break
|
||||||
\ g:pencil#autoformat_exclude_re) >= 0
|
|
||||||
let l:okay_to_enable = 0
|
|
||||||
break
|
|
||||||
en
|
|
||||||
endfo
|
|
||||||
if l:okay_to_enable
|
|
||||||
set formatoptions+=a
|
|
||||||
en
|
en
|
||||||
el
|
endfo
|
||||||
set formatoptions-=a
|
if l:okay_to_enable
|
||||||
|
set formatoptions+=a
|
||||||
en
|
en
|
||||||
endf
|
endf
|
||||||
|
|
||||||
@@ -82,8 +76,8 @@ fun! pencil#setAutoFormat(mode)
|
|||||||
let b:last_autoformat = a:mode == -1 ? !b:last_autoformat : a:mode
|
let b:last_autoformat = a:mode == -1 ? !b:last_autoformat : a:mode
|
||||||
if b:last_autoformat
|
if b:last_autoformat
|
||||||
aug pencil_autoformat
|
aug pencil_autoformat
|
||||||
au InsertEnter <buffer> call s:enable_autoformat(1)
|
au InsertEnter <buffer> call s:enable_autoformat()
|
||||||
au InsertLeave <buffer> call s:enable_autoformat(0)
|
au InsertLeave <buffer> set formatoptions-=a
|
||||||
aug END
|
aug END
|
||||||
el
|
el
|
||||||
sil! au! pencil_autoformat * <buffer>
|
sil! au! pencil_autoformat * <buffer>
|
||||||
@@ -151,11 +145,15 @@ fun! pencil#init(...) abort
|
|||||||
setl textwidth=0
|
setl textwidth=0
|
||||||
setl wrap
|
setl wrap
|
||||||
setl linebreak
|
setl linebreak
|
||||||
|
" TODO breakat not working yet with n and m-dash
|
||||||
|
setl breakat-=* " avoid breaking footnote*
|
||||||
|
setl breakat-=@ " avoid breaking at email addresses
|
||||||
setl colorcolumn=0 " doesn't align as expected
|
setl colorcolumn=0 " doesn't align as expected
|
||||||
el
|
el
|
||||||
setl textwidth<
|
setl textwidth<
|
||||||
setl wrap< nowrap<
|
setl wrap< nowrap<
|
||||||
setl linebreak< nolinebreak<
|
setl linebreak< nolinebreak<
|
||||||
|
setl breakat<
|
||||||
setl colorcolumn<
|
setl colorcolumn<
|
||||||
en
|
en
|
||||||
|
|
||||||
@@ -171,7 +169,6 @@ fun! pencil#init(...) abort
|
|||||||
|
|
||||||
"if b:wrap_mode == s:WRAP_MODE_SOFT
|
"if b:wrap_mode == s:WRAP_MODE_SOFT
|
||||||
" " augment with additional chars
|
" " augment with additional chars
|
||||||
" " TODO not working yet with n and m-dash
|
|
||||||
" set breakat=\ !@*-+;:,./?([{
|
" set breakat=\ !@*-+;:,./?([{
|
||||||
"en
|
"en
|
||||||
en
|
en
|
||||||
@@ -198,17 +195,20 @@ fun! pencil#init(...) abort
|
|||||||
setl formatoptions+=n " recognize numbered lists
|
setl formatoptions+=n " recognize numbered lists
|
||||||
setl formatoptions+=1 " don't break line before 1 letter word
|
setl formatoptions+=1 " don't break line before 1 letter word
|
||||||
setl formatoptions+=t " autoformat of text (vim default)
|
setl formatoptions+=t " autoformat of text (vim default)
|
||||||
setl formatoptions+=c " autoformat of comments (vim default)
|
|
||||||
|
|
||||||
" clean out stuff we likely don't want
|
" clean out stuff we likely don't want
|
||||||
setl formatoptions-=2 " use indent of 2nd line for rest of paragraph
|
setl formatoptions-=2 " use indent of 2nd line for rest of paragraph
|
||||||
setl formatoptions-=v " only break line at blank entered during insert
|
setl formatoptions-=v " only break line at blank entered during insert
|
||||||
setl formatoptions-=w " avoid erratic behavior if mixed spaces
|
setl formatoptions-=w " avoid erratic behavior if mixed spaces
|
||||||
setl formatoptions-=a " autoformat will turn on with Insert in HardPencil mode
|
setl formatoptions-=a " autoformat will turn on with Insert in HardPencil mode
|
||||||
setl formatoptions-=r " don't insert comment leader
|
|
||||||
setl formatoptions-=o " don't insert comment leader
|
setl formatoptions-=o " don't insert comment leader
|
||||||
|
|
||||||
if has('conceal')
|
" plasticboy/vim-markdown sets these to handle bullet points
|
||||||
|
" as comments. Not changing for now.
|
||||||
|
"setl formatoptions-=c " no autoformat of comments
|
||||||
|
"setl formatoptions+=r " don't insert comment leader
|
||||||
|
|
||||||
|
if has('conceal') && v:version >= 703
|
||||||
exe ':setl conceallevel=' . g:pencil#conceallevel
|
exe ':setl conceallevel=' . g:pencil#conceallevel
|
||||||
exe ':setl concealcursor=' . g:pencil#concealcursor
|
exe ':setl concealcursor=' . g:pencil#concealcursor
|
||||||
en
|
en
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ if !exists('g:pencil#autoformat')
|
|||||||
let g:pencil#autoformat = 1
|
let g:pencil#autoformat = 1
|
||||||
en
|
en
|
||||||
|
|
||||||
if !exists('g:pencil#autoformat_exclude')
|
if !exists('g:pencil#autoformat_blacklist')
|
||||||
" by default, pencil does NOT start autoformat if inside any of
|
" by default, pencil does NOT start autoformat if inside any of
|
||||||
" the following syntax groups
|
" the following syntax groups
|
||||||
"
|
"
|
||||||
@@ -38,7 +38,7 @@ if !exists('g:pencil#autoformat_exclude')
|
|||||||
"'mkdCode', 'mkdIndentCode' (plasticboy/vim-markdown)
|
"'mkdCode', 'mkdIndentCode' (plasticboy/vim-markdown)
|
||||||
"'markdownFencedCodeBlock', 'markdownInlineCode' (gabrielelana/vim-markdown)
|
"'markdownFencedCodeBlock', 'markdownInlineCode' (gabrielelana/vim-markdown)
|
||||||
"'txtCode' (timcharper/textile.vim)
|
"'txtCode' (timcharper/textile.vim)
|
||||||
let g:pencil#autoformat_exclude = [
|
let g:pencil#autoformat_blacklist = [
|
||||||
\ 'markdownCode',
|
\ 'markdownCode',
|
||||||
\ 'markdownHighlight[A-Za-z0-9]+',
|
\ 'markdownHighlight[A-Za-z0-9]+',
|
||||||
\ 'mkdCode',
|
\ 'mkdCode',
|
||||||
@@ -48,8 +48,8 @@ if !exists('g:pencil#autoformat_exclude')
|
|||||||
\ 'txtCode',
|
\ 'txtCode',
|
||||||
\ ]
|
\ ]
|
||||||
en
|
en
|
||||||
let g:pencil#autoformat_exclude_re =
|
let g:pencil#autoformat_blacklist_re =
|
||||||
\ '\v(' . join(g:pencil#autoformat_exclude, '|') . ')'
|
\ '\v(' . join(g:pencil#autoformat_blacklist, '|') . ')'
|
||||||
|
|
||||||
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