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:
Reed Esau
2014-08-27 04:34:01 -06:00
parent 82d39c442d
commit 14f49ac597
3 changed files with 41 additions and 41 deletions

View File

@@ -23,8 +23,8 @@ smooth the path to writing prose.
* When using hard line breaks, enables autoformat while inserting text
* Buffer-scoped configuration (with a few minor exceptions, _pencil_
preserves your global settings)
* Support for Vims Conceal feature to hide markup defined by Syntax
plugins (e.g., `_` and `*` markup for styled text in \_*Markdown\_*)
* Support for Vims Conceal feature to hide markup defined by Syntax
plugins (e.g., `_` and `*` markup for styled text in \_*Markdown*\_)
* Pure Vimscript with no dependencies
Need spell-check and other features? Vim is about customization. To
@@ -121,11 +121,11 @@ to set the behavior for the current buffer:
_This autoformat feature affects *HardPencil* (hard line break) mode only._
When inserting text while in *HardPencil* mode, Vims autoformat feature will be
When inserting text while in *HardPencil* mode, Vims autoformat feature will be
enabled by default and can offer many of the same benefits as soft line wrap.
An exception: if used with popular syntax modules\*, _pencil_ will **disable**
autoformat when you enter Insert mode from inside a code block.
An exception: if used with popular syntax modules\*, _pencil_ will **disable**
autoformat when you enter Insert mode from inside a code block.
Where you need to manually enable/disable autoformat, you can do so with a command:
@@ -159,8 +159,8 @@ augroup END
...where by default, files of type `text` will use hard line endings, but
with autoformat disabled.
(*) Advanced users will want to check out `g:pencil#autoformat_exclude` to set
highlight groups for which autoformat will not be enabled.
(\*) Advanced users will want to check out `g:pencil#autoformat_blacklist`
to set highlight groups for which autoformat will not be enabled.
### Manual formatting
@@ -192,8 +192,8 @@ let g:pencil#textwidth = 74
### Sentence spacing
By default, when formatting text (through `gwip`, e.g.) only one space
will be inserted after a period(`.`), exclamation point(`!`), or question
By default, when formatting text (through `gwip`, e.g.) only one space
will be inserted after a period(`.`), exclamation point(`!`), or question
mark(`?`). You can change this default:
```vim
@@ -232,8 +232,8 @@ For more details on Vims Conceal feature, see:
#### Concealing styled text in Markdown
Syntax plugins such as [tpope/vim-markdown][tm] support concealing the
`_` and `*` characters when displaying \_*italic*\_, \*\*__bold__\*\*, and
Syntax plugins such as [tpope/vim-markdown][tm] support concealing the
markup characters when displaying \_*italic*\_, \*\*__bold__\*\*, and
\*\*\*___bold italic___\*\*\* styled text.
To use Vims Conceal feature with Markdown, you will need to install:
@@ -258,7 +258,7 @@ terminal to support **bold** and _italic_ styles.
## 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,
_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:
```
```html
<!-- 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`:
```
```html
<!-- vim: set tw=0 :-->
```

View File

@@ -53,24 +53,18 @@ fun! s:imap(preserve_completion, key, icmd)
en
endf
fun! s:enable_autoformat(mode)
" mode=1 InsertEnter
" mode=0 InsertLeave
if a:mode
" don't enable autoformat if in a code block (or table)
let l:okay_to_enable = 1
for l:sid in synstack(line('.'), col('.'))
if match(synIDattr(l:sid, 'name'),
\ g:pencil#autoformat_exclude_re) >= 0
let l:okay_to_enable = 0
break
en
endfo
if l:okay_to_enable
set formatoptions+=a
fun! s:enable_autoformat()
" don't enable autoformat if in a code block (TODO or table)
let l:okay_to_enable = 1
for l:sid in synstack(line('.'), col('.'))
if match(synIDattr(l:sid, 'name'),
\ g:pencil#autoformat_blacklist_re) >= 0
let l:okay_to_enable = 0
break
en
el
set formatoptions-=a
endfo
if l:okay_to_enable
set formatoptions+=a
en
endf
@@ -82,8 +76,8 @@ fun! pencil#setAutoFormat(mode)
let b:last_autoformat = a:mode == -1 ? !b:last_autoformat : a:mode
if b:last_autoformat
aug pencil_autoformat
au InsertEnter <buffer> call s:enable_autoformat(1)
au InsertLeave <buffer> call s:enable_autoformat(0)
au InsertEnter <buffer> call s:enable_autoformat()
au InsertLeave <buffer> set formatoptions-=a
aug END
el
sil! au! pencil_autoformat * <buffer>
@@ -151,11 +145,15 @@ fun! pencil#init(...) abort
setl textwidth=0
setl wrap
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
el
setl textwidth<
setl wrap< nowrap<
setl linebreak< nolinebreak<
setl breakat<
setl colorcolumn<
en
@@ -171,7 +169,6 @@ fun! pencil#init(...) abort
"if b:wrap_mode == s:WRAP_MODE_SOFT
" " augment with additional chars
" " TODO not working yet with n and m-dash
" set breakat=\ !@*-+;:,./?([{
"en
en
@@ -198,17 +195,20 @@ fun! pencil#init(...) abort
setl formatoptions+=n " recognize numbered lists
setl formatoptions+=1 " don't break line before 1 letter word
setl formatoptions+=t " autoformat of text (vim default)
setl formatoptions+=c " autoformat of comments (vim default)
" clean out stuff we likely don't want
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-=w " avoid erratic behavior if mixed spaces
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
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 concealcursor=' . g:pencil#concealcursor
en

View File

@@ -30,7 +30,7 @@ if !exists('g:pencil#autoformat')
let g:pencil#autoformat = 1
en
if !exists('g:pencil#autoformat_exclude')
if !exists('g:pencil#autoformat_blacklist')
" by default, pencil does NOT start autoformat if inside any of
" the following syntax groups
"
@@ -38,7 +38,7 @@ if !exists('g:pencil#autoformat_exclude')
"'mkdCode', 'mkdIndentCode' (plasticboy/vim-markdown)
"'markdownFencedCodeBlock', 'markdownInlineCode' (gabrielelana/vim-markdown)
"'txtCode' (timcharper/textile.vim)
let g:pencil#autoformat_exclude = [
let g:pencil#autoformat_blacklist = [
\ 'markdownCode',
\ 'markdownHighlight[A-Za-z0-9]+',
\ 'mkdCode',
@@ -48,8 +48,8 @@ if !exists('g:pencil#autoformat_exclude')
\ 'txtCode',
\ ]
en
let g:pencil#autoformat_exclude_re =
\ '\v(' . join(g:pencil#autoformat_exclude, '|') . ')'
let g:pencil#autoformat_blacklist_re =
\ '\v(' . join(g:pencil#autoformat_blacklist, '|') . ')'
if !exists('g:pencil#joinspaces')
" by default, only one space after full stop (.)