Comment and code cleanup

This commit is contained in:
Craig Earls 2013-02-12 16:04:02 -07:00
parent 28659c58c3
commit 5eb322c0a2
8 changed files with 58 additions and 49 deletions

View file

@ -64,11 +64,12 @@
(goto-char (point-min)) (goto-char (point-min))
(while (re-search-forward (while (re-search-forward
(concat "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+" (concat "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+"
"\\(.+?\\)\\(\t\\|\n\\| [ \t]\\)") nil t) ;matches first line of transaction "\\(.+?\\)\\(\t\\|\n\\| [ \t]\\)") nil t) ;; matches first line
(unless (and (>= origin (match-beginning 0)) (unless (and (>= origin (match-beginning 0))
(< origin (match-end 0))) (< origin (match-end 0)))
(setq payees-list (cons (match-string-no-properties 3) (setq payees-list (cons (match-string-no-properties 3)
payees-list))))) ;add the payee to the list payees-list))))) ;; add the payee
;; to the list
(pcomplete-uniqify-list (nreverse payees-list)))) (pcomplete-uniqify-list (nreverse payees-list))))
(defvar ledger-account-tree nil) (defvar ledger-account-tree nil)
@ -130,7 +131,7 @@
(if (eq (save-excursion (if (eq (save-excursion
(ledger-thing-at-point)) 'transaction) (ledger-thing-at-point)) 'transaction)
(if (null current-prefix-arg) (if (null current-prefix-arg)
(ledger-payees) ; this completes against payee names (ledger-payees) ;; this completes against payee names
(progn (progn
(let ((text (buffer-substring (line-beginning-position) (let ((text (buffer-substring (line-beginning-position)
(line-end-position)))) (line-end-position))))

View file

@ -132,8 +132,8 @@ customizable to ease retro-entry.")
(< (nth 1 t1) (nth 1 t2))))) (< (nth 1 t1) (nth 1 t2)))))
(defun ledger-time-subtract (t1 t2) (defun ledger-time-subtract (t1 t2)
"Subtract two time values. "Subtract two time values. Return the difference in the format
Return the difference in the format of a time value." of a time value."
(let ((borrow (< (cadr t1) (cadr t2)))) (let ((borrow (< (cadr t1) (cadr t2))))
(list (- (car t1) (car t2) (if borrow 1 0)) (list (- (car t1) (car t2) (if borrow 1 0))
(- (+ (if borrow 65536 0) (cadr t1)) (cadr t2))))) (- (+ (if borrow 65536 0) (cadr t1)) (cadr t2)))))

View file

@ -125,14 +125,13 @@ When REGEX is nil, unhide everything, and remove higlight"
(temp (point-max))) (temp (point-max)))
(mapcar (lambda (match) (mapcar (lambda (match)
(progn (progn
(setq temp prev-end) ;need a swap so that the (setq temp prev-end) ;; need a swap so that
;last form in the lambda ;; the last form in
;is the (make-overlay) ;; the lambda is the
(setq prev-end (1+ (cadr match))) ;add 1 so ;; (make-overlay)
;that we skip (setq prev-end (1+ (cadr match)))
;the empty ;; add 1 so that we skip the
;line after ;; empty line after the xact
;the xact
(make-overlay (make-overlay
temp temp
(car match) (car match)
@ -216,9 +215,9 @@ When REGEX is nil, unhide everything, and remove higlight"
(save-excursion (save-excursion
(let ((bounds (ledger-find-xact-extents (match-beginning 0)))) (let ((bounds (ledger-find-xact-extents (match-beginning 0))))
(push bounds lines) (push bounds lines)
(setq curpoint (cadr bounds)))) ;move to the end of the (setq curpoint (cadr bounds)))) ;; move to the end of
;xact, no need to search ;; the xact, no need to
;inside it more ;; search inside it more
(goto-char curpoint)) (goto-char curpoint))
(forward-line 1)) (forward-line 1))
(setq lines (nreverse lines))))) (setq lines (nreverse lines)))))

View file

