From 76379c4886e7420ce8954b845ec85d3bc01f7591 Mon Sep 17 00:00:00 2001 From: thdox Date: Fri, 18 Sep 2015 20:34:59 +0200 Subject: [PATCH 1/8] Bring back UNDOCUMENTED tag as the CODE has not yet been documented. --- doc/ledger3.texi | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/ledger3.texi b/doc/ledger3.texi index a3794050..bcdfab06 100644 --- a/doc/ledger3.texi +++ b/doc/ledger3.texi @@ -5902,6 +5902,7 @@ or testing small journal files not associated with your main financial database. @item --debug @var{CODE} +@value{FIXME:UNDOCUMENTED} If ledger has been built with debug options this will provide extra data during the run. From 3e605f677fcfaa3bec83b9c770f386428ab9d902 Mon Sep 17 00:00:00 2001 From: thdox Date: Fri, 18 Sep 2015 20:43:00 +0200 Subject: [PATCH 2/8] For consistency with description of --subtotal that is line 7067. --- doc/ledger3.texi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/ledger3.texi b/doc/ledger3.texi index bcdfab06..f2b3c682 100644 --- a/doc/ledger3.texi +++ b/doc/ledger3.texi @@ -6757,8 +6757,8 @@ week. @item --subtotal @itemx -s -Group all postings together. This is very similar to the totals shown by -the balance report. +Cause all transactions in a @command{register} report to be collapsed +into a single, subtotaled transaction. @item --tail @var{INT} @itemx --last @var{INT} From 075ac7d4d01e9b317540e7d2d6de92b2848afee0 Mon Sep 17 00:00:00 2001 From: thdox Date: Fri, 18 Sep 2015 20:51:33 +0200 Subject: [PATCH 3/8] Restoring @code as this is an keyword external to ledger itself. --- doc/ledger3.texi | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/ledger3.texi b/doc/ledger3.texi index f2b3c682..5d8ab55c 100644 --- a/doc/ledger3.texi +++ b/doc/ledger3.texi @@ -8247,8 +8247,8 @@ Evaluate @var{string} as format just like the @option{--format} option. @end defun @defun format_date date format -Return the @var{date} as a string using @var{format}. See strftime (3) -for format string details. +Return the @var{date} as a string using @var{format}. See +@code{strftime (3)} for format string details. @smallexample @c command:9605B13,with_input:3406FC1 $ ledger -f expr.dat --format "%(format_date(date, '%A, %B %d. %Y'))\n" reg assets @end smallexample @@ -8258,8 +8258,8 @@ Friday, January 16. 2015 @end defun @defun format_datetime datetime format -Return the @var{datetime} as a string using @var{format}. Refer to strftime (3) -for format string details. +Return the @var{datetime} as a string using @var{format}. Refer to +@code{strftime (3)} for format string details. @end defun @defun get_at sequence index @@ -8600,8 +8600,8 @@ $ ledger -f expr.dat --format "%12(5*O)\n" reg assets @end smallexample @item [DATEFMT] -Inserts the result of formatting a posting's date with a date -format string, exactly like those supported by strftime (3). For +Inserts the result of formatting a posting's date with a date format +string, exactly like those supported by @code{strftime (3)}. For example: @samp{%[%Y/%m/%d %H:%M:%S]}. @item S From e6a2579f349d7935657d20344115bb6903ea707d Mon Sep 17 00:00:00 2001 From: Matus Goljer Date: Sat, 19 Sep 2015 13:57:13 +0200 Subject: [PATCH 4/8] Add a function to "dwim" align. If no region is active, align the current transaction. If a region is active, align all postings in the region. --- lisp/ledger-post.el | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lisp/ledger-post.el b/lisp/ledger-post.el index 21e856db..f648ea8f 100644 --- a/lisp/ledger-post.el +++ b/lisp/ledger-post.el @@ -146,6 +146,13 @@ at beginning of account" (setq lines-left (not (eobp))))) (setq inhibit-modification-hooks nil)))) +(defun ledger-post-align-dwim () + "Align all the posting of the current xact the current region." + (interactive) + (if (use-region-p) + (call-interactively 'ledger-post-align-postings) + (call-interactively 'ledger-post-align-xact))) + (defun ledger-post-edit-amount () "Call 'calc-mode' and push the amount in the posting to the top of stack." (interactive) From 1995a7e0ac748f6709e5051780468361bfee654d Mon Sep 17 00:00:00 2001 From: Matus Goljer Date: Sat, 19 Sep 2015 13:58:16 +0200 Subject: [PATCH 5/8] Bind M-q to ledger-post-align-dwim. There is very little reason to have M-q bound to fill-paragraph in ledger, so let's use it for aligning instead. --- lisp/ledger-mode.el | 1 + 1 file changed, 1 insertion(+) diff --git a/lisp/ledger-mode.el b/lisp/ledger-mode.el index f2eb4b21..30f25dfc 100644 --- a/lisp/ledger-mode.el +++ b/lisp/ledger-mode.el @@ -285,6 +285,7 @@ With a prefix argument, remove the effective date." (define-key map [(meta ?p)] 'ledger-navigate-prev-xact-or-directive) (define-key map [(meta ?n)] 'ledger-navigate-next-xact-or-directive) + (define-key map [(meta ?q)] 'ledger-post-align-dwim) map) "Keymap for `ledger-mode'.") From 593a07364de6bc7d1c4ccdfdc9bc47b2ba3098e8 Mon Sep 17 00:00:00 2001 From: Matus Goljer Date: Mon, 21 Sep 2015 20:45:51 +0200 Subject: [PATCH 6/8] Fill comment paragraph with ledger-post-align-dwim In addition to re-aligning postings, if the point is in a comment, just fill that comment as regular plaintext. --- lisp/ledger-post.el | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lisp/ledger-post.el b/lisp/ledger-post.el index f648ea8f..5696d0e4 100644 --- a/lisp/ledger-post.el +++ b/lisp/ledger-post.el @@ -147,11 +147,17 @@ at beginning of account" (setq inhibit-modification-hooks nil)))) (defun ledger-post-align-dwim () - "Align all the posting of the current xact the current region." + "Align all the posting of the current xact or the current region. + +If the point is in a comment, fill the comment paragraph as +regular text." (interactive) - (if (use-region-p) - (call-interactively 'ledger-post-align-postings) - (call-interactively 'ledger-post-align-xact))) + (cond + ((nth 4 (syntax-ppss)) + (call-interactively 'ledger-post-align-postings) + (fill-paragraph)) + ((use-region-p) (call-interactively 'ledger-post-align-postings)) + (t (call-interactively 'ledger-post-align-xact)))) (defun ledger-post-edit-amount () "Call 'calc-mode' and push the amount in the posting to the top of stack." From 758a224131dcc23147969aa691fb0825470253c5 Mon Sep 17 00:00:00 2001 From: Matus Goljer Date: Mon, 21 Sep 2015 21:21:31 +0200 Subject: [PATCH 7/8] Fix amount-regex to properly capture integer part. If the integer part was 2 digits, because the integer part was non-greedy, it only captured as much as necessary, namely one digit. The other digit was captured by the 5th group's [:word:] not 4th because that one is also optional. This results in incorrect reporting of amount length and broken aligning. Also move the decimal dot matching from 3rd group to 4th, and quote the dot. --- lisp/ledger-regex.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lisp/ledger-regex.el b/lisp/ledger-regex.el index 5d525d95..cf86b2f9 100644 --- a/lisp/ledger-regex.el +++ b/lisp/ledger-regex.el @@ -27,8 +27,8 @@ (defconst ledger-amount-regex (concat "\\( \\|\t\\| \t\\)[ \t]*-?" "\\([A-Z$€£₹_(]+ *\\)?" - "\\(-?[0-9,\\.]+?\\)" - "\\(.[0-9)]+\\)?" + "\\(-?[0-9,]+\\)" + "\\(\\.[0-9)]+\\)?" "\\( *[[:word:]€£₹_\"]+\\)?" "\\([ \t]*[@={]@?[^\n;]+?\\)?" "\\([ \t]+;.+?\\|[ \t]*\\)?$")) From 767ab3e39c8dd6024c0904370654e5f0a9e24b2d Mon Sep 17 00:00:00 2001 From: Matus Goljer Date: Mon, 28 Sep 2015 18:03:32 +0200 Subject: [PATCH 8/8] Align amounts on the decimal separator. That is: A $10.00 B $5 C -$15.00 Before the numbers aligned at the end of the last digit. --- lisp/ledger-post.el | 3 +-- lisp/ledger-regex.el | 10 ++++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lisp/ledger-post.el b/lisp/ledger-post.el index 5696d0e4..d741442a 100644 --- a/lisp/ledger-post.el +++ b/lisp/ledger-post.el @@ -79,8 +79,7 @@ point at beginning of the commodity." (when (re-search-forward ledger-amount-regex end t) (goto-char (match-beginning 0)) (skip-syntax-forward " ") - (- (or (match-end 4) - (match-end 3)) (point))))) + (- (match-end 3) (point))))) (defun ledger-next-account (&optional end) "Move to the beginning of the posting, or status marker, limit to END. diff --git a/lisp/ledger-regex.el b/lisp/ledger-regex.el index cf86b2f9..6ced0223 100644 --- a/lisp/ledger-regex.el +++ b/lisp/ledger-regex.el @@ -27,8 +27,14 @@ (defconst ledger-amount-regex (concat "\\( \\|\t\\| \t\\)[ \t]*-?" "\\([A-Z$€£₹_(]+ *\\)?" - "\\(-?[0-9,]+\\)" - "\\(\\.[0-9)]+\\)?" + ;; We either match just a number after the commodity with no + ;; decimal or thousand separators or a number with thousand + ;; separators. If we have a decimal part starting with `,' + ;; or `.', because the match is non-greedy, it must leave at + ;; least one of those symbols for the following capture + ;; group, which then finishes the decimal part. + "\\(-?\\(?:[0-9]+\\|[0-9,.]+?\\)\\)" + "\\([,.][0-9)]+\\)?" "\\( *[[:word:]€£₹_\"]+\\)?" "\\([ \t]*[@={]@?[^\n;]+?\\)?" "\\([ \t]+;.+?\\|[ \t]*\\)?$"))