The Great Renaming

To better follow naming standards used in the accounting community --
particularly those relating to double-entry accounting -- the following
technical terms in Ledger have been changed:

 - what was "entry" is now "transaction"
 - what was "transaction" is now "posting"

Correspondingly, the shorthand names "entry" and "xact" have been
changed to "xact" and "post", respectively.
This commit is contained in:
John Wiegley 2009-02-23 18:39:54 -04:00
parent 310e339464
commit 057506ab6d
2 changed files with 162 additions and 95 deletions

View file

@ -35,11 +35,11 @@
;; To use this module: Load this file, open a ledger data file, and ;; To use this module: Load this file, open a ledger data file, and
;; type M-x ledger-mode. Once this is done, you can type: ;; type M-x ledger-mode. Once this is done, you can type:
;; ;;
;; C-c C-a add a new entry, based on previous entries ;; C-c C-a add a new transaction, based on previous transactions
;; C-c C-e toggle cleared status of an entry ;; C-c C-e toggle cleared status of an transaction
;; C-c C-y set default year for entry mode ;; C-c C-y set default year for transaction mode
;; C-c C-m set default month for entry mode ;; C-c C-m set default month for transaction mode
;; C-c C-r reconcile uncleared entries related to an account ;; C-c C-r reconcile uncleared transactions related to an account
;; C-c C-o C-r run a ledger report ;; C-c C-o C-r run a ledger report
;; C-C C-o C-g goto the ledger report buffer ;; C-C C-o C-g goto the ledger report buffer
;; C-c C-o C-e edit the defined ledger reports ;; C-c C-o C-e edit the defined ledger reports
@ -48,7 +48,7 @@
;; C-c C-o C-k kill the ledger report buffer ;; C-c C-o C-k kill the ledger report buffer
;; ;;
;; In the reconcile buffer, use SPACE to toggle the cleared status of ;; In the reconcile buffer, use SPACE to toggle the cleared status of
;; a transaction, C-x C-s to save changes (to the ledger file as ;; a posting, C-x C-s to save changes (to the ledger file as
;; well). ;; well).
;; ;;
;; The ledger reports command asks the user to select a report to run ;; The ledger reports command asks the user to select a report to run
@ -85,8 +85,8 @@
:type 'file :type 'file
:group 'ledger) :group 'ledger)
(defcustom ledger-clear-whole-entries nil (defcustom ledger-clear-whole-transactions nil
"If non-nil, clear whole entries, not individual transactions." "If non-nil, clear whole transactions, not individual postings."
:type 'boolean :type 'boolean
:group 'ledger) :group 'ledger)
@ -121,8 +121,8 @@ text that should replace the format specifier."
:type 'alist :type 'alist
:group 'ledger) :group 'ledger)
(defcustom ledger-default-acct-transaction-indent " " (defcustom ledger-default-acct-posting-indent " "
"Default indentation for account transactions in an entry." "Default indentation for account postings in an transaction."
:type 'string :type 'string
:group 'ledger) :group 'ledger)
@ -147,12 +147,12 @@ text that should replace the format specifier."
(defvar ledger-year (ledger-current-year) (defvar ledger-year (ledger-current-year)
"Start a ledger session with the current year, but make it "Start a ledger session with the current year, but make it
customizable to ease retro-entry.") customizable to ease retro-transaction.")
(defvar ledger-month (ledger-current-month) (defvar ledger-month (ledger-current-month)
"Start a ledger session with the current month, but make it "Start a ledger session with the current month, but make it
customizable to ease retro-entry.") customizable to ease retro-transaction.")
(defun ledger-iterate-entries (callback) (defun ledger-iterate-transactions (callback)
(goto-char (point-min)) (goto-char (point-min))
(let* ((now (current-time)) (let* ((now (current-time))
(current-year (nth 5 (decode-time now)))) (current-year (nth 5 (decode-time now))))
@ -194,18 +194,18 @@ Return the difference in the format of a time value."
(defun ledger-find-slot (moment) (defun ledger-find-slot (moment)
(catch 'found (catch 'found
(ledger-iterate-entries (ledger-iterate-transactions
(function (function
(lambda (start date mark desc) (lambda (start date mark desc)
(if (ledger-time-less-p moment date) (if (ledger-time-less-p moment date)
(throw 'found t))))))) (throw 'found t)))))))
(defun ledger-add-entry (entry-text &optional insert-at-point) (defun ledger-add-transaction (transaction-text &optional insert-at-point)
(interactive (interactive
(list (list
(read-string "Entry: " (concat ledger-year "/" ledger-month "/")))) (read-string "Transaction: " (concat ledger-year "/" ledger-month "/"))))
(let* ((args (with-temp-buffer (let* ((args (with-temp-buffer
(insert entry-text) (insert transaction-text)
(eshell-parse-arguments (point-min) (point-max)))) (eshell-parse-arguments (point-min) (point-max))))
(ledger-buf (current-buffer)) (ledger-buf (current-buffer))
exit-code) exit-code)
@ -221,7 +221,7 @@ Return the difference in the format of a time value."
(insert (insert
(with-temp-buffer (with-temp-buffer
(setq exit-code (setq exit-code
(apply #'ledger-run-ledger ledger-buf "entry" (apply #'ledger-run-ledger ledger-buf "xact"
(mapcar 'eval args))) (mapcar 'eval args)))
(goto-char (point-min)) (goto-char (point-min))
(if (looking-at "Error: ") (if (looking-at "Error: ")
@ -231,7 +231,7 @@ Return the difference in the format of a time value."
(buffer-string))) (buffer-string)))
"\n")))) "\n"))))
(defun ledger-current-entry-bounds () (defun ledger-current-transaction-bounds ()
(save-excursion (save-excursion
(when (or (looking-at "^[0-9]") (when (or (looking-at "^[0-9]")
(re-search-backward "^[0-9]" nil t)) (re-search-backward "^[0-9]" nil t))
@ -240,12 +240,12 @@ Return the difference in the format of a time value."
(forward-line)) (forward-line))
(cons (copy-marker beg) (point-marker)))))) (cons (copy-marker beg) (point-marker))))))
(defun ledger-delete-current-entry () (defun ledger-delete-current-transaction ()
(interactive) (interactive)
(let ((bounds (ledger-current-entry-bounds))) (let ((bounds (ledger-current-transaction-bounds)))
(delete-region (car bounds) (cdr bounds)))) (delete-region (car bounds) (cdr bounds))))
(defun ledger-toggle-current-entry (&optional style) (defun ledger-toggle-current-transaction (&optional style)
(interactive) (interactive)
(let (clear) (let (clear)
(save-excursion (save-excursion
@ -275,7 +275,7 @@ Return the difference in the format of a time value."
'pending 'pending
'cleared))) 'cleared)))
(defun ledger-entry-state () (defun ledger-transaction-state ()
(save-excursion (save-excursion
(when (or (looking-at "^[0-9]") (when (or (looking-at "^[0-9]")
(re-search-backward "^[0-9]" nil t)) (re-search-backward "^[0-9]" nil t))
@ -285,30 +285,30 @@ Return the difference in the format of a time value."
((looking-at "\\*\\s-*") 'cleared) ((looking-at "\\*\\s-*") 'cleared)
(t nil))))) (t nil)))))
(defun ledger-transaction-state () (defun ledger-posting-state ()
(save-excursion (save-excursion
(goto-char (line-beginning-position)) (goto-char (line-beginning-position))
(skip-syntax-forward " ") (skip-syntax-forward " ")
(cond ((looking-at "!\\s-*") 'pending) (cond ((looking-at "!\\s-*") 'pending)
((looking-at "\\*\\s-*") 'cleared) ((looking-at "\\*\\s-*") 'cleared)
(t (ledger-entry-state))))) (t (ledger-transaction-state)))))
(defun ledger-toggle-current-transaction (&optional style) (defun ledger-toggle-current-posting (&optional style)
"Toggle the cleared status of the transaction under point. "Toggle the cleared status of the posting under point.
Optional argument STYLE may be `pending' or `cleared', depending Optional argument STYLE may be `pending' or `cleared', depending
on which type of status the caller wishes to indicate (default is on which type of status the caller wishes to indicate (default is
`cleared'). `cleared').
This function is rather complicated because it must preserve both This function is rather complicated because it must preserve both
the overall formatting of the ledger entry, as well as ensuring the overall formatting of the ledger transaction, as well as ensuring
that the most minimal display format is used. This could be that the most minimal display format is used. This could be
achieved more certainly by passing the entry to ledger for achieved more certainly by passing the transaction to ledger for
formatting, but doing so causes inline math expressions to be formatting, but doing so causes inline math expressions to be
dropped." dropped."
(interactive) (interactive)
(let ((bounds (ledger-current-entry-bounds)) (let ((bounds (ledger-current-transaction-bounds))
clear cleared) clear cleared)
;; Uncompact the entry, to make it easier to toggle the ;; Uncompact the transaction, to make it easier to toggle the
;; transaction ;; posting
(save-excursion (save-excursion
(goto-char (car bounds)) (goto-char (car bounds))
(skip-chars-forward "0-9./= \t") (skip-chars-forward "0-9./= \t")
@ -329,7 +329,7 @@ dropped."
(if (search-forward " " (line-end-position) t) (if (search-forward " " (line-end-position) t)
(delete-char 2)) (delete-char 2))
(forward-line)))) (forward-line))))
;; Toggle the individual transaction ;; Toggle the individual posting
(save-excursion (save-excursion
(goto-char (line-beginning-position)) (goto-char (line-beginning-position))
(when (looking-at "[ \t]") (when (looking-at "[ \t]")
@ -367,7 +367,7 @@ dropped."
((looking-at " ") ((looking-at " ")
(delete-char 1)))) (delete-char 1))))
(setq clear inserted))))) (setq clear inserted)))))
;; Clean up the entry so that it displays minimally ;; Clean up the transaction so that it displays minimally
(save-excursion (save-excursion
(goto-char (car bounds)) (goto-char (car bounds))
(forward-line) (forward-line)
@ -415,9 +415,9 @@ dropped."
(defun ledger-toggle-current (&optional style) (defun ledger-toggle-current (&optional style)
(interactive) (interactive)
(if ledger-clear-whole-entries (if ledger-clear-whole-transactions
(ledger-toggle-current-entry style) (ledger-toggle-current-transaction style)
(ledger-toggle-current-transaction style))) (ledger-toggle-current-posting style)))
(defvar ledger-mode-abbrev-table) (defvar ledger-mode-abbrev-table)
@ -439,18 +439,18 @@ dropped."
(set (make-local-variable 'pcomplete-termination-string) "") (set (make-local-variable 'pcomplete-termination-string) "")
(let ((map (current-local-map))) (let ((map (current-local-map)))
(define-key map [(control ?c) (control ?a)] 'ledger-add-entry) (define-key map [(control ?c) (control ?a)] 'ledger-add-transaction)
(define-key map [(control ?c) (control ?d)] 'ledger-delete-current-entry) (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 ?y)] 'ledger-set-year)
(define-key map [(control ?c) (control ?m)] 'ledger-set-month) (define-key map [(control ?c) (control ?m)] 'ledger-set-month)
(define-key map [(control ?c) (control ?c)] 'ledger-toggle-current) (define-key map [(control ?c) (control ?c)] 'ledger-toggle-current)
(define-key map [(control ?c) (control ?e)] 'ledger-toggle-current-entry) (define-key map [(control ?c) (control ?e)] 'ledger-toggle-current-transaction)
(define-key map [(control ?c) (control ?r)] 'ledger-reconcile) (define-key map [(control ?c) (control ?r)] 'ledger-reconcile)
(define-key map [(control ?c) (control ?s)] 'ledger-sort) (define-key map [(control ?c) (control ?s)] 'ledger-sort)
(define-key map [tab] 'pcomplete) (define-key map [tab] 'pcomplete)
(define-key map [(control ?i)] 'pcomplete) (define-key map [(control ?i)] 'pcomplete)
(define-key map [(control ?c) tab] 'ledger-fully-complete-entry) (define-key map [(control ?c) tab] 'ledger-fully-complete-transaction)
(define-key map [(control ?c) (control ?i)] 'ledger-fully-complete-entry) (define-key map [(control ?c) (control ?i)] 'ledger-fully-complete-transaction)
(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 ?g)] 'ledger-report-goto) (define-key map [(control ?c) (control ?o) (control ?g)] 'ledger-report-goto)
(define-key map [(control ?c) (control ?o) (control ?a)] 'ledger-report-redo) (define-key map [(control ?c) (control ?o) (control ?a)] 'ledger-report-redo)
@ -516,7 +516,7 @@ dropped."
(defun ledger-reconcile-add () (defun ledger-reconcile-add ()
(interactive) (interactive)
(with-current-buffer ledger-buf (with-current-buffer ledger-buf
(call-interactively #'ledger-add-entry)) (call-interactively #'ledger-add-transaction))
(ledger-reconcile-refresh)) (ledger-reconcile-refresh))
(defun ledger-reconcile-delete () (defun ledger-reconcile-delete ()
@ -525,7 +525,7 @@ dropped."
(when (equal (car where) "<stdin>") (when (equal (car where) "<stdin>")
(with-current-buffer ledger-buf (with-current-buffer ledger-buf
(goto-char (cdr where)) (goto-char (cdr where))
(ledger-delete-current-entry)) (ledger-delete-current-transaction))
(let ((inhibit-read-only t)) (let ((inhibit-read-only t))
(goto-char (line-beginning-position)) (goto-char (line-beginning-position))
(delete-region (point) (1+ (line-end-position))) (delete-region (point) (1+ (line-end-position)))
@ -579,23 +579,23 @@ dropped."
(read (current-buffer)))))))) (read (current-buffer))))))))
(dolist (item items) (dolist (item items)
(let ((index 1)) (let ((index 1))
(dolist (xact (nthcdr 5 item)) (dolist (post (nthcdr 5 item))
(let ((beg (point)) (let ((beg (point))
(where (where
(with-current-buffer buf (with-current-buffer buf
(cons (cons
(nth 0 item) (nth 0 item)
(if ledger-clear-whole-entries (if ledger-clear-whole-transactions
(save-excursion (save-excursion
(goto-line (nth 1 item)) (goto-line (nth 1 item))
(point-marker)) (point-marker))
(save-excursion (save-excursion
(goto-line (nth 0 xact)) (goto-line (nth 0 post))
(point-marker))))))) (point-marker)))))))
(insert (format "%s %-30s %-25s %15s\n" (insert (format "%s %-30s %-25s %15s\n"
(format-time-string "%m/%d" (nth 2 item)) (format-time-string "%m/%d" (nth 2 item))
(nth 4 item) (nth 1 xact) (nth 2 xact))) (nth 4 item) (nth 1 post) (nth 2 post)))
(if (nth 3 xact) (if (nth 3 post)
(set-text-properties beg (1- (point)) (set-text-properties beg (1- (point))
(list 'face 'bold (list 'face 'bold
'where where)) 'where where))
@ -623,7 +623,7 @@ dropped."
(defvar ledger-reconcile-mode-abbrev-table) (defvar ledger-reconcile-mode-abbrev-table)
(define-derived-mode ledger-reconcile-mode text-mode "Reconcile" (define-derived-mode ledger-reconcile-mode text-mode "Reconcile"
"A mode for reconciling ledger entries." "A mode for reconciling ledger transactions."
(let ((map (make-sparse-keymap))) (let ((map (make-sparse-keymap)))
(define-key map [(control ?m)] 'ledger-reconcile-visit) (define-key map [(control ?m)] 'ledger-reconcile-visit)
(define-key map [return] 'ledger-reconcile-visit) (define-key map [return] 'ledger-reconcile-visit)
@ -642,12 +642,12 @@ dropped."
;; Context sensitivity ;; Context sensitivity
(defconst ledger-line-config (defconst ledger-line-config
'((entry '((transaction
(("^\\(\\([0-9][0-9][0-9][0-9]/\\)?[01]?[0-9]/[0123]?[0-9]\\)[ \t]+\\(\\([!*]\\)[ \t]\\)?[ \t]*\\((\\(.*\\))\\)?[ \t]*\\(.*?\\)[ \t]*;\\(.*\\)[ \t]*$" (("^\\(\\([0-9][0-9][0-9][0-9]/\\)?[01]?[0-9]/[0123]?[0-9]\\)[ \t]+\\(\\([!*]\\)[ \t]\\)?[ \t]*\\((\\(.*\\))\\)?[ \t]*\\(.*?\\)[ \t]*;\\(.*\\)[ \t]*$"
(date nil status nil nil code payee comment)) (date nil status nil nil code payee comment))
("^\\(\\([0-9][0-9][0-9][0-9]/\\)?[01]?[0-9]/[0123]?[0-9]\\)[ \t]+\\(\\([!*]\\)[ \t]\\)?[ \t]*\\((\\(.*\\))\\)?[ \t]*\\(.*\\)[ \t]*$" ("^\\(\\([0-9][0-9][0-9][0-9]/\\)?[01]?[0-9]/[0123]?[0-9]\\)[ \t]+\\(\\([!*]\\)[ \t]\\)?[ \t]*\\((\\(.*\\))\\)?[ \t]*\\(.*\\)[ \t]*$"
(date nil status nil nil code payee)))) (date nil status nil nil code payee))))
(acct-transaction (acct-posting
(("\\(^[ \t]+\\)\\(.*?\\)[ \t]+\\([$]\\)\\(-?[0-9]*\\(\\.[0-9]*\\)?\\)[ \t]*;[ \t]*\\(.*?\\)[ \t]*$" (("\\(^[ \t]+\\)\\(.*?\\)[ \t]+\\([$]\\)\\(-?[0-9]*\\(\\.[0-9]*\\)?\\)[ \t]*;[ \t]*\\(.*?\\)[ \t]*$"
(indent account commodity amount nil comment)) (indent account commodity amount nil comment))
("\\(^[ \t]+\\)\\(.*?\\)[ \t]+\\([$]\\)\\(-?[0-9]*\\(\\.[0-9]*\\)?\\)[ \t]*$" ("\\(^[ \t]+\\)\\(.*?\\)[ \t]+\\([$]\\)\\(-?[0-9]*\\(\\.[0-9]*\\)?\\)[ \t]*$"
@ -704,13 +704,13 @@ the fields in the line in a association list."
(cond ((equal (point) (line-end-position)) (cond ((equal (point) (line-end-position))
'(empty-line nil nil)) '(empty-line nil nil))
((memq first-char '(?\ ?\t)) ((memq first-char '(?\ ?\t))
(ledger-extract-context-info 'acct-transaction pos)) (ledger-extract-context-info 'acct-posting pos))
((memq first-char '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9)) ((memq first-char '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))
(ledger-extract-context-info 'entry pos)) (ledger-extract-context-info 'transaction pos))
((equal first-char ?\=) ((equal first-char ?\=)
'(automated-entry nil nil)) '(automated-transaction nil nil))
((equal first-char ?\~) ((equal first-char ?\~)
'(period-entry nil nil)) '(period-transaction nil nil))
((equal first-char ?\!) ((equal first-char ?\!)
'(command-directive)) '(command-directive))
((equal first-char ?\;) ((equal first-char ?\;)
@ -775,13 +775,13 @@ specified line, returns nil."
(defun ledger-context-goto-field-end (context-info field-name) (defun ledger-context-goto-field-end (context-info field-name)
(goto-char (ledger-context-field-end-position context-info field-name))) (goto-char (ledger-context-field-end-position context-info field-name)))
(defun ledger-entry-payee () (defun ledger-transaction-payee ()
"Returns the payee of the entry containing point or nil." "Returns the payee of the transaction containing point or nil."
(let ((i 0)) (let ((i 0))
(while (eq (ledger-context-line-type (ledger-context-other-line i)) 'acct-transaction) (while (eq (ledger-context-line-type (ledger-context-other-line i)) 'acct-posting)
(setq i (- i 1))) (setq i (- i 1)))
(let ((context-info (ledger-context-other-line i))) (let ((context-info (ledger-context-other-line i)))
(if (eq (ledger-context-line-type context-info) 'entry) (if (eq (ledger-context-line-type context-info) 'transaction)
(ledger-context-field-value context-info 'payee) (ledger-context-field-value context-info 'payee)
nil)))) nil))))
@ -904,25 +904,25 @@ otherwise the current buffer file is used."
"Substitute a payee name "Substitute a payee name
The user is prompted to enter a payee and that is substitued. If 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 point is in an transaction, the payee for that transaction is used as the
default." default."
;; It is intended copmletion should be available on existing ;; It is intended copmletion should be available on existing
;; payees, but the list of possible completions needs to be ;; payees, but the list of possible completions needs to be
;; developed to allow this. ;; developed to allow this.
(ledger-read-string-with-default "Payee" (regexp-quote (ledger-entry-payee)))) (ledger-read-string-with-default "Payee" (regexp-quote (ledger-transaction-payee))))
(defun ledger-report-account-format-specifier () (defun ledger-report-account-format-specifier ()
"Substitute an account name "Substitute an account name
The user is prompted to enter an account name, which can be any The user is prompted to enter an account name, which can be any
regular expression identifying an account. If point is on an account regular expression identifying an account. If point is on an account
transaction line for an entry, the full account name on that line is posting line for an transaction, the full account name on that line is
the default." the default."
;; It is intended completion should be available on existing account ;; It is intended completion should be available on existing account
;; names, but it remains to be implemented. ;; names, but it remains to be implemented.
(let* ((context (ledger-context-at-point)) (let* ((context (ledger-context-at-point))
(default (default
(if (eq (ledger-context-line-type context) 'acct-transaction) (if (eq (ledger-context-line-type context) 'acct-posting)
(regexp-quote (ledger-context-field-value context 'account)) (regexp-quote (ledger-context-field-value context 'account))
nil))) nil)))
(ledger-read-string-with-default "Account" default))) (ledger-read-string-with-default "Account" default)))
@ -1037,13 +1037,13 @@ the default."
(goto-char (line-beginning-position)) (goto-char (line-beginning-position))
(cond ((looking-at "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.+?)\\)?\\s-+") (cond ((looking-at "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.+?)\\)?\\s-+")
(goto-char (match-end 0)) (goto-char (match-end 0))
'entry) 'transaction)
((looking-at "^\\s-+\\([*!]\\s-+\\)?[[(]?\\(.\\)") ((looking-at "^\\s-+\\([*!]\\s-+\\)?[[(]?\\(.\\)")
(goto-char (match-beginning 2)) (goto-char (match-beginning 2))
'transaction) 'posting)
((looking-at "^\\(sun\\|mon\\|tue\\|wed\\|thu\\|fri\\|sat\\)\\s-+") ((looking-at "^\\(sun\\|mon\\|tue\\|wed\\|thu\\|fri\\|sat\\)\\s-+")
(goto-char (match-end 0)) (goto-char (match-end 0))
'entry) 'transaction)
(t (t
(ignore (goto-char here)))))) (ignore (goto-char here))))))
@ -1064,9 +1064,9 @@ the default."
args))) args)))
(cons (reverse args) (reverse begins))))) (cons (reverse args) (reverse begins)))))
(defun ledger-entries () (defun ledger-transactions ()
(let ((origin (point)) (let ((origin (point))
entries-list) transactions-list)
(save-excursion (save-excursion
(goto-char (point-min)) (goto-char (point-min))
(while (re-search-forward (while (re-search-forward
@ -1074,9 +1074,9 @@ the default."
"\\(.+?\\)\\(\t\\|\n\\| [ \t]\\)") nil t) "\\(.+?\\)\\(\t\\|\n\\| [ \t]\\)") nil t)
(unless (and (>= origin (match-beginning 0)) (unless (and (>= origin (match-beginning 0))
(< origin (match-end 0))) (< origin (match-end 0)))
(setq entries-list (cons (match-string-no-properties 3) (setq transactions-list (cons (match-string-no-properties 3)
entries-list))))) transactions-list)))))
(pcomplete-uniqify-list (nreverse entries-list)))) (pcomplete-uniqify-list (nreverse transactions-list))))
(defvar ledger-account-tree nil) (defvar ledger-account-tree nil)
@ -1093,12 +1093,12 @@ the default."
(setq elements (split-string account-path ":")) (setq elements (split-string account-path ":"))
(let ((root ledger-account-tree)) (let ((root ledger-account-tree))
(while elements (while elements
(let ((entry (assoc (car elements) root))) (let ((transaction (assoc (car elements) root)))
(if entry (if transaction
(setq root (cdr entry)) (setq root (cdr transaction))
(setq entry (cons (car elements) (list t))) (setq transaction (cons (car elements) (list t)))
(nconc root (list entry)) (nconc root (list transaction))
(setq root (cdr entry)))) (setq root (cdr transaction))))
(setq elements (cdr elements))))))))) (setq elements (cdr elements)))))))))
(defun ledger-accounts () (defun ledger-accounts ()
@ -1108,11 +1108,11 @@ the default."
(root ledger-account-tree) (root ledger-account-tree)
(prefix nil)) (prefix nil))
(while (cdr elements) (while (cdr elements)
(let ((entry (assoc (car elements) root))) (let ((transaction (assoc (car elements) root)))
(if entry (if transaction
(setq prefix (concat prefix (and prefix ":") (setq prefix (concat prefix (and prefix ":")
(car elements)) (car elements))
root (cdr entry)) root (cdr transaction))
(setq root nil elements nil))) (setq root nil elements nil)))
(setq elements (cdr elements))) (setq elements (cdr elements)))
(and root (and root
@ -1133,16 +1133,16 @@ the default."
(interactive) (interactive)
(while (pcomplete-here (while (pcomplete-here
(if (eq (save-excursion (if (eq (save-excursion
(ledger-thing-at-point)) 'entry) (ledger-thing-at-point)) 'transaction)
(if (null current-prefix-arg) (if (null current-prefix-arg)
(ledger-entries) ; this completes against entry names (ledger-transactions) ; this completes against transaction names
(progn (progn
(let ((text (buffer-substring (line-beginning-position) (let ((text (buffer-substring (line-beginning-position)
(line-end-position)))) (line-end-position))))
(delete-region (line-beginning-position) (delete-region (line-beginning-position)
(line-end-position)) (line-end-position))
(condition-case err (condition-case err
(ledger-add-entry text t) (ledger-add-transaction text t)
((error) ((error)
(insert text)))) (insert text))))
(forward-line) (forward-line)
@ -1152,30 +1152,30 @@ the default."
(throw 'pcompleted t))) (throw 'pcompleted t)))
(ledger-accounts))))) (ledger-accounts)))))
(defun ledger-fully-complete-entry () (defun ledger-fully-complete-transaction ()
"Do appropriate completion for the thing at point" "Do appropriate completion for the thing at point"
(interactive) (interactive)
(let ((name (caar (ledger-parse-arguments))) (let ((name (caar (ledger-parse-arguments)))
xacts) posts)
(save-excursion (save-excursion
(when (eq 'entry (ledger-thing-at-point)) (when (eq 'transaction (ledger-thing-at-point))
(when (re-search-backward (when (re-search-backward
(concat "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+" (concat "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+"
(regexp-quote name) "\\(\t\\|\n\\| [ \t]\\)") nil t) (regexp-quote name) "\\(\t\\|\n\\| [ \t]\\)") nil t)
(forward-line) (forward-line)
(while (looking-at "^\\s-+") (while (looking-at "^\\s-+")
(setq xacts (cons (buffer-substring-no-properties (setq posts (cons (buffer-substring-no-properties
(line-beginning-position) (line-beginning-position)
(line-end-position)) (line-end-position))
xacts)) posts))
(forward-line)) (forward-line))
(setq xacts (nreverse xacts))))) (setq posts (nreverse posts)))))
(when xacts (when posts
(save-excursion (save-excursion
(insert ?\n) (insert ?\n)
(while xacts (while posts
(insert (car xacts) ?\n) (insert (car posts) ?\n)
(setq xacts (cdr xacts)))) (setq posts (cdr posts))))
(forward-line) (forward-line)
(goto-char (line-end-position)) (goto-char (line-end-position))
(if (re-search-backward "\\(\t\\| [ \t]\\)" nil t) (if (re-search-backward "\\(\t\\| [ \t]\\)" nil t)
@ -1219,7 +1219,7 @@ This is done so that the last digit falls in COLUMN, which defaults to 52."
(defalias 'ledger-align-dollars 'ledger-align-amounts) (defalias 'ledger-align-dollars 'ledger-align-amounts)
;; A sample entry sorting function, which works if entry dates are of ;; A sample transaction sorting function, which works if transaction dates are of
;; the form YYYY/mm/dd. ;; the form YYYY/mm/dd.
(defun ledger-sort () (defun ledger-sort ()

67
tools/rename.sh Executable file
View file

@ -0,0 +1,67 @@
#!/bin/zsh
git reset --hard
rm -f src/system.hh.gch ledger
for file in *(.) contrib/*(.) doc/*(.) plan/*(.) python/*(.) src/*(.) test/*(.) test/*/*(.) tools/*(.)
do
echo Renaming items in $file ...
perl -i -pe 's/xact/fazole/g;' $file 2> /dev/null
perl -i -pe 's/XACT/FAZOLE/g;' $file 2> /dev/null
perl -i -pe 's/Xact/Fazole/g;' $file 2> /dev/null
perl -i -pe 's/xacts/fazoles/g;' $file 2> /dev/null
perl -i -pe 's/XACTS/FAZOLES/g;' $file 2> /dev/null
perl -i -pe 's/Xacts/Fazoles/g;' $file 2> /dev/null
perl -i -pe 's/transaction/brazole/g;' $file 2> /dev/null
perl -i -pe 's/TRANSACTION/BRAZOLE/g;' $file 2> /dev/null
perl -i -pe 's/Transaction/Brazole/g;' $file 2> /dev/null
perl -i -pe 's/transactions/brazoles/g;' $file 2> /dev/null
perl -i -pe 's/TRANSACTIONS/BRAZOLES/g;' $file 2> /dev/null
perl -i -pe 's/Transactions/Brazoles/g;' $file 2> /dev/null
perl -i -pe 's/entry/xact/g;' $file 2> /dev/null
perl -i -pe 's/ENTRY/XACT/g;' $file 2> /dev/null
perl -i -pe 's/Entry/Xact/g;' $file 2> /dev/null
perl -i -pe 's/entries/xacts/g;' $file 2> /dev/null
perl -i -pe 's/ENTRIES/XACTS/g;' $file 2> /dev/null
perl -i -pe 's/Entries/Xacts/g;' $file 2> /dev/null
perl -i -pe 's/entrys/xacts/g;' $file 2> /dev/null
perl -i -pe 's/ENTRYS/XACTS/g;' $file 2> /dev/null
perl -i -pe 's/Entrys/Xacts/g;' $file 2> /dev/null
perl -i -pe 's/fazoles/posts/g;' $file 2> /dev/null
perl -i -pe 's/FAZOLES/POSTS/g;' $file 2> /dev/null
perl -i -pe 's/Fazoles/Posts/g;' $file 2> /dev/null
perl -i -pe 's/fazole/post/g;' $file 2> /dev/null
perl -i -pe 's/FAZOLE/POST/g;' $file 2> /dev/null
perl -i -pe 's/Fazole/Post/g;' $file 2> /dev/null
perl -i -pe 's/brazoles/postings/g;' $file 2> /dev/null
perl -i -pe 's/BRAZOLES/POSTINGS/g;' $file 2> /dev/null
perl -i -pe 's/Brazoles/Postings/g;' $file 2> /dev/null
perl -i -pe 's/brazole/posting/g;' $file 2> /dev/null
perl -i -pe 's/BRAZOLE/POSTING/g;' $file 2> /dev/null
perl -i -pe 's/Brazole/Posting/g;' $file 2> /dev/null
perl -i -pe 's/\@dirxact/\@direntry/g;' $file 2> /dev/null
perl -i -pe 's/\@end dirxact/\@end direntry/g;' $file 2> /dev/null
done
mv src/xact.h src/fazole.h
mv src/xact.cc src/fazole.cc
mv src/entry.h src/xact.h
mv src/entry.cc src/xact.cc
mv src/fazole.h src/post.h
mv src/fazole.cc src/post.cc
mv src/py_xact.py src/fazole.py
mv src/py_entry.py src/py_xact.py
mv src/fazole.py src/py_post.py
ln -sf ~/Products/ledger/ledger .
tools/myacprep