ledger.vim: split into multiple files
for better extendability
This commit is contained in:
parent
7c67866b22
commit
b96df34d75
2 changed files with 79 additions and 59 deletions
|
|
@ -1,27 +1,26 @@
|
||||||
" Vim syntax file
|
" Vimwiki filetype plugin file
|
||||||
" filetype: ledger
|
" filetype: ledger
|
||||||
" Version: 0.1.0
|
" Version: 0.1.0
|
||||||
" by Johann Klähn; Use according to the terms of the GPL>=2.
|
" by Johann Klähn; Use according to the terms of the GPL>=2.
|
||||||
" by Stefan Karrmann; Use according to the terms of the GPL>=2.
|
|
||||||
" by Wolfgang Oertl; Use according to the terms of the GPL>=2.
|
|
||||||
" Revision history
|
|
||||||
" 2009-06-12 J. Klähn: Use all available columns for foldtext
|
|
||||||
" 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)
|
|
||||||
" vim:ts=2:sw=2:sts=2:foldmethod=marker
|
" vim:ts=2:sw=2:sts=2:foldmethod=marker
|
||||||
|
|
||||||
if version < 600
|
if exists("b:did_ftplugin")
|
||||||
syntax clear
|
|
||||||
elseif exists("b:current_sytax")
|
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
let b:did_ftplugin = 1
|
||||||
|
|
||||||
|
let b:undo_ftplugin = "setlocal ".
|
||||||
|
\ "foldmethod< foldtext< ".
|
||||||
|
\ "include< comments< "
|
||||||
|
|
||||||
|
" don't fill fold lines --> cleaner look
|
||||||
|
setl fillchars="fold: "
|
||||||
|
setl foldtext=LedgerFoldText()
|
||||||
|
setl foldmethod=syntax
|
||||||
|
setl include=^!include
|
||||||
|
setl comments=b:;
|
||||||
|
|
||||||
" You can set a maximal number of columns the fold text (excluding amount)
|
" You can set a maximal number of columns the fold text (excluding amount)
|
||||||
" will use by overriding g:ledger_maxwidth in your .vimrc.
|
" will use by overriding g:ledger_maxwidth in your .vimrc.
|
||||||
" When maxwidth is zero, the amount will be displayed at the far right side
|
" When maxwidth is zero, the amount will be displayed at the far right side
|
||||||
|
|
@ -29,38 +28,6 @@ endif
|
||||||
if !exists('g:ledger_maxwidth')
|
if !exists('g:ledger_maxwidth')
|
||||||
let g:ledger_maxwidth = 0
|
let g:ledger_maxwidth = 0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" for debugging
|
|
||||||
syntax clear
|
|
||||||
|
|
||||||
" region: a transaction containing postings
|
|
||||||
syn region transNorm start=/^\d/ skip=/^\s/ end=/^/
|
|
||||||
\ fold keepend transparent contains=transDate, Metadata
|
|
||||||
syn match transDate /^\d\S\+/ contained
|
|
||||||
syn match Metadata /^\s\+;.*/ contained
|
|
||||||
syn match Comment /^;.*$/
|
|
||||||
|
|
||||||
highlight default link Comment SpecialKey
|
|
||||||
highlight default link Metadata SpecialKey
|
|
||||||
highlight default link transDate Question
|
|
||||||
|
|
||||||
function! s:multibyte_strlen(text) "{{{
|
|
||||||
return strlen(substitute(a:text, ".", "x", "g"))
|
|
||||||
endf "}}}
|
|
||||||
|
|
||||||
function s:get_columns(win) "{{{
|
|
||||||
" As long as vim doesn't provide a command natively,
|
|
||||||
" we have to compute the available columns.
|
|
||||||
" see :help todo.txt -> /Add argument to winwidth()/
|
|
||||||
" FIXME: Although this will propably never be used with debug mode enabled
|
|
||||||
" this should take the signs column into account (:help sign.txt)
|
|
||||||
let columns = (winwidth(a:win) == 0 ? 80 : winwidth(a:win)) - &foldcolumn
|
|
||||||
if &number
|
|
||||||
" line('w$') is the line number of the last line
|
|
||||||
let columns -= max([len(line('w$'))+1, &numberwidth])
|
|
||||||
endif
|
|
||||||
return columns
|
|
||||||
endf "}}}
|
|
||||||
|
|
||||||
let s:rx_amount = '\('.
|
let s:rx_amount = '\('.
|
||||||
\ '\%([0-9]\+\)'.
|
\ '\%([0-9]\+\)'.
|
||||||
|
|
@ -71,8 +38,7 @@ let s:rx_amount = '\('.
|
||||||
\ '\s*\%([[:alpha:]¢$€£]\+\s*\)\?'.
|
\ '\s*\%([[:alpha:]¢$€£]\+\s*\)\?'.
|
||||||
\ '\%(\s*;.*\)\?$'
|
\ '\%(\s*;.*\)\?$'
|
||||||
|
|
||||||
" folding: how to represent a transaction in one line.
|
function! LedgerFoldText() "{{{1
|
||||||
function! LedgerFoldText()
|
|
||||||
" find amount
|
" find amount
|
||||||
let amount = ""
|
let amount = ""
|
||||||
let lnum = v:foldstart
|
let lnum = v:foldstart
|
||||||
|
|
@ -112,13 +78,24 @@ function! LedgerFoldText()
|
||||||
let foldtext = substitute(foldtext, '.\{'.columns.'}\zs.*$', '', '')
|
let foldtext = substitute(foldtext, '.\{'.columns.'}\zs.*$', '', '')
|
||||||
|
|
||||||
return printf(fmt, foldtext, amount)
|
return printf(fmt, foldtext, amount)
|
||||||
endfunction
|
endfunction "}}}
|
||||||
|
|
||||||
|
" Helper functions {{{1
|
||||||
|
function! s:multibyte_strlen(text) "{{{2
|
||||||
|
return strlen(substitute(a:text, ".", "x", "g"))
|
||||||
|
endfunction "}}}
|
||||||
|
|
||||||
|
function s:get_columns(win) "{{{2
|
||||||
|
" As long as vim doesn't provide a command natively,
|
||||||
|
" we have to compute the available columns.
|
||||||
|
" see :help todo.txt -> /Add argument to winwidth()/
|
||||||
|
" FIXME: Although this will propably never be used with debug mode enabled
|
||||||
|
" this should take the signs column into account (:help sign.txt)
|
||||||
|
let columns = (winwidth(a:win) == 0 ? 80 : winwidth(a:win)) - &foldcolumn
|
||||||
|
if &number
|
||||||
|
" line('w$') is the line number of the last line
|
||||||
|
let columns -= max([len(line('w$'))+1, &numberwidth])
|
||||||
|
endif
|
||||||
|
return columns
|
||||||
|
endfunction "}}}
|
||||||
|
|
||||||
set foldtext=LedgerFoldText()
|
|
||||||
set foldmethod=syntax
|
|
||||||
|
|
||||||
" syncinc is easy: search for the first transaction.
|
|
||||||
syn sync clear
|
|
||||||
syn sync match ledgerSync grouphere transNorm "^\d"
|
|
||||||
|
|
||||||
let b:current_syntax = "ledger"
|
|
||||||
43
contrib/vim/syntax/ledger.vim
Normal file
43
contrib/vim/syntax/ledger.vim
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
" Vim syntax file
|
||||||
|
" filetype: ledger
|
||||||
|
" Version: 0.1.0
|
||||||
|
" by Johann Klähn; Use according to the terms of the GPL>=2.
|
||||||
|
" by Stefan Karrmann; Use according to the terms of the GPL>=2.
|
||||||
|
" by Wolfgang Oertl; Use according to the terms of the GPL>=2.
|
||||||
|
" Revision history
|
||||||
|
" 2009-06-12 J. Klähn: Use all available columns for foldtext
|
||||||
|
" 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)
|
||||||
|
" vim:ts=2:sw=2:sts=2:foldmethod=marker
|
||||||
|
|
||||||
|
if version < 600
|
||||||
|
syntax clear
|
||||||
|
elseif exists("b:current_sytax")
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
|
||||||
|
" for debugging
|
||||||
|
syntax clear
|
||||||
|
|
||||||
|
" region: a transaction containing postings
|
||||||
|
syn region transNorm start=/^\d/ skip=/^\s/ end=/^/
|
||||||
|
\ fold keepend transparent contains=transDate, Metadata
|
||||||
|
syn match transDate /^\d\S\+/ contained
|
||||||
|
syn match Metadata /^\s\+;.*/ contained
|
||||||
|
syn match Comment /^;.*$/
|
||||||
|
|
||||||
|
highlight default link Comment SpecialKey
|
||||||
|
highlight default link Metadata SpecialKey
|
||||||
|
highlight default link transDate Question
|
||||||
|
|
||||||
|
" syncinc is easy: search for the first transaction.
|
||||||
|
syn sync clear
|
||||||
|
syn sync match ledgerSync grouphere transNorm "^\d"
|
||||||
|
|
||||||
|
let b:current_syntax = "ledger"
|
||||||
Loading…
Add table
Reference in a new issue