branch: elpa/csv2ledger
commit a0a328df02f0c7f7960cf5f7c470e111f2e36299
Author: Joost Kremers <joostkrem...@fastmail.fm>
Commit: Joost Kremers <joostkrem...@fastmail.fm>

    New function `c2l-convert-region`.
---
 csv2ledger.el | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/csv2ledger.el b/csv2ledger.el
index 4dae11020b..a040dbb826 100644
--- a/csv2ledger.el
+++ b/csv2ledger.el
@@ -309,6 +309,30 @@ in `c2l-csv-columns'."
     (kill-new entry)
     (message entry)))
 
+(defun c2l-convert-region (start end)
+  "Convert the CSV entries in the region to ledger entries.
+START and END describe the region.  Note that it is assumed that
+START does indeed refer to the start of the region and END to its
+end.  In other words, START must be smaller than END.  START and
+END do not have to point to the start of end of a line, but the
+conversion always takes the whole line into account.
+
+This function always returns nil.  The converted entries are
+placed in the buffer \"*Csv2Ledger Results*\", which is erased
+beforehand if it already exists."
+  (interactive "r")
+  (let ((buffer (get-buffer-create "*Csv2Ledger Results*")))
+    (with-current-buffer buffer
+      (erase-buffer))
+    (save-mark-and-excursion
+      (goto-char start)
+      (beginning-of-line)
+      (while (< (point) end)
+        (let ((entry (c2l-csv-line-to-ledger (c2l-get-current-row))))
+          (with-current-buffer buffer
+            (insert entry "\n")))
+        (forward-line 1)))))
+
 (provide 'csv2ledger)
 
 ;;; csv2ledger.el ends here

Reply via email to