 				 (nth 1 emacs-xact)  ;; return line-no of xact
 				 (nth 0 posting))))) ;; return line-no of posting
 
-(defun ledger-do-reconcile ()
+(defun ledger-do-reconcile (&optional sort)
   "Return the number of uncleared transactions in the account and display them in the *Reconcile* buffer."
   (let* ((buf ledger-buf)
          (account ledger-acct)
 				 (ledger-success nil)
+				 (sort-by (if sort
+											sort
+											"(date)"))
          (xacts
           (with-temp-buffer
 						(when (ledger-exec-ledger buf (current-buffer)
-																			"--uncleared" "--real" "emacs" account)
+																			"--uncleared" "--real" "emacs" "--sort" sort-by account)
 							(setq ledger-success t)
 							(goto-char (point-min))
 							(unless (eobp)

  (let ((inhibit-read-only t))
    (erase-buffer)
    (prog1
				(ledger-do-reconcile)
      (set-buffer-modified-p t))))

(defun ledger-reconcile-refresh-after-save ()

		(define-key map [?q] 'ledger-reconcile-quit)
		(define-key map [?b] 'ledger-display-balance)

		(define-key map [(control ?c) (control ?a)] (ledger-reconcile-change-sort-key-and-refresh "(amount)"))

		(define-key map [(control ?c) (control ?d)] (ledger-reconcile-change-sort-key-and-refresh "(date)"))

		(define-key map [(control ?c) (control ?p)] (ledger-reconcile-change-sort-key-and-refresh "(payee)"))

		(define-key map [menu-bar] (make-sparse-keymap "ldg-recon-menu"))
		(define-key map [menu-bar ldg-recon-menu] (cons "Reconcile" map))
		(define-key map [menu-bar ldg-recon-menu qui] '("Quit" . ledger-reconcile-quit))
