Added rough asciidoc support, per #25

See the ticket for current limitations.

Also improved README.
This commit is contained in:
Reed Esau
2015-01-10 01:48:07 -07:00
parent b60e5ba728
commit ad195ab208
3 changed files with 51 additions and 39 deletions

View File

@@ -8,8 +8,8 @@
![demo](http://i.imgur.com/0KYl5vU.gif) ![demo](http://i.imgur.com/0KYl5vU.gif)
- - - - - -
[Note: demo will be updated soon with the _newly_ renamed commands (see [Note: demo above needs to be updated with the _recently_ renamed
below), but the legacy ones still work.] commands (see below), but the legacy ones shown still work.]
# Features # Features
@@ -17,15 +17,16 @@ The _pencil_ plugin aspires to make Vim as powerful a tool for writers as
it is for coders by focusing narrowly on the handful of tweaks needed to it is for coders by focusing narrowly on the handful of tweaks needed to
smooth the path to writing prose. smooth the path to writing prose.
* For editing prose-oriented file types such as _text_, _markdown_, _mail_, * For editing prose-oriented file types such as _text_, _markdown_,
_rst_, _tex_, and _textile_. _mail_, _rst_, _tex_, _textile_, and _asciidoc_.
* Agnostic on soft line wrap _versus_ hard line breaks, supporting both * Agnostic on soft line wrap _versus_ hard line breaks, supporting both
* Auto-detects wrap mode via modeline and sampling * Auto-detects wrap mode via `modeline` and sampling
* Adjusts navigation key mappings to suit the wrap mode * Adjusts navigation key mappings to suit the wrap mode
* Creates undo points on common punctuation during Insert mode, including * Creates undo points on common punctuation during Insert mode, including
deletion via line `<C-U>` and word `<C-W>` deletion via line `<C-U>` and word `<C-W>`
* When using hard line breaks, enables autoformat while inserting text, except * When using hard line breaks, _pencil_ enables Vims autoformat while
for tables and code blocks where you wont want it inserting text, except for tables and code blocks where you wont want
it
* Buffer-scoped configuration (with a few minor exceptions, _pencil_ preserves * Buffer-scoped configuration (with a few minor exceptions, _pencil_ preserves
your global settings) your global settings)
* Support for Vims Conceal feature to hide markup defined by Syntax plugins * Support for Vims Conceal feature to hide markup defined by Syntax plugins
@@ -75,14 +76,14 @@ tool in expressing yourself. For more details on vi-style editing, see...
# Installation # Installation
Install using Vundle, vim-plug, NeoBundle, Pathogen, or your favorite Vim _pencil_ is best installed using a Vim package manager, such as Vundle,
package manager. Plug, NeoBundle, or Pathogen.
_For those new to Vim: before installing this plugin, consider getting _For those new to Vim: before installing this plugin, consider getting
comfortable with the basics of Vim by working through one of the many comfortable with the basics of Vim by working through one of the many
tutorials available._ tutorials available._
## Vundle #### Vundle
Add to your `.vimrc` and save: Add to your `.vimrc` and save:
@@ -99,7 +100,7 @@ Plugin 'reedes/vim-pencil'
For Vundle version < 0.10.2, replace `Plugin` with `Bundle` above. For Vundle version < 0.10.2, replace `Plugin` with `Bundle` above.
## vim-plug #### Plug
Add to your `.vimrc` and save: Add to your `.vimrc` and save:
@@ -114,7 +115,7 @@ Plug 'reedes/vim-pencil'
:PlugInstall :PlugInstall
``` ```
## NeoBundle #### NeoBundle
Add to your `.vimrc` and save: Add to your `.vimrc` and save:
@@ -129,7 +130,7 @@ NeoBundle 'reedes/vim-pencil'
:NeoBundleInstall :NeoBundleInstall
``` ```
## Pathogen #### Pathogen
Run the following in a terminal: Run the following in a terminal:
@@ -140,7 +141,10 @@ git clone https://github.com/reedes/vim-pencil
# Configuration # Configuration
## Basic configuration ## Basic initialization
Though optional, initializing _pencil_ by `FileType` will automatically
set up your buffers for editing prose.
Add support for your desired filetypes to your `.vimrc`: Add support for your desired filetypes to your `.vimrc`:
@@ -160,11 +164,11 @@ You can initialize several prose-oriented plugins together:
```vim ```vim
augroup pencil augroup pencil
autocmd! autocmd!
autocmd FileType markdown,mkd call pencil#init() | autocmd FileType markdown,mkd call pencil#init()
\ call lexical#init() | \ | call lexical#init()
\ call litecorrect#init() | \ | call litecorrect#init()
\ call textobj#quote#init() | \ | call textobj#quote#init()
\ call textobj#sentence#init() \ | call textobj#sentence#init()
augroup END augroup END
``` ```
@@ -184,7 +188,7 @@ In most cases you can set a default to suit your preference and let
auto-detection figure out what to do. auto-detection figure out what to do.
```vim ```vim
let g:pencil#wrapModeDefault = 'soft' " or 'hard' let g:pencil#wrapModeDefault = 'soft' " default is 'hard'
augroup pencil augroup pencil
autocmd! autocmd!
@@ -203,15 +207,15 @@ if auto-detect might suggest soft line wrap.
You can enable, disable, and toggle _pencil_ as a command: You can enable, disable, and toggle _pencil_ as a command:
* `Pencil` - enable pencil with auto-detection * `Pencil` - initialize _pencil_ with auto-detect for the current buffer
* `PencilOff` - removes navigation mappings and restores buffer to global settings * `PencilOff` - removes navigation mappings and restores buffer to global settings
* `PencilToggle` - if on, turns off; if off, enables with detection * `PencilToggle` - if on, turns off; if off, initializes with auto-detect
Because auto-detect might not work as intended, you can invoke a command Because auto-detect might not work as intended, you can invoke a command
to set the behavior for the current buffer: to set the behavior for the current buffer:
* `PencilSoft` - enable soft line wrap mode * `PencilSoft` - initialize _pencil_ with soft line wrap mode
* `PencilHard` - enable hard line break mode * `PencilHard` - initialize _pencil_ with hard line break mode (and autoformat)
## Automatic formatting ## Automatic formatting
@@ -233,13 +237,6 @@ Where you need to manually enable/disable autoformat, you can do so with a comma
* `PFormatOff` - disables autoformat * `PFormatOff` - disables autoformat
* `PFormatToggle` - toggle to enable if disabled, etc. * `PFormatToggle` - toggle to enable if disabled, etc.
Or optionally map the toggle command to a key of your choice in your
`.vimrc`:
```vim
nnoremap <silent> <leader>p :PFormatToggle<cr>
```
To set the default behavior, add to your `.vimrc`: To set the default behavior, add to your `.vimrc`:
```vim ```vim
@@ -460,6 +457,12 @@ let g:pencil#autoformat_blacklist = [
\ 'texRefZone', \ 'texRefZone',
\ 'texSection$', \ 'texSection$',
\ 'texTitle', \ 'texTitle',
\ 'asciidocAttribute',
\ 'asciidocList',
\ 'asciidocLiteral',
\ 'asciidoc[A-Za-z]*Block',
\ 'asciidoc[A-Za-z]*Macro',
\ 'asciidoc[A-Za-z]*Title',
\ ] \ ]
``` ```
@@ -482,14 +485,14 @@ 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 ```html
<!-- vim: set tw=74 :--> <!-- vim: set tw=73 :-->
``` ```
This is an **optional** modeline that tells Vim to run the following This is an **optional** modeline that tells Vim to run the following
command upon loading the file into a buffer: command upon loading the file into a buffer:
```vim ```vim
:set textwidth=74 :set textwidth=73
``` ```
It tells _pencil_ to assume hard line breaks, regardless of whether or It tells _pencil_ to assume hard line breaks, regardless of whether or
@@ -591,7 +594,7 @@ with its own Markdown variant.
# Future development # Future development
If youve spotted a problem or have an idea on improving this plugin, If youve spotted a problem or have an idea on improving this plugin,
please post it to the github project issue page. please post it to the github project issue page or submit a pull request.
``` ```
<!-- vim: set tw=73 :--> <!-- vim: set tw=73 :-->

View File

@@ -99,9 +99,11 @@ fun! s:maybe_enable_autoformat()
" which we DO want autoformat to be enabled (e.g., " which we DO want autoformat to be enabled (e.g.,
" tpope's markdownCode) " tpope's markdownCode)
if !l:okay_to_enable if !l:okay_to_enable
" one final check for an empty stack at the start of the line " 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 if !l:found_empty
if synstack(l:line, 1) == [] if synstack(l:line, 1) == [] ||
\ (l:last_col > 2 && synstack(l:line, l:last_col-1) == [])
let l:found_empty = 1 let l:found_empty = 1
en en
en en
@@ -139,7 +141,7 @@ fun! pencil#setAutoFormat(af)
sil! au! pencil_autoformat * <buffer> sil! au! pencil_autoformat * <buffer>
if l:nu_af && !l:is_hard if l:nu_af && !l:is_hard
echohl WarningMsg echohl WarningMsg
echo "autoformat can only be enabled in hard break line mode" echo "autoformat can only be enabled in hard line break mode"
echohl NONE echohl NONE
return return
en en

View File

@@ -66,8 +66,7 @@ if !exists('g:pencil#autoformat_blacklist')
" markdownFencedCodeBlock, markdownInlineCode, markdownRule, markdownH[0-9] (gabrielelana/vim-markdown) " markdownFencedCodeBlock, markdownInlineCode, markdownRule, markdownH[0-9] (gabrielelana/vim-markdown)
" mmdTable[A-Za-z0-9]* (mattly/vim-markdown-enhancements) " mmdTable[A-Za-z0-9]* (mattly/vim-markdown-enhancements)
" txtCode (timcharper/textile.vim) " txtCode (timcharper/textile.vim)
" rst* (syntax file shipped with vim) " rst*,tex*,asciidoc* (syntax file shipped with vim)
" tex* (syntax file shipped with vim)
let g:pencil#autoformat_blacklist = [ let g:pencil#autoformat_blacklist = [
\ 'markdownCode', \ 'markdownCode',
\ 'markdownH[0-9]', \ 'markdownH[0-9]',
@@ -96,6 +95,12 @@ if !exists('g:pencil#autoformat_blacklist')
\ 'texRefZone', \ 'texRefZone',
\ 'texSection$', \ 'texSection$',
\ 'texTitle', \ 'texTitle',
\ 'asciidocAttribute',
\ 'asciidocList',
\ 'asciidocLiteral',
\ '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 =
@@ -109,6 +114,8 @@ if !exists('g:pencil#autoformat_inline_whitelist')
let g:pencil#autoformat_inline_whitelist = [ let g:pencil#autoformat_inline_whitelist = [
\ 'markdownCode', \ 'markdownCode',
\ 'markdownLink', \ 'markdownLink',
\ 'asciidocMacro',
\ 'asciidocQuotedMonospaced',
\ ] \ ]
en en
let g:pencil#autoformat_inline_whitelist_re = let g:pencil#autoformat_inline_whitelist_re =