Renamed ldg-account.el to ldg-post.el
This commit is contained in:
parent
f672ddafc3
commit
a5d99cc9d3
1 changed files with 29 additions and 29 deletions
|
|
@ -1,23 +1,23 @@
|
||||||
(require 'ldg-regex)
|
(require 'ldg-regex)
|
||||||
|
|
||||||
(defgroup ledger-account nil
|
(defgroup ledger-post nil
|
||||||
""
|
""
|
||||||
:group 'ledger)
|
:group 'ledger)
|
||||||
|
|
||||||
(defcustom ledger-account-auto-adjust-amounts t
|
(defcustom ledger-post-auto-adjust-amounts t
|
||||||
"If non-nil, ."
|
"If non-nil, ."
|
||||||
:type 'boolean
|
:type 'boolean
|
||||||
:group 'ledger-account)
|
:group 'ledger-post)
|
||||||
|
|
||||||
(declare-function iswitchb-read-buffer "iswitchb"
|
(declare-function iswitchb-read-buffer "iswitchb"
|
||||||
(prompt &optional default require-match start matches-set))
|
(prompt &optional default require-match start matches-set))
|
||||||
(defvar iswitchb-temp-buflist)
|
(defvar iswitchb-temp-buflist)
|
||||||
|
|
||||||
(defvar ledger-account-current-list nil)
|
(defvar ledger-post-current-list nil)
|
||||||
|
|
||||||
(defun ledger-account-find-all ()
|
(defun ledger-post-find-all ()
|
||||||
(let ((origin (point))
|
(let ((origin (point))
|
||||||
(ledger-account-list nil)
|
(ledger-post-list nil)
|
||||||
account-path elements)
|
account-path elements)
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
|
|
@ -27,11 +27,11 @@
|
||||||
(< origin (match-end 0)))
|
(< origin (match-end 0)))
|
||||||
(setq account-path (match-string-no-properties 2))
|
(setq account-path (match-string-no-properties 2))
|
||||||
(unless (string-match "\\`\\s-*;" account-path)
|
(unless (string-match "\\`\\s-*;" account-path)
|
||||||
(add-to-list 'ledger-account-list account-path))))
|
(add-to-list 'ledger-post-list account-path))))
|
||||||
(setq ledger-account-current-list
|
(setq ledger-post-current-list
|
||||||
(nreverse ledger-account-list)))))
|
(nreverse ledger-post-list)))))
|
||||||
|
|
||||||
(defun ledger-account-completing-read (prompt choices)
|
(defun ledger-post-completing-read (prompt choices)
|
||||||
"Use iswitchb as a completing-read replacement to choose from 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
|
PROMPT is a string to prompt with. CHOICES is a list of strings
|
||||||
to choose from."
|
to choose from."
|
||||||
|
|
@ -41,12 +41,12 @@ to choose from."
|
||||||
(setq iswitchb-temp-buflist choices))))
|
(setq iswitchb-temp-buflist choices))))
|
||||||
(iswitchb-read-buffer prompt)))
|
(iswitchb-read-buffer prompt)))
|
||||||
|
|
||||||
(defun ledger-account-select ()
|
(defun ledger-post-pick-account ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(let* ((account
|
(let* ((account
|
||||||
(ledger-account-completing-read "Account: "
|
(ledger-post-completing-read "Account: "
|
||||||
(or ledger-account-current-list
|
(or ledger-post-current-list
|
||||||
(ledger-account-find-all))))
|
(ledger-post-find-all))))
|
||||||
(account-len (length account))
|
(account-len (length account))
|
||||||
(pos (point)))
|
(pos (point)))
|
||||||
(goto-char (line-beginning-position))
|
(goto-char (line-beginning-position))
|
||||||
|
|
@ -64,22 +64,22 @@ to choose from."
|
||||||
(delete-char 1)))))))
|
(delete-char 1)))))))
|
||||||
(goto-char pos)))
|
(goto-char pos)))
|
||||||
|
|
||||||
(defun ledger-account-align-amount ()
|
(defun ledger-post-align-amount ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(set-mark (line-beginning-position))
|
(set-mark (line-beginning-position))
|
||||||
(goto-char (1+ (line-end-position)))
|
(goto-char (1+ (line-end-position)))
|
||||||
(ledger-align-amounts)))
|
(ledger-align-amounts)))
|
||||||
|
|
||||||
(defun ledger-account-maybe-align (beg end len)
|
(defun ledger-post-maybe-align (beg end len)
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(goto-char beg)
|
(goto-char beg)
|
||||||
(when (< end (line-end-position))
|
(when (< end (line-end-position))
|
||||||
(goto-char (line-beginning-position))
|
(goto-char (line-beginning-position))
|
||||||
(if (looking-at ledger-regex-post-line)
|
(if (looking-at ledger-regex-post-line)
|
||||||
(ledger-account-align-amount)))))
|
(ledger-post-align-amount)))))
|
||||||
|
|
||||||
(defun ledger-account-edit-amount ()
|
(defun ledger-post-edit-amount ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(goto-char (line-beginning-position))
|
(goto-char (line-beginning-position))
|
||||||
(when (re-search-forward ledger-regex-post-line (line-end-position) t)
|
(when (re-search-forward ledger-regex-post-line (line-end-position) t)
|
||||||
|
|
@ -93,7 +93,7 @@ to choose from."
|
||||||
(setq val (replace-match "" nil nil val)))
|
(setq val (replace-match "" nil nil val)))
|
||||||
(calc-eval val 'push)))))
|
(calc-eval val 'push)))))
|
||||||
|
|
||||||
(defun ledger-account-prev-xact ()
|
(defun ledger-post-prev-xact ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(backward-paragraph)
|
(backward-paragraph)
|
||||||
(when (re-search-backward ledger-regex-xact-line nil t)
|
(when (re-search-backward ledger-regex-xact-line nil t)
|
||||||
|
|
@ -101,22 +101,22 @@ to choose from."
|
||||||
(re-search-forward ledger-regex-post-line)
|
(re-search-forward ledger-regex-post-line)
|
||||||
(goto-char (match-end 3))))
|
(goto-char (match-end 3))))
|
||||||
|
|
||||||
(defun ledger-account-next-xact ()
|
(defun ledger-post-next-xact ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(when (re-search-forward ledger-regex-xact-line nil t)
|
(when (re-search-forward ledger-regex-xact-line nil t)
|
||||||
(goto-char (match-beginning 0))
|
(goto-char (match-beginning 0))
|
||||||
(re-search-forward ledger-regex-post-line)
|
(re-search-forward ledger-regex-post-line)
|
||||||
(goto-char (match-end 3))))
|
(goto-char (match-end 3))))
|
||||||
|
|
||||||
(defun ledger-account-setup ()
|
(defun ledger-post-setup ()
|
||||||
(let ((map (current-local-map)))
|
(let ((map (current-local-map)))
|
||||||
(define-key map [(meta ?p)] 'ledger-account-prev-xact)
|
(define-key map [(meta ?p)] 'ledger-post-prev-xact)
|
||||||
(define-key map [(meta ?n)] 'ledger-account-next-xact)
|
(define-key map [(meta ?n)] 'ledger-post-next-xact)
|
||||||
(define-key map [(control ?c) (control ?c)] 'ledger-account-select)
|
(define-key map [(control ?c) (control ?c)] 'ledger-post-pick-account)
|
||||||
(define-key map [(control ?c) (control ?e)] 'ledger-account-select))
|
(define-key map [(control ?c) (control ?e)] 'ledger-post-edit-amount))
|
||||||
(if ledger-account-auto-adjust-amounts
|
(if ledger-post-auto-adjust-amounts
|
||||||
(add-hook 'after-change-functions 'ledger-account-maybe-align t t)))
|
(add-hook 'after-change-functions 'ledger-post-maybe-align t t)))
|
||||||
|
|
||||||
(add-hook 'ledger-mode-hook 'ledger-account-setup)
|
(add-hook 'ledger-mode-hook 'ledger-post-setup)
|
||||||
|
|
||||||
(provide 'ldg-account)
|
(provide 'ldg-post)
|
||||||
Loading…
Add table
Reference in a new issue