Lisp code cleanup.
Mostly went through and clarified variable names. Rather than "entry" for everything, use "transaction" and "posting" as appropriate to improve readability.
This commit is contained in:
parent
36a00113d9
commit
e3b37ac19e
8 changed files with 60 additions and 46 deletions
|
|
@ -30,10 +30,10 @@
|
|||
(goto-char (line-beginning-position))
|
||||
(cond ((looking-at "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.+?)\\)?\\s-+")
|
||||
(goto-char (match-end 0))
|
||||
'entry)
|
||||
'transaction)
|
||||
((looking-at "^\\s-+\\([*!]\\s-+\\)?[[(]?\\(.\\)")
|
||||
(goto-char (match-beginning 2))
|
||||
'transaction)
|
||||
'posting)
|
||||
((looking-at "^\\(sun\\|mon\\|tue\\|wed\\|thu\\|fri\\|sat\\)\\s-+")
|
||||
(goto-char (match-end 0))
|
||||
'entry)
|
||||
|
|
@ -57,24 +57,26 @@
|
|||
args)))
|
||||
(cons (reverse args) (reverse begins)))))
|
||||
|
||||
(defun ledger-entries ()
|
||||
(defun ledger-payees ()
|
||||
(let ((origin (point))
|
||||
entries-list)
|
||||
payees-list)
|
||||
(save-excursion
|
||||
(goto-char (point-min))
|
||||
(while (re-search-forward
|
||||
(concat "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+"
|
||||
"\\(.+?\\)\\(\t\\|\n\\| [ \t]\\)") nil t)
|
||||
"\\(.+?\\)\\(\t\\|\n\\| [ \t]\\)") nil t) ;matches first line of transaction
|
||||
(unless (and (>= origin (match-beginning 0))
|
||||
(< origin (match-end 0)))
|
||||
(setq entries-list (cons (match-string-no-properties 3)
|
||||
entries-list)))))
|
||||
(pcomplete-uniqify-list (nreverse entries-list))))
|
||||
(setq payees-list (cons (match-string-no-properties 3)
|
||||
payees-list))))) ;add the payee to the list
|
||||
(pcomplete-uniqify-list (nreverse payees-list))))
|
||||
|
||||
(defvar ledger-account-tree nil)
|
||||
|
||||
(defun ledger-find-accounts ()
|
||||
(let ((origin (point)) account-path elements)
|
||||
(let ((origin (point))
|
||||
account-path
|
||||
elements)
|
||||
(save-excursion
|
||||
(setq ledger-account-tree (list t))
|
||||
(goto-char (point-min))
|
||||
|
|
@ -126,16 +128,16 @@
|
|||
(interactive)
|
||||
(while (pcomplete-here
|
||||
(if (eq (save-excursion
|
||||
(ledger-thing-at-point)) 'entry)
|
||||
(ledger-thing-at-point)) 'transaction)
|
||||
(if (null current-prefix-arg)
|
||||
(ledger-entries) ; this completes against entry names
|
||||
(ledger-payees) ; this completes against payee names
|
||||
(progn
|
||||
(let ((text (buffer-substring (line-beginning-position)
|
||||
(line-end-position))))
|
||||
(delete-region (line-beginning-position)
|
||||
(line-end-position))
|
||||
(condition-case err
|
||||
(ledger-add-entry text t)
|
||||
(ledger-add-transaction text t)
|
||||
((error)
|
||||
(insert text))))
|
||||
(forward-line)
|
||||
|
|
@ -151,7 +153,7 @@
|
|||
(let ((name (caar (ledger-parse-arguments)))
|
||||
xacts)
|
||||
(save-excursion
|
||||
(when (eq 'entry (ledger-thing-at-point))
|
||||
(when (eq 'transaction (ledger-thing-at-point))
|
||||
(when (re-search-backward
|
||||
(concat "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+"
|
||||
(regexp-quote name) "\\(\t\\|\n\\| [ \t]\\)") nil t)
|
||||
|
|
|
|||
|
|
@ -70,8 +70,8 @@ customizable to ease retro-entry.")
|
|||
(make-variable-buffer-local 'highlight-overlay)
|
||||
|
||||
(let ((map (current-local-map)))
|
||||
(define-key map [(control ?c) (control ?a)] 'ledger-add-entry)
|
||||
(define-key map [(control ?c) (control ?d)] 'ledger-delete-current-entry)
|
||||
(define-key map [(control ?c) (control ?a)] 'ledger-add-transaction)
|
||||
(define-key map [(control ?c) (control ?d)] 'ledger-delete-current-transaction)
|
||||
(define-key map [(control ?c) (control ?y)] 'ledger-set-year)
|
||||
(define-key map [(control ?c) (control ?m)] 'ledger-set-month)
|
||||
(define-key map [(control ?c) (control ?c)] 'ledger-toggle-current)
|
||||
|
|
@ -119,8 +119,8 @@ customizable to ease retro-entry.")
|
|||
(define-key map [sep4] '(menu-item "--"))
|
||||
(define-key map [edit-amount] '(menu-item "Calc on Amount" ledger-post-edit-amount))
|
||||
(define-key map [sep] '(menu-item "--"))
|
||||
(define-key map [delete-xact] '(menu-item "Delete Entry" ledger-delete-current-entry))
|
||||
(define-key map [add-xact] '(menu-item "Add Entry" ledger-add-entry :enable ledger-works))
|
||||
(define-key map [delete-xact] '(menu-item "Delete Entry" ledger-delete-current-transaction))
|
||||
(define-key map [add-xact] '(menu-item "Add Transaction" ledger-add-transaction :enable ledger-works))
|
||||
(define-key map [sep3] '(menu-item "--"))
|
||||
(define-key map [reconcile] '(menu-item "Reconcile Account" ledger-reconcile :enable ledger-works))
|
||||
(define-key map [reconcile] '(menu-item "Hide Xacts" ledger-occur))))
|
||||
|
|
@ -140,13 +140,13 @@ Return the difference in the format of a time value."
|
|||
|
||||
(defun ledger-find-slot (moment)
|
||||
(catch 'found
|
||||
(ledger-iterate-entries
|
||||
(ledger-iterate-transactions
|
||||
(function
|
||||
(lambda (start date mark desc)
|
||||
(if (ledger-time-less-p moment date)
|
||||
(throw 'found t)))))))
|
||||
|
||||
(defun ledger-iterate-entries (callback)
|
||||
(defun ledger-iterate-transactions (callback)
|
||||
(goto-char (point-min))
|
||||
(let* ((now (current-time))
|
||||
(current-year (nth 5 (decode-time now))))
|
||||
|
|
@ -187,11 +187,11 @@ Return the difference in the format of a time value."
|
|||
(setq ledger-month (read-string "Month: " (ledger-current-month)))
|
||||
(setq ledger-month (format "%02d" newmonth))))
|
||||
|
||||
(defun ledger-add-entry (entry-text &optional insert-at-point)
|
||||
(defun ledger-add-transaction (transaction-text &optional insert-at-point)
|
||||
(interactive (list
|
||||
(read-string "Entry: " (concat ledger-year "/" ledger-month "/"))))
|
||||
(read-string "Transaction: " (concat ledger-year "/" ledger-month "/"))))
|
||||
(let* ((args (with-temp-buffer
|
||||
(insert entry-text)
|
||||
(insert transaction-text)
|
||||
(eshell-parse-arguments (point-min) (point-max))))
|
||||
(ledger-buf (current-buffer))
|
||||
exit-code)
|
||||
|
|
@ -208,7 +208,7 @@ Return the difference in the format of a time value."
|
|||
(insert
|
||||
(with-temp-buffer
|
||||
(setq exit-code
|
||||
(apply #'ledger-exec-ledger ledger-buf ledger-buf "entry"
|
||||
(apply #'ledger-exec-ledger ledger-buf ledger-buf "xact"
|
||||
(mapcar 'eval args)))
|
||||
(goto-char (point-min))
|
||||
(if (looking-at "Error: ")
|
||||
|
|
@ -219,7 +219,7 @@ Return the difference in the format of a time value."
|
|||
(insert (car args) " \n\n")
|
||||
(end-of-line -1)))))
|
||||
|
||||
(defun ledger-current-entry-bounds ()
|
||||
(defun ledger-current-transaction-bounds ()
|
||||
(save-excursion
|
||||
(when (or (looking-at "^[0-9]")
|
||||
(re-search-backward "^[0-9]" nil t))
|
||||
|
|
@ -228,9 +228,9 @@ Return the difference in the format of a time value."
|
|||
(forward-line))
|
||||
(cons (copy-marker beg) (point-marker))))))
|
||||
|
||||
(defun ledger-delete-current-entry ()
|
||||
(defun ledger-delete-current-transaction ()
|
||||
(interactive)
|
||||
(let ((bounds (ledger-current-entry-bounds)))
|
||||
(let ((bounds (ledger-current-transaction-bounds)))
|
||||
(delete-region (car bounds) (cdr bounds))))
|
||||
|
||||
(provide 'ldg-mode)
|
||||
|
|
|
|||
|
|
@ -47,10 +47,6 @@
|
|||
(require 'ldg-fonts)
|
||||
(require 'ldg-occur)
|
||||
|
||||
;(autoload #'ledger-mode "ldg-mode" nil t)
|
||||
;(autoload #'ledger-fully-complete-entry "ldg-complete" nil t)
|
||||
;(autoload #'ledger-toggle-current "ldg-state" nil t)
|
||||
|
||||
(autoload #'ledger-texi-update-test "ldg-texi" nil t)
|
||||
(autoload #'ledger-texi-update-examples "ldg-texi" nil t)
|
||||
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ This is done so that the last digit falls in COLUMN, which defaults to 52."
|
|||
(goto-char (line-beginning-position))
|
||||
(when (re-search-forward ledger-post-line-regexp (line-end-position) t)
|
||||
(goto-char (match-end ledger-regex-post-line-group-account)) ;go to the and of the account
|
||||
(let ((end-of-amount (re-search-forward "[-.,0-9]+" (line-end-position) t))) ;determine if the is an amount to edit
|
||||
(let ((end-of-amount (re-search-forward "[-.,0-9]+" (line-end-position) t))) ;determine if there is an amount to edit
|
||||
(if end-of-amount
|
||||
(let ((val (match-string 0)))
|
||||
(goto-char (match-beginning 0))
|
||||
|
|
@ -171,8 +171,7 @@ This is done so that the last digit falls in COLUMN, which defaults to 52."
|
|||
(if (search-backward " " (- (point) 3) t)
|
||||
(goto-char (line-end-position))
|
||||
(insert " "))
|
||||
(calc))
|
||||
))))
|
||||
(calc))))))
|
||||
|
||||
(defun ledger-post-prev-xact ()
|
||||
(interactive)
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@
|
|||
(defun ledger-reconcile-add ()
|
||||
(interactive)
|
||||
(with-current-buffer ledger-buf
|
||||
(call-interactively #'ledger-add-entry))
|
||||
(call-interactively #'ledger-add-transaction))
|
||||
(ledger-reconcile-refresh))
|
||||
|
||||
(defun ledger-reconcile-delete ()
|
||||
|
|
@ -128,7 +128,7 @@
|
|||
(when (ledger-reconcile-get-buffer where)
|
||||
(with-current-buffer (ledger-reconcile-get-buffer where)
|
||||
(goto-char (cdr where))
|
||||
(ledger-delete-current-entry))
|
||||
(ledger-delete-current-transaction))
|
||||
(let ((inhibit-read-only t))
|
||||
(goto-char (line-beginning-position))
|
||||
(delete-region (point) (1+ (line-end-position)))
|
||||
|
|
@ -159,6 +159,23 @@
|
|||
(set-buffer-modified-p nil)
|
||||
(ledger-display-balance))
|
||||
|
||||
(defun ledger-reconcile-finish ()
|
||||
"Mark all pending transactions as cleared, save the buffers and exit reconcile mode"
|
||||
(interactive)
|
||||
(save-excursion
|
||||
(goto-char (point-min))
|
||||
(while (not (eobp))
|
||||
(let ((where (get-text-property (point) 'where))
|
||||
(face (get-text-property (point) 'face)))
|
||||
(if (and (eq face 'bold)
|
||||
(when (is-stdin (car where))))
|
||||
(with-current-buffer ledger-buf
|
||||
(goto-char (cdr where))
|
||||
(ledger-toggle-current 'cleared))))
|
||||
(forward-line 1)))
|
||||
(ledger-reconcile-save))
|
||||
|
||||
|
||||
(defun ledger-reconcile-quit ()
|
||||
(interactive)
|
||||
(ledger-reconcile-quit-cleanup)
|
||||
|
|
@ -191,7 +208,7 @@
|
|||
(cons
|
||||
buf
|
||||
(save-excursion
|
||||
(if ledger-clear-whole-entries
|
||||
(if ledger-clear-whole-transactions
|
||||
(goto-line (nth 1 emacs-xact))
|
||||
(goto-line (nth 0 posting)))
|
||||
(1+ (point-marker))))))) ;Add 1 to make sure the marker is within the transaction
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@
|
|||
(with-current-buffer data-buffer
|
||||
(cons
|
||||
(nth 0 post)
|
||||
(if ledger-clear-whole-entries
|
||||
(if ledger-clear-whole-transactions
|
||||
(save-excursion
|
||||
(goto-line (nth 1 post))
|
||||
(point-marker))
|
||||
|
|
|
|||
|
|
@ -216,7 +216,7 @@ end of a ledger file which is included in some other file."
|
|||
The user is prompted to enter a payee and that is substitued. If
|
||||
point is in an entry, the payee for that entry is used as the
|
||||
default."
|
||||
;; It is intended copmletion should be available on existing
|
||||
;; It is intended completion should be available on existing
|
||||
;; payees, but the list of possible completions needs to be
|
||||
;; developed to allow this.
|
||||
(ledger-read-string-with-default "Payee" (regexp-quote (ledger-entry-payee))))
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@
|
|||
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
;; MA 02111-1307, USA.
|
||||
|
||||
(defcustom ledger-clear-whole-entries nil
|
||||
"If non-nil, clear whole entries, not individual transactions."
|
||||
(defcustom ledger-clear-whole-transactions nil
|
||||
"If non-nil, clear whole transactions, not individual postings."
|
||||
:type 'boolean
|
||||
:group 'ledger)
|
||||
|
||||
|
|
@ -32,7 +32,7 @@
|
|||
'pending
|
||||
'cleared)))
|
||||
|
||||
(defun ledger-entry-state ()
|
||||
(defun ledger-transaction-state ()
|
||||
(save-excursion
|
||||
(when (or (looking-at "^[0-9]")
|
||||
(re-search-backward "^[0-9]" nil t))
|
||||
|
|
@ -42,13 +42,13 @@
|
|||
((looking-at "\\*\\s-*") 'cleared)
|
||||
(t nil)))))
|
||||
|
||||
(defun ledger-transaction-state ()
|
||||
(defun ledger-posting-state ()
|
||||
(save-excursion
|
||||
(goto-char (line-beginning-position))
|
||||
(skip-syntax-forward " ")
|
||||
(cond ((looking-at "!\\s-*") 'pending)
|
||||
((looking-at "\\*\\s-*") 'cleared)
|
||||
(t (ledger-entry-state)))))
|
||||
(t (ledger-transaction-state)))))
|
||||
|
||||
(defun ledger-toggle-current-transaction (&optional style)
|
||||
"Toggle the cleared status of the transaction under point.
|
||||
|
|
@ -172,15 +172,15 @@ dropped."
|
|||
|
||||
(defun ledger-toggle-current (&optional style)
|
||||
(interactive)
|
||||
(if (or ledger-clear-whole-entries
|
||||
(eq 'entry (ledger-thing-at-point)))
|
||||
(if (or ledger-clear-whole-transactions
|
||||
(eq 'transaction (ledger-thing-at-point)))
|
||||
(progn
|
||||
(save-excursion
|
||||
(forward-line)
|
||||
(goto-char (line-beginning-position))
|
||||
(while (and (not (eolp))
|
||||
(save-excursion
|
||||
(not (eq 'entry (ledger-thing-at-point)))))
|
||||
(not (eq 'transaction (ledger-thing-at-point)))))
|
||||
(if (looking-at "\\s-+[*!]")
|
||||
(ledger-toggle-current-transaction nil))
|
||||
(forward-line)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue