diff options
-rw-r--r-- | README.rst | 53 | ||||
-rwxr-xr-x | build.py | 18 | ||||
-rw-r--r-- | ftplugin/rst_tables.vim | 34 | ||||
-rw-r--r-- | src/base.vim | 28 | ||||
-rw-r--r-- | src/rst_tables.py | 6 |
5 files changed, 139 insertions, 0 deletions
diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..c1e77fc --- /dev/null +++ b/README.rst @@ -0,0 +1,53 @@ +Installation +------------ +1. Install the following packages from PyPI: + + - vim_bridge_: This is required for the vim plugin scripts, to call + directly into Python functions. + +2. Clone the git repository:: + + git clone git://github.com/nvie/vim-rst-tables.git + cd vim-rst-tables + +3. Copy the file ``ftplugin/rst_tables.vim`` to your ``~/.vim/ftplugin`` + directory + +.. _vim_bridge: http://pypi.python.org/pypi/vim_bridge + + +Usage +----- +1. Open a reStructuredText file +2. Create some kind of table outline + + .. code_block:: rst + This is paragraph text *before* the table. + + Column 1 Column 2 + Foo Put two (or more) spaces as a field separator. + Bar Even very very long lines like these are fine, as long as you do not put in line endings here. + Qux This is the last line. + + This is paragraph text *after* the table. + +2. Put your cursor somewhere in the table. +3. Press ``,,c`` (to create the table). The output will look something like + this: + + .. code_block:: rst + This is paragraph text *before* the table. + + +==========+=========================================================+ + | Column 1 | Column 2 | + +==========+=========================================================+ + | Foo | Put two (or more) spaces as a field separator. | + +----------+---------------------------------------------------------+ + | Bar | Even very very long lines like these are fine, as long | + | | as you do not put in line endings here. | + +----------+---------------------------------------------------------+ + | Qux | This is the last line. | + +----------+---------------------------------------------------------+ + + This is paragraph text *after* the table. + diff --git a/build.py b/build.py new file mode 100755 index 0000000..a700549 --- /dev/null +++ b/build.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python +import os + +source_dir = 'src' +output_dir = 'ftplugin' + + +def build(): + py_src = file(os.path.join(source_dir, 'rst_tables.py')).read() + vim_src = file(os.path.join(source_dir, 'base.vim')).read() + combined_src = vim_src.replace('__PYTHON_SOURCE__', py_src) + if not os.path.exists(output_dir): + os.mkdir(output_dir) + output_path = os.path.join(output_dir, 'rst_tables.vim') + file(output_path, 'w').write(combined_src) + +if __name__ == '__main__': + build() diff --git a/ftplugin/rst_tables.vim b/ftplugin/rst_tables.vim new file mode 100644 index 0000000..c847c70 --- /dev/null +++ b/ftplugin/rst_tables.vim @@ -0,0 +1,34 @@ +" +" reStructuredText tables plugin +" Language: Python (ft=python) +" Maintainer: Vincent Driessen <vincent@datafox.nl> +" Version: Vim 7 (may work with lower Vim versions, but not tested) +" URL: http://github.com/nvie/vim-rst-tables +" + +" Only do this when not done yet for this buffer +if exists("g:loaded_rst_tables_ftplugin") + finish +endif +let loaded_rst_tables_ftplugin = 1 + +python << endpython +import vim +import os +import os.path +from vim_bridge import bridged + + + +endpython + +" Add mappings, unless the user didn't want this. +" The default mapping is registered, unless the user remapped it already. +if !exists("no_plugin_maps") && !exists("no_rst_table_maps") + if !hasmapto('CreateTable(') + noremap <silent> <leader><leader>c :call CreateTable()<CR> + endif + if !hasmapto('ReformatTable(') + noremap <silent> <leader><leader>f :call ReformatTable()<CR> + endif +endif diff --git a/src/base.vim b/src/base.vim new file mode 100644 index 0000000..fc30e05 --- /dev/null +++ b/src/base.vim @@ -0,0 +1,28 @@ +" +" reStructuredText tables plugin +" Language: Python (ft=python) +" Maintainer: Vincent Driessen <vincent@datafox.nl> +" Version: Vim 7 (may work with lower Vim versions, but not tested) +" URL: http://github.com/nvie/vim-rst-tables +" + +" Only do this when not done yet for this buffer +if exists("g:loaded_rst_tables_ftplugin") + finish +endif +let loaded_rst_tables_ftplugin = 1 + +python << endpython +__PYTHON_SOURCE__ +endpython + +" Add mappings, unless the user didn't want this. +" The default mapping is registered, unless the user remapped it already. +if !exists("no_plugin_maps") && !exists("no_rst_table_maps") + if !hasmapto('CreateTable(') + noremap <silent> <leader><leader>c :call CreateTable()<CR> + endif + if !hasmapto('ReformatTable(') + noremap <silent> <leader><leader>f :call ReformatTable()<CR> + endif +endif diff --git a/src/rst_tables.py b/src/rst_tables.py new file mode 100644 index 0000000..4fd8d0f --- /dev/null +++ b/src/rst_tables.py @@ -0,0 +1,6 @@ +import vim +import os +import os.path +from vim_bridge import bridged + + |