;; -*- mode: emacs-lisp -*-
;;
;; Emacs setup for Ledger.
;;

;; Add local emacs-lisp extension to load-path and load it.
(add-to-list 'load-path (concat project-current "/editors/emacs"))
(require 'beancount)

;; Automatically open .beancount files in beancount-mode.
(add-to-list 'auto-mode-alist '("\\.beancount$" . beancount-mode))


;; Support parsing Python logging errors, with a suitable logging.basicConfig()
;; format.
(unless (assq 'python-logging compilation-error-regexp-alist-alist)

  (add-to-list
   'compilation-error-regexp-alist-alist
   '(python-logging "\\(ERROR\\|WARNING\\):\\s-*\\([^:]+\\):\\([0-9]+\\)\\s-*:" 2 3))

  (add-to-list
   'compilation-error-regexp-alist 'python-logging)
  )


;; Experimental: Bind a key to reformat the entire file using bean-format.
(defun beancount-format-file ()
  (interactive)
  (let ((line-no (line-number-at-pos)))
      (call-process-region (point-min) (point-max) "bean-format" t (current-buffer))
      (goto-line line-no)
      (recenter)
      ))

(define-key* beancount-mode-map [(control c)(F)] 'beancount-format-file)
