Code cleanup
This commit is contained in:
parent
ed692ee9a8
commit
19adbf0400
5 changed files with 26 additions and 69 deletions
|
|
@ -78,10 +78,11 @@
|
||||||
(ledger-mode-dump-group 'ledger))
|
(ledger-mode-dump-group 'ledger))
|
||||||
|
|
||||||
|
|
||||||
(defsubst ledger-current-year ()
|
(defun ledger-current-year ()
|
||||||
"The default current year for adding transactions."
|
"The default current year for adding transactions."
|
||||||
(format-time-string "%Y"))
|
(format-time-string "%Y"))
|
||||||
(defsubst ledger-current-month ()
|
|
||||||
|
(defun ledger-current-month ()
|
||||||
"The default current month for adding transactions."
|
"The default current month for adding transactions."
|
||||||
(format-time-string "%m"))
|
(format-time-string "%m"))
|
||||||
|
|
||||||
|
|
@ -310,15 +311,14 @@ With a prefix argument, remove the effective date. "
|
||||||
["Re-run Report" ledger-report-redo ledger-works]
|
["Re-run Report" ledger-report-redo ledger-works]
|
||||||
["Save Report" ledger-report-save ledger-works]
|
["Save Report" ledger-report-save ledger-works]
|
||||||
["Edit Report" ledger-report-edit ledger-works]
|
["Edit Report" ledger-report-edit ledger-works]
|
||||||
["Kill Report" ledger-report-kill ledger-works]
|
["Kill Report" ledger-report-kill ledger-works]))
|
||||||
))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(define-derived-mode ledger-mode text-mode "Ledger"
|
(define-derived-mode ledger-mode text-mode "Ledger"
|
||||||
"A mode for editing ledger data files."
|
"A mode for editing ledger data files."
|
||||||
(ledger-check-version)
|
(ledger-check-version)
|
||||||
(ledger-schedule-check-available)
|
(ledger-schedule-check-available)
|
||||||
(ledger-post-setup)
|
;;(ledger-post-setup)
|
||||||
|
|
||||||
(set-syntax-table ledger-mode-syntax-table)
|
(set-syntax-table ledger-mode-syntax-table)
|
||||||
(set (make-local-variable 'comment-start) "; ")
|
(set (make-local-variable 'comment-start) "; ")
|
||||||
|
|
@ -338,6 +338,7 @@ With a prefix argument, remove the effective date. "
|
||||||
'ledger-complete-at-point)
|
'ledger-complete-at-point)
|
||||||
(add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
|
(add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
|
||||||
|
|
||||||
|
;(add-hook 'after-save-hook)
|
||||||
(add-hook 'post-command-hook 'ledger-highlight-xact-under-point nil t)
|
(add-hook 'post-command-hook 'ledger-highlight-xact-under-point nil t)
|
||||||
(add-hook 'before-revert-hook 'ledger-occur-remove-all-overlays nil t)
|
(add-hook 'before-revert-hook 'ledger-occur-remove-all-overlays nil t)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -148,8 +148,7 @@ Used for coordinating `ledger-occur' with other buffers, like reconcile."
|
||||||
"Remove the transaction hiding overlays."
|
"Remove the transaction hiding overlays."
|
||||||
(interactive)
|
(interactive)
|
||||||
(remove-overlays (point-min)
|
(remove-overlays (point-min)
|
||||||
(point-max) ledger-occur-overlay-property-name t)
|
(point-max) ledger-occur-overlay-property-name t))
|
||||||
(setq ledger-occur-overlay-list nil))
|
|
||||||
|
|
||||||
(defun ledger-occur-find-matches (regex)
|
(defun ledger-occur-find-matches (regex)
|
||||||
"Return a list of 2-number tuples describing the beginning and end of transactions meeting REGEX."
|
"Return a list of 2-number tuples describing the beginning and end of transactions meeting REGEX."
|
||||||
|
|
|
||||||
|
|
@ -49,19 +49,6 @@
|
||||||
(const :tag "iswitchb completion" :iswitchb) )
|
(const :tag "iswitchb completion" :iswitchb) )
|
||||||
:group 'ledger-post)
|
:group 'ledger-post)
|
||||||
|
|
||||||
(defun ledger-post-all-accounts ()
|
|
||||||
"Return a list of all accounts in the buffer."
|
|
||||||
(let ((origin (point))
|
|
||||||
(ledger-post-list nil)
|
|
||||||
account elements)
|
|
||||||
(save-excursion
|
|
||||||
(goto-char (point-min))
|
|
||||||
(while (re-search-forward ledger-post-line-regexp nil t)
|
|
||||||
(unless (and (>= origin (match-beginning 0))
|
|
||||||
(< origin (match-end 0)))
|
|
||||||
(add-to-list 'ledger-post-list (ledger-regex-post-line-account))))
|
|
||||||
(nreverse ledger-post-list))))
|
|
||||||
|
|
||||||
(declare-function iswitchb-read-buffer "iswitchb"
|
(declare-function iswitchb-read-buffer "iswitchb"
|
||||||
(prompt &optional default require-match start matches-set))
|
(prompt &optional default require-match start matches-set))
|
||||||
|
|
||||||
|
|
@ -82,37 +69,8 @@ to choose from."
|
||||||
(t
|
(t
|
||||||
(completing-read prompt choices))))
|
(completing-read prompt choices))))
|
||||||
|
|
||||||
(defvar ledger-post-current-list nil)
|
|
||||||
|
|
||||||
(defun ledger-post-pick-account ()
|
(defun ledger-next-amount (&optional end)
|
||||||
"Insert an account entered by the user."
|
|
||||||
(interactive)
|
|
||||||
(let* ((account
|
|
||||||
(ledger-post-completing-read
|
|
||||||
"Account: " (or ledger-post-current-list
|
|
||||||
(setq ledger-post-current-list
|
|
||||||
(ledger-post-all-accounts)))))
|
|
||||||
(account-len (length account))
|
|
||||||
(pos (point)))
|
|
||||||
(goto-char (line-beginning-position))
|
|
||||||
(when (re-search-forward ledger-post-line-regexp (line-end-position) t)
|
|
||||||
(let ((existing-len (length (ledger-regex-post-line-account))))
|
|
||||||
(goto-char (match-beginning ledger-regex-post-line-group-account))
|
|
||||||
(delete-region (match-beginning ledger-regex-post-line-group-account)
|
|
||||||
(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)))))))
|
|
||||||
(goto-char pos)))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defsubst ledger-next-amount (&optional end)
|
|
||||||
"Move point to the next amount, as long as it is not past END.
|
"Move point to the next amount, as long as it is not past END.
|
||||||
Return the width of the amount field as an integer and leave
|
Return the width of the amount field as an integer and leave
|
||||||
point at beginning of the commodity."
|
point at beginning of the commodity."
|
||||||
|
|
@ -161,7 +119,7 @@ region align the posting on the current line."
|
||||||
(end-region (if end
|
(end-region (if end
|
||||||
end
|
end
|
||||||
(if mark-first (point) (mark))))
|
(if mark-first (point) (mark))))
|
||||||
acct-start-column acct-end-column acct-adjust amt-width
|
acct-start-column acct-end-column acct-adjust amt-width amt-adjust
|
||||||
(lines-left 1))
|
(lines-left 1))
|
||||||
;; Condition point and mark to the beginning and end of lines
|
;; Condition point and mark to the beginning and end of lines
|
||||||
(goto-char end-region)
|
(goto-char end-region)
|
||||||
|
|
@ -246,11 +204,6 @@ region align the posting on the current line."
|
||||||
(re-search-forward ledger-post-line-regexp)
|
(re-search-forward ledger-post-line-regexp)
|
||||||
(goto-char (match-end ledger-regex-post-line-group-account))))
|
(goto-char (match-end ledger-regex-post-line-group-account))))
|
||||||
|
|
||||||
(defun ledger-post-setup ()
|
|
||||||
"Configure `ledger-mode' to auto-align postings."
|
|
||||||
(add-hook 'after-save-hook #'(lambda () (setq ledger-post-current-list nil)) t t))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(provide 'ledger-post)
|
(provide 'ledger-post)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -360,18 +360,22 @@ Optional EDIT the command."
|
||||||
(defun ledger-report-redo ()
|
(defun ledger-report-redo ()
|
||||||
"Redo the report in the current ledger report buffer."
|
"Redo the report in the current ledger report buffer."
|
||||||
(interactive)
|
(interactive)
|
||||||
(ledger-report-goto)
|
|
||||||
(setq buffer-read-only nil)
|
(if (get-buffer ledger-report-buffer-name)
|
||||||
(erase-buffer)
|
(progn
|
||||||
(ledger-do-report ledger-report-cmd)
|
(pop-to-buffer (get-buffer ledger-report-buffer-name))
|
||||||
(setq buffer-read-only nil))
|
(shrink-window-if-larger-than-buffer)
|
||||||
|
(setq buffer-read-only nil)
|
||||||
|
(erase-buffer)
|
||||||
|
(ledger-do-report ledger-report-cmd)
|
||||||
|
(setq buffer-read-only nil))))
|
||||||
|
|
||||||
(defun ledger-report-quit ()
|
(defun ledger-report-quit ()
|
||||||
"Quit the ledger report buffer by burying it."
|
"Quit the ledger report buffer."
|
||||||
(interactive)
|
(interactive)
|
||||||
(ledger-report-goto)
|
(ledger-report-goto)
|
||||||
(set-window-configuration ledger-original-window-cfg)
|
(set-window-configuration ledger-original-window-cfg)
|
||||||
(bury-buffer (get-buffer ledger-report-buffer-name)))
|
(kill-buffer (get-buffer ledger-report-buffer-name)))
|
||||||
|
|
||||||
(defun ledger-report-kill ()
|
(defun ledger-report-kill ()
|
||||||
"Kill the ledger report buffer."
|
"Kill the ledger report buffer."
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,7 @@ MOMENT is an encoded date"
|
||||||
mark desc)))))
|
mark desc)))))
|
||||||
(forward-line))))
|
(forward-line))))
|
||||||
|
|
||||||
(defsubst ledger-goto-line (line-number)
|
(defun ledger-goto-line (line-number)
|
||||||
"Rapidly move point to line LINE-NUMBER."
|
"Rapidly move point to line LINE-NUMBER."
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(forward-line (1- line-number)))
|
(forward-line (1- line-number)))
|
||||||
|
|
@ -170,8 +170,8 @@ MOMENT is an encoded date"
|
||||||
|
|
||||||
(defun ledger-add-transaction (transaction-text &optional insert-at-point)
|
(defun ledger-add-transaction (transaction-text &optional insert-at-point)
|
||||||
"Use ledger xact TRANSACTION-TEXT to add a transaction to the buffer.
|
"Use ledger xact TRANSACTION-TEXT to add a transaction to the buffer.
|
||||||
If INSERT-AT-POINT is non-nil insert the transaction
|
If INSERT-AT-POINT is non-nil insert the transaction there,
|
||||||
there, otherwise call `ledger-xact-find-slot' to insert it at the
|
otherwise call `ledger-xact-find-slot' to insert it at the
|
||||||
correct chronological place in the buffer."
|
correct chronological place in the buffer."
|
||||||
(interactive (list
|
(interactive (list
|
||||||
;; Note: This isn't "just" the date - it can contain
|
;; Note: This isn't "just" the date - it can contain
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue