branch: elpa/beancount commit 029d0c9cc8d503c531cbeff35258a22816402e3c Merge: 2303612b22 ddd4b87257 Author: Martin Blais <bl...@furius.ca> Commit: Martin Blais <bl...@furius.ca>
(Merge remote-tracking branch 'github/main') --- .gitignore | 1 + beancount.el | 46 +++++++++++++++++++++++++++++----------------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index bdc4ea6af6..d6016d7db3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +*~ *.elc /beancount-autoloads.el /beancount-pkg.el diff --git a/beancount.el b/beancount.el index e05b15fe62..8cf43d0950 100644 --- a/beancount.el +++ b/beancount.el @@ -223,7 +223,7 @@ _not_ followed by an account.") (defconst beancount-account-regexp (concat (regexp-opt beancount-account-categories) - "\\(?::[[:upper:][:digit:]][[:alnum:]-_]+\\)+") + "\\(?::[[:upper:][:digit:]][[:alnum:]-_]*\\)+") "A regular expression to match account names.") (defconst beancount-number-regexp "[-+]?[0-9]+\\(?:,[0-9]\\{3\\}\\)*\\(?:\\.[0-9]*\\)?" @@ -233,13 +233,13 @@ _not_ followed by an account.") "A regular expression to match currencies.") (defconst beancount-flag-regexp - ;; Single char that is neither a space nor a lower-case letter. - "[^ a-z]") + ;; Single character: Certain symbols plus uppercase letters. + ;; case-fold-search t will cause a single lowercase letter to match also. + "[!#%&*?A-Z]") (defconst beancount-transaction-regexp (concat "^\\(" beancount-date-regexp "\\) +" - "\\(?:txn +\\)?" - "\\(" beancount-flag-regexp "\\) +" + "\\(\\(?:txn+\\)\\|" beancount-flag-regexp "\\) +" "\\(\".*\"\\)")) (defconst beancount-posting-regexp @@ -358,6 +358,7 @@ are reserved for the mode anyway.)") (define-key map (kbd "M-RET") #'beancount-insert-date) (define-key map (vconcat p [(\')]) #'beancount-insert-account) (define-key map (vconcat p [(control c)]) #'beancount-transaction-clear) + (define-key map (vconcat p [(control f)]) #'beancount-transaction-flag) (define-key map (vconcat p [(control l)]) #'beancount-check) (define-key map (vconcat p [(control q)]) #'beancount-query) (define-key map (vconcat p [(control x)]) #'beancount-context) @@ -725,6 +726,17 @@ transaction as pending." (if (looking-at beancount-transaction-regexp) (replace-match flag t t nil 2)))))) +(defun beancount-transaction-flag (arg) + "Prompt for a flag and set the transaction's flag to the +response, uppercased." + (interactive "cFlag:") + (save-excursion + (save-match-data + (let ((flag (upcase (char-to-string arg)))) + (beancount-goto-transaction-begin) + (if (looking-at beancount-transaction-regexp) + (replace-match flag t t nil 2)))))) + (defun beancount-insert-account (account-name) "Insert one of the valid account names in this file. Uses ido niceness according to `beancount-use-ido'." @@ -1263,21 +1275,21 @@ Essentially a much simplified version of `next-line'." (defun beancount-fava () "Start (and open) or stop the fava server." (interactive) - (if beancount--fava-process - (progn - (delete-process beancount--fava-process) - (setq beancount--fava-process nil) - (message "Fava process killed")) - (setq beancount--fava-process - (start-process "fava" (get-buffer-create "*fava*") "fava" - (if (eq 'beancount-mode major-mode) (buffer-file-name) - (read-file-name "File to load: ")))) - (set-process-filter beancount--fava-process #'beancount--fava-filter) - (message "Fava process started"))) + (when beancount--fava-process + (delete-process beancount--fava-process) + (setq beancount--fava-process nil) + (message "Fava process killed")) + (setq beancount--fava-process + (start-process "fava" (get-buffer-create "*fava*") "fava" + (if (eq 'beancount-mode major-mode) (buffer-file-name) + (read-file-name "File to load: ")))) + (set-process-filter beancount--fava-process #'beancount--fava-filter) + (message "Fava process started")) (defun beancount--fava-filter (_process output) "Open fava url as soon as the address is announced." - (if-let ((url (string-match "Running Fava on \\(http://.+:[0-9]+\\)\n" output))) + (with-current-buffer "*fava*" (insert output)) + (if-let ((url (string-match "Starting Fava on \\(http://.+:[0-9]+\\)\n" output))) (browse-url (match-string 1 output)))) ;;; Xref backend