Comment and code cleanup
This commit is contained in:
parent
28659c58c3
commit
5eb322c0a2
8 changed files with 58 additions and 49 deletions
|
|
@ -64,11 +64,12 @@
|
|||
(goto-char (point-min))
|
||||
(while (re-search-forward
|
||||
(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))
|
||||
(< origin (match-end 0)))
|
||||
(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))))
|
||||
|
||||
(defvar ledger-account-tree nil)
|
||||
|
|
@ -130,7 +131,7 @@
|
|||
(if (eq (save-excursion
|
||||
(ledger-thing-at-point)) 'transaction)
|
||||
(if (null current-prefix-arg)
|
||||
(ledger-payees) ; this completes against payee names
|
||||
(ledger-payees) ;; this completes against payee names
|
||||
(progn
|
||||
(let ((text (buffer-substring (line-beginning-position)
|
||||
(line-end-position))))
|
||||
|
|
|
|||
|
|
@ -132,8 +132,8 @@ customizable to ease retro-entry.")
|
|||
(< (nth 1 t1) (nth 1 t2)))))
|
||||
|
||||
(defun ledger-time-subtract (t1 t2)
|
||||
"Subtract two time values.
|
||||
Return the difference in the format of a time value."
|
||||
"Subtract two time values. Return the difference in the format
|
||||
of a time value."
|
||||
(let ((borrow (< (cadr t1) (cadr t2))))
|
||||
(list (- (car t1) (car t2) (if borrow 1 0))
|
||||
(- (+ (if borrow 65536 0) (cadr t1)) (cadr t2)))))
|
||||
|
|
|
|||
|
|
@ -125,14 +125,13 @@ When REGEX is nil, unhide everything, and remove higlight"
|
|||
(temp (point-max)))
|
||||
(mapcar (lambda (match)
|
||||
(progn
|
||||
(setq temp prev-end) ;need a swap so that the
|
||||
;last form in the lambda
|
||||
;is the (make-overlay)
|
||||
(setq prev-end (1+ (cadr match))) ;add 1 so
|
||||
;that we skip
|
||||
;the empty
|
||||
;line after
|
||||
;the xact
|
||||
(setq temp prev-end) ;; need a swap so that
|
||||
;; the last form in
|
||||
;; the lambda is the
|
||||
;; (make-overlay)
|
||||
(setq prev-end (1+ (cadr match)))
|
||||
;; add 1 so that we skip the
|
||||
;; empty line after the xact
|
||||
(make-overlay
|
||||
temp
|
||||
(car match)
|
||||
|
|
@ -216,9 +215,9 @@ When REGEX is nil, unhide everything, and remove higlight"
|
|||
(save-excursion
|
||||
(let ((bounds (ledger-find-xact-extents (match-beginning 0))))
|
||||
(push bounds lines)
|
||||
(setq curpoint (cadr bounds)))) ;move to the end of the
|
||||
;xact, no need to search
|
||||
;inside it more
|
||||
(setq curpoint (cadr bounds)))) ;; move to the end of
|
||||
;; the xact, no need to
|
||||
;; search inside it more
|
||||
(goto-char curpoint))
|
||||
(forward-line 1))
|
||||
(setq lines (nreverse lines)))))
|
||||
|
|
|
|||
|
|
@ -63,8 +63,8 @@
|
|||
|
||||
(defun ledger-post-completing-read (prompt 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
|
||||
to choose from."
|
||||
PROMPT is a string to prompt with. CHOICES is a list of
|
||||
strings to choose from."
|
||||
(cond
|
||||
(ledger-post-use-iswitchb
|
||||
(let* ((iswitchb-use-virtual-buffers nil)
|
||||
|
|
@ -113,7 +113,8 @@ to choose from."
|
|||
|
||||
(defun ledger-align-amounts (&optional column)
|
||||
"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")
|
||||
(if (or (null column) (= column 1))
|
||||
(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)
|
||||
(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 there is an amount to edit
|
||||
(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
|
||||
(if end-of-amount
|
||||
(let ((val (match-string 0)))
|
||||
(goto-char (match-beginning 0))
|
||||
(delete-region (match-beginning 0) (match-end 0))
|
||||
(calc)
|
||||
(while (string-match "," val)
|
||||
(setq val (replace-match "" nil nil val))) ;gets rid of commas
|
||||
(calc-eval val 'push)) ;edit the amount
|
||||
(progn ;make sure there are two spaces after the account name and go to calc
|
||||
(setq val (replace-match "" nil nil val))) ;; gets rid of commas
|
||||
(calc-eval val 'push)) ;; edit the amount
|
||||
(progn ;;make sure there are two spaces after the account name and go to calc
|
||||
(if (search-backward " " (- (point) 3) t)
|
||||
(goto-char (line-end-position))
|
||||
(insert " "))
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@
|
|||
(setq status (ledger-toggle-current (if ledger-reconcile-toggle-to-pending
|
||||
'pending
|
||||
'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)
|
||||
(line-end-position)
|
||||
(list 'face))
|
||||
|
|
@ -193,8 +193,8 @@
|
|||
(ledger-reconcile-quit-cleanup)
|
||||
(let ((buf ledger-buf)
|
||||
(recon-buf (get-buffer ledger-recon-buffer-name)))
|
||||
;Make sure you delete the window before you delete the buffer,
|
||||
;otherwise, madness ensues
|
||||
;; Make sure you delete the window before you delete the buffer,
|
||||
;; otherwise, madness ensues
|
||||
(with-current-buffer recon-buf
|
||||
(delete-window (get-buffer-window recon-buf))
|
||||
(kill-buffer recon-buf))
|
||||
|
|
@ -223,7 +223,8 @@
|
|||
(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
|
||||
(1+ (point-marker))))))) ;;Add 1 to make sure the marker is
|
||||
;;within the transaction
|
||||
|
||||
(defun ledger-do-reconcile ()
|
||||
"get the uncleared transactions in the account and display them
|
||||
|
|
@ -269,11 +270,11 @@
|
|||
(set-buffer-modified-p nil)
|
||||
(toggle-read-only t)
|
||||
|
||||
; this next piece of code ensures that the last of the visible
|
||||
; transactions in the ledger buffer is at the bottom of the main
|
||||
; window. The key to this is to ensure the window is selected
|
||||
; when the buffer point is moved and recentered. If they aren't
|
||||
; strange things happen.
|
||||
;; this next piece of code ensures that the last of the visible
|
||||
;; transactions in the ledger buffer is at the bottom of the main
|
||||
;; window. The key to this is to ensure the window is selected
|
||||
;; when the buffer point is moved and recentered. If they aren't
|
||||
;; strange things happen.
|
||||
|
||||
(let
|
||||
((recon-window (get-buffer-window (get-buffer ledger-recon-buffer-name))))
|
||||
|
|
@ -299,20 +300,24 @@
|
|||
(defun ledger-reconcile (account)
|
||||
(interactive "sAccount to reconcile: ")
|
||||
(let ((buf (current-buffer))
|
||||
(rbuf (get-buffer ledger-recon-buffer-name))) ;this means only one *Reconcile* buffer, ever
|
||||
(if rbuf ; *Reconcile* already exists
|
||||
(rbuf (get-buffer ledger-recon-buffer-name))) ;; this means
|
||||
;; only one
|
||||
;; *Reconcile*
|
||||
;; buffer, ever
|
||||
(if rbuf ;; *Reconcile* already exists
|
||||
(with-current-buffer rbuf
|
||||
(set 'ledger-acct account) ; already buffer local
|
||||
(set 'ledger-acct account) ;; already buffer local
|
||||
(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)
|
||||
(set 'ledger-buf buf))) ; should already be buffer-local
|
||||
(set 'ledger-buf buf))) ;; should already be
|
||||
;; buffer-local
|
||||
(if ledger-fold-on-reconcile
|
||||
(ledger-occur-change-regex account ledger-buf))
|
||||
(set-buffer (get-buffer ledger-recon-buffer-name))
|
||||
(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)
|
||||
(if ledger-fold-on-reconcile
|
||||
(ledger-occur-mode account buf))
|
||||
|
|
|
|||
|
|
@ -69,8 +69,7 @@
|
|||
(set-text-properties beg (1- (point))
|
||||
(list 'where where))))
|
||||
(setq index (1+ index)))))
|
||||
(goto-char (point-min))
|
||||
)
|
||||
(goto-char (point-min)))
|
||||
|
||||
(defun ledger-register-generate (&optional data-buffer &rest args)
|
||||
(let ((buf (or data-buffer (current-buffer))))
|
||||
|
|
|
|||
|
|
@ -33,16 +33,19 @@
|
|||
(forward-paragraph))
|
||||
|
||||
(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)
|
||||
(new-end end))
|
||||
(save-excursion
|
||||
(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))
|
||||
(goto-char end)
|
||||
(ledger-next-record-function) ;make sure end of region is at the beginning of
|
||||
;next record after the region
|
||||
(ledger-next-record-function) ;; make sure end of region is at
|
||||
;; the beginning of next record
|
||||
;; after the region
|
||||
(setq new-end (point))
|
||||
(narrow-to-region beg end)
|
||||
(goto-char (point-min))
|
||||
|
|
|
|||
|
|
@ -81,11 +81,11 @@ dropped."
|
|||
new-status cur-status)
|
||||
;; Uncompact the entry, to make it easier to toggle the
|
||||
;; transaction
|
||||
(save-excursion ;this excursion unclears the posting
|
||||
(goto-char (car bounds)) ;beginning of xact
|
||||
(skip-chars-forward "0-9./= \t") ;skip the date
|
||||
(save-excursion ;; this excursion unclears the posting
|
||||
(goto-char (car bounds)) ;; beginning of xact
|
||||
(skip-chars-forward "0-9./= \t") ;; skip the date
|
||||
(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
|
||||
(when cur-status
|
||||
(let ((here (point)))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue