summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ledger-mode.el25
-rw-r--r--lisp/ledger-post.el91
2 files changed, 56 insertions, 60 deletions
diff --git a/lisp/ledger-mode.el b/lisp/ledger-mode.el
index 4fc90f60..d3045661 100644
--- a/lisp/ledger-mode.el
+++ b/lisp/ledger-mode.el
@@ -228,17 +228,20 @@ With a prefix argument, remove the effective date."
(defun ledger-mode-clean-buffer ()
"Indent, remove multiple line feeds and sort the buffer."
(interactive)
- (ledger-navigate-beginning-of-xact)
- (beginning-of-line)
- (let ((target (buffer-substring (point) (progn
- (end-of-line)
- (point)))))
- (untabify (point-min) (point-max))
- (ledger-sort-buffer)
- (ledger-post-align-postings (point-min) (point-max))
- (ledger-mode-remove-extra-lines)
- (goto-char (point-min))
- (search-forward target)))
+ (let ((start (point-min-marker))
+ (end (point-max-marker)))
+ (goto-char start)
+ (ledger-navigate-beginning-of-xact)
+ (beginning-of-line)
+ (let ((target (buffer-substring (point) (progn
+ (end-of-line)
+ (point)))))
+ (untabify start end)
+ (ledger-sort-buffer)
+ (ledger-post-align-postings start end)
+ (ledger-mode-remove-extra-lines)
+ (goto-char start)
+ (search-forward target))))
(defvar ledger-mode-map
(let ((map (make-sparse-keymap)))
diff --git a/lisp/ledger-post.el b/lisp/ledger-post.el
index 11cd5847..a316129d 100644
--- a/lisp/ledger-post.el
+++ b/lisp/ledger-post.el
@@ -110,55 +110,48 @@ at beginning of account"
(set-mark (point)))
(let ((inhibit-modification-hooks t)
- (mark-first (< (mark) (point)))
- acct-start-column acct-end-column acct-adjust amt-width amt-adjust
- (lines-left 1))
-
- (unless beg (setq beg (if mark-first (mark) (point))))
- (unless end (setq end (if mark-first (mark) (point))))
- ;; Condition point and mark to the beginning and end of lines
- (goto-char end)
- (setq end (line-end-position))
- (goto-char beg)
- (goto-char
- (setq beg
- (line-beginning-position)))
-
- (untabify beg end)
-
- ;; if untabify actually changed anything, then our begin and end are not correct.
- (goto-char end)
- (setq end (line-end-position))
- (goto-char beg)
- (goto-char
- (setq beg
- (line-beginning-position)))
-
- ;; This is the guts of the alignment loop
- (while (and (or (setq acct-start-column (ledger-next-account (line-end-position)))
- lines-left)
- (< (point) end))
- (when acct-start-column
- (setq acct-end-column (save-excursion
- (goto-char (match-end 2))
- (current-column)))
- (when (/= (setq acct-adjust (- ledger-post-account-alignment-column acct-start-column)) 0)
- (setq acct-end-column (+ acct-end-column acct-adjust)) ;;adjust the account ending column
- (if (> acct-adjust 0)
- (insert (make-string acct-adjust ? ))
- (delete-char acct-adjust)))
- (when (setq amt-width (ledger-next-amount (line-end-position)))
- (if (/= 0 (setq amt-adjust (- (if (> (- ledger-post-amount-alignment-column amt-width)
- (+ 2 acct-end-column))
- ledger-post-amount-alignment-column ;;we have room
- (+ acct-end-column 2 amt-width))
- amt-width
- (current-column))))
- (if (> amt-adjust 0)
- (insert (make-string amt-adjust ? ))
- (delete-char amt-adjust)))))
- (forward-line)
- (setq lines-left (not (eobp))))
+ (mark-first (< (mark) (point)))
+ acct-start-column acct-end-column acct-adjust amt-width amt-adjust
+ (lines-left 1))
+
+ (unless beg (setq beg (if mark-first (mark) (point))))
+ (unless end (setq end (if mark-first (mark) (point))))
+
+ ;; Extend region to whole lines
+ (let ((start-marker (set-marker (make-marker) (save-excursion
+ (goto-char beg)
+ (line-beginning-position))))
+ (end-marker (set-marker (make-marker) (save-excursion
+ (goto-char end)
+ (line-end-position)))))
+ (untabify start-marker end-marker)
+ (goto-char start-marker)
+
+ ;; This is the guts of the alignment loop
+ (while (and (or (setq acct-start-column (ledger-next-account (line-end-position)))
+ lines-left)
+ (< (point) end-marker))
+ (when acct-start-column
+ (setq acct-end-column (save-excursion
+ (goto-char (match-end 2))
+ (current-column)))
+ (when (/= (setq acct-adjust (- ledger-post-account-alignment-column acct-start-column)) 0)
+ (setq acct-end-column (+ acct-end-column acct-adjust)) ;;adjust the account ending column
+ (if (> acct-adjust 0)
+ (insert (make-string acct-adjust ? ))
+ (delete-char acct-adjust)))
+ (when (setq amt-width (ledger-next-amount (line-end-position)))
+ (if (/= 0 (setq amt-adjust (- (if (> (- ledger-post-amount-alignment-column amt-width)
+ (+ 2 acct-end-column))
+ ledger-post-amount-alignment-column ;;we have room
+ (+ acct-end-column 2 amt-width))
+ amt-width
+ (current-column))))
+ (if (> amt-adjust 0)
+ (insert (make-string amt-adjust ? ))
+ (delete-char amt-adjust)))))
+ (forward-line)
+ (setq lines-left (not (eobp)))))
(setq inhibit-modification-hooks nil))))
(defun ledger-post-edit-amount ()