Skip to content

Commit 9dc24c2

Browse files
committed
implement folding of trailing newlines
Fixes #20.
1 parent 327cf47 commit 9dc24c2

File tree

3 files changed

+37
-25
lines changed

3 files changed

+37
-25
lines changed

README.mkd

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,25 @@ behaviour of the ledger filetype.
5656

5757
let g:ledger_fillstring = ' -'
5858

59-
My special tip is to use so-called digraphs: Press <C-K> followed by the
60-
two-characters key sequence below. (in insert-mode)
61-
62-
'. = ˙ or ': = ¨ --> ˙˙˙˙˙˙ or ¨¨¨¨¨¨
63-
', = ¸ --> ¸¸¸¸¸¸
64-
.M = · --> ······
65-
>> = » --> »»»»»»
66-
67-
All those look rather unobtrusive and provide a good visual aid to find the
68-
correct amount.
69-
7059
* If you want the account completion to be sorted by level of detail/depth
7160
instead of alphabetical, include the following line:
7261

7362
let g:ledger_detailed_first = 1
7463

64+
* By default vim will fold ledger transactions, leaving surrounding blank lines
65+
unfolded. You can use `g:ledger_fold_blanks` to hide blank lines following a
66+
transaction.
67+
68+
let g:ledger_fold_blanks = 0
69+
70+
A value of 0 will disable folding of blank lines, 1 will allow folding of a
71+
single blank line between transactions; any larger value will enable folding
72+
undconditionally.
73+
74+
Note that only lines containing no trailing spaces are considered for
75+
folding. You can take advantage of this to disable this feature on a
76+
case-by-case basis.
77+
7578
Completion
7679
----------
7780

doc/ledger.txt

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,25 @@ behaviour of the ledger filetype.
7171

7272
let g:ledger_fillstring = ' -'
7373

74-
My special tip is to use so-called digraphs: Press <C-K> followed by the
75-
two-characters key sequence below. (in insert-mode)
76-
77-
'. = ˙ or ': = ¨ --> ˙˙˙˙˙˙ or ¨¨¨¨¨¨
78-
', = ¸ --> ¸¸¸¸¸¸
79-
.M = · --> ······
80-
>> = » --> »»»»»»
81-
82-
All those look rather unobtrusive and provide a good visual aid to find the
83-
correct amount.
84-
8574
* If you want the account completion to be sorted by level of detail/depth
8675
instead of alphabetical, include the following line:
8776

8877
let g:ledger_detailed_first = 1
8978

79+
* By default vim will fold ledger transactions, leaving surrounding blank lines
80+
unfolded. You can use 'g:ledger_fold_blanks' to hide blank lines following a
81+
transaction.
82+
83+
let g:ledger_fold_blanks = 0
84+
85+
A value of 0 will disable folding of blank lines, 1 will allow folding of a
86+
single blank line between transactions; any larger value will enable folding
87+
undconditionally.
88+
89+
Note that only lines containing no trailing spaces are considered for
90+
folding. You can take advantage of this to disable this feature on a
91+
case-by-case basis.
92+
9093
==============================================================================
9194
COMPLETION *ledger-completion*
9295

syntax/ledger.vim

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,21 @@ endif
1515
let s:oe = v:version < 704 ? '' : '\%#=1'
1616
let s:lb1 = v:version < 704 ? '\@<=' : '\@1<='
1717

18+
let s:fb = get(g:, 'ledger_fold_blanks', 0)
19+
let s:skip = s:fb > 0 ? '\|^\n' : ''
20+
if s:fb == 1
21+
let s:skip .= '\n\@!'
22+
endif
23+
1824
" for debugging
1925
syntax clear
2026

2127
" DATE[=EDATE] [*|!] [(CODE)] DESC <-- first line of transaction
2228
" ACCOUNT AMOUNT [; NOTE] <-- posting
2329

24-
syn region ledgerTransaction start=/^[[:digit:]~=]/ skip=/^\s/ end=/^/
25-
\ fold keepend transparent
26-
\ contains=ledgerTransactionDate,ledgerMetadata,ledgerPosting,ledgerTransactionExpression
30+
exe 'syn region ledgerTransaction start=/^[[:digit:]~=]/ '.
31+
\ 'skip=/^\s'. s:skip . '/ end=/^/ fold keepend transparent '.
32+
\ 'contains=ledgerTransactionDate,ledgerMetadata,ledgerPosting,ledgerTransactionExpression'
2733
syn match ledgerTransactionDate /^\d\S\+/ contained
2834
syn match ledgerTransactionExpression /^[=~]\s\+\zs.*/ contained
2935
syn match ledgerPosting /^\s\+[^[:blank:];][^;]*\ze\%($\|;\)/

0 commit comments

Comments
 (0)