From 3013d6afbe4ca23de1571579082d325b44fef4d5 Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Wed, 18 Aug 2010 14:11:51 +0200 Subject: Add initial files. --- README.rst | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ build.py | 18 +++++++++++++++++ ftplugin/rst_tables.vim | 34 +++++++++++++++++++++++++++++++ src/base.vim | 28 ++++++++++++++++++++++++++ src/rst_tables.py | 6 ++++++ 5 files changed, 139 insertions(+) create mode 100644 README.rst create mode 100755 build.py create mode 100644 ftplugin/rst_tables.vim create mode 100644 src/base.vim create mode 100644 src/rst_tables.py 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 +" 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 c :call CreateTable() + endif + if !hasmapto('ReformatTable(') + noremap f :call ReformatTable() + 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 +" 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 c :call CreateTable() + endif + if !hasmapto('ReformatTable(') + noremap f :call ReformatTable() + 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 + + -- cgit v1.2.3