0

How do I concatenate a column into a string in Org mode? I want to get abc instead of ((a) (b) (c)) as a result. Or is there simply a header that I can tweak?

#+name: example-table
| i |
|---|
| a |
| b |
| c |

#+begin_src elisp :var input=example-table
  (format "%s" input)
#+end_src

#+RESULTS:
: ((a) (b) (c))
1

1 Answer 1

1

maybe this will work:

(mapconcat (lambda (x) (format "%s" (car x))) input)

For versions of Emacs earlier than 29, the separator argument to mapconcat is mandatory, so the call should be:

(mapconcat (lambda (x) (format "%s" (car x))) input "")
;; or...
(mapconcat (lambda (x) (format "%s" (car x))) input nil)

specifying an empty string as the separator.

4
  • In addition to your being first to answer, your solution has the advantage of working for columns of numbers (which are not converted to strings by Org mode). But there is a small problem: t cannot be used as the name of the variable - it is a reserved symbol in Emacs Lisp. I edited your answer to fix that.
    – NickD
    Nov 4, 2023 at 20:57
  • @NickD thanks, didn't know that. Nov 4, 2023 at 21:04
  • This code gives me the followin error let: Wrong number of arguments: mapconcat, 2. The documentation mentions a seperator. When call it with "" as a third argument it works for me
    – leonardo
    Nov 4, 2023 at 21:58
  • You are right - earlier versions of mapconcat required a separator argument. Current versions make this argument optional. Edited the answer to mention that.
    – NickD
    Nov 5, 2023 at 0:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.