Lots of code cleanup. (if () (progn …) ==> (when () …) all over the place

This commit is contained in:
Craig Earls 2013-03-25 01:21:19 -04:00
parent cc62e6a886
commit d3fe4c666f
12 changed files with 156 additions and 186 deletions

View file

@ -50,7 +50,7 @@
(string-to-number (string-to-number
(ledger-commodity-string-number-decimalize (ledger-commodity-string-number-decimalize
(delete-and-extract-region (match-beginning 0) (match-end 0)) :from-user)) (delete-and-extract-region (match-beginning 0) (match-end 0)) :from-user))
(nth 0 (split-string (buffer-substring (point-min) (point-max)))))) (nth 0 (split-string (buffer-substring-no-properties (point-min) (point-max))))))
((re-search-forward "0" nil t) ((re-search-forward "0" nil t)
;; couldn't find a decimal number, look for a single 0, ;; couldn't find a decimal number, look for a single 0,
;; indicating account with zero balance ;; indicating account with zero balance

View file

@ -19,9 +19,6 @@
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
;; MA 02111-1307, USA. ;; MA 02111-1307, USA.
;;(require 'esh-util)
;;(require 'esh-arg)
;;; Commentary: ;;; Commentary:
;; Functions providing payee and account auto complete. ;; Functions providing payee and account auto complete.
@ -126,7 +123,7 @@ Return tree structure"
(if (null current-prefix-arg) (if (null current-prefix-arg)
(ledger-payees-in-buffer) ;; this completes against payee names (ledger-payees-in-buffer) ;; this completes against payee names
(progn (progn
(let ((text (buffer-substring (line-beginning-position) (let ((text (buffer-substring-no-properties (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))
@ -154,7 +151,7 @@ Does not use ledger xact"
;; Search backward for a matching payee ;; Search backward for a matching payee
(when (re-search-backward (when (re-search-backward
(concat "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+\\(.*" (concat "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+\\(.*"
(regexp-quote name) ".*\\)" ) nil t) ;; "\\(\t\\|\n\\| [ \t]\\)" (regexp-quote name) ".*\\)" ) nil t)
(setq rest-of-name (match-string 3)) (setq rest-of-name (match-string 3))
;; Start copying the postings ;; Start copying the postings
(forward-line) (forward-line)
@ -180,7 +177,7 @@ Does not use ledger xact"
(defun ledger-pcomplete (&optional interactively) (defun ledger-pcomplete (&optional interactively)
"Complete rip-off of pcomplete from pcomplete.el, only added "Complete rip-off of pcomplete from pcomplete.el, only added
ledger-magic-tab in the previos commads list so that ledger-magic-tab in the previous commands list so that
ledger-magic-tab would cycle properly" ledger-magic-tab would cycle properly"
(interactive "p") (interactive "p")
(if (and interactively (if (and interactively

View file

@ -53,7 +53,7 @@
(with-current-buffer ledger-output-buffer (with-current-buffer ledger-output-buffer
(goto-char (point-min)) (goto-char (point-min))
(if (and (> (buffer-size) 1) (looking-at (regexp-quote "While"))) (if (and (> (buffer-size) 1) (looking-at (regexp-quote "While")))
nil nil ;; failure, there is an error starting with "While"
ledger-output-buffer))) ledger-output-buffer)))
(defun ledger-exec-ledger (input-buffer &optional output-buffer &rest args) (defun ledger-exec-ledger (input-buffer &optional output-buffer &rest args)
@ -77,27 +77,24 @@
(defun ledger-version-greater-p (needed) (defun ledger-version-greater-p (needed)
"Verify the ledger binary is usable for `ledger-mode' (version greater than NEEDED)." "Verify the ledger binary is usable for `ledger-mode' (version greater than NEEDED)."
(let ((buffer ledger-buf) (let ((buffer ledger-buf)
(version-strings '()) (version-strings '()))
(version-number))
(with-temp-buffer (with-temp-buffer
(if (ledger-exec-ledger (current-buffer) (current-buffer) "--version") (when (ledger-exec-ledger (current-buffer) (current-buffer) "--version")
(progn
(goto-char (point-min)) (goto-char (point-min))
(delete-horizontal-space) (delete-horizontal-space)
(setq version-strings (split-string (setq version-strings (split-string
(buffer-substring-no-properties (point) (buffer-substring-no-properties (point)
(point-max)))) (point-max))))
(if (and (string-match (regexp-quote "Ledger") (car version-strings)) (if (and (string-match (regexp-quote "Ledger") (car version-strings))
(or (string= needed (car (cdr version-strings))) (or (string= needed (cadr version-strings))
(string< needed (car (cdr version-strings))))) (string< needed (cadr version-strings))))
t t ;; success
nil)))))) nil))))) ;;failure
(defun ledger-check-version () (defun ledger-check-version ()
"Verify that ledger works and is modern enough." "Verify that ledger works and is modern enough."
(interactive) (interactive)
(setq ledger-works (ledger-version-greater-p ledger-version-needed)) (if (setq ledger-works (ledger-version-greater-p ledger-version-needed))
(if ledger-works
(message "Good Ledger Version") (message "Good Ledger Version")
(message "Bad Ledger Version"))) (message "Bad Ledger Version")))

View file

@ -33,16 +33,16 @@
(setq ledger-environment-alist nil) (setq ledger-environment-alist nil)
(goto-char (point-min)) (goto-char (point-min))
(while (re-search-forward "^--.+?\\($\\|[ ]\\)" nil t ) (while (re-search-forward "^--.+?\\($\\|[ ]\\)" nil t )
(let ((matchb (match-beginning 0)) ;; save the match data, string-match stomp on it (let ((matchb (match-beginning 0)) ;; save the match data, string-match stamp on it
(matche (match-end 0))) (matche (match-end 0)))
(end-of-line) (end-of-line)
(setq ledger-environment-alist (setq ledger-environment-alist
(append ledger-environment-alist (append ledger-environment-alist
(list (cons (let ((flag (buffer-substring (+ 2 matchb) matche))) (list (cons (let ((flag (buffer-substring-no-properties (+ 2 matchb) matche)))
(if (string-match "[ \t\n\r]+\\'" flag) (if (string-match "[ \t\n\r]+\\'" flag)
(replace-match "" t t flag) (replace-match "" t t flag)
flag)) flag))
(let ((value (buffer-substring matche (point) ))) (let ((value (buffer-substring-no-properties matche (point) )))
(if (> (length value) 0) (if (> (length value) 0)
value value
t)))))))) t))))))))
@ -53,16 +53,12 @@
(let ((init-base-name (file-name-nondirectory ledger-init-file-name))) (let ((init-base-name (file-name-nondirectory ledger-init-file-name)))
(if (get-buffer init-base-name) ;; init file already loaded, parse it and leave it (if (get-buffer init-base-name) ;; init file already loaded, parse it and leave it
(ledger-init-parse-initialization init-base-name) (ledger-init-parse-initialization init-base-name)
(if (and ;; init file not loaded, load, parse and kill (when (and ledger-init-file-name
ledger-init-file-name
(file-exists-p ledger-init-file-name) (file-exists-p ledger-init-file-name)
(file-readable-p ledger-init-file-name)) (file-readable-p ledger-init-file-name))
(progn
(find-file-noselect ledger-init-file-name) (find-file-noselect ledger-init-file-name)
(ledger-init-parse-initialization init-base-name) (ledger-init-parse-initialization init-base-name)
(kill-buffer init-base-name)))))) (kill-buffer init-base-name)))))
(provide 'ldg-init) (provide 'ldg-init)

View file

@ -63,7 +63,6 @@
"Highlight transactions that match REGEX in BUFFER, hiding others. "Highlight transactions that match REGEX in BUFFER, hiding others.
When REGEX is nil, unhide everything, and remove higlight" When REGEX is nil, unhide everything, and remove higlight"
(progn
(set-buffer buffer) (set-buffer buffer)
(setq ledger-occur-mode (setq ledger-occur-mode
(if (or (null regex) (if (or (null regex)
@ -76,14 +75,12 @@ When REGEX is nil, unhide everything, and remove higlight"
(let* ((buffer-matches (ledger-occur-find-matches regex)) (let* ((buffer-matches (ledger-occur-find-matches regex))
(ovl-bounds (ledger-occur-create-xact-overlay-bounds buffer-matches))) (ovl-bounds (ledger-occur-create-xact-overlay-bounds buffer-matches)))
(setq ledger-occur-overlay-list (setq ledger-occur-overlay-list
(ledger-occur-create-xact-overlays ovl-bounds)) (append (ledger-occur-create-xact-overlays ovl-bounds)
(setq ledger-occur-overlay-list
(append ledger-occur-overlay-list
(ledger-occur-create-narrowed-overlays buffer-matches))) (ledger-occur-create-narrowed-overlays buffer-matches)))
(setq ledger-occur-last-match regex) (setq ledger-occur-last-match regex)
(if (get-buffer-window buffer) (if (get-buffer-window buffer)
(select-window (get-buffer-window buffer))))) (select-window (get-buffer-window buffer)))))
(recenter))) (recenter))
(defun ledger-occur (regex) (defun ledger-occur (regex)
"Perform a simple grep in current buffer for the regular expression REGEX. "Perform a simple grep in current buffer for the regular expression REGEX.
@ -163,12 +160,11 @@ Argument OVL-BOUNDS contains bounds for the transactions to be left visible."
(defun ledger-occur-quit-buffer (buffer) (defun ledger-occur-quit-buffer (buffer)
"Quits hidings transaction in the given BUFFER. "Quits hidings transaction in the given BUFFER.
Used for coordinating `ledger-occur' with other buffers, like reconcile." Used for coordinating `ledger-occur' with other buffers, like reconcile."
(progn
(set-buffer buffer) (set-buffer buffer)
(setq ledger-occur-mode nil) (setq ledger-occur-mode nil)
(force-mode-line-update) (force-mode-line-update)
(ledger-occur-remove-overlays) (ledger-occur-remove-overlays)
(recenter))) (recenter))
(defun ledger-occur-remove-overlays () (defun ledger-occur-remove-overlays ()
"Remove the transaction hiding overlays." "Remove the transaction hiding overlays."

View file

@ -135,7 +135,7 @@ Return the width of the amount field as an integer."
(match-end 3)) (point)))) (match-end 3)) (point))))
(defvar ledger-post-account-regex (defvar ledger-post-account-regex
(concat "\\(^[ ]+\\)" (concat "\\(^[ \t]+\\)"
"\\([\\[(*!;a-zA-Z0-9]+?\\)")) "\\([\\[(*!;a-zA-Z0-9]+?\\)"))
(defun ledger-next-account (&optional end) (defun ledger-next-account (&optional end)

View file

@ -66,9 +66,10 @@ reconcile-finish will mark all pending posting cleared."
(defun ledger-reconcile-get-cleared-or-pending-balance () (defun ledger-reconcile-get-cleared-or-pending-balance ()
"Calculate the cleared or pending balance of the account." "Calculate the cleared or pending balance of the account."
(interactive) (interactive)
;; these vars are buffer local, need to hold them for use in the
;; temp buffer below
(let ((buffer ledger-buf) (let ((buffer ledger-buf)
(account ledger-acct) (account ledger-acct))
(val nil))
(with-temp-buffer (with-temp-buffer
;; note that in the line below, the --format option is ;; note that in the line below, the --format option is
;; separated from the actual format string. emacs does not ;; separated from the actual format string. emacs does not
@ -77,16 +78,15 @@ reconcile-finish will mark all pending posting cleared."
(if (ledger-exec-ledger buffer (current-buffer) (if (ledger-exec-ledger buffer (current-buffer)
"balance" "--limit" "cleared or pending" "--empty" "balance" "--limit" "cleared or pending" "--empty"
"--format" "%(display_total)" account) "--format" "%(display_total)" account)
(setq val
(ledger-split-commodity-string (ledger-split-commodity-string
(buffer-substring-no-properties (point-min) (point-max)))))))) (buffer-substring-no-properties (point-min) (point-max)))))))
(defun ledger-display-balance () (defun ledger-display-balance ()
"Display the cleared-or-pending balance. "Display the cleared-or-pending balance.
And calculate the target-delta of the account being reconciled." And calculate the target-delta of the account being reconciled."
(interactive) (interactive)
(let* ((pending (ledger-reconcile-get-cleared-or-pending-balance))) (let* ((pending (ledger-reconcile-get-cleared-or-pending-balance)))
(if pending (when pending
(if ledger-target (if ledger-target
(message "Pending balance: %s, Difference from target: %s" (message "Pending balance: %s, Difference from target: %s"
(ledger-commodity-to-string pending) (ledger-commodity-to-string pending)
@ -150,23 +150,21 @@ Return the number of uncleared xacts found."
(interactive) (interactive)
(let ((inhibit-read-only t)) (let ((inhibit-read-only t))
(erase-buffer) (erase-buffer)
(prog1 (ledger-do-reconcile) (prog1
(set-buffer-modified-p t) (ledger-do-reconcile)
;;(goto-char (point-min)) (set-buffer-modified-p t))))
)))
(defun ledger-reconcile-refresh-after-save () (defun ledger-reconcile-refresh-after-save ()
"Refresh the recon-window after the ledger buffer is saved." "Refresh the recon-window after the ledger buffer is saved."
(let ((curbuf (current-buffer)) (let ((curbuf (current-buffer))
(curpoint (point)) (curpoint (point))
(recon-buf (get-buffer ledger-recon-buffer-name))) (recon-buf (get-buffer ledger-recon-buffer-name)))
(if (buffer-live-p recon-buf) (when (buffer-live-p recon-buf)
(progn
(with-current-buffer recon-buf (with-current-buffer recon-buf
(ledger-reconcile-refresh) (ledger-reconcile-refresh)
(set-buffer-modified-p nil)) (set-buffer-modified-p nil))
(select-window (get-buffer-window curbuf)) (select-window (get-buffer-window curbuf))
(goto-char curpoint))))) (goto-char curpoint))))
(defun ledger-reconcile-add () (defun ledger-reconcile-add ()
"Use ledger xact to add a new transaction." "Use ledger xact to add a new transaction."
@ -247,7 +245,7 @@ and exit reconcile mode"
(if recon-buf (if recon-buf
(with-current-buffer recon-buf (with-current-buffer recon-buf
(ledger-reconcile-quit-cleanup) (ledger-reconcile-quit-cleanup)
(set 'buf ledger-buf) (setq buf ledger-buf)
;; 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
(delete-window (get-buffer-window recon-buf)) (delete-window (get-buffer-window recon-buf))
@ -261,10 +259,9 @@ and exit reconcile mode"
(if (buffer-live-p buf) (if (buffer-live-p buf)
(with-current-buffer buf (with-current-buffer buf
(remove-hook 'after-save-hook 'ledger-reconcile-refresh-after-save t) (remove-hook 'after-save-hook 'ledger-reconcile-refresh-after-save t)
(if ledger-narrow-on-reconcile (when ledger-narrow-on-reconcile
(progn
(ledger-occur-quit-buffer buf) (ledger-occur-quit-buffer buf)
(ledger-highlight-xact-under-point))))))) (ledger-highlight-xact-under-point))))))
(defun ledger-marker-where-xact-is (emacs-xact posting) (defun ledger-marker-where-xact-is (emacs-xact posting)
"Find the position of the EMACS-XACT in the `ledger-buf'. "Find the position of the EMACS-XACT in the `ledger-buf'.
@ -285,14 +282,13 @@ POSTING is used in `ledger-clear-whole-transactions' is nil."
(ledger-success nil) (ledger-success nil)
(xacts (xacts
(with-temp-buffer (with-temp-buffer
(if (ledger-exec-ledger buf (current-buffer) (when (ledger-exec-ledger buf (current-buffer)
"--uncleared" "--real" "emacs" account) "--uncleared" "--real" "emacs" account)
(progn
(setq ledger-success t) (setq ledger-success t)
(goto-char (point-min)) (goto-char (point-min))
(unless (eobp) (unless (eobp)
(if (looking-at "(") (if (looking-at "(")
(read (current-buffer))))))))) ;current-buffer is the *temp* created above (read (current-buffer)))))))) ;current-buffer is the *temp* created above
(if (and ledger-success (> (length xacts) 0)) (if (and ledger-success (> (length xacts) 0))
(let ((date-format (cdr (assoc "date-format" ledger-environment-alist)))) (let ((date-format (cdr (assoc "date-format" ledger-environment-alist))))
(dolist (xact xacts) (dolist (xact xacts)
@ -351,15 +347,15 @@ moved and recentered. If they aren't strange things happen."
(defun ledger-reconcile-track-xact () (defun ledger-reconcile-track-xact ()
"Force the ledger buffer to recenter on the transaction at point in the reconcile buffer." "Force the ledger buffer to recenter on the transaction at point in the reconcile buffer."
(if (member this-command (list 'next-line (if (and ledger-buffer-tracks-reconcile-buffer
(member this-command (list 'next-line
'previous-line 'previous-line
'mouse-set-point 'mouse-set-point
'ledger-reconcile-toggle 'ledger-reconcile-toggle
'end-of-buffer 'end-of-buffer
'beginning-of-buffer)) 'beginning-of-buffer)))
(if ledger-buffer-tracks-reconcile-buffer
(save-excursion (save-excursion
(ledger-reconcile-visit t))))) (ledger-reconcile-visit t))))
(defun ledger-reconcile-open-windows (buf rbuf) (defun ledger-reconcile-open-windows (buf rbuf)
"Ensure that the ledger buffer BUF is split by RBUF." "Ensure that the ledger buffer BUF is split by RBUF."
@ -373,24 +369,21 @@ moved and recentered. If they aren't strange things happen."
(interactive) (interactive)
(let ((account (ledger-post-read-account-with-prompt "Account to reconcile")) (let ((account (ledger-post-read-account-with-prompt "Account to reconcile"))
(buf (current-buffer)) (buf (current-buffer))
(rbuf (get-buffer ledger-recon-buffer-name))) ;; this means (rbuf (get-buffer ledger-recon-buffer-name)))
;; only one ;; this means only one *Reconcile* buffer, ever Set up the
;; *Reconcile* ;; reconcile buffer
;; buffer, ever
;; Set up the reconcile buffer
(if rbuf ;; *Reconcile* already exists (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)) (when (not (eq buf rbuf))
(progn ;; called from some other ledger-mode buffer ;; called from some other ledger-mode buffer
(ledger-reconcile-quit-cleanup) (ledger-reconcile-quit-cleanup)
(set 'ledger-buf buf))) ;; should already be (set 'ledger-buf buf)) ;; should already be buffer-local
;; buffer-local
(unless (get-buffer-window rbuf) (unless (get-buffer-window rbuf)
(ledger-reconcile-open-windows buf rbuf))) (ledger-reconcile-open-windows buf rbuf)))
(progn ;; no recon-buffer, starting from scratch. ;; 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)
(with-current-buffer (setq rbuf (with-current-buffer (setq rbuf
@ -399,7 +392,7 @@ moved and recentered. If they aren't strange things happen."
(ledger-reconcile-mode) (ledger-reconcile-mode)
(make-local-variable 'ledger-target) (make-local-variable 'ledger-target)
(set (make-local-variable 'ledger-buf) buf) (set (make-local-variable 'ledger-buf) buf)
(set (make-local-variable 'ledger-acct) account)))) (set (make-local-variable 'ledger-acct) account)))
;; Narrow the ledger buffer ;; Narrow the ledger buffer
(with-current-buffer rbuf (with-current-buffer rbuf

View file

@ -30,8 +30,7 @@
(defgroup ledger-report nil (defgroup ledger-report nil
"Customization option for the Report buffer" "Customization option for the Report buffer"
:group 'ledger :group 'ledger)
)
(defcustom ledger-reports (defcustom ledger-reports
'(("bal" "ledger -f %(ledger-file) bal") '(("bal" "ledger -f %(ledger-file) bal")
@ -319,8 +318,7 @@ Optional EDIT the command."
(let ((file (match-string 1)) (let ((file (match-string 1))
(line (string-to-number (match-string 2)))) (line (string-to-number (match-string 2))))
(delete-region (match-beginning 0) (match-end 0)) (delete-region (match-beginning 0) (match-end 0))
(if file (when file
(progn
(set-text-properties (line-beginning-position) (line-end-position) (set-text-properties (line-beginning-position) (line-end-position)
(list 'ledger-source (cons file (save-window-excursion (list 'ledger-source (cons file (save-window-excursion
(save-excursion (save-excursion
@ -330,7 +328,7 @@ Optional EDIT the command."
(point-marker)))))) (point-marker))))))
(add-text-properties (line-beginning-position) (line-end-position) (add-text-properties (line-beginning-position) (line-end-position)
(list 'face 'ledger-font-report-clickable-face)) (list 'face 'ledger-font-report-clickable-face))
(end-of-line)))))) (end-of-line)))))
(goto-char data-pos))) (goto-char data-pos)))
@ -340,8 +338,7 @@ Optional EDIT the command."
(let* ((prop (get-text-property (point) 'ledger-source)) (let* ((prop (get-text-property (point) 'ledger-source))
(file (if prop (car prop))) (file (if prop (car prop)))
(line-or-marker (if prop (cdr prop)))) (line-or-marker (if prop (cdr prop))))
(if (and file line-or-marker) (when (and file line-or-marker)
(progn
(find-file-other-window file) (find-file-other-window file)
(widen) (widen)
(if (markerp line-or-marker) (if (markerp line-or-marker)
@ -353,7 +350,7 @@ Optional EDIT the command."
(let ((start-of-txn (point))) (let ((start-of-txn (point)))
(forward-paragraph) (forward-paragraph)
(narrow-to-region start-of-txn (point)) (narrow-to-region start-of-txn (point))
(backward-paragraph))))))) (backward-paragraph))))))
(defun ledger-report-goto () (defun ledger-report-goto ()
"Goto the ledger report buffer." "Goto the ledger report buffer."

View file

@ -223,7 +223,7 @@ returns true if the date meets the requirements"
;; read the descriptor string into a lisp object the transform the ;; read the descriptor string into a lisp object the transform the
;; string descriptor into useable things ;; string descriptor into useable things
(ledger-transform-auto-tree (ledger-transform-auto-tree
(read (buffer-substring (point-min) (point-max)))))) (read (buffer-substring-no-properties (point-min) (point-max))))))
(defun ledger-transform-auto-tree (tree) (defun ledger-transform-auto-tree (tree)
"Takes a lisp list of date descriptor strings, TREE, and returns a string with a lambda function of date." "Takes a lisp list of date descriptor strings, TREE, and returns a string with a lambda function of date."

View file

@ -48,25 +48,21 @@
(defun ledger-sort-insert-start-mark () (defun ledger-sort-insert-start-mark ()
(interactive) (interactive)
(let (has-old-marker)
(save-excursion (save-excursion
(goto-char (point-min)) (goto-char (point-min))
(setq has-old-marker (ledger-sort-find-start)) (if (ledger-sort-find-start)
(if has-old-marker
(delete-region (match-beginning 0) (match-end 0)))) (delete-region (match-beginning 0) (match-end 0))))
(beginning-of-line) (beginning-of-line)
(insert "\n; Ledger-mode: Start sort\n\n"))) (insert "\n; Ledger-mode: Start sort\n\n"))
(defun ledger-sort-insert-end-mark () (defun ledger-sort-insert-end-mark ()
(interactive) (interactive)
(let (has-old-marker)
(save-excursion (save-excursion
(goto-char (point-min)) (goto-char (point-min))
(setq has-old-marker (ledger-sort-find-end)) (if (ledger-sort-find-end)
(if has-old-marker
(delete-region (match-beginning 0) (match-end 0)))) (delete-region (match-beginning 0) (match-end 0))))
(beginning-of-line) (beginning-of-line)
(insert "\n; Ledger-mode: End sort\n\n"))) (insert "\n; Ledger-mode: End sort\n\n"))
(defun ledger-sort-region (beg end) (defun ledger-sort-region (beg end)
"Sort the region from BEG to END in chronological order." "Sort the region from BEG to END in chronological order."

View file

@ -245,10 +245,9 @@ dropped."
(eq (ledger-state-from-char (char-after)) 'cleared)) (eq (ledger-state-from-char (char-after)) 'cleared))
(progn (progn
(delete-char 1) (delete-char 1)
(if (and style (eq style 'cleared)) (when (and style (eq style 'cleared))
(progn
(insert " *") (insert " *")
(setq status 'cleared)))) (setq status 'cleared)))
(if (and style (eq style 'pending)) (if (and style (eq style 'pending))
(progn (progn
(insert " ! ") (insert " ! ")

View file

@ -44,12 +44,10 @@ within the transaction."
(backward-paragraph) (backward-paragraph)
(if (/= (point) (point-min)) (if (/= (point) (point-min))
(forward-line)) (forward-line))
(beginning-of-line) (setq beg-pos (line-beginning-position))
(setq beg-pos (point))
(forward-paragraph) (forward-paragraph)
(forward-line -1) (forward-line -1)
(end-of-line) (setq end-pos (1+ (line-end-position)))
(setq end-pos (1+ (point)))
(list beg-pos end-pos)))) (list beg-pos end-pos))))
@ -80,7 +78,8 @@ within the transaction."
(defsubst ledger-goto-line (line-number) (defsubst ledger-goto-line (line-number)
"Rapidly move point to line LINE-NUMBER." "Rapidly move point to line LINE-NUMBER."
(goto-char (point-min)) (forward-line (1- line-number))) (goto-char (point-min))
(forward-line (1- line-number)))
(defun ledger-thing-at-point () (defun ledger-thing-at-point ()
"Describe thing at points. Return 'transaction, 'posting, or nil." "Describe thing at points. Return 'transaction, 'posting, or nil."
@ -105,7 +104,7 @@ within the transaction."
(concat ledger-year "/" ledger-month "/") 'ledger-minibuffer-history))) (concat ledger-year "/" ledger-month "/") 'ledger-minibuffer-history)))
(let* ((here (point)) (let* ((here (point))
(extents (ledger-find-xact-extents (point))) (extents (ledger-find-xact-extents (point)))
(transaction (buffer-substring (car extents) (cadr extents))) (transaction (buffer-substring-no-properties (car extents) (cadr extents)))
encoded-date) encoded-date)
(if (string-match ledger-date-regex date) (if (string-match ledger-date-regex date)
(setq encoded-date (setq encoded-date