[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/csv2ledger 2531e81bcf 082/190: Add user option c2l-transac
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/csv2ledger 2531e81bcf 082/190: Add user option c2l-transaction-modify-function. |
Date: |
Sun, 2 Jun 2024 15:59:47 -0400 (EDT) |
branch: elpa/csv2ledger
commit 2531e81bcf80591db001904164990f7b08af74e5
Author: Joost Kremers <joostkremers@fastmail.fm>
Commit: Joost Kremers <joostkremers@fastmail.fm>
Add user option c2l-transaction-modify-function.
---
csv2ledger.el | 26 +++++++++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)
diff --git a/csv2ledger.el b/csv2ledger.el
index 1e3c733a9c..48b1bbea20 100644
--- a/csv2ledger.el
+++ b/csv2ledger.el
@@ -120,6 +120,17 @@ set them directly."
(c2l-set-options)))
:group 'csv2ledger)
+(defcustom c2l-transaction-modify-function #'identity
+ "Function to modify a transaction.
+This should be a single function that takes an alist representing
+a transaction and returns a modified alist. Any kind of
+modification is possible, including modifying, adding or deleting
+fields. Importantly, because the function is passed the entire
+entry, it is possible to modify or create a field based on the
+values of other fields."
+ :type 'function
+ :group 'csv2ledger)
+
(defcustom c2l-field-modify-functions nil
"List of functions to modify fields in an entry.
This option should be an alist mapping field names (as symbols)
@@ -360,8 +371,15 @@ strings are interpreted according to the template in
`c2l-base-account'. The target account is determined on the
basis of the matchers in `c2l-account-matchers-file'. If none is
found, the value of `c2l-fallback-account' is used. If that
-option is unset, the user is asked for an account."
- (let* ((fields (--remove (eq (car it) '_) (-zip-pair c2l-csv-columns row)))
+option is unset, the user is asked for an account.
+
+This function first creates an alist of field-value pairs, then
+passes it to `c2l-transaction-modify-function' and subsequently
+applies the functions in `c2l-field-modify-functions' to the
+individual fields. After that, the `title' and `account' fields
+are added. Additionally, the `amount' field is added or, if
+already, present, its value is updated."
+ (let* ((fields (funcall c2l-transaction-modify-function (--remove (eq (car
it) '_) (-zip-pair c2l-csv-columns row))))
(parsed-fields (mapcar (lambda (item)
(let ((field (car item))
(value (cdr item)))
@@ -379,7 +397,9 @@ option is unset, the user is asked for an account."
c2l--accounts))))
(push (cons 'account account) parsed-fields)
(push (cons 'title title) parsed-fields)
- (push (cons 'amount amount) parsed-fields)
+ (if (assq 'amount parsed-fields)
+ (setf (alist-get 'amount parsed-fields) amount)
+ (push (cons 'amount amount) parsed-fields))
(c2l--compose-entry parsed-fields)))
(defun c2l--get-current-row ()
- [nongnu] elpa/csv2ledger 59ba841805 086/190: Guard against empty payee and sender in c2l-title-is-payee-or-sender, (continued)
- [nongnu] elpa/csv2ledger 59ba841805 086/190: Guard against empty payee and sender in c2l-title-is-payee-or-sender, ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger 6076653a0f 084/190: Rename local variable in c2l--csv-line-to-ledger., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger af1129653d 178/190: Make auto-clearing of transactions with effective date optional., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger 66d5a39b99 116/190: Replace point-at-{bol|eol} with pos-{bol|eol}., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger 3925c6b34a 113/190: Small fixes to the README., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger e6a7312467 112/190: Small updates to the README., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger cc5050faaf 117/190: Fix doc string for c2l-create-amount, ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger d00914d9f1 044/190: c2l-csv-line-to-ledger: Check c2l-fallback-account before asking the user., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger 466a098d2b 034/190: Extract new function `c2l-get-current-row` from `c2l-csv-entry-as-kill`., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger 799beb345b 035/190: New function `c2l-has-header`., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger 2531e81bcf 082/190: Add user option c2l-transaction-modify-function.,
ELPA Syncer <=
- [nongnu] elpa/csv2ledger 81322ebde0 072/190: Use c2l--amount-p in c2l--has-header., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger bf995e11cb 080/190: Rename balancing account back to target account., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger 521edc8471 081/190: Do not create c2l-base-account as a buffer-local variable., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger ea515e3ae6 074/190: Set default value of c2l-base-account to "Assets:Unknown"., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger c72b617d68 159/190: Fix typo in the README, ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger 3a309c795a 139/190: Fix the README., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger 0bcf56f4b8 140/190: Update the README., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger f299813350 146/190: Recognise amounts without cents in c2l--amount-p, ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger 2b2f8267f2 161/190: Update README., ELPA Syncer, 2024/06/03
- [nongnu] elpa/csv2ledger 7a3c55377e 154/190: Small update to the README, ELPA Syncer, 2024/06/03