@ -63,8 +63,8 @@
(defun ledger-post-completing-read (prompt choices) (defun ledger-post-completing-read (prompt choices)
"Use iswitchb as a completing-read replacement to choose from choices. "Use iswitchb as a completing-read replacement to choose from choices.
PROMPT is a string to prompt with. CHOICES is a list of strings PROMPT is a string to prompt with. CHOICES is a list of
to choose from." strings to choose from."
(cond (cond
(ledger-post-use-iswitchb (ledger-post-use-iswitchb
(let* ((iswitchb-use-virtual-buffers nil) (let* ((iswitchb-use-virtual-buffers nil)
@ -113,7 +113,8 @@ to choose from."
(defun ledger-align-amounts (&optional column) (defun ledger-align-amounts (&optional column)
"Align amounts in the current region. "Align amounts in the current region.
This is done so that the last digit falls in COLUMN, which defaults to 52." This is done so that the last digit falls in COLUMN, which
defaults to 52."
(interactive "p") (interactive "p")
(if (or (null column) (= column 1)) (if (or (null column) (= column 1))
(setq column ledger-post-amount-alignment-column)) (setq column ledger-post-amount-alignment-column))
@ -157,17 +158,18 @@ This is done so that the last digit falls in COLUMN, which defaults to 52."
(interactive) (interactive)
(goto-char (line-beginning-position)) (goto-char (line-beginning-position))
(when (re-search-forward ledger-post-line-regexp (line-end-position) t) (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 (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 there 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 (if end-of-amount
(let ((val (match-string 0))) (let ((val (match-string 0)))
(goto-char (match-beginning 0)) (goto-char (match-beginning 0))
(delete-region (match-beginning 0) (match-end 0)) (delete-region (match-beginning 0) (match-end 0))
(calc) (calc)
(while (string-match "," val) (while (string-match "," val)
(setq val (replace-match "" nil nil val))) ;gets rid of commas (setq val (replace-match "" nil nil val))) ;; gets rid of commas
(calc-eval val 'push)) ;edit the amount (calc-eval val 'push)) ;; edit the amount
(progn ;make sure there are two spaces after the account name and go to calc (progn ;;make sure there are two spaces after the account name and go to calc
(if (search-backward " " (- (point) 3) t) (if (search-backward " " (- (point) 3) t)
(goto-char (line-end-position)) (goto-char (line-end-position))
(insert " ")) (insert " "))

View file

@ -92,7 +92,7 @@
(setq status (ledger-toggle-current (if ledger-reconcile-toggle-to-pending (setq status (ledger-toggle-current (if ledger-reconcile-toggle-to-pending
'pending 'pending
'cleared)))) 'cleared))))
;remove the existing face and add the new face ;; remove the existing face and add the new face
(remove-text-properties (line-beginning-position) (remove-text-properties (line-beginning-position)
(line-end-position) (line-end-position)
(list 'face)) (list 'face))
@ -193,8 +193,8 @@
(ledger-reconcile-quit-cleanup) (ledger-reconcile-quit-cleanup)
(let ((buf ledger-buf) (let ((buf ledger-buf)
(recon-buf (get-buffer ledger-recon-buffer-name))) (recon-buf (get-buffer ledger-recon-buffer-name)))
;Make sure you delete the window before you delete the buffer, ;; Make sure you delete the window before you delete the buffer,
;otherwise, madness ensues ;; otherwise, madness ensues
(with-current-buffer recon-buf (with-current-buffer recon-buf
(delete-window (get-buffer-window recon-buf)) (delete-window (get-buffer-window recon-buf))
(kill-buffer recon-buf)) (kill-buffer recon-buf))
@ -223,7 +223,8 @@
(if ledger-clear-whole-transactions (if ledger-clear-whole-transactions
(goto-line (nth 1 emacs-xact)) (goto-line (nth 1 emacs-xact))
(goto-line (nth 0 posting))) (goto-line (nth 0 posting)))
(1+ (point-marker))))))) ;Add 1 to make sure the marker is within the transaction (1+ (point-marker))))))) ;;Add 1 to make sure the marker is
;;within the transaction
(defun ledger-do-reconcile () (defun ledger-do-reconcile ()
"get the uncleared transactions in the account and display them "get the uncleared transactions in the account and display them
@ -269,11 +270,11 @@
(set-buffer-modified-p nil) (set-buffer-modified-p nil)
(toggle-read-only t) (toggle-read-only t)
; this next piece of code ensures that the last of the visible ;; this next piece of code ensures that the last of the visible
; transactions in the ledger buffer is at the bottom of the main ;; transactions in the ledger buffer is at the bottom of the main
; window. The key to this is to ensure the window is selected ;; window. The key to this is to ensure the window is selected
; when the buffer point is moved and recentered. If they aren't ;; when the buffer point is moved and recentered. If they aren't
; strange things happen. ;; strange things happen.
(let (let
((recon-window (get-buffer-window (get-buffer ledger-recon-buffer-name)))) ((recon-window (get-buffer-window (get-buffer ledger-recon-buffer-name))))
@ -299,20 +300,24 @@
(defun ledger-reconcile (account) (defun ledger-reconcile (account)
(interactive "sAccount to reconcile: ") (interactive "sAccount to reconcile: ")
(let ((buf (current-buffer)) (let ((buf (current-buffer))
(rbuf (get-buffer ledger-recon-buffer-name))) ;this means only one *Reconcile* buffer, ever (rbuf (get-buffer ledger-recon-buffer-name))) ;; this means
(if rbuf ; *Reconcile* already exists ;; only one
;; *Reconcile*
;; buffer, ever
(if rbuf ;; *Reconcile* already exists
(with-current-buffer rbuf (with-current-buffer rbuf
(set 'ledger-acct account) ; already buffer local (set 'ledger-acct account) ;; already buffer local
(if (not (eq buf rbuf)) (if (not (eq buf rbuf))
(progn ; called from some other ledger-mode buffer (progn ;; called from some other ledger-mode buffer
(ledger-reconcile-quit-cleanup) (ledger-reconcile-quit-cleanup)
(set 'ledger-buf buf))) ; should already be buffer-local (set 'ledger-buf buf))) ;; should already be
;; buffer-local
(if ledger-fold-on-reconcile (if ledger-fold-on-reconcile
(ledger-occur-change-regex account ledger-buf)) (ledger-occur-change-regex account ledger-buf))
(set-buffer (get-buffer ledger-recon-buffer-name)) (set-buffer (get-buffer ledger-recon-buffer-name))
(ledger-reconcile-refresh)) (ledger-reconcile-refresh))
(progn ; no recon-buffer, starting from scratch. (progn ;; no recon-buffer, starting from scratch.
(add-hook 'after-save-hook 'ledger-reconcile-refresh-after-save nil t) (add-hook 'after-save-hook 'ledger-reconcile-refresh-after-save nil t)
(if ledger-fold-on-reconcile (if ledger-fold-on-reconcile
(ledger-occur-mode account buf)) (ledger-occur-mode account buf))

View file

@ -69,8 +69,7 @@
(set-text-properties beg (1- (point)) (set-text-properties beg (1- (point))
(list 'where where)))) (list 'where where))))
(setq index (1+ index))))) (setq index (1+ index)))))
(goto-char (point-min)) (goto-char (point-min)))
)
(defun ledger-register-generate (&optional data-buffer &rest args) (defun ledger-register-generate (&optional data-buffer &rest args)
(let ((buf (or data-buffer (current-buffer)))) (let ((buf (or data-buffer (current-buffer))))

View file

@ -33,16 +33,19 @@
(forward-paragraph)) (forward-paragraph))
(defun ledger-sort-region (beg end) (defun ledger-sort-region (beg end)
(interactive "r") ;load beg and end from point and mark automagically (interactive "r") ;; load beg and end from point and mark
;; automagically
(let ((new-beg beg) (let ((new-beg beg)
(new-end end)) (new-end end))
(save-excursion (save-excursion
(save-restriction (save-restriction
(ledger-next-record-function) ;make sure point is at the beginning of a xact (ledger-next-record-function) ;; make sure point is at the
;; beginning of a xact
(setq new-beg (point)) (setq new-beg (point))
(goto-char end) (goto-char end)
(ledger-next-record-function) ;make sure end of region is at the beginning of (ledger-next-record-function) ;; make sure end of region is at
;next record after the region ;; the beginning of next record
;; after the region
(setq new-end (point)) (setq new-end (point))
(narrow-to-region beg end) (narrow-to-region beg end)
(goto-char (point-min)) (goto-char (point-min))

View file

@ -81,11 +81,11 @@ dropped."
new-status cur-status) new-status cur-status)
;; Uncompact the entry, to make it easier to toggle the ;; Uncompact the entry, to make it easier to toggle the
;; transaction ;; transaction
(save-excursion ;this excursion unclears the posting (save-excursion ;; this excursion unclears the posting
(goto-char (car bounds)) ;beginning of xact (goto-char (car bounds)) ;; beginning of xact
(skip-chars-forward "0-9./= \t") ;skip the date (skip-chars-forward "0-9./= \t") ;; skip the date
(setq cur-status (and (member (char-after) '(?\* ?\!)) (setq cur-status (and (member (char-after) '(?\* ?\!))
(ledger-state-from-char (char-after)))) ;if the next char is !, * store it (ledger-state-from-char (char-after))))
;;if cur-status if !, or * then delete the marker ;;if cur-status if !, or * then delete the marker
(when cur-status (when cur-status
(let ((here (point))) (let ((here (point)))