Minor refactoring and code cleanup
This commit is contained in:
parent
0f9212071a
commit
bfc925f52f
4 changed files with 30 additions and 62 deletions
|
|
@ -35,39 +35,10 @@
|
||||||
:type 'boolean
|
:type 'boolean
|
||||||
:group 'ledger-fontification)
|
:group 'ledger-fontification)
|
||||||
|
|
||||||
;; (defun ledger-fontify-whole-buffer ()
|
|
||||||
;; (interactive)
|
|
||||||
;; (save-excursion
|
|
||||||
;; (message "Ledger fontify whole buffer")
|
|
||||||
;; (goto-char (point-min))
|
|
||||||
|
|
||||||
;; (while (not (eobp))
|
|
||||||
;; (cond ((looking-at ledger-xact-start-regex)
|
|
||||||
;; (ledger-fontify-xact-at (point)))
|
|
||||||
;; ((looking-at ledger-directive-start-regex)
|
|
||||||
;; (ledger-fontify-directive-at (point))))
|
|
||||||
;; (ledger-xact-next-xact-or-directive) ;; gets to beginning of next xact
|
|
||||||
;; )))
|
|
||||||
|
|
||||||
;; (defun ledger-fontify-activate ()
|
|
||||||
;; "add hook to fontify after buffer changes"
|
|
||||||
;; (interactive)
|
|
||||||
;; (if (string= (format-mode-line 'mode-name) "Ledger")
|
|
||||||
;; (progn
|
|
||||||
;; (ledger-fontify-whole-buffer)
|
|
||||||
;; (add-hook 'after-change-functions 'ledger-fontify-buffer-part)
|
|
||||||
;; (add-hook 'before-change-functions 'ledger-fontify-ensure-activation)
|
|
||||||
;; (message "ledger-fontify-activate called"))))
|
|
||||||
|
|
||||||
;; (defun ledger-fontify-ensure-activation (beg end)
|
|
||||||
;; (if (string= (format-mode-line 'mode-name) "Ledger")
|
|
||||||
;; (add-hook 'after-change-functions 'ledger-fontify-buffer-part)))
|
|
||||||
|
|
||||||
(defun ledger-fontify-buffer-part (beg end len)
|
(defun ledger-fontify-buffer-part (beg end len)
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(unless beg (setq beg (point-min)))
|
(unless beg (setq beg (point-min)))
|
||||||
(unless end (setq end (point-max)))
|
(unless end (setq end (point-max)))
|
||||||
(unless len (setq len (- end beg)))
|
|
||||||
(goto-char beg)
|
(goto-char beg)
|
||||||
(while (< (point) end)
|
(while (< (point) end)
|
||||||
(cond ((or (looking-at ledger-xact-start-regex)
|
(cond ((or (looking-at ledger-xact-start-regex)
|
||||||
|
|
@ -118,6 +89,7 @@
|
||||||
(re-search-forward ledger-posting-regex)
|
(re-search-forward ledger-posting-regex)
|
||||||
(if (match-string 1)
|
(if (match-string 1)
|
||||||
(save-match-data (setq state (ledger-state-from-string (s-trim (match-string 1))))))
|
(save-match-data (setq state (ledger-state-from-string (s-trim (match-string 1))))))
|
||||||
|
;;; FIX THIS. Pull the COND to the outer level and put the fontify-set-face inside. It will be clearer
|
||||||
(ledger-fontify-set-face (list (match-beginning 0) (match-end 2))
|
(ledger-fontify-set-face (list (match-beginning 0) (match-end 2))
|
||||||
(cond ((eq state 'cleared)
|
(cond ((eq state 'cleared)
|
||||||
'ledger-font-posting-account-cleared-face)
|
'ledger-font-posting-account-cleared-face)
|
||||||
|
|
@ -127,9 +99,9 @@
|
||||||
'ledger-font-posting-account-face)))
|
'ledger-font-posting-account-face)))
|
||||||
(ledger-fontify-set-face (list (match-beginning 4) (match-end 4))
|
(ledger-fontify-set-face (list (match-beginning 4) (match-end 4))
|
||||||
(cond ((eq state 'cleared)
|
(cond ((eq state 'cleared)
|
||||||
'ledger-font-posting-account-cleared-face)
|
'ledger-font-posting-amount-cleared-face)
|
||||||
((eq state 'cleared)
|
((eq state 'cleared)
|
||||||
'ledger-font-posting-account-pending-face)
|
'ledger-font-posting-amount-pending-face)
|
||||||
(t
|
(t
|
||||||
'ledger-font-posting-amount-face)))
|
'ledger-font-posting-amount-face)))
|
||||||
(ledger-fontify-set-face (list (match-beginning 5) (match-end 5))
|
(ledger-fontify-set-face (list (match-beginning 5) (match-end 5))
|
||||||
|
|
|
||||||
|
|
@ -261,8 +261,8 @@ With a prefix argument, remove the effective date. "
|
||||||
(define-key map [(control ?c) (control ?o) (control ?r)] 'ledger-report)
|
(define-key map [(control ?c) (control ?o) (control ?r)] 'ledger-report)
|
||||||
(define-key map [(control ?c) (control ?o) (control ?s)] 'ledger-report-save)
|
(define-key map [(control ?c) (control ?o) (control ?s)] 'ledger-report-save)
|
||||||
|
|
||||||
(define-key map [(meta ?p)] 'ledger-post-prev-xact)
|
(define-key map [(meta ?p)] 'ledger-xact-prev-xact)
|
||||||
(define-key map [(meta ?n)] 'ledger-post-next-xact)
|
(define-key map [(meta ?n)] 'ledger-xact-next-xact-or-directive)
|
||||||
map)
|
map)
|
||||||
"Keymap for `ledger-mode'.")
|
"Keymap for `ledger-mode'.")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,6 @@ point at beginning of the commodity."
|
||||||
(- (or (match-end 4)
|
(- (or (match-end 4)
|
||||||
(match-end 3)) (point)))))
|
(match-end 3)) (point)))))
|
||||||
|
|
||||||
|
|
||||||
(defun ledger-next-account (&optional end)
|
(defun ledger-next-account (&optional end)
|
||||||
"Move point to the beginning of the next account, or status marker (!*), as long as it is not past END.
|
"Move point to the beginning of the next account, or status marker (!*), as long as it is not past END.
|
||||||
Return the column of the beginning of the account and leave point
|
Return the column of the beginning of the account and leave point
|
||||||
|
|
@ -164,8 +163,6 @@ region align the posting on the current line."
|
||||||
(setq lines-left (not (eobp))))
|
(setq lines-left (not (eobp))))
|
||||||
(setq inhibit-modification-hooks nil))))
|
(setq inhibit-modification-hooks nil))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(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."
|
||||||
(interactive)
|
(interactive)
|
||||||
|
|
@ -186,24 +183,6 @@ region align the posting on the current line."
|
||||||
(insert " "))
|
(insert " "))
|
||||||
(calc))))))
|
(calc))))))
|
||||||
|
|
||||||
(defun ledger-post-prev-xact ()
|
|
||||||
"Move point to the previous transaction."
|
|
||||||
(interactive)
|
|
||||||
(backward-paragraph)
|
|
||||||
(when (re-search-backward ledger-xact-line-regexp nil t)
|
|
||||||
(goto-char (match-beginning 0))
|
|
||||||
(re-search-forward ledger-post-line-regexp)
|
|
||||||
(goto-char (match-end ledger-regex-post-line-group-account))))
|
|
||||||
|
|
||||||
(defun ledger-post-next-xact ()
|
|
||||||
"Move point to the next transaction."
|
|
||||||
(interactive)
|
|
||||||
(when (re-search-forward ledger-xact-line-regexp nil t)
|
|
||||||
(goto-char (match-beginning 0))
|
|
||||||
(re-search-forward ledger-post-line-regexp)
|
|
||||||
(goto-char (match-end ledger-regex-post-line-group-account))))
|
|
||||||
|
|
||||||
|
|
||||||
(provide 'ledger-post)
|
(provide 'ledger-post)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -212,7 +212,7 @@ beginning with whitespace"
|
||||||
(not (looking-at "[ \t]\\|\\(^$\\)")))
|
(not (looking-at "[ \t]\\|\\(^$\\)")))
|
||||||
|
|
||||||
(defun ledger-xact-next-xact-or-directive ()
|
(defun ledger-xact-next-xact-or-directive ()
|
||||||
"move to the beginning of the next xact"
|
"move to the beginning of the next xact or directive"
|
||||||
(interactive)
|
(interactive)
|
||||||
(beginning-of-line)
|
(beginning-of-line)
|
||||||
(if (ledger-xact-start-xact-or-directive-p) ; if we are the start of an xact, move forward to the next xact
|
(if (ledger-xact-start-xact-or-directive-p) ; if we are the start of an xact, move forward to the next xact
|
||||||
|
|
@ -224,13 +224,30 @@ beginning with whitespace"
|
||||||
(ledger-xact-start-xact-or-directive-p)))
|
(ledger-xact-start-xact-or-directive-p)))
|
||||||
(forward-line))))
|
(forward-line))))
|
||||||
|
|
||||||
(defun ledger-xact-next-xact ()
|
(defun ledger-xact-prev-xact ()
|
||||||
(interactive)
|
"Move point to the previous transaction."
|
||||||
(beginning-of-line)
|
(interactive)
|
||||||
(if (looking-at ledger-xact-start-regex)
|
(backward-paragraph)
|
||||||
(forward-line))
|
(when (re-search-backward ledger-xact-line-regexp nil t)
|
||||||
(re-search-forward ledger-xact-start-regex)
|
(goto-char (match-beginning 0))
|
||||||
(forward-line -1))
|
(re-search-forward ledger-post-line-regexp)
|
||||||
|
(goto-char (match-end ledger-regex-post-line-group-account))))
|
||||||
|
|
||||||
|
;; (defun ledger-post-next-xact ()
|
||||||
|
;; "Move point to the next transaction."
|
||||||
|
;; (interactive)
|
||||||
|
;; (when (re-search-forward ledger-xact-line-regexp nil t)
|
||||||
|
;; (goto-char (match-beginning 0))
|
||||||
|
;; (re-search-forward ledger-post-line-regexp)
|
||||||
|
;; (goto-char (match-end ledger-regex-post-line-group-account))))
|
||||||
|
|
||||||
|
;; (defun ledger-xact-next-xact ()
|
||||||
|
;; (interactive)
|
||||||
|
;; (beginning-of-line)
|
||||||
|
;; (if (looking-at ledger-xact-start-regex)
|
||||||
|
;; (forward-line))
|
||||||
|
;; (re-search-forward ledger-xact-start-regex)
|
||||||
|
;; (forward-line -1))
|
||||||
|
|
||||||
|
|
||||||
(provide 'ledger-xact)
|
(provide 'ledger-xact)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue