[emacs] Use markers instead of raw positions to make cleaning work better
Sometimes cleaning a buffer would leave the end of the buffer uncleaned, because the end position would be moved along the way. This commit makes the corresponding code use markers instead, which track the changes in the buffer, and therefore ensure that the entire buffer is acted upon.
This commit is contained in:
parent
c8dd5d4a0a
commit
b623306591
2 changed files with 53 additions and 57 deletions
|
|
@ -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)
|
||||
(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 (point-min) (point-max))
|
||||
(untabify start end)
|
||||
(ledger-sort-buffer)
|
||||
(ledger-post-align-postings (point-min) (point-max))
|
||||
(ledger-post-align-postings start end)
|
||||
(ledger-mode-remove-extra-lines)
|
||||
(goto-char (point-min))
|
||||
(search-forward target)))
|
||||
(goto-char start)
|
||||
(search-forward target))))
|
||||
|
||||
(defvar ledger-mode-map
|
||||
(let ((map (make-sparse-keymap)))
|
||||
|
|
|
|||
|
|
@ -116,28 +116,21 @@ at beginning of account"
|
|||
|
||||
(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))
|
||||
;; Extend region to whole lines
|
||||
(let ((start-marker (set-marker (make-marker) (save-excursion
|
||||
(goto-char beg)
|
||||
(goto-char
|
||||
(setq beg
|
||||
(line-beginning-position)))
|
||||
(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))
|
||||
(< (point) end-marker))
|
||||
(when acct-start-column
|
||||
(setq acct-end-column (save-excursion
|
||||
(goto-char (match-end 2))
|
||||
|
|
@ -158,7 +151,7 @@ at beginning of account"
|
|||
(insert (make-string amt-adjust ? ))
|
||||
(delete-char amt-adjust)))))
|
||||
(forward-line)
|
||||
(setq lines-left (not (eobp))))
|
||||
(setq lines-left (not (eobp)))))
|
||||
(setq inhibit-modification-hooks nil))))
|
||||
|
||||
(defun ledger-post-edit-amount ()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue