summaryrefslogtreecommitdiffstats
path: root/indent
diff options
context:
space:
mode:
authorAdam Stankiewicz <sheerun@sher.pl>2020-05-20 20:24:48 +0200
committerAdam Stankiewicz <sheerun@sher.pl>2020-05-20 20:24:48 +0200
commit685aeaaeb1b3fb6e3a9b4304799663f62bc8e1b3 (patch)
tree8fc5312e37d21b97d1b6e668ad4a7b81e6ff7314 /indent
parenta9cc6fd2188ddc37257c834b6f5a5fa86d0eebd5 (diff)
downloadvim-polyglot-685aeaaeb1b3fb6e3a9b4304799663f62bc8e1b3.tar.gz
vim-polyglot-685aeaaeb1b3fb6e3a9b4304799663f62bc8e1b3.zip
Add ledger support, closes #488v4.4.1
Diffstat (limited to 'indent')
-rw-r--r--indent/ledger.vim52
1 files changed, 52 insertions, 0 deletions
diff --git a/indent/ledger.vim b/indent/ledger.vim
new file mode 100644
index 00000000..9dde49b6
--- /dev/null
+++ b/indent/ledger.vim
@@ -0,0 +1,52 @@
+if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'ledger') == -1
+
+" Vim filetype indent file
+" filetype: ledger
+" by Johann Klähn; Use according to the terms of the GPL>=2.
+" vim:ts=2:sw=2:sts=2:foldmethod=marker
+
+scriptencoding utf-8
+
+if exists('b:did_indent')
+ finish
+endif
+let b:did_indent = 1
+
+setl autoindent
+setl indentexpr=GetLedgerIndent()
+
+if exists('*GetLedgerIndent')
+ finish
+endif
+
+function GetLedgerIndent(...)
+ " You can pass in a line number when calling this function manually.
+ let lnum = a:0 > 0 ? a:1 : v:lnum
+ " If this line is empty look at (the indentation of) the last line.
+ " Note that inside of a transaction no blank lines are allowed.
+ let line = getline(lnum)
+ let prev = getline(lnum - 1)
+
+ if line =~# '^\s\+\S'
+ " Lines that already are indented (→postings, sub-directives) keep their indentation.
+ return &shiftwidth
+ elseif line =~# '^\s*$'
+ " Current line is empty, try to guess its type based on the previous line.
+ if prev =~# '^\([[:digit:]~=]\|\s\+\S\)'
+ " This is very likely a posting or a sub-directive.
+ " While lines following the start of a transaction are automatically
+ " indented you will have to indent the first line following a
+ " pre-declaration manually. This makes it easier to type long lists of
+ " 'account' pre-declarations without sub-directives, for example.
+ return &shiftwidth
+ else
+ return 0
+ endif
+ else
+ " Everything else is not indented:
+ " start of transactions, pre-declarations, apply/end-lines
+ return 0
+ endif
+endf
+
+endif