Skip to content

Commit 675ceca

Browse files
jabranhamjdek
authored andcommitted
New 'ledger-indent-region' function
* ledger-mode.el (ledger-mode): Set indent-region-function. * ledger-post.el (ledger-indent-region): New function that indents the region by calling ledger-indent-line for each line. Closes bug #197 Signed-off-by: J. Dekker <jdek@itanimul.li>
1 parent 11e748d commit 675ceca

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

ledger-mode.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ With a prefix argument, remove the effective date."
331331
(ledger-init-load-init-file)
332332
(setq-local comment-start ";")
333333
(setq-local indent-line-function #'ledger-indent-line)
334-
(setq-local indent-region-function 'ledger-post-align-postings)
334+
(setq-local indent-region-function #'ledger-indent-region))
335335
(setq-local beginning-of-defun-function #'ledger-navigate-beginning-of-xact)
336336
(setq-local end-of-defun-function #'ledger-navigate-end-of-xact))
337337

ledger-post.el

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,20 @@ The current region is used, or, if no region, the current line."
147147
(when ledger-post-auto-align
148148
(ledger-post-align-postings (line-beginning-position) (line-end-position))))
149149

150+
(defun ledger-indent-region (beg end)
151+
"Indent the region from BEG to END.
152+
This works by calling `ledger-indent-line' for each line."
153+
(save-excursion
154+
(goto-char beg)
155+
(beginning-of-line)
156+
(ledger-indent-line)
157+
(while (< (point) end)
158+
(forward-line)
159+
(ledger-indent-line))
160+
(when (progn (beginning-of-line)
161+
(looking-at-p "^[[:space:]]*$"))
162+
(delete-region (point) (line-end-position)))))
163+
150164
(defun ledger-post-align-dwim ()
151165
"Align all the posting of the current xact or the current region.
152166

test/post-test.el

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ http://bugs.ledger-cli.org/show_bug.cgi?id=924"
258258
"
259259
(indent-region (point-min) (point-max))
260260
(should
261-
(equal (buffer-string)
261+
(equal (buffer-substring-no-properties (point-min) (point-max))
262262
"1994/01/10 * Mother
263263
Actif:Courant:BnpCc 500,00 F ; Étrennes
264264
Revenu:Autre:CadeauReçu
@@ -453,6 +453,22 @@ http://bugs.ledger-cli.org/show_bug.cgi?id=946"
453453
Assets:Bar
454454
" ))))
455455

456+
(ert-deftest ledger-post/test-197 ()
457+
"Regress test for Bug #197"
458+
:tags '(post regress)
459+
(ledger-tests-with-temp-file
460+
"2019/08/13 Test
461+
this 8000 GBP
462+
out"
463+
(let ((ledger-post-auto-align nil))
464+
(set-mark-command nil)
465+
(goto-char (point-max))
466+
(call-interactively #'indent-for-tab-command)
467+
(should (string= (buffer-substring-no-properties (point-min) (point-max))
468+
"2019/08/13 Test
469+
this 8000 GBP
470+
out")))))
471+
456472

457473
(provide 'post-test)
458474

0 commit comments

Comments
 (0)