(defun hash-keys (hashtable)
  "Return all keys in hashtable."
  (let (allkeys)
    (maphash (lambda (kk vv) (setq allkeys (cons kk allkeys))) hashtable)
    allkeys))

(defun dsg-ledger-all-accounts ()
  "Returns a list of the accounts in this file."
  (let ((origin (point)) (accounts (make-hash-table)))
    (save-excursion
      (goto-char (point-min))
      (while (re-search-forward
              "^[ \t]+\\([*!]\\s-+\\)?[[(]?\\(.+?\\)\\(\t\\|\n\\| [ \t]\\)" nil 
t)
        (unless (and (>= origin (match-beginning 0))
                     (< origin (match-end 0)))
          (puthash (match-string-no-properties 2) t accounts))))
    (hash-keys accounts)))

(defun on-empty-line ()
  (save-excursion
    (beginning-of-line)
    (= (line-end-position) (point))))

(defun dsg-ledger-insert-account ()
  "Prompts the user for an account to insert at point."
  (interactive)
  (let ((accounts (dsg-ledger-all-accounts)))
    (insert
     (if (on-empty-line) " " "")
     (ido-completing-read "Account: " accounts) "    ")))


-- 
[email protected] | langtonlabs.org | flickr.com/photos/glasser/


-- 
To unsubscribe, reply using "remove me" as the subject.

Reply via email to