mirror of
https://github.com/preservim/vim-pencil.git
synced 2025-11-19 23:33:39 -05:00
Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ad18a74cf0 | ||
|
|
470f9ca44c | ||
|
|
f9cbfca887 | ||
|
|
01a3a95c72 | ||
|
|
08ee355694 | ||
|
|
2f62713ed9 | ||
|
|
5e6ba37a94 | ||
|
|
ebbfc350b8 | ||
|
|
b36e21556d | ||
|
|
4e82b996e4 | ||
|
|
6b6c2f08bf | ||
|
|
dd8321a2d5 | ||
|
|
f89a3ac998 | ||
|
|
290b0872d0 | ||
|
|
632ae63c2c | ||
|
|
5f819bfec0 | ||
|
|
45f4c46cfe | ||
|
|
536311e98c | ||
|
|
c465e30c19 | ||
|
|
320c7fc284 | ||
|
|
02283c81e6 | ||
|
|
96546d4b17 |
212
README.markdown
212
README.markdown
@@ -8,9 +8,6 @@
|
||||

|
||||
- - -
|
||||
|
||||
[Note: demo above needs to be updated with the _recently_ renamed
|
||||
commands (see below), but the legacy ones shown still work.]
|
||||
|
||||
# Features
|
||||
|
||||
The _pencil_ plugin aspires to make Vim as powerful a tool for writers as
|
||||
@@ -48,7 +45,8 @@ Several reasons have been offered:
|
||||
to reach for mouse, track pad, or arrow keys
|
||||
* Minimal chording, with many mnemonic-friendly commands
|
||||
* Sophisticated capabilities for navigating and manipulating text
|
||||
* Highly configurable to suit your needs, with many great plugins available
|
||||
* Highly configurable, enabling you to build a workflow that suits your
|
||||
needs, with many great plugins available
|
||||
* No proprietary format lock-in
|
||||
|
||||
But while such reasons might be sound, they remain scant justification to
|
||||
@@ -68,21 +66,28 @@ tool in expressing yourself. For more details on vi-style editing, see...
|
||||
* [Your problem with Vim is that you don't grok vi][gv] (December 2011)
|
||||
* [Intro to Vim's Grammar][ig] (January 2013)
|
||||
* [Why Atom Can’t Replace Vim, Learning the lesson of vi][wa] (March 2014)
|
||||
* [Language of Vim/Neovim][lovn] (January 2015)
|
||||
|
||||
[ls]: http://yanpritzker.com/2011/12/16/learn-to-speak-vim-verbs-nouns-and-modifiers/
|
||||
[gv]: http://stackoverflow.com/questions/1218390/what-is-your-most-productive-shortcut-with-vim/1220118#1220118
|
||||
[ig]: http://takac.github.io/2013/01/30/vim-grammar/
|
||||
[wa]: https://medium.com/p/433852f4b4d1
|
||||
[lovn]: http://allsyed.com/language-of-vim-neovim/
|
||||
|
||||
# Installation
|
||||
|
||||
_pencil_ is best installed using a Vim package manager, such as Vundle,
|
||||
Plug, NeoBundle, or Pathogen.
|
||||
_pencil_ is best installed using a Vim package manager, such as
|
||||
[Vundle][vnd], [Plug][plg], [NeoBundle][nbn], or [Pathogen][pth].
|
||||
|
||||
_For those new to Vim: before installing this plugin, consider getting
|
||||
comfortable with the basics of Vim by working through one of the many
|
||||
tutorials available._
|
||||
|
||||
[vnd]: https://github.com/gmarik/Vundle.vim
|
||||
[plg]: https://github.com/junegunn/vim-plug
|
||||
[nbn]: https://github.com/Shougo/neobundle.vim
|
||||
[pth]: https://github.com/tpope/vim-pathogen
|
||||
|
||||
#### Vundle
|
||||
|
||||
Add to your `.vimrc` and save:
|
||||
@@ -98,8 +103,6 @@ Plugin 'reedes/vim-pencil'
|
||||
:PluginInstall
|
||||
```
|
||||
|
||||
For Vundle version < 0.10.2, replace `Plugin` with `Bundle` above.
|
||||
|
||||
#### Plug
|
||||
|
||||
Add to your `.vimrc` and save:
|
||||
@@ -143,8 +146,8 @@ git clone https://github.com/reedes/vim-pencil
|
||||
|
||||
## Basic initialization
|
||||
|
||||
Though optional, initializing _pencil_ by `FileType` will automatically
|
||||
set up your buffers for editing prose.
|
||||
Initializing _pencil_ by `FileType` is _optional_, though doing so will
|
||||
automatically set up your buffers for editing prose.
|
||||
|
||||
Add support for your desired filetypes to your `.vimrc`:
|
||||
|
||||
@@ -172,10 +175,8 @@ augroup pencil
|
||||
augroup END
|
||||
```
|
||||
|
||||
For other prose-oriented plugins, consult the [See also](#see-also)
|
||||
section below.
|
||||
|
||||
For more details, see the advanced initialization section below.
|
||||
For a list of other prose-oriented plugins, consult the [See
|
||||
also](#see-also) section below.
|
||||
|
||||
## Hard line breaks or soft line wrap?
|
||||
|
||||
@@ -208,27 +209,27 @@ if auto-detect might suggest soft line wrap.
|
||||
You can enable, disable, and toggle _pencil_ as a command:
|
||||
|
||||
* `Pencil` - initialize _pencil_ with auto-detect for the current buffer
|
||||
* `PencilOff` - removes navigation mappings and restores buffer to global settings
|
||||
* `PencilToggle` - if on, turns off; if off, initializes with auto-detect
|
||||
* `NoPencil` (or `PencilOff`) - removes navigation mappings and restores buffer to global settings
|
||||
* `TogglePencil` (or `PencilToggle`) - if on, turns off; if off, initializes with auto-detect
|
||||
|
||||
Because auto-detect might not work as intended, you can invoke a command
|
||||
to set the behavior for the current buffer:
|
||||
|
||||
* `PencilSoft` - initialize _pencil_ with soft line wrap mode
|
||||
* `PencilHard` - initialize _pencil_ with hard line break mode (and Vim’s autoformat)
|
||||
* `SoftPencil` (or `PencilSoft`) - initialize _pencil_ with soft line wrap mode
|
||||
* `HardPencil` (or `PencilHard`) - initialize _pencil_ with hard line break mode (and Vim’s autoformat)
|
||||
|
||||
## Automatic formatting
|
||||
|
||||
_The ‘autoformat’ feature affects *PencilHard* (hard line break) mode
|
||||
_The ‘autoformat’ feature affects *HardPencil* (hard line break) mode
|
||||
only._
|
||||
|
||||
When inserting text while in *PencilHard* mode, Vim’s autoformat feature
|
||||
When inserting text while in *HardPencil* mode, Vim’s autoformat feature
|
||||
will be enabled by default and can offer many of the same benefits as
|
||||
soft line wrap.
|
||||
|
||||
One useful exception (aka 'blacklisting'): if used with popular
|
||||
prose-oriented syntax plugins, _pencil_ will **not** enable autoformat when
|
||||
you enter Insert mode from inside a code block or table. (See the
|
||||
One useful exception (aka 'blacklisting'): if used with popular
|
||||
prose-oriented syntax plugins, _pencil_ will **not** enable autoformat when
|
||||
you enter Insert mode from inside a code block or table. (See the
|
||||
advanced section below for more details on the blacklisting feature.)
|
||||
|
||||
Where you need to manually enable/disable autoformat for the current
|
||||
@@ -257,10 +258,17 @@ augroup END
|
||||
...where by default, files of type `text` will use hard line endings, but
|
||||
with autoformat disabled.
|
||||
|
||||
Optionally, you can map a key in your `.vimrc` to toggle Vim's autoformat:
|
||||
|
||||
```vim
|
||||
noremap <buffer> <silent> <F7> :<C-u>PFormatToggle<cr>
|
||||
inoremap <buffer> <silent> <F7> <C-o>:PFormatToggle<cr>
|
||||
```
|
||||
|
||||
## Manual formatting
|
||||
|
||||
Note that you need not rely on autoformat exclusively and can manually
|
||||
reformat paragraphs with standard Vim commands:
|
||||
Note that you need not rely on Vim’s autoformat exclusively and can
|
||||
manually reformat paragraphs with standard Vim commands:
|
||||
|
||||
* `gqip` or `gwip` - format current paragraph
|
||||
* `vipJ` - unformat (i.e., join all lines with hard line breaks) in current paragraph
|
||||
@@ -276,7 +284,7 @@ nnoremap <silent> Q gwip
|
||||
|
||||
## Default textwidth
|
||||
|
||||
You can configure the textwidth to be used in **PencilHard** mode when no
|
||||
You can configure the textwidth to be used in **HardPencil** mode when no
|
||||
textwidth is set globally, locally, or available via modeline. It
|
||||
defaults to `74`, but you can change that value in your `.vimrc`:
|
||||
|
||||
@@ -353,7 +361,7 @@ terminal to support **bold** and _italic_ styles.
|
||||
## Status line indicator
|
||||
|
||||
Your status line can reflect the wrap mode for _pencil_ buffers. For
|
||||
example, `␍` to represent `PencilHard` (hard line break) mode. To
|
||||
example, `␍` to represent `HardPencil` (hard line break) mode. To
|
||||
configure your status line and ruler, add to your `.vimrc`:
|
||||
|
||||
```vim
|
||||
@@ -367,12 +375,22 @@ or if using [bling/vim-airline][va]:
|
||||
let g:airline_section_x = '%{PencilMode()}'
|
||||
```
|
||||
|
||||
If you don’t like the default indicators, you can specify different ones:
|
||||
The default indicators now include ‘auto’ for when Vim’s autoformat is
|
||||
activated in hard line break mode.
|
||||
|
||||
```vim
|
||||
let g:pencil#mode_indicators = {'hard': '␍', 'soft': '⤸', 'off': '',}
|
||||
let g:pencil#mode_indicators = {'hard': 'H', 'auto': 'A', 'soft': 'S', 'off': '',}
|
||||
```
|
||||
|
||||
If Unicode is detected, the default indicators are:
|
||||
|
||||
```vim
|
||||
let g:pencil#mode_indicators = {'hard': '␍', 'auto': 'ª', 'soft': '⤸', 'off': '',}
|
||||
```
|
||||
|
||||
If you don’t like the default indicators, you can specify your own in
|
||||
your `.vimrc`.
|
||||
|
||||
Note that `PencilMode()` will return blank for buffers in which _pencil_
|
||||
has not been initialized.
|
||||
|
||||
@@ -391,89 +409,74 @@ You can override _pencil_ and other configuration settings when initializing:
|
||||
```vim
|
||||
augroup pencil
|
||||
autocmd!
|
||||
autocmd FileType markdown,mkd call pencil#init() |
|
||||
\ call litecorrect#init() |
|
||||
\ setl spell spl=en_us fdl=4 noru nonu nornu |
|
||||
\ setl fdo+=search
|
||||
autocmd Filetype git,gitsendemail,*commit*,*COMMIT* |
|
||||
\ call pencil#init({'wrap': 'hard', 'textwidth': 72}) |
|
||||
\ call litecorrect#init() |
|
||||
\ setl spell spl=en_us et sw=2 ts=2 noai
|
||||
autocmd Filetype mail call pencil#init({'wrap': 'hard', 'textwidth': 60}) |
|
||||
\ call litecorrect#init() |
|
||||
\ setl spell spl=en_us et sw=2 ts=2 noai nonu nornu
|
||||
autocmd Filetype html,xml call pencil#init({'wrap': 'soft'}) |
|
||||
\ call litecorrect#init() |
|
||||
\ setl spell spl=en_us et sw=2 ts=2
|
||||
autocmd FileType markdown,mkd call pencil#init()
|
||||
\ | call litecorrect#init()
|
||||
\ | setl spell spl=en_us fdl=4 noru nonu nornu
|
||||
\ | setl fdo+=search
|
||||
autocmd Filetype git,gitsendemail,*commit*,*COMMIT*
|
||||
\ call pencil#init({'wrap': 'hard', 'textwidth': 72})
|
||||
\ | call litecorrect#init()
|
||||
\ | setl spell spl=en_us et sw=2 ts=2 noai
|
||||
autocmd Filetype mail call pencil#init({'wrap': 'hard', 'textwidth': 60})
|
||||
\ | call litecorrect#init()
|
||||
\ | setl spell spl=en_us et sw=2 ts=2 noai nonu nornu
|
||||
autocmd Filetype html,xml call pencil#init({'wrap': 'soft'})
|
||||
\ | call litecorrect#init()
|
||||
\ | setl spell spl=en_us et sw=2 ts=2
|
||||
augroup END
|
||||
```
|
||||
|
||||
Alternatives include `after/ftplugin` modules as well as refactoring initialization
|
||||
statements into a function.
|
||||
|
||||
### Autoformat blacklisting
|
||||
### Autoformat blacklisting (and whitelisting)
|
||||
|
||||
_The ‘autoformat’ feature affects *PencilHard* (hard line break) mode
|
||||
_The ‘autoformat’ feature affects *HardPencil* (hard line break) mode
|
||||
only._
|
||||
|
||||
When editing formatted text, such as a table or code block, autoformat
|
||||
will wreak havoc with the formatting. In these cases you will want to
|
||||
temporarily deactivate autoformat, such as with the `PFormatOff` or
|
||||
`PFormatToggle` commands described above. However, in most cases, you won’t
|
||||
need to do this.
|
||||
When editing formatted text, such as a table or code block, Vim’s
|
||||
autoformat will wreak havoc with the formatting. In these cases you will
|
||||
want to temporarily deactivate autoformat, such as with the `PFormatOff`
|
||||
or `PFormatToggle` commands described above. However, in most cases, you
|
||||
won’t need to do this.
|
||||
|
||||
_pencil_ will detect the syntax highlight group at the cursor position to
|
||||
determine whether or not autoformat should be activated.
|
||||
|
||||
If autoformat is on, it will be activated at the time you enter Insert
|
||||
mode provided that the syntax highlighting group at the cursor position is
|
||||
_not_ in the blacklist. The current blacklist is:
|
||||
If you haven’t explicitly disabled autoformat, it will be activated at
|
||||
the time you enter Insert mode provided that the syntax highlighting
|
||||
group at the cursor position is _not_ in the blacklist.
|
||||
|
||||
Blacklists are now declared by file type. The default blacklists (and
|
||||
whitelists) are declared in the `plugin/pencil.vim` module. Here’s an
|
||||
excerpt showing the configuration for the ‘markdown’ file type:
|
||||
|
||||
```vim
|
||||
let g:pencil#autoformat_blacklist = [
|
||||
\ 'markdownCode',
|
||||
\ 'markdownH[0-9]',
|
||||
\ 'markdownUrl',
|
||||
\ 'markdownIdDeclaration',
|
||||
\ 'markdownLink',
|
||||
\ 'markdownRule',
|
||||
\ 'markdownHighlight[A-Za-z0-9]+',
|
||||
\ 'mkdCode',
|
||||
\ 'mkdRule',
|
||||
\ 'htmlH[0-9]',
|
||||
\ 'mkdIndentCode',
|
||||
\ 'markdownFencedCodeBlock',
|
||||
\ 'markdownInlineCode',
|
||||
\ 'mmdTable[A-Za-z0-9]*',
|
||||
\ 'txtCode',
|
||||
\ 'rstCodeBlock',
|
||||
\ 'rstDirective',
|
||||
\ 'rstLiteralBlock',
|
||||
\ 'rstSections',
|
||||
\ 'texBeginEndName',
|
||||
\ 'texDelimiter',
|
||||
\ 'texDocType',
|
||||
\ 'texInputFile',
|
||||
\ 'texMath',
|
||||
\ 'texRefZone',
|
||||
\ 'texSection$',
|
||||
\ 'texTitle',
|
||||
\ 'asciidocAttribute',
|
||||
\ 'asciidocList',
|
||||
\ 'asciidocLiteral',
|
||||
\ 'asciidoc[A-Za-z]*Block',
|
||||
\ 'asciidoc[A-Za-z]*Macro',
|
||||
\ 'asciidoc[A-Za-z]*Title',
|
||||
\ ]
|
||||
let g:pencil#autoformat_config = {
|
||||
\ 'markdown': {
|
||||
\ 'black': [
|
||||
\ '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)',
|
||||
\ ],
|
||||
\ },
|
||||
[snip]
|
||||
\ }
|
||||
```
|
||||
|
||||
_WARNING: the implementation of this blacklist may be changing in the
|
||||
future._
|
||||
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 activated.
|
||||
|
||||
There’s also a whitelist to override the blacklist. See code for details.
|
||||
|
||||
You can override this in your `.vimrc`. Additions to defaults with good
|
||||
use cases are welcome.
|
||||
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
|
||||
|
||||
@@ -543,6 +546,16 @@ If no such lines found, _pencil_ falls back to the default wrap mode.
|
||||
* [Vim Training Class - Basic motions and commands][tc] - video tutorial by Shawn Biddle
|
||||
* [Vim for Writers][vw] - guide to the basics geared to writers
|
||||
|
||||
Bloggers and developers discuss _pencil_ and its brethern:
|
||||
|
||||
* [Reed Esau's growing list of Vim plugins for writers][regl] (2014) - by @pengwynn
|
||||
* [Distraction Free Writing in Vim][dfwiv] (2014) - by @tlattimore
|
||||
* [Safari Blog: Turning vim into an IDE through vim plugins][tviai] (2014) - by @jameydeorio
|
||||
* [Quick tops for writing prose with Vim][qtfwp] (2014) - by @benoliver999
|
||||
* [UseVim: Reed Esau's Writing Plugins][rewp] (2015) - by @alexyoung
|
||||
* [Tomasino Labs: Vim in Context][vic] (2015) - by @jamestomasino
|
||||
* [Writing with Vim][wwv] (2015) - by Pat Ambrosio
|
||||
|
||||
Other plugins of specific interest to writers:
|
||||
|
||||
* [tpope/vim-abolish][ab] - search for, substitute, and abbr. multiple variants of a word
|
||||
@@ -550,6 +563,13 @@ Other plugins of specific interest to writers:
|
||||
* [junegunn/limelight.vim][jl] - focus mode that brightens current paragraph
|
||||
* [junegunn/goyo.vim][jg] - distraction-free editing mode
|
||||
|
||||
[qtfwp]: http://benoliver999.com/technology/2014/12/06/vimforprose/
|
||||
[wwv]: https://lilii.co/aardvark/writing-with-vim
|
||||
[vic]: https://labs.tomasino.org/vim-in-context.html
|
||||
[rewp]: http://usevim.com/2015/05/27/reedes/
|
||||
[tviai]: https://www.safaribooksonline.com/blog/2014/11/23/way-vim-ide/
|
||||
[regl]: http://wynnnetherland.com/journal/reed-esau-s-growing-list-of-vim-plugins-for-writers/
|
||||
[dfwiv]: http://tlattimore.com/blog/distraction-free-writing-in-vim/
|
||||
[ab]: http://github.com/tpope/vim-abolish
|
||||
[ex]: http://github.com/tommcdo/vim-exchange
|
||||
[jl]: http://github.com/junegunn/limelight.vim
|
||||
@@ -599,8 +619,8 @@ with its own Markdown variant.
|
||||
|
||||
# Future development
|
||||
|
||||
If you’ve spotted a problem or have an idea on improving this plugin,
|
||||
please post it to the github project issue page or submit a pull request.
|
||||
If you’ve spotted a problem or have an idea on improving _pencil_,
|
||||
please report it as an issue, or better yet submit a pull request.
|
||||
|
||||
```
|
||||
<!-- vim: set tw=73 :-->
|
||||
|
||||
@@ -44,7 +44,7 @@ fun! s:detect_wrap_mode() abort
|
||||
return s:WRAP_MODE_DEFAULT
|
||||
endf
|
||||
|
||||
fun! s:imap(preserve_completion, key, icmd)
|
||||
fun! s:imap(preserve_completion, key, icmd) abort
|
||||
if a:preserve_completion
|
||||
exe ":ino <buffer> <silent> <expr> " . a:key . " pumvisible() ? \"" . a:key . "\" : \"" . a:icmd . "\""
|
||||
el
|
||||
@@ -52,8 +52,20 @@ fun! s:imap(preserve_completion, key, icmd)
|
||||
en
|
||||
endf
|
||||
|
||||
fun! s:maybe_enable_autoformat()
|
||||
" don't enable autoformat if in a code block or table
|
||||
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: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
|
||||
let l:has_white_re = len(l:white) > 0
|
||||
let l:black_re = l:has_black_re ? '\v(' . join( l:black, '|') . ')' : ''
|
||||
let l:white_re = l:has_white_re ? '\v(' . join( l:white, '|') . ')' : ''
|
||||
let l:enforce_previous_line = get(l:af_cfg, 'enforce-previous-line', 0)
|
||||
|
||||
let l:okay_to_enable = 1
|
||||
let l:line = line('.')
|
||||
let l:col = col('.')
|
||||
@@ -88,17 +100,21 @@ fun! s:maybe_enable_autoformat()
|
||||
endw
|
||||
en
|
||||
" enforce blacklist by scanning for syntax matches
|
||||
for l:sid in l:stack
|
||||
if match(synIDattr(l:sid, 'name'),
|
||||
\ g:pencil#autoformat_blacklist_re) >= 0
|
||||
let l:okay_to_enable = 0
|
||||
break
|
||||
en
|
||||
endfo
|
||||
" enforce whitelist by detecting inline `markup` for
|
||||
" which we DO want autoformat to be enabled (e.g.,
|
||||
" tpope's markdownCode)
|
||||
if !l:okay_to_enable
|
||||
if l:has_black_re
|
||||
for l:sid in l:stack
|
||||
if match(synIDattr(l:sid, 'name'), l:black_re) >= 0
|
||||
let l:okay_to_enable = 0
|
||||
"echohl WarningMsg
|
||||
"echo 'hit blacklist line=' . l:line . ' col=' . l:col .
|
||||
" \ ' name=' . synIDattr(l:sid, 'name')
|
||||
"echohl NONE
|
||||
break
|
||||
en
|
||||
endfo
|
||||
en
|
||||
" enforce whitelist by detecting inline `markup` for which we DO want
|
||||
" autoformat to be enabled (e.g., tpope's markdownCode)
|
||||
if l:has_white_re && !l:okay_to_enable
|
||||
" one final check for an empty stack at the start and end of line,
|
||||
" either of which greenlights a whitelist check
|
||||
if !l:found_empty
|
||||
@@ -109,20 +125,30 @@ fun! s:maybe_enable_autoformat()
|
||||
en
|
||||
if l:found_empty
|
||||
for l:sid in l:stack
|
||||
if match(synIDattr(l:sid, 'name'),
|
||||
\ g:pencil#autoformat_inline_whitelist_re) >= 0
|
||||
if match(synIDattr(l:sid, 'name'), l:white_re) >= 0
|
||||
let l:okay_to_enable = 1
|
||||
break
|
||||
en
|
||||
endfo
|
||||
en
|
||||
en
|
||||
" disallow enable if start of previous line is in blacklist,
|
||||
if l:has_black_re && l:enforce_previous_line && l:okay_to_enable && l:line > 1
|
||||
let l:prev_stack = synstack(l:line - 1, 1)
|
||||
for l:sid in l:prev_stack
|
||||
if len(l:sid) > 0 &&
|
||||
\ match(synIDattr(l:sid, 'name'), l:black_re) >= 0
|
||||
let l:okay_to_enable = 0
|
||||
break
|
||||
en
|
||||
endfo
|
||||
en
|
||||
if l:okay_to_enable
|
||||
set formatoptions+=a
|
||||
en
|
||||
endf
|
||||
|
||||
fun! pencil#setAutoFormat(af)
|
||||
fun! pencil#setAutoFormat(af) abort
|
||||
" 1=auto, 0=manual, -1=toggle
|
||||
if !exists('b:last_autoformat')
|
||||
let b:last_autoformat = 0
|
||||
@@ -136,7 +162,6 @@ fun! pencil#setAutoFormat(af)
|
||||
au InsertEnter <buffer> call s:maybe_enable_autoformat()
|
||||
au InsertLeave <buffer> set formatoptions-=a
|
||||
aug END
|
||||
let b:last_autoformat = l:nu_af
|
||||
el
|
||||
sil! au! pencil_autoformat * <buffer>
|
||||
if l:nu_af && !l:is_hard
|
||||
@@ -146,6 +171,7 @@ fun! pencil#setAutoFormat(af)
|
||||
return
|
||||
en
|
||||
en
|
||||
let b:last_autoformat = l:nu_af
|
||||
endf
|
||||
|
||||
" Create mappings for word processing
|
||||
@@ -217,7 +243,7 @@ fun! pencil#init(...) abort
|
||||
setl breakat-=@ " avoid breaking at email addresses
|
||||
en
|
||||
|
||||
if has('syntax')
|
||||
if exists('&colorcolumn')
|
||||
setl colorcolumn=0 " doesn't align as expected
|
||||
en
|
||||
el
|
||||
@@ -229,7 +255,7 @@ fun! pencil#init(...) abort
|
||||
setl breakat<
|
||||
en
|
||||
|
||||
if has('syntax')
|
||||
if exists('&colorcolumn')
|
||||
setl colorcolumn<
|
||||
en
|
||||
en
|
||||
@@ -395,7 +421,14 @@ fun! pencil#init(...) abort
|
||||
ino <buffer> : :<c-g>u
|
||||
ino <buffer> <c-u> <c-g>u<c-u>
|
||||
ino <buffer> <c-w> <c-g>u<c-w>
|
||||
ino <buffer> <cr> <c-g>u<cr>
|
||||
|
||||
" map <cr> only if not already mapped
|
||||
if empty(maparg('<cr>', 'i'))
|
||||
ino <buffer> <cr> <c-g>u<cr>
|
||||
let b:pencil_cr_mapped = 1
|
||||
el
|
||||
let b:pencil_cr_mapped = 0
|
||||
en
|
||||
el
|
||||
sil! iu <buffer> .
|
||||
sil! iu <buffer> !
|
||||
@@ -405,7 +438,11 @@ fun! pencil#init(...) abort
|
||||
sil! iu <buffer> :
|
||||
sil! iu <buffer> <c-u>
|
||||
sil! iu <buffer> <c-w>
|
||||
sil! iu <buffer> <cr>
|
||||
|
||||
" unmap <cr> only if we mapped it ourselves
|
||||
if exists('b:pencil_cr_mapped') && b:pencil_cr_mapped
|
||||
sil! iu <buffer> <cr>
|
||||
en
|
||||
en
|
||||
endf
|
||||
|
||||
|
||||
@@ -31,7 +31,11 @@ fun! PencilMode()
|
||||
if b:pencil_wrap_mode ==# s:WRAP_MODE_SOFT
|
||||
return get(g:pencil#mode_indicators, 'soft', 'S')
|
||||
elsei b:pencil_wrap_mode ==# s:WRAP_MODE_HARD
|
||||
return get(g:pencil#mode_indicators, 'hard', 'H')
|
||||
if &fo =~ 'a'
|
||||
return get(g:pencil#mode_indicators, 'auto', 'A')
|
||||
el
|
||||
return get(g:pencil#mode_indicators, 'hard', 'H')
|
||||
en
|
||||
el
|
||||
return get(g:pencil#mode_indicators, 'off', '')
|
||||
en
|
||||
@@ -57,9 +61,9 @@ if !exists('g:pencil#autoformat')
|
||||
let g:pencil#autoformat = 1
|
||||
en
|
||||
|
||||
if !exists('g:pencil#autoformat_blacklist')
|
||||
" by default, pencil does NOT start autoformat if inside any of
|
||||
" the following syntax groups
|
||||
if !exists('g:pencil#autoformat_config')
|
||||
" 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)
|
||||
@@ -67,59 +71,56 @@ if !exists('g:pencil#autoformat_blacklist')
|
||||
" mmdTable[A-Za-z0-9]* (mattly/vim-markdown-enhancements)
|
||||
" txtCode (timcharper/textile.vim)
|
||||
" rst*,tex*,asciidoc* (syntax file shipped with vim)
|
||||
let g:pencil#autoformat_blacklist = [
|
||||
\ 'markdownCode',
|
||||
\ 'markdownH[0-9]',
|
||||
\ 'markdownUrl',
|
||||
\ 'markdownIdDeclaration',
|
||||
\ 'markdownLink',
|
||||
\ 'markdownRule',
|
||||
\ 'markdownHighlight[A-Za-z0-9]+',
|
||||
\ 'mkdCode',
|
||||
\ 'mkdRule',
|
||||
\ 'htmlH[0-9]',
|
||||
\ 'mkdIndentCode',
|
||||
\ 'markdownFencedCodeBlock',
|
||||
\ 'markdownInlineCode',
|
||||
\ 'mmdTable[A-Za-z0-9]*',
|
||||
\ 'txtCode',
|
||||
\ 'rstCodeBlock',
|
||||
\ 'rstDirective',
|
||||
\ 'rstLiteralBlock',
|
||||
\ 'rstSections',
|
||||
\ 'texBeginEndName',
|
||||
\ 'texDelimiter',
|
||||
\ 'texDocType',
|
||||
\ 'texInputFile',
|
||||
\ 'texMath',
|
||||
\ 'texRefZone',
|
||||
\ 'texSection$',
|
||||
\ 'texTitle',
|
||||
\ 'asciidocAttribute',
|
||||
\ 'asciidocList',
|
||||
\ 'asciidocLiteral',
|
||||
\ 'asciidoc[A-Za-z]*Block',
|
||||
\ 'asciidoc[A-Za-z]*Macro',
|
||||
\ 'asciidoc[A-Za-z]*Title',
|
||||
\ ]
|
||||
let g:pencil#autoformat_config = {
|
||||
\ 'markdown': {
|
||||
\ 'black': [
|
||||
\ '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)',
|
||||
\ ],
|
||||
\ },
|
||||
\ 'asciidoc': {
|
||||
\ 'black': [
|
||||
\ 'asciidoc(AttributeList|AttributeEntry|ListLabel|Literal|SideBar|Source|Sect[0-9])',
|
||||
\ 'asciidoc[A-Za-z]*(Block|Macro|Title)',
|
||||
\ ],
|
||||
\ 'white': [
|
||||
\ 'asciidoc(AttributeRef|Macro)',
|
||||
\ ],
|
||||
\ 'enforce-previous-line': 1,
|
||||
\ },
|
||||
\ 'rst': {
|
||||
\ 'black': [
|
||||
\ 'rst(CodeBlock|Directive|LiteralBlock|Sections)',
|
||||
\ ],
|
||||
\ },
|
||||
\ 'tex': {
|
||||
\ 'black': [
|
||||
\ 'tex(BeginEndName|Delimiter|DocType|InputFile|Math|RefZone|Statement|Title)',
|
||||
\ 'texSection$',
|
||||
\ ],
|
||||
\ 'enforce-previous-line': 1,
|
||||
\ },
|
||||
\ 'textile': {
|
||||
\ 'black': [
|
||||
\ 'txtCode',
|
||||
\ ],
|
||||
\ },
|
||||
\ }
|
||||
en
|
||||
let g:pencil#autoformat_blacklist_re =
|
||||
\ '\v(' . join(g:pencil#autoformat_blacklist, '|') . ')'
|
||||
|
||||
if !exists('g:pencil#autoformat_inline_whitelist')
|
||||
" grant autoformat a reprieve (allow enabling) if any of
|
||||
" following syntax groups doesn't dominate the whole line
|
||||
"
|
||||
"'markdownCode' (tpope/vim-markdown)
|
||||
let g:pencil#autoformat_inline_whitelist = [
|
||||
\ 'markdownCode',
|
||||
\ 'markdownLink',
|
||||
\ 'asciidocMacro',
|
||||
\ 'asciidocQuotedMonospaced',
|
||||
\ ]
|
||||
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
|
||||
let g:pencil#autoformat_inline_whitelist_re =
|
||||
\ '\v(' . join(g:pencil#autoformat_inline_whitelist, '|') . ')'
|
||||
|
||||
if !exists('g:pencil#joinspaces')
|
||||
" by default, only one space after full stop (.)
|
||||
@@ -159,9 +160,9 @@ en
|
||||
if !exists('g:pencil#mode_indicators')
|
||||
" used to set PencilMode() for statusline
|
||||
if s:unicode_enabled()
|
||||
let g:pencil#mode_indicators = {'hard': '␍', 'soft': '⤸', 'off': '',}
|
||||
let g:pencil#mode_indicators = {'hard': '␍', 'auto': 'ª', 'soft': '⤸', 'off': '',}
|
||||
el
|
||||
let g:pencil#mode_indicators = {'hard': 'H', 'soft': 'S', 'off': '',}
|
||||
let g:pencil#mode_indicators = {'hard': 'H', 'auto': 'A', 'soft': 'S', 'off': '',}
|
||||
en
|
||||
en
|
||||
|
||||
@@ -169,23 +170,23 @@ en
|
||||
|
||||
com -nargs=0 Pencil call pencil#init({'wrap': 'on' })
|
||||
com -nargs=0 PencilOff call pencil#init({'wrap': 'off' })
|
||||
com -nargs=0 NoPencil call pencil#init({'wrap': 'off' })
|
||||
com -nargs=0 HardPencil call pencil#init({'wrap': 'hard'})
|
||||
com -nargs=0 PencilHard call pencil#init({'wrap': 'hard'})
|
||||
com -nargs=0 SoftPencil call pencil#init({'wrap': 'soft'})
|
||||
com -nargs=0 PencilSoft call pencil#init({'wrap': 'soft'})
|
||||
com -nargs=0 PencilToggle call pencil#init({'wrap': 'toggle'})
|
||||
com -nargs=0 TogglePencil call pencil#init({'wrap': 'toggle'})
|
||||
com -nargs=0 PFormat call pencil#setAutoFormat(1)
|
||||
com -nargs=0 PFormatOff call pencil#setAutoFormat(0)
|
||||
com -nargs=0 PFormatToggle call pencil#setAutoFormat(-1)
|
||||
|
||||
" NOTE: legacy commands will be disabled by default at some point
|
||||
" NOTE: legacy commands have been disabled by default as of 31-Dec-15
|
||||
if !exists('g:pencil#legacyCommands')
|
||||
let g:pencil#legacyCommands = 1
|
||||
let g:pencil#legacyCommands = 0
|
||||
en
|
||||
if g:pencil#legacyCommands
|
||||
com -nargs=0 HardPencil call pencil#init({'wrap': 'hard'})
|
||||
com -nargs=0 SoftPencil call pencil#init({'wrap': 'soft'})
|
||||
com -nargs=0 DropPencil call pencil#init({'wrap': 'off' })
|
||||
com -nargs=0 NoPencil call pencil#init({'wrap': 'off' })
|
||||
com -nargs=0 TogglePencil call pencil#init({'wrap': 'toggle'})
|
||||
com -nargs=0 AutoPencil call pencil#setAutoFormat(1)
|
||||
com -nargs=0 ManualPencil call pencil#setAutoFormat(0)
|
||||
com -nargs=0 ShiftPencil call pencil#setAutoFormat(-1)
|
||||
|
||||
Reference in New Issue
Block a user