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))
|
||||
|
||||
|
||||
(defsubst ledger-current-year ()
|
||||
(defun ledger-current-year ()
|
||||
"The default current year for adding transactions."
|
||||
(format-time-string "%Y"))
|
||||
(defsubst ledger-current-month ()
|
||||
|
||||
(defun ledger-current-month ()
|
||||
"The default current month for adding transactions."
|
||||
(format-time-string "%m"))
|
||||
|
||||
|
|
@ -310,15 +311,14 @@ With a prefix argument, remove the effective date. "
|
|||
["Re-run Report" ledger-report-redo ledger-works]
|
||||
["Save Report" ledger-report-save ledger-works]
|
||||
["Edit Report" ledger-report-edit ledger-works]
|
||||
["Kill Report" ledger-report-kill ledger-works]
|
||||
))
|
||||
["Kill Report" ledger-report-kill ledger-works]))
|
||||
|
||||
;;;###autoload
|
||||
(define-derived-mode ledger-mode text-mode "Ledger"
|
||||
"A mode for editing ledger data files."
|
||||
(ledger-check-version)
|
||||
(ledger-schedule-check-available)
|
||||
(ledger-post-setup)
|
||||
;;(ledger-post-setup)
|
||||
|
||||
(set-syntax-table ledger-mode-syntax-table)
|
||||
(set (make-local-variable 'comment-start) "; ")
|
||||
|
|
@ -338,6 +338,7 @@ With a prefix argument, remove the effective date. "
|
|||
'ledger-complete-at-point)
|
||||
(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 '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."
|
||||
(interactive)
|
||||
(remove-overlays (point-min)
|
||||
(point-max) ledger-occur-overlay-property-name t)
|
||||
(setq ledger-occur-overlay-list nil))
|
||||
(point-max) ledger-occur-overlay-property-name t))
|
||||
|
||||
(defun ledger-occur-find-matches (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) )
|
||||
: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"
|
||||
(prompt &optional default require-match start matches-set))
|
||||
|
||||
|
|
@ -82,37 +69,8 @@ to choose from."
|
|||
(t
|
||||
(completing-read prompt choices))))
|
||||
|
||||
(defvar ledger-post-current-list nil)
|
||||
|
||||
(defun ledger-post-pick-account ()
|
||||
"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)
|
||||
(defun ledger-next-amount (&optional 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
|
||||
point at beginning of the commodity."
|
||||
|
|
@ -161,7 +119,7 @@ region align the posting on the current line."
|
|||
(end-region (if end
|
||||
end
|
||||
(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))
|
||||
;; Condition point and mark to the beginning and end of lines
|
||||
(goto-char end-region)
|
||||
|
|
@ -246,11 +204,6 @@ region align the posting on the current line."
|
|||
(re-search-forward ledger-post-line-regexp)
|
||||
(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)
|
||||
|
||||
|
|
|
|||
|
|
@ -360,18 +360,22 @@ Optional EDIT the command."
|
|||
(defun ledger-report-redo ()
|
||||
"Redo the report in the current ledger report buffer."
|
||||
(interactive)
|
||||
(ledger-report-goto)
|
||||
|
||||
(if (get-buffer ledger-report-buffer-name)
|
||||
(progn
|
||||
(pop-to-buffer (get-buffer ledger-report-buffer-name))
|
||||
(shrink-window-if-larger-than-buffer)
|
||||
(setq buffer-read-only nil)
|
||||
(erase-buffer)
|
||||
(ledger-do-report ledger-report-cmd)
|
||||
(setq buffer-read-only nil))
|
||||
(setq buffer-read-only nil))))
|
||||
|
||||
(defun ledger-report-quit ()
|
||||
"Quit the ledger report buffer by burying it."
|
||||
"Quit the ledger report buffer."
|
||||
(interactive)
|
||||
(ledger-report-goto)
|
||||
(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 ()
|
||||
"Kill the ledger report buffer."
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ MOMENT is an encoded date"
|
|||
mark desc)))))
|
||||
(forward-line))))
|
||||
|
||||
(defsubst ledger-goto-line (line-number)
|
||||
(defun ledger-goto-line (line-number)
|
||||
"Rapidly move point to line LINE-NUMBER."
|
||||
(goto-char (point-min))
|
||||
(forward-line (1- line-number)))
|
||||
|
|
@ -170,8 +170,8 @@ MOMENT is an encoded date"
|
|||
|
||||
(defun ledger-add-transaction (transaction-text &optional insert-at-point)
|
||||
"Use ledger xact TRANSACTION-TEXT to add a transaction to the buffer.
|
||||
If INSERT-AT-POINT is non-nil insert the transaction
|
||||
there, otherwise call `ledger-xact-find-slot' to insert it at the
|
||||
If INSERT-AT-POINT is non-nil insert the transaction there,
|
||||
otherwise call `ledger-xact-find-slot' to insert it at the
|
||||
correct chronological place in the buffer."
|
||||
(interactive (list
|
||||
;; Note: This isn't "just" the date - it can contain
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue