Permalink
Browse files

Initial commit.

  • Loading branch information...
0 parents commit 67d8bd7f936fb0527ad8062a04a3657ac3ffa5e9 @mikewest committed Oct 31, 2010
Showing with 83 additions and 0 deletions.
  1. +12 −0 LICENSE.markdown
  2. +4 −0 README.markdown
  3. +67 −0 plugin/vimroom.vim
12 LICENSE.markdown
@@ -0,0 +1,12 @@
+Copyright (c) 2010 Mike West, http://mikewest.org/
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+
+Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+
+Neither the name of the software nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 README.markdown
@@ -0,0 +1,4 @@
+Vimroom
+=======
+
+Readme goes here.
67 plugin/vimroom.vim
@@ -0,0 +1,67 @@
+"============================================================================
+"File: vimroom.vim
+"Description: Vaguely emulates a writeroom-like environment in Vim by
+" splitting the current window in such a way as to center a column
+" of user-specified width, wrap the text, and break lines.
+"Maintainer: Mike West <mike@mikewest.org>
+"Version: 0.1
+"Last Change: 2010-10-31
+"License: BSD <../LICENSE.markdown>
+"============================================================================
+
+" The typical start to any vim plugin: If the plugin has already been loaded,
+" exit as quickly as possible.
+if exists( "g:loaded_vimroom_plugin" )
+ finish
+endif
+let g:loaded_vimroom_plugin = 1
+
+" The desired column width. Defaults to 80:
+if !exists( "g:vimroom_width" )
+ let g:vimroom_width = 80
+endif
+
+" The minimum sidebar size. Defaults to 5:
+if !exists( "g:vimroom_min_sidebar_width" )
+ let g:vimroom_min_sidebar_width = 5
+endif
+
+" The background color. Defaults to "black"
+if !exists( "g:vimroom_background" )
+ let g:vimroom_background = "black"
+endif
+
+
+" Given the desired column width, and minimum sidebar width, determine
+" the minimum window width necessary for splitting to make sense
+let s:minwidth = g:vimroom_width + ( g:vimroom_min_sidebar_width * 2 )
+
+function! s:is_the_screen_wide_enough()
+ return winwidth( winnr() ) >= s:minwidth
+endfunction
+
+function! s:sidebar_size()
+ return ( winwidth( winnr() ) - g:vimroom_width - 2 ) / 2
+endfunction
+
+function! <SID>Vimroomize()
@FND
FND added a line comment Nov 4, 2010

Why make this inaccessible? I'd quite like to add a command (to my .vimrc) that invokes VimRoom rather than using a mapping.

@mikewest
Owner
mikewest added a line comment Nov 4, 2010

Can your command invoke <Plug>Vimroomize? I was thinking of that as the "public API", so to speak... but if it doesn't work for you for whatever reason, I can flip things around. :)

@FND
FND added a line comment Nov 4, 2010

I'd tried that (:<Plug>Vimroomize): "E488: Trailing characters"
Perhaps I'm misunderstanding this (Vim scripting fu is weak), but I thought <Plug> was internal to the respective script?

@mikewest
Owner
mikewest added a line comment Nov 4, 2010

<Plug> isn't internal to the script. <SID> is script-specific, <Plug> is just a character that you can't type, generally used to prefix plugin API functions.

Can you throw the command you're writing in your .vimrc into a gist? I guess I'm just not understanding what you're trying to do. :)

@FND
FND added a line comment Nov 4, 2010

It's really as simple as this:

$ grep Vimroom ~/.vimrc
command VRoom <Plug>Vimroomize

Then, when invoking :VRoom, I get "E492: Not an editor command: <80><fd>QVimroomize" (I got a different error when invoking :<Plug>Vimroomize manually before).

Things are a bit more complicated in my actual .vimrc:
FND/homedir@1926e0a
(granted, I'm a bit insane - but I had tested the above with VimRoom as a regular plugin)

What I'd want there is something like:

command Room call LoadPlugin("vimroom") | Vimroomize
@mikewest
Owner
mikewest added a line comment Nov 5, 2010

As I'm stuck at home for a variety of reasons, I'll take a look at this tonight. :)

@mikewest
Owner
mikewest added a line comment Nov 5, 2010

I think you're right... I can't figure out how to use the <Plug> syntax to call the function without a mapping.

I'll play with it a tiny bit more tomorrow (because I still have the vague impression that it's somehow The Right Way™), but I'll probably end up just opening up the plugin a bit. I'll let you know. :)

@mikewest
Owner
mikewest added a line comment Nov 6, 2010

In v0.4, I've added :VimroomToggle (and changed the <Plug> mapping name to match...). I hope that works for you!

@FND
FND added a line comment Nov 6, 2010

Works great - thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ if s:is_the_screen_wide_enough()
+ let s:sidebar = s:sidebar_size()
+ exec( "leftabove " . s:sidebar . "vsplit new" )
+ wincmd l
+ exec( "rightbelow " . s:sidebar . "vsplit new" )
+ wincmd h
+ set wrap
+ set linebreak
+ exec( "hi VertSplit ctermbg=" . g:vimroom_background . " ctermfg=" . g:vimroom_background . " guifg=" . g:vimroom_background . " guibg=" . g:vimroom_background )
+ set fillchars+=vert:\
+ endif
+endfunction
+
+" Create a mapping for the `Vimroomize` function
+noremap <silent> <Plug>Vimroomize :call <SID>Vimroomize()<CR>
+
+" If no mapping exists, map it to `<Leader>V`.
+if !hasmapto( '<Plug>Vimroomize' )
+ nmap <silent> <Leader>V <Plug>Vimroomize
+endif

0 comments on commit 67d8bd7

Please sign in to comment.