More armor plating on ledger-post-align-postings
This commit is contained in:
parent
0bcef93e29
commit
53778317cb
1 changed files with 45 additions and 41 deletions
|
|
@ -138,24 +138,28 @@ Return the column of the beginning of the account"
|
||||||
"Align all accounts and amounts within region, if there is no
|
"Align all accounts and amounts within region, if there is no
|
||||||
region alight the posting on the current line."
|
region alight the posting on the current line."
|
||||||
(interactive)
|
(interactive)
|
||||||
(save-excursion
|
(let ((region-boundaries-verified nil)) (save-excursion
|
||||||
;; If there is no region set
|
;; If there is no region set
|
||||||
(when (or (not (mark))
|
(when (or (not (mark))
|
||||||
(= (point) (mark)))
|
(= (point) (mark)))
|
||||||
(beginning-of-line)
|
(beginning-of-line)
|
||||||
(set-mark (point))
|
(set-mark (point))
|
||||||
(goto-char (1+ (line-end-position))))
|
(goto-char (line-end-position))
|
||||||
|
(setq region-boundaries-verified t))
|
||||||
|
|
||||||
(let* ((mark-first (< (mark) (point)))
|
(let* ((mark-first (< (mark) (point)))
|
||||||
(begin (if mark-first (mark) (point)))
|
(begin (if mark-first (mark) (point)))
|
||||||
(end (if mark-first (point-marker) (mark-marker)))
|
(end (if mark-first (point-marker) (mark-marker)))
|
||||||
acc-col amt-offset)
|
acc-col amt-offset)
|
||||||
|
(if (not region-boundaries-verified)
|
||||||
|
(progn
|
||||||
(goto-char end)
|
(goto-char end)
|
||||||
(end-of-line)
|
(end-of-line)
|
||||||
(setq end (point-marker))
|
(setq end (point-marker))
|
||||||
(goto-char begin)
|
(goto-char begin)
|
||||||
(beginning-of-line)
|
(beginning-of-line)
|
||||||
(setq begin (point-marker))
|
(setq begin (point-marker)))
|
||||||
|
(goto-char begin))
|
||||||
(while (setq acc-col (ledger-next-account end))
|
(while (setq acc-col (ledger-next-account end))
|
||||||
;; Adjust account position if necessary
|
;; Adjust account position if necessary
|
||||||
(let ((acc-adjust (- ledger-post-account-alignment-column acc-col)))
|
(let ((acc-adjust (- ledger-post-account-alignment-column acc-col)))
|
||||||
|
|
@ -179,7 +183,7 @@ region alight the posting on the current line."
|
||||||
(skip-chars-forward "^ \t")
|
(skip-chars-forward "^ \t")
|
||||||
(delete-horizontal-space)
|
(delete-horizontal-space)
|
||||||
(insert " "))))))
|
(insert " "))))))
|
||||||
(forward-line)))))
|
(forward-line))))))
|
||||||
|
|
||||||
(defun ledger-post-maybe-align (beg end len)
|
(defun ledger-post-maybe-align (beg end len)
|
||||||
"Align amounts only if point is in a posting.
|
"Align amounts only if point is in a posting.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue