Merge branch 'next'
This commit is contained in:
commit
3bb4cb6b60
7 changed files with 92 additions and 31 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
This is the ledger filetype for vim.
|
This is the ledger filetype for vim.
|
||||||
Copy each file to the corresponding directory in your ~/.vim directory.
|
Copy each file to the corresponding directory in your ~/.vim directory.
|
||||||
Then include the following line in your .vimrc or in ~/.vim/filetype.vim
|
Then include the following line in your .vimrc or in ~/.vim/filetype.vim
|
||||||
au BufNewFile,BufRead *.ldg,*.ledger setf ledger
|
au BufNewFile,BufRead *.ldg,*.ledger setf ledger | comp ledger
|
||||||
You can also use a modeline like this in every ledger file
|
You can also use a modeline like this in every ledger file
|
||||||
vim:filetype=ledger
|
vim:filetype=ledger
|
||||||
|
|
||||||
|
|
|
||||||
31
contrib/vim/compiler/ledger.vim
Normal file
31
contrib/vim/compiler/ledger.vim
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
" Vim Compiler File
|
||||||
|
" Compiler: ledger
|
||||||
|
" by Johann Klähn; Use according to the terms of the GPL>=2.
|
||||||
|
" vim:ts=2:sw=2:sts=2:foldmethod=marker
|
||||||
|
|
||||||
|
if exists("current_compiler")
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
let current_compiler = "ledger"
|
||||||
|
|
||||||
|
if exists(":CompilerSet") != 2
|
||||||
|
command -nargs=* CompilerSet setlocal <args>
|
||||||
|
endif
|
||||||
|
|
||||||
|
if ! exists("g:ledger_bin") || ! executable(g:ledger_bin)
|
||||||
|
if executable('ledger')
|
||||||
|
let g:ledger_bin = 'ledger'
|
||||||
|
else
|
||||||
|
echoerr "ledger command not found. Set g:ledger_bin or extend $PATH."
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
" %-G throws away blank lines, everything else is assumed to be part of a
|
||||||
|
" multi-line error message.
|
||||||
|
CompilerSet errorformat=%-G,%EWhile\ parsing\ file\ \"%f\"\\,\ line\ %l:%.%#,%ZError:\ %m,%C%.%#
|
||||||
|
|
||||||
|
" unfortunately there is no 'check file' command,
|
||||||
|
" so we will just use a query that returns no results. ever.
|
||||||
|
exe 'CompilerSet makeprg='.g:ledger_bin.'\ -f\ %\ reg\ not\ ''.*''\ \>\ /dev/null'
|
||||||
|
|
||||||
|
|
@ -25,25 +25,36 @@ endif
|
||||||
" for debugging
|
" for debugging
|
||||||
syntax clear
|
syntax clear
|
||||||
|
|
||||||
|
" DATE[=EDATE] [*|!] [(CODE)] DESC <-- first line of transaction
|
||||||
|
" ACCOUNT AMOUNT [; NOTE] <-- posting
|
||||||
|
|
||||||
" region: a transaction containing postings
|
" region: a transaction containing postings
|
||||||
syn region transNorm start=/^[[:digit:]~]/ skip=/^\s/ end=/^/
|
syn region transNorm start=/^[[:digit:]~]/ skip=/^\s/ end=/^/
|
||||||
\ fold keepend transparent contains=transDate, Metadata, Posting
|
\ fold keepend transparent contains=transDate,Metadata,Posting
|
||||||
syn match transDate /^\d\S\+/ contained
|
syn match transDate /^\d\S\+/ contained
|
||||||
syn match Metadata /^\s\+;.*/ contained
|
syn match Metadata /^\s\+;.*/ contained contains=MetadataTag
|
||||||
syn match Comment /^;.*$/
|
syn match Comment /^;.*$/
|
||||||
" every space in an account name shall be surrounded by two non-spaces
|
" 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
|
" 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
|
syn match Posting /^\s\+[^[:blank:];].*$/ contained transparent contains=Account,Amount
|
||||||
|
" FIXME: add other symbols?
|
||||||
|
let s:currency = '\([$€£¢]\|\w\+\)'
|
||||||
|
let s:figures = '\d\+\([.,]\d\+\)*'
|
||||||
|
let s:amount = '-\?\('.s:figures.'\s*'.s:currency.'\|'.s:currency.'\s*'.s:figures.'\)'
|
||||||
|
exe 'syn match Amount /'.s:amount.'/ contained'
|
||||||
|
syn match MetadataTag /:\zs[^:]\+\ze:\|;\s*\zs[^:]\+\ze:[^:]\+$/ contained
|
||||||
|
|
||||||
|
|
||||||
highlight default link transDate Question
|
highlight default link transDate Constant
|
||||||
highlight default link Metadata PreProc
|
highlight default link Metadata Tag
|
||||||
|
highlight default link MetadataTag Type
|
||||||
|
highlight default link Amount Number
|
||||||
highlight default link Comment Comment
|
highlight default link Comment Comment
|
||||||
highlight default link Account Identifier
|
highlight default link Account Identifier
|
||||||
|
|
||||||
" syncinc is easy: search for the first transaction.
|
" syncinc is easy: search for the first transaction.
|
||||||
syn sync clear
|
syn sync clear
|
||||||
syn sync match ledgerSync grouphere transNorm "^\d"
|
syn sync match ledgerSync grouphere transNorm "^[[:digit:]~]"
|
||||||
|
|
||||||
let b:current_syntax = "ledger"
|
let b:current_syntax = "ledger"
|
||||||
|
|
|
||||||
|
|
@ -152,31 +152,46 @@ customizable to ease retro-entry.")
|
||||||
"Start a ledger session with the current month, but make it
|
"Start a ledger session with the current month, but make it
|
||||||
customizable to ease retro-entry.")
|
customizable to ease retro-entry.")
|
||||||
|
|
||||||
|
(defvar ledger-rx-constituents
|
||||||
|
(append (list (cons 'date
|
||||||
|
(rx (opt (group (= 4 digit)) (in "./"))
|
||||||
|
(group (1+ digit)) (in "./")
|
||||||
|
(group (1+ digit))))
|
||||||
|
(cons 'opt-mark
|
||||||
|
(rx (opt (group "*") (1+ blank)))))
|
||||||
|
rx-constituents))
|
||||||
|
|
||||||
|
(defmacro ledger-rx (&rest body)
|
||||||
|
`(let ((rx-constituents ledger-rx-constituents))
|
||||||
|
(rx ,@body)))
|
||||||
|
|
||||||
|
(defun ledger--iterate-dispatch (nyear nmonth nday nmark ndesc)
|
||||||
|
(let ((start (point))
|
||||||
|
(year (match-string nyear))
|
||||||
|
(month (string-to-number (match-string nmonth)))
|
||||||
|
(day (string-to-number (match-string nday)))
|
||||||
|
(mark (match-string nmark))
|
||||||
|
(desc (match-string ndesc)))
|
||||||
|
(if (and year (> (length year) 0))
|
||||||
|
(setq year (string-to-number year)))
|
||||||
|
(funcall callback start
|
||||||
|
(encode-time 0 0 0 day month
|
||||||
|
(or year current-year))
|
||||||
|
mark desc)))
|
||||||
|
|
||||||
(defun ledger-iterate-entries (callback)
|
(defun ledger-iterate-entries (callback)
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(let* ((now (current-time))
|
(let* ((now (current-time))
|
||||||
(current-year (nth 5 (decode-time now))))
|
(current-year (nth 5 (decode-time now))))
|
||||||
(while (not (eobp))
|
(while (not (eobp))
|
||||||
(when (looking-at
|
(cond ((looking-at (rx "Y" (1+ blank) (group (1+ digit))))
|
||||||
(concat "\\(Y\\s-+\\([0-9]+\\)\\|"
|
(setq current-year (string-to-number (match-string 1))))
|
||||||
"\\([0-9]\\{4\\}+\\)?[./]?"
|
|
||||||
"\\([0-9]+\\)[./]\\([0-9]+\\)\\s-+"
|
((looking-at (ledger-rx date "=" date (1+ blank) opt-mark (group (1+ nonl))))
|
||||||
"\\(\\*\\s-+\\)?\\(.+\\)\\)"))
|
(ledger--iterate-dispatch 1 2 3 7 8))
|
||||||
(let ((found (match-string 2)))
|
|
||||||
(if found
|
((looking-at (ledger-rx date (1+ blank) opt-mark (group (1+ nonl))))
|
||||||
(setq current-year (string-to-number found))
|
(ledger--iterate-dispatch 1 2 3 4 5)))
|
||||||
(let ((start (match-beginning 0))
|
|
||||||
(year (match-string 3))
|
|
||||||
(month (string-to-number (match-string 4)))
|
|
||||||
(day (string-to-number (match-string 5)))
|
|
||||||
(mark (match-string 6))
|
|
||||||
(desc (match-string 7)))
|
|
||||||
(if (and year (> (length year) 0))
|
|
||||||
(setq year (string-to-number year)))
|
|
||||||
(funcall callback start
|
|
||||||
(encode-time 0 0 0 day month
|
|
||||||
(or year current-year))
|
|
||||||
mark desc)))))
|
|
||||||
(forward-line))))
|
(forward-line))))
|
||||||
|
|
||||||
(defun ledger-time-less-p (t1 t2)
|
(defun ledger-time-less-p (t1 t2)
|
||||||
|
|
|
||||||
|
|
@ -174,7 +174,7 @@ value_t period_command(call_scope_t& args)
|
||||||
return NULL_VALUE;
|
return NULL_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
value_t args_command(call_scope_t& args)
|
value_t query_command(call_scope_t& args)
|
||||||
{
|
{
|
||||||
report_t& report(find_scope<report_t>(args));
|
report_t& report(find_scope<report_t>(args));
|
||||||
std::ostream& out(report.output_stream);
|
std::ostream& out(report.output_stream);
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ value_t parse_command(call_scope_t& args);
|
||||||
value_t eval_command(call_scope_t& args);
|
value_t eval_command(call_scope_t& args);
|
||||||
value_t format_command(call_scope_t& args);
|
value_t format_command(call_scope_t& args);
|
||||||
value_t period_command(call_scope_t& args);
|
value_t period_command(call_scope_t& args);
|
||||||
value_t args_command(call_scope_t& args);
|
value_t query_command(call_scope_t& args);
|
||||||
|
|
||||||
} // namespace ledger
|
} // namespace ledger
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1272,7 +1272,7 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
|
||||||
switch (*p) {
|
switch (*p) {
|
||||||
case 'a':
|
case 'a':
|
||||||
if (is_eq(p, "args"))
|
if (is_eq(p, "args"))
|
||||||
return WRAP_FUNCTOR(args_command);
|
return WRAP_FUNCTOR(query_command);
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
if (is_eq(p, "eval"))
|
if (is_eq(p, "eval"))
|
||||||
|
|
@ -1294,6 +1294,10 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
|
||||||
else if (is_eq(p, "period"))
|
else if (is_eq(p, "period"))
|
||||||
return WRAP_FUNCTOR(period_command);
|
return WRAP_FUNCTOR(period_command);
|
||||||
break;
|
break;
|
||||||
|
case 'q':
|
||||||
|
if (is_eq(p, "query"))
|
||||||
|
return WRAP_FUNCTOR(query_command);
|
||||||
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
if (is_eq(p, "template"))
|
if (is_eq(p, "template"))
|
||||||
return WRAP_FUNCTOR(template_command);
|
return WRAP_FUNCTOR(template_command);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue