summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-06-28 12:38:12 +0100
committerJohn Wiegley <johnw@newartisans.com>2009-06-28 12:38:12 +0100
commit6fbce9dd1aefb08b42a4f800e7c702679f39d6d5 (patch)
tree5330fc7fedb4f6b8ced051efbe156ce4ef05f504
parentd0c47b1bc2dd963652ca97d534ed0e3a2f23db9f (diff)
parent1d8111b43c8c7c355bb45c9c1973e05f885b0603 (diff)
downloadfork-ledger-6fbce9dd1aefb08b42a4f800e7c702679f39d6d5.tar.gz
fork-ledger-6fbce9dd1aefb08b42a4f800e7c702679f39d6d5.tar.bz2
fork-ledger-6fbce9dd1aefb08b42a4f800e7c702679f39d6d5.zip
Merge commit 'kljohann/master' into next
-rw-r--r--contrib/vim/README57
-rw-r--r--contrib/vim/ftplugin/ledger.vim27
-rw-r--r--contrib/vim/syntax/ledger.vim2
3 files changed, 80 insertions, 6 deletions
diff --git a/contrib/vim/README b/contrib/vim/README
new file mode 100644
index 00000000..7c56f6da
--- /dev/null
+++ b/contrib/vim/README
@@ -0,0 +1,57 @@
+
+This is the ledger filetype for vim.
+Copy each file to the corresponding directory in your ~/.vim directory.
+Then include the following line in your .vimrc or in ~/.vim/filetype.vim
+ au BufNewFile,BufRead *.ldg,*.ledger setf ledger
+You can also use a modeline like this in every ledger file
+ vim:filetype=ledger
+
+Configuration
+======================================================================
+Include the following let-statements somewhere in your .vimrc
+to modify the behaviour of the ledger filetype.
+
+Number of colums that will be used to display the foldtext.
+Set this when you think that the amount is too far off to the right.
+let g:ledger_maxwidth = 80
+
+String that will be used to fill the space between account name
+and amount in the foldtext. Set this to get some kind of lines
+or visual aid.
+let g:ledger_fillstring = ' -'
+
+Revision history
+======================================================================
+ 2009-06-17 J. Klähn: Highlight account text
+ Updated documentation and added fillstring option.
+ 2009-06-15 J. Klähn: Split into multiple files
+ 2009-06-12 J. Klähn: Use all available columns for foldtext
+ Also rewrote foldtext generation.
+ 2009-03-25 J. Klähn: Allow Metadata
+ in transactions and postings (Ledger 3.0)
+ Also fixed alignment for multi-byte-characters
+ 2009-01-28 S.Karrmann: minor fixes
+ 2009-01-27 third version by S.Karrmann.
+ better extraction of the amount of the posting
+ decimal separator can be one of '.' and ','.
+ 2005-02-05 first version (partly copied from ledger.vim 0.0.1)
+
+License
+=======
+Copyright 2009 by Johann Klähn
+Copyright 2009 by Stefan Karrmann
+Copyright 2005 by Wolfgang Oertl
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+
diff --git a/contrib/vim/ftplugin/ledger.vim b/contrib/vim/ftplugin/ledger.vim
index cef0d81e..a2a4c468 100644
--- a/contrib/vim/ftplugin/ledger.vim
+++ b/contrib/vim/ftplugin/ledger.vim
@@ -1,4 +1,4 @@
-" Vimwiki filetype plugin file
+" Vim filetype plugin file
" filetype: ledger
" Version: 0.1.0
" by Johann Klähn; Use according to the terms of the GPL>=2.
@@ -12,7 +12,7 @@ let b:did_ftplugin = 1
let b:undo_ftplugin = "setlocal ".
\ "foldmethod< foldtext< ".
- \ "include< comments< "
+ \ "include< comments< iskeyword< "
" don't fill fold lines --> cleaner look
setl fillchars="fold: "
@@ -20,6 +20,10 @@ setl foldtext=LedgerFoldText()
setl foldmethod=syntax
setl include=^!include
setl comments=b:;
+" so you can use C-X C-N completion on accounts
+" FIXME: Does not work with something like:
+" Assets:Accountname with Spaces
+setl iskeyword+=:
" You can set a maximal number of columns the fold text (excluding amount)
" will use by overriding g:ledger_maxwidth in your .vimrc.
@@ -29,6 +33,10 @@ if !exists('g:ledger_maxwidth')
let g:ledger_maxwidth = 0
endif
+if !exists('g:ledger_fillstring')
+ let g:ledger_fillstring = ' '
+endif
+
let s:rx_amount = '\('.
\ '\%([0-9]\+\)'.
\ '\%([,.][0-9]\+\)*'.
@@ -49,9 +57,7 @@ function! LedgerFoldText() "{{{1
if line !~ '^\s\+;'
" No comment, look for amount...
let groups = matchlist(line, s:rx_amount)
- echomsg string(groups)
if ! empty(groups)
- echomsg amount
let amount = groups[1]
break
endif
@@ -73,7 +79,18 @@ function! LedgerFoldText() "{{{1
" add spaces so the text is always long enough when we strip it
" to a certain width (fake table)
- let foldtext .= repeat(' ', s:get_columns(0))
+ if strlen(g:ledger_fillstring)
+ " add extra spaces so fillstring aligns
+ let filen = s:multibyte_strlen(g:ledger_fillstring)
+ let folen = s:multibyte_strlen(foldtext)
+ let foldtext .= repeat(' ', filen - (folen%filen))
+
+ let foldtext .= repeat(g:ledger_fillstring,
+ \ s:get_columns(0)/filen)
+ else
+ let foldtext .= repeat(' ', s:get_columns(0))
+ endif
+
" we don't use slices[:5], because that messes up multibyte characters
let foldtext = substitute(foldtext, '.\{'.columns.'}\zs.*$', '', '')
diff --git a/contrib/vim/syntax/ledger.vim b/contrib/vim/syntax/ledger.vim
index 1c1968e4..8914cf2a 100644
--- a/contrib/vim/syntax/ledger.vim
+++ b/contrib/vim/syntax/ledger.vim
@@ -33,7 +33,7 @@ syn match Metadata /^\s\+;.*/ contained
syn match Comment /^;.*$/
" every space in an account name shall be surrounded by two non-spaces
" every account name ends with a tab, two spaces or the end of the line
-syn match Account /^\s\+\zs\%(\S\|\S \S\)\+\ze\%([ ]\{2,}\|\t\s*\|\s*$\)/ contained
+syn match Account /^\s\+\zs\%(\S \S\|\S\)\+\ze\%([ ]\{2,}\|\t\s*\|\s*$\)/ contained
syn match Posting /^\s\+[^[:blank:];].*$/ contained transparent contains=Account