Skip to content

Commit

Permalink
Canonicalize automap/doc spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate Soares committed Nov 16, 2012
1 parent ab091c6 commit bd85465
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 72 deletions.
96 changes: 47 additions & 49 deletions doc/viewport.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,64 +26,59 @@ Viewport makes your views better. It helps you:
=============================================================================
CONFIGURATION *viewport-config*

*g:viewport_loaded*
Use this to disable the plugin entirely: >
let g:viewport_loaded = 1
<

*g:viewport_filetypes*
This setting allows you to control automatic view creation by filetype. It's
a very versatile setting. It can be any of:
0: Disable completely.
1: Enable for all filetypes (default)
A whitelist: Enable for only the filetypes in this list.
A blackdict: Enable unless the filetype is in the dict with a 0 value.
0 Disable completely.
1 Enable for all filetypes
A whitelist Enable for only the filetypes in this list.
A blackdict Enable dict[filetype] is 0
Default: 1

*g:viewport_forbidden_files*
A list of regexes. Files which match the regex will not have views created.
The file will be fully expanded before the regex is used. Default: >
['^/dev/null$', '^/tmp']
<
The file will be fully expanded before the regex is used.
Default: ['^/dev/null$', '^/tmp']

*g:viewport_forbidden_settings*
A list of settings which, if set, signal that views should not be made.
Default: >
['diff']
<
Default: ['diff']

*g:viewport_forbidden_vars*
A list of variable names (given as strings), which, if existing and set,
signal that views should not be made. Default: >
['b:viewport_disable']
<
This allows you to set 'b:viewport_disable' in a file to locally disable
viewport.
signal that views should not be made.
Default: ['b:viewport_disable']

*g:viewport_automap*
Whether to make the default keybindings. See |viewport-mappings|.
Enables the default mappings when non-empty. See |viewport-mappings|.
If set to a letter, all mappings will be bound under <leader><letter>.
If set to 1, all mappings will be bound under <leader>v.
Default: 0

=============================================================================
COMMANDS *viewport-commands*

:ViewportClear[!] [settings] *:ViewportClear*
Clears views.

If used without [!] or [settings], it removes the view for the current
file. If used with [!] and without [settings], it removes all view
files. If used without [!] and with [settings], each setting in
[settings] is removed from the view file. The full name of the setting
must be given, i.e. 'tabstop' instead of 'ts'. If used with [!] and
with [settings], each setting in [settings] is removed from all view
files. This is very useful if you change your workflow and want to
remove settings from all view files, e.g. > :ViewportClear! autochdir
< will clear the 'autochdir' from all views, letting them default to
the global setting.
Clears a view file.

If [settings] is given it's used as a list of settings to clear from
the file instead of clearing the whole file entirely. Use the long
names of settings.

[!] makes the command apply to all views instead of just the current
file view.

Examples:
>
" Clear 'tabstop', 'shiftwidth', and 'expandtab' from all views
:ViewportClear! tabstop shiftwidth expandtab
" Remove this file's view
:ViewportClear
<
:ViewportClear only clears default (unnumbered) views. It assumes that
if you've made numbered views that those are for special purpose and
does not remove them.

TODO: Detect numbers in [settings] and remove numbered views.

=============================================================================
STATUSLINE *viewport-statusline*

Expand All @@ -102,34 +97,37 @@ viewport#statusline([{level}]) *viewport#statusline*
INFO:
'[no view]' if the file has no view.

