Permalink
Browse files

Added statusline function. Added write_without_statusline option.

Made docs & functions conform to vim styles.
  • Loading branch information...
1 parent e71accf commit eb9d3cd234b6583ad50ce24093579e49fc1e0bc1 @Soares committed Oct 12, 2012
Showing with 74 additions and 54 deletions.
  1. +22 −19 autoload/write.vim
  2. +42 −29 doc/write.txt
  3. +10 −6 plugin/write.vim
View
@@ -5,11 +5,14 @@ let g:write#autoloaded = 1
" Sets the buffer as writer-friendly.
-" Args:
-" {string} bang Whether or not to force full writing mode.
-function! write#On(bang)
+" @param {string} bang Whether or not to force full writing mode.
+function! write#start(bang)
setlocal spell wrap display+=lastline nolist linebreak
- if a:bang != '' || &tw == 0
+ if g:write_without_statusline
+ let b:write_laststatus_bak = &laststatus
+ set laststatus=0
+ endif
+ if !empty(a:bang) || &tw == 0
setlocal tw=0 nonu nornu
let b:writing=2
else
@@ -22,10 +25,13 @@ endfunction
" Unsets the buffer as writer-friendly.
" Will only undo changes that write.vim made.
-function! write#Off()
+function! write#stop()
if b:writing == 2
setlocal tw< nonu< nornu<
endif
+ if g:write_without_statusline
+ let &laststatus = b:write_laststatus_bak
+ endif
setlocal spell< wrap< display< list< linebreak<
let b:writing=0
silent! unmap <buffer> k
@@ -34,30 +40,27 @@ endfunction
" Toggles write mode.
-" Args:
-" {string} bang Whether or not to force full writing mode.
-function! write#Toggle(bang)
+" @param {string} bang Whether or not to force full writing mode.
+function! write#toggle(bang)
if exists('b:writing') && b:writing > 0
- call write#Off()
+ call write#stop()
else
- call write#On(bang)
+ call write#start(bang)
endif
endfunction
" Toggles writing mode only if writing has never been set for this buffer
-" Args:
-" {string} bang Whether or not to force full writing mode.
-function! write#Reenter(bang)
+" @param {string} bang Whether or not to force full writing mode.
+function! write#restart(bang)
if !exists('b:writing')
- call write#On(a:bang)
+ call write#start(a:bang)
endif
endfunction
-" Checks if write mode is on.
-" Returns:
-" Nonzero if and only if write mode is on.
-function! write#Writing()
- return b:writing
+" Makes a statusline flag if writin mode is on.
+" @return {string}
+function! write#statusline()
+ return b:writing ? '[W]' : ''
endfunction
View
@@ -1,45 +1,49 @@
-*write.txt* Get your author on.
-*write* *write.vim*
+*write.txt* Get your author on. *write* *write.vim*
Author: Nate Soares <http://so8r.es/>
License: Same terms as Vim itself (see |license|)
=============================================================================
-CONTENTS *write-contents*
- 1. Introduction................................|write-intro|
- 2. Configuration...............................|write-config|
- 3. Commands....................................|write-commands|
- 4. Extras......................................|write-extras|
- 5. About.......................................|write-about|
+CONTENTS *write-contents*
+ 1. Introduction..............................|write-intro|
+ 2. Configuration.............................|write-config|
+ 3. Commands..................................|write-commands|
+ 4. Status line...............................|write-statusline|
+ 5. Mappings..................................|write-mappings|
+ 6. Extras....................................|write-extras|
+ 7. About.....................................|write-about|
==============================================================================
-INTRODUCTION *write*
+INTRODUCTION *write-intro*
Vim writing mode, for writing non-code text (books, novels, etc.).
+GUI not required.
==============================================================================
-CONFIGURATION *write-commands*
+CONFIGURATION *write-commands*
*g:loaded_write*
Use this to disable the plugin entirely: >
let g:loaded_write = 1
<
+ *g:write_without_statusline*
+If true, disable the statusline while writing.
+This is enabled by default because |laststatus| can not be set locally. The
+statusline will be turned off for all windows. This may be disorienting.
+If you want the statusline off only when the writing window is the only
+window you should 'set laststatus=1' instead.
*g:write_auto*
A list of filetypes that should automatically go into write mode. If the
filetype string ends with a '!', that filetype will automatically go into full
write mode. For example: >
let g:write_auto=['markdown', 'help', 'text!']
<
-Will set up autocommands on markdown, help, and text files to put them into
-write mode, and text files will be forced into full write mode regardless of
-|textwidth| settings.
-
==============================================================================
-COMMANDS *write-commands*
+COMMANDS *write-commands*
- *:WriteOn[!]*
+:WriteOn[!] *:WriteOn*
Turn writing mode on. Effects include:
* Spell checking
@@ -49,12 +53,11 @@ Turn writing mode on. Effects include:
In addition, if |textwidth| is off then line numbers are turned off and soft
wrapping is turned on. If you want hard line wrapping set 'textwidth' to
-a non-zero value before calling WriteOn.
+before calling :WriteOn.
If you want to force soft wrapping despite the value of 'textwidth', use: >
:WriteOn!
<
-
If you want |textwidth| automatically managed by filetype, check out the
|longlines| plugin at <http://github.com/Soares/longlines.vim>.
@@ -71,23 +74,33 @@ that differed from the global value, writer.vim will clobber those settings.
Toggles writing mode. The bang, if given, will be passed to |:WriteOn|
==============================================================================
-EXTRAS *write-extras*
+STATUSLINE *write-statusline*
-Status Line *write#Writing*
- *write-statusline*
-Returns non-zero if writing mode is on. Useful for statusline flags. We
-recommend adding something like >
+ *write#statusline()*
+Returns '[W]' if write mode is on, '' otherwise. Perfect for use in
+a statusline. Use >
set statusline+=%#ModeMsg#
- set statusline+=%{write#Writing()?'[W]':''}
+ set statusline+=%{write#statusline()}
set statusline+=%*
<
-to your statusline.
+to add this flag to your statuslien.
+
+==============================================================================
+MAPPINGS *write-mappings*
-Mappings *write-mappings*
-Write.vim does not provide mappings for you. You'll have to set them yourself.
-We suggest something along the lines of: >
- noremap <leader>W :Write<CR>
+Write.vim does not change your mappings by default. We suggest something along
+the lines of >
+ noremap <leader>w :Write<CR>
<
+Consider using |g:write_auto| to automatically enable writing mode for certain
+filetypes. It's more effective than such a key mapping.
+
+==============================================================================
+EXTRAS *write-extras*
+
+You may check the 'b:writing' variable to see if writing mode is currently
+enabled. You can use this to write your own statusline functions if you do not
+like the style of |write#statusline()|.
==============================================================================
ABOUT *write-about*
View
@@ -1,32 +1,36 @@
" write.vim: Get your author on.
-"
" Author: Nate Soares <http://so8r.es>
" Version: 1.0
" License: The same as vim itself. (See |license|)
" GetLatestVimScripts: 4249 1 :AutoInstall: write.zip
-
if exists('g:loaded_write') || &cp || v:version < 700
finish
endif
let g:loaded_write = 1
-command! -bang WriteOn call write#On('<bang>')
-command! WriteOff call write#Off()
-command! -bang Write call write#Toggle('<bang>')
+if !exists('g:write_without_statusline')
+ let g:write_without_statusline = 0
+endif
if !exists('g:write_auto')
let g:write_auto = []
endif
+
+command! -bang WriteOn call write#start('<bang>')
+command! WriteOff call write#stop()
+command! -bang Write call write#toggle('<bang>')
+
+
if len(g:write_auto) > 0
augroup write
autocmd!
for s:ft in g:write_auto
let s:bang = s:ft =~# '!$' ? "'!'" : "''"
let s:ft = substitute(s:ft, '!$', '', '')
- exe 'autocmd FileType '.s:ft.' call write#Reenter('.s:bang.')'
+ exe 'autocmd FileType '.s:ft.' call write#restart('.s:bang.')'
endfor
augroup end
endif

0 comments on commit eb9d3cd

Please sign in to comment.