From a3361db4b19465412fd9193ebc64bbb4a45a6c3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Wed, 3 Sep 2025 02:17:49 +0200 Subject: [PATCH] Add comments completion --- ledger-complete.el | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ledger-complete.el b/ledger-complete.el index 36430a62..1465a1a3 100644 --- a/ledger-complete.el +++ b/ledger-complete.el @@ -304,6 +304,14 @@ an alist (ACCOUNT-ELEMENT . NODE)." (match-string 2) (match-string 3) (match-string 4) (match-string 5) (match-string 6) (= (line-end-position) (match-end 0))))) + (;; Transaction comments + (eq 'comment (car (cdr (ledger-context-at-point)))) + (save-excursion + (back-to-indentation) + (search-forward ";") + (skip-chars-forward " \t") + (setq start (point))) + (setq collection (cons 'nullary #'ledger-comments-list))) (;; Payees (eq 'transaction (save-excursion @@ -352,6 +360,18 @@ an alist (ACCOUNT-ELEMENT . NODE)." (defun ledger-trim-trailing-whitespace (str) (replace-regexp-in-string "[ \t]*$" "" str)) +(defun ledger-comments-list () + "Collect comments from the buffer." + (let ((comments '())) + (save-excursion + (goto-char (point-min)) + ;; FIXME: This only catches comments at beginning of lines and + ;; starting with some spaces (so "transaction comments"). There + ;; can also be comments after payees or prices too + (while (re-search-forward "^[ \t]+;[ \t]*\\(?1:.+\\)$" nil t) + (push (match-string-no-properties 1) comments))) + (sort (delete-dups comments) #'string-lessp))) + (defun ledger-fully-complete-xact () "Completes a transaction if there is another matching payee in the buffer.