We suggest something like the following in your statusline: >
We suggest something like the following in your statusline:
>
set statusline+=%#ModeMsg#
set statusline+=%{viewport#statusline(g:hume#0#MESSAGE)}
set statusline+=%#WarningMsg#
set statusline+=%{viewport#statusline(g:hume#0#INFO)}
set statusline+=%*
<
<
You are encouraged to customize this to your own needs. See
|viewport#views()| for help with customization.

=============================================================================
MAPPINGS *viewport-mappings*

Viewport does not set any mappings by default. We suggest something like the
following to your vimrc: >
" Delete this file's view
noremap <leader>vx :ViewportClear
" Delete all file's views
noremap <leader>vd :ViewportClear!
" Unset a setting globally.
noremap <leader>vu :ViewportClear! ¬
" Unset a setting in Only this view
noremap <leader>vo :ViewportClear ¬
following to your vimrc:
>
noremap <leader>vd :ViewportClear! " Delete all views
noremap <leader>ve :ViewportClear ¬ " Erase setting for file
noremap <leader>vu :ViewportClear! ¬ " Erase setting for all
noremap <leader>vx :ViewportClear " Delete view for file
<
NOTE: the '¬' marker should not be included, it is there to show you trailing
whitespace. In those commands you're supposed to type a setting which will be
cleared, e.g.
>
\vetabstop<CR>
<
Notice the '¬' marker. That should not be in your mappings, but rather shows
that you should have trailing whitespace in the line.
Do not include comments in your own mappings.

Notice also that none of these mappings end with <CR>. This helps prevent the
Notice that none of these mappings end with <CR>. This helps prevent the
accidental deletion of view files, as you'll have to type the key binding and
then press enter. If you don't want this safeguard, add <CR> to the end of the
first two mappings.
Expand Down
62 changes: 39 additions & 23 deletions plugin/viewport.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,40 @@ endif
let g:loaded_viewport = 1


" g:viewport_forbidden_files: A list of regexes which forbid certain files.
" g:viewport_forbidden_settings: A list of settings which prevent view creation.
" g:viewport_forbidden_vars: A list of vars which, if existing, signal a mode
" wherein views should not be created.
" g:viewport_filetypes: Enable/disable viewport by filetype.
" Enable/disable viewport by filetype.
" 0: Disable viewport completely.
" 1: Enable for all filetypes (default)
" [list]: Enable for only the filetypes in this list.
" {dict}: Enable unless the filetype is in the dict with a 0 value.
" g:viewport_autoview: Whether to automatically make views.
" g:viewport_automap: Whether to make the default keybindings
call hume#0#def('viewport', {
\ 'filetypes': 1,
\ 'forbidden_files': ['^/dev/null$', '^/tmp'],
\ 'forbidden_settings': ['diff'],
\ 'forbidden_vars': ['b:viewport_disable'],
\ 'automap': 0,
\ })
if !exists('g:viewport_filetypes')
let g:viewport_filetypes = 1
endif

" A list of regexes which forbid certain files.
if !exists('g:viewport_forbidden_files')
let g:viewport_forbidden_files = ['^/dev/null$', '^/tmp']
endif

" A list of settings which prevent view creation.
if !exists('g:viewport_forbidden_settings')
let g:viewport_forbidden_settings = ['diff']
endif

" A list of vars which, if existing, signal a mode
" wherein views should not be created.
if !exists('g:viewport_forbidden_vars')
let g:viewport_forbidden_vars = ['b:viewport_disable']
endif

" Whether to automatically make views.
if !exists('g:viewport_autoview')
let g:viewport_autoview = 1
endif

" Whether to make the default keybindings
if !exists('g:viewport_automap')
let g:viewport_automap = 0
endif


" The main Viewport command
Expand All @@ -43,13 +59,13 @@ if type(g:viewport_filetypes) != type(0) || g:viewport_filetypes
endif


if g:viewport_automap
" Delete this file's view
noremap <leader>vx :ViewportClear
" Delete all file's views
noremap <leader>vd :ViewportClear!
" *U*nset a setting globally.
noremap <leader>vu :ViewportClear!
" Unset a setting in *O*nly this view
noremap <leader>vo :ViewportClear
if !empty(g:viewport_automap)
if type(g:viewport_automap) == type(1)
let g:viewport_automap = 'v'
endif

exe 'noremap <leader>' . g:viewport_automap . 'd :ViewportClear!'
exe 'noremap <leader>' . g:viewport_automap . 'e :ViewportClear '
exe 'noremap <leader>' . g:viewport_automap . 'u :ViewportClear! '
exe 'noremap <leader>' . g:viewport_automap . 'x :ViewportClear'
endif

0 comments on commit bd85465

Please sign in to comment.