Fixed some formatting problems and fixed bug 1007 aligning decimal comma amounts with period thousand separators.
This commit is contained in:
parent
aec2c7af3f
commit
0ed6b0f1c3
2 changed files with 63 additions and 63 deletions
|
|
@ -45,8 +45,8 @@
|
|||
"Which completion engine to use, :iswitchb or :ido chose those engines,
|
||||
:built-in uses built-in Ledger-mode completion"
|
||||
:type '(radio (const :tag "built in completion" :built-in)
|
||||
(const :tag "ido completion" :ido)
|
||||
(const :tag "iswitchb completion" :iswitchb) )
|
||||
(const :tag "ido completion" :ido)
|
||||
(const :tag "iswitchb completion" :iswitchb) )
|
||||
:group 'ledger-post)
|
||||
|
||||
(defun ledger-post-all-accounts ()
|
||||
|
|
@ -72,15 +72,15 @@
|
|||
PROMPT is a string to prompt with. CHOICES is a list of strings
|
||||
to choose from."
|
||||
(cond ((eq ledger-post-use-completion-engine :iswitchb)
|
||||
(let* ((iswitchb-use-virtual-buffers nil)
|
||||
(iswitchb-make-buflist-hook
|
||||
(lambda ()
|
||||
(setq iswitchb-temp-buflist choices))))
|
||||
(iswitchb-read-buffer prompt)))
|
||||
((eq ledger-post-use-completion-engine :ido)
|
||||
(ido-completing-read prompt choices))
|
||||
(t
|
||||
(completing-read prompt choices))))
|
||||
(let* ((iswitchb-use-virtual-buffers nil)
|
||||
(iswitchb-make-buflist-hook
|
||||
(lambda ()
|
||||
(setq iswitchb-temp-buflist choices))))
|
||||
(iswitchb-read-buffer prompt)))
|
||||
((eq ledger-post-use-completion-engine :ido)
|
||||
(ido-completing-read prompt choices))
|
||||
(t
|
||||
(completing-read prompt choices))))
|
||||
|
||||
(defvar ledger-post-current-list nil)
|
||||
|
||||
|
|
@ -102,12 +102,12 @@ to choose from."
|
|||
(match-end ledger-regex-post-line-group-account))
|
||||
(insert account)
|
||||
(cond
|
||||
((> existing-len account-len)
|
||||
(insert (make-string (- existing-len account-len) ? )))
|
||||
((< existing-len account-len)
|
||||
(dotimes (n (- account-len existing-len))
|
||||
(if (looking-at "[ \t]\\( [ \t]\\|\t\\)")
|
||||
(delete-char 1)))))))
|
||||
((> existing-len account-len)
|
||||
(insert (make-string (- existing-len account-len) ? )))
|
||||
((< existing-len account-len)
|
||||
(dotimes (n (- account-len existing-len))
|
||||
(if (looking-at "[ \t]\\( [ \t]\\|\t\\)")
|
||||
(delete-char 1)))))))
|
||||
(goto-char pos)))
|
||||
|
||||
|
||||
|
|
@ -131,11 +131,11 @@ Return the column of the beginning of the account and leave point
|
|||
at beginning of account"
|
||||
(if (> end (point))
|
||||
(when (re-search-forward ledger-account-any-status-regex (1+ end) t)
|
||||
;; the 1+ is to make sure we can catch the newline
|
||||
(if (match-beginning 1)
|
||||
(goto-char (match-beginning 1))
|
||||
(goto-char (match-beginning 2)))
|
||||
(current-column))))
|
||||
;; the 1+ is to make sure we can catch the newline
|
||||
(if (match-beginning 1)
|
||||
(goto-char (match-beginning 1))
|
||||
(goto-char (match-beginning 2)))
|
||||
(current-column))))
|
||||
|
||||
(defun ledger-post-align-xact (pos)
|
||||
(interactive "d")
|
||||
|
|
@ -150,52 +150,52 @@ region align the posting on the current line."
|
|||
|
||||
(save-excursion
|
||||
(if (or (not (mark))
|
||||
(not (use-region-p)))
|
||||
(set-mark (point)))
|
||||
(not (use-region-p)))
|
||||
(set-mark (point)))
|
||||
|
||||
(let* ((inhibit-modification-hooks t)
|
||||
(mark-first (< (mark) (point)))
|
||||
(begin-region (if beg
|
||||
beg
|
||||
(if mark-first (mark) (point))))
|
||||
(end-region (if end
|
||||
end
|
||||
(if mark-first (point) (mark))))
|
||||
acct-start-column acct-end-column acct-adjust amt-width
|
||||
(lines-left 1))
|
||||
(mark-first (< (mark) (point)))
|
||||
(begin-region (if beg
|
||||
beg
|
||||
(if mark-first (mark) (point))))
|
||||
(end-region (if end
|
||||
end
|
||||
(if mark-first (point) (mark))))
|
||||
acct-start-column acct-end-column acct-adjust amt-width
|
||||
(lines-left 1))
|
||||
;; Condition point and mark to the beginning and end of lines
|
||||
(goto-char end-region)
|
||||
(setq end-region (line-end-position))
|
||||
(goto-char begin-region)
|
||||
(goto-char
|
||||
(setq begin-region
|
||||
(line-beginning-position)))
|
||||
(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-region))
|
||||
(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))))
|
||||
lines-left)
|
||||
(< (point) end-region))
|
||||
(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))))
|
||||
|
||||
|
||||
|
|
@ -214,11 +214,11 @@ region align the posting on the current line."
|
|||
(delete-region (match-beginning 0) (match-end 0))
|
||||
(calc)
|
||||
(calc-eval val-string 'push)) ;; edit the amount
|
||||
(progn ;;make sure there are two spaces after the account name and go to calc
|
||||
(if (search-backward " " (- (point) 3) t)
|
||||
(goto-char (line-end-position))
|
||||
(insert " "))
|
||||
(calc))))))
|
||||
(progn ;;make sure there are two spaces after the account name and go to calc
|
||||
(if (search-backward " " (- (point) 3) t)
|
||||
(goto-char (line-end-position))
|
||||
(insert " "))
|
||||
(calc))))))
|
||||
|
||||
(defun ledger-post-prev-xact ()
|
||||
"Move point to the previous transaction."
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
(defconst ledger-amount-regex
|
||||
(concat "\\( \\|\t\\| \t\\)[ \t]*-?"
|
||||
"\\([A-Z$€£_]+ *\\)?"
|
||||
"\\(-?[0-9,]+?\\)"
|
||||
"\\(-?[0-9,\\.]+?\\)"
|
||||
"\\(.[0-9]+\\)?"
|
||||
"\\( *[[:word:]€£_\"]+\\)?"
|
||||
"\\([ \t]*[@={]@?[^\n;]+?\\)?"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue