From e6a2579f349d7935657d20344115bb6903ea707d Mon Sep 17 00:00:00 2001 From: Matus Goljer Date: Sat, 19 Sep 2015 13:57:13 +0200 Subject: 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(+) (limited to 'lisp/ledger-post.el') 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) -- cgit v1.2.3 From 593a07364de6bc7d1c4ccdfdc9bc47b2ba3098e8 Mon Sep 17 00:00:00 2001 From: Matus Goljer Date: Mon, 21 Sep 2015 20:45:51 +0200 Subject: 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(-) (limited to 'lisp/ledger-post.el') 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." -- cgit v1.2.3 From 767ab3e39c8dd6024c0904370654e5f0a9e24b2d Mon Sep 17 00:00:00 2001 From: Matus Goljer Date: Mon, 28 Sep 2015 18:03:32 +0200 Subject: 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(-) (limited to 'lisp/ledger-post.el') 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]*\\)?$")) -- cgit v1.2.3