1

I tried to use the code provided by John Kitchin in https://stackoverflow.com/a/27240183/11376268 to convert my CSV file to org mode but I get the following error message:

Debugger entered--Lisp error: (void-function loop)
  (loop for line in (cdr lines) do (setq values (split-string line ",")) (loop for property in properties for value in values do (org-entry-put (point) property value)))
  (let ((lines (let ((temp-buffer (generate-new-buffer " *temp*" t))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (insert-file-contents "data.csv") (split-string (buffer-string) "\n")) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))))) (properties) (values)) (setq properties (split-string (car lines) ",")) (loop for line in (cdr lines) do (setq values (split-string line ",")) (loop for property in properties for value in values do (org-entry-put (point) property value))))
  (progn (let ((lines (let ((temp-buffer (generate-new-buffer " *temp*" t))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (insert-file-contents "data.csv") (split-string (buffer-string) "\n")) (and (buffer-name temp-buffer) ...))))) (properties) (values)) (setq properties (split-string (car lines) ",")) (loop for line in (cdr lines) do (setq values (split-string line ",")) (loop for property in properties for value in values do (org-entry-put (point) property value)))))
  elisp--eval-last-sexp(nil)
  eval-last-sexp(nil)
  funcall-interactively(eval-last-sexp nil)
  command-execute(eval-last-sexp)

I use GNU Emacs 28.1 (build 2, x86_64-w64-mingw32).

What have I done wrong?

data.csv looks like this:

Name,Tel,Mobile,Fax
John,11111,22222,33333

The code I used:

(let ((lines (with-temp-buffer
               (insert-file-contents "data.csv")
               (split-string (buffer-string) "\n")))
      (properties)
      (values))

  (setq properties (split-string (car lines) ","))

  (loop for line in (cdr lines)
        do
        (setq values (split-string line ","))
        (loop for property in properties
              for value in values
              do
              (org-entry-put (point) property value))))
Drew
  • 29,895
  • 7
  • 74
  • 104
Hababa
  • 11
  • 2
  • Try using 'cl-loop' instead of 'loop', which is a function from common lisp (CL). However, I recommend migrating this question to [Emacs SE](https://emacs.stackexchange.com/). – Juancho Jun 17 '22 at 13:58

1 Answers1

3

Insert a plain csv-file as is, mark the region in buffer and call M-x org-table-convert-region RET.

Andreas Röhler
  • 4,804
  • 14
  • 18