branch: elpa/csv2ledger commit 799beb345b5f8381d163a638dbdf74498d5fb738 Author: Joost Kremers <joost.krem...@ipsoft.com> Commit: Joost Kremers <joost.krem...@ipsoft.com>
New function `c2l-has-header`. --- csv2ledger.el | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/csv2ledger.el b/csv2ledger.el index c0c150562a..b7583574b0 100644 --- a/csv2ledger.el +++ b/csv2ledger.el @@ -278,6 +278,17 @@ Return value is a list of values as strings." (line (buffer-substring-no-properties (point-at-bol) (point-at-eol)))) (parse-csv-string line separator quote-char))) +(defun c2l-has-header () + "Return non-nil if the current CSV buffer appears to have a header. +Essentially, this function just takes the field that should +contain the amount and checks if it contains something that looks +like a number." + (save-mark-and-excursion + (goto-char (point-min)) + (let* ((row (c2l-get-current-row)) + (fields (--remove (eq (car it) '_) (-zip-pair c2l-csv-columns row)))) + (not (string-match-p "[0-9,.-]+" (alist-get 'amount fields)))))) + ;;;###autoload (defun c2l-set-base-account () "Set `c2l-base-account'."