Permalink
Browse files

Implemented delayed loading and write#Writing

  • Loading branch information...
1 parent f597d12 commit 708763bac9d409c89debc9dfa288ebb73a9027d2 @Soares committed Oct 4, 2012
Showing with 66 additions and 58 deletions.
  1. +41 −0 autoload/write.vim
  2. +25 −28 doc/write.txt
  3. +0 −30 plugin/write.vim
View
@@ -0,0 +1,41 @@
+if exists("g:write#autoloaded") || &cp || v:version < 700
+ finish
+endif
+let g:write#autoloaded = 1
+
+
+" Sets the buffer as writer-friendly.
+function! write#On()
+ let b:writing=1
+ setlocal spell wrap linebreak display+=lastline nonu nornu nolist
+ noremap <buffer> <silent> k gk
+ noremap <buffer> <silent> j gj
+endfunction
+
+
+" Unsets the buffer as writer-friendly.
+" Will only undo changes that write.vim made.
+function! write#Off()
+ let b:writing=0
+ setlocal spell< wrap< linebreak< display< nu< rnu< list<
+ silent! unmap <buffer> k
+ silent! unmap <buffer> j
+endfunction
+
+
+" Toggles write mode.
+function! write#Toggle()
+ if exists('b:writing') && b:writing > 0
+ call write#Off()
+ else
+ call write#On()
+ endif
+endfunction
+
+
+" Checks if write mode is on.
+" Returns:
+" Nonzero if and only if write mode is on.
+function! write#Writing()
+ return b:writing
+endfunction
View
@@ -3,48 +3,45 @@
Author: Nate Soares <http://so8r.es/>
License: Same terms as Vim itself (see |license|)
+==============================================================================
INTRODUCTION *write*
Vim writing mode, for writing non-code text (books, novels, etc.).
-COMMANDS *write-commands*
-
- *write-:WriteOn*
-:WriteOn Turn writing mode on. This does the following:
- - soft wrap lines
- - make j & k navigate screenwise, not linewise
- - turn selling on
- - turn line numbers off
- As well as a few other tweaks that make writing easier.
-
-
- *write-:WriteOff*
-:WriteOff Turn writing mode off. Resets all values changed by
- :WriteOn (which are changed locally) to the global
- values.
-
- *write-:Write*
-:Write Toggles writing mode.
+==============================================================================
+COMMANDS *write-commands*
+ *:WriteOn*
Turn writing mode on. This does the following:
+- soft wrap lines
+- make j & k navigate screenwise, not linewise
+- turn spelling on
+- turn line numbers off
+As well as a few other tweaks that make writing easier.
-FUNCTIONS *write-Functions*
+ *:WriteOff*
+Turn writing mode off. Resets all values changed by :WriteOn (which are
+changed locally) to the global values.
- *write#On*
-write#On Turn writing mode on.
+ *:Write*
+Toggles writing mode.
- *write#Off*
-write#Off Turn writing mode off.
- *write#Toggle*
-write#Toggle Toggle writing mode.
+==============================================================================
+EXTRAS *write-extras*
- *write#Writing*
-write#Writing True if writing mode is activated.
- Useful for statusline flags and/or other plugins.
+ *write#Writing*
+True if writing mode is on. Useful for statusline flags. We recommend adding
+something like >
+ set statusline+=%#ModeMsg#
+ set statusline+=%{write#Writing()?'[W]':''}
+ set statusline+=%*
+<
+to your statusline.
+==============================================================================
ABOUT *write-about*
Grab the latest version or report a bug on GitHub:
View
@@ -10,36 +10,6 @@ if exists("g:loaded_write") || &cp || v:version < 700
endif
let g:loaded_write = 1
-let g:write_writing = 0
-
-" Sets the buffer as writer-friendly.
-function! write#On()
- let g:write_writing=1
- setlocal wrap linebreak nolist
- setlocal display+=lastline
- noremap <buffer> <silent> k gk
- noremap <buffer> <silent> j gj
- setlocal spell nornu nonu
-endfunction
command! WriteOn call write#On()
-
-" Unsets the buffer as writer-friendly.
-" Will only undo changes that write.vim made.
-function! write#Off()
- let g:write_writing=0
- setlocal wrap< linebreak< nolist< display<
- silent! unmap <buffer> k
- silent! unmap <buffer> j
- setlocal spell< rnu< nu<
-endfunction
command! WriteOff call write#Off()
-
-" Toggles write mode.
-function! write#Toggle()
- if g:write_writing
- call write#Off()
- else
- call write#On()
- endif
-endfunction
command! Write call write#Toggle()

0 comments on commit 708763b

Please sign in to comment.