7

I am trying to get a list of buffers through elisp. So I created the following function:

(mapcar (function buffer-name) (buffer-list))

This works when I do something like:

(minibuffer-message (mapcar (function buffer-name) (buffer-list)))

However, the following line of code does not work:

(insert (mapcar (function buffer-name) (buffer-list)))

Q: Could this just be a noob mistake? Is there a better way of doing it?

1 Answer 1

9

insert takes an arbitrary number of strings or characters as arguments, so it bails when you hand it a list of strings.

Try this:

(insert (mapconcat (function buffer-name) (buffer-list) " "))

Or this:

(apply #'insert (mapcar (function buffer-name) (buffer-list)))
1
  • +1 for mapconcat – it's bailed me out of a tough situation countless times Commented Dec 9, 2014 at 0:11

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.