Fix Bug 966 Auto Indent conflicts with undo. Removed the auto-indent function and added an indent xact function

This commit is contained in:
Craig Earls 2013-06-03 16:39:36 -07:00
parent cb6f4b9890
commit c23c994b22
2 changed files with 7 additions and 16 deletions

View file

@ -153,6 +153,7 @@ Can indent, complete or align depending on context."
(define-key map [(control ?c) (control ?l)] 'ledger-display-ledger-stats) (define-key map [(control ?c) (control ?l)] 'ledger-display-ledger-stats)
(define-key map [tab] 'ledger-magic-tab) (define-key map [tab] 'ledger-magic-tab)
(define-key map [(control tab)] 'ledger-post-align-xact)
(define-key map [(control ?i)] 'ledger-magic-tab) (define-key map [(control ?i)] 'ledger-magic-tab)
(define-key map [(control ?c) tab] 'ledger-fully-complete-xact) (define-key map [(control ?c) tab] 'ledger-fully-complete-xact)
(define-key map [(control ?c) (control ?i)] 'ledger-fully-complete-xact) (define-key map [(control ?c) (control ?i)] 'ledger-fully-complete-xact)
@ -188,6 +189,7 @@ Can indent, complete or align depending on context."
(define-key map [sort-start] '(menu-item "Mark Sort Beginning" ledger-sort-insert-start-mark)) (define-key map [sort-start] '(menu-item "Mark Sort Beginning" ledger-sort-insert-start-mark))
(define-key map [sort-buff] '(menu-item "Sort Buffer" ledger-sort-buffer)) (define-key map [sort-buff] '(menu-item "Sort Buffer" ledger-sort-buffer))
(define-key map [sort-reg] '(menu-item "Sort Region" ledger-sort-region :enable mark-active)) (define-key map [sort-reg] '(menu-item "Sort Region" ledger-sort-region :enable mark-active))
(define-key map [align-xact] '(menu-item "Align Xact" ledger-post-align-xact))
(define-key map [align-reg] '(menu-item "Align Region" ledger-post-align-postings :enable mark-active)) (define-key map [align-reg] '(menu-item "Align Region" ledger-post-align-postings :enable mark-active))
(define-key map [sep2] '(menu-item "--")) (define-key map [sep2] '(menu-item "--"))
(define-key map [copy-xact] '(menu-item "Copy Trans at Point" ledger-copy-transaction-at-point)) (define-key map [copy-xact] '(menu-item "Copy Trans at Point" ledger-copy-transaction-at-point))

View file

@ -31,11 +31,6 @@
"Options for controlling how Ledger-mode deals with postings and completion" "Options for controlling how Ledger-mode deals with postings and completion"
:group 'ledger) :group 'ledger)
(defcustom ledger-post-auto-adjust-postings t
"If non-nil, adjust account and amount to columns set below"
:type 'boolean
:group 'ledger-post)
(defcustom ledger-post-account-alignment-column 4 (defcustom ledger-post-account-alignment-column 4
"The column Ledger-mode attempts to align accounts to." "The column Ledger-mode attempts to align accounts to."
:type 'integer :type 'integer
@ -141,6 +136,11 @@ at beginning of account"
(goto-char (match-beginning 2))) (goto-char (match-beginning 2)))
(current-column)))) (current-column))))
(defun ledger-post-align-xact (pos)
(interactive "d")
(let ((bounds (ledger-find-xact-extents pos)))
(ledger-post-align-postings (car bounds) (cadr bounds))))
(defun ledger-post-align-postings (&optional beg end) (defun ledger-post-align-postings (&optional beg end)
"Align all accounts and amounts within region, if there is no "Align all accounts and amounts within region, if there is no
region align the posting on the current line." region align the posting on the current line."
@ -198,16 +198,6 @@ region align the posting on the current line."
(setq inhibit-modification-hooks nil)))) (setq inhibit-modification-hooks nil))))
(defun ledger-post-maybe-align (beg end len)
"Align amounts only if point is in a posting.
BEG, END, and LEN control how far it can align."
(if ledger-post-auto-adjust-postings
(save-excursion
(goto-char beg)
(when (<= end (line-end-position))
(goto-char (line-beginning-position))
(if (looking-at ledger-post-line-regexp)
(ledger-post-align-postings))))))
(defun ledger-post-edit-amount () (defun ledger-post-edit-amount ()
"Call 'calc-mode' and push the amount in the posting to the top of stack." "Call 'calc-mode' and push the amount in the posting to the top of stack."
@ -248,7 +238,6 @@ BEG, END, and LEN control how far it can align."
(defun ledger-post-setup () (defun ledger-post-setup ()
"Configure `ledger-mode' to auto-align postings." "Configure `ledger-mode' to auto-align postings."
(add-hook 'after-change-functions 'ledger-post-maybe-align t t)
(add-hook 'after-save-hook #'(lambda () (setq ledger-post-current-list nil)) t t)) (add-hook 'after-save-hook #'(lambda () (setq ledger-post-current-list nil)) t t))