I'm using terminal.app on OS X, and when typing in emacs I often want to copy the text and paste it into some other program. When I do, I find that copied text has some spaces unexpectedly replaced by tabs.

I assume I'm copying the text that emacs has sent to the terminal which I suppose doesn't have to match the actual document, but what's the right way to do this?

  • I'm also curious as to why this happens.
    – Jon Hess
    Mar 6, 2014 at 22:48

1 Answer 1


If the buffer doesn't actually contain tabs, then you can use the Mac utility pbcopy to copy its contents into the cut buffer.

  1. Set a region with mark and point around the text you want to copy.
  2. Run shell-command-on-region, normally bound to M-| .
  3. Type pbcopy Return.

The contents of the region are now in the cut buffer and you can paste them normally. I would roll the last two steps into some Lisp to save typing. Put this code in .emacs

(defun copy-region-to-cut-buffer (beg end)
  (interactive "r")
  (call-process-region beg end "pbcopy"))

and bind the new command to a key of your choice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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