In org-mode if I am typing the lines will wrap to the next line at around 70 characters. However if I yank text from the OS clipboard into the org-mode buffer, then the text will not wrap but be on one long line. How can I get the text to wrap upon being yanked?

1 Answer 1


M-q which is the command fill-paragraph.

There's also fill-region. This command is more accurate because the region is automatically defined as whatever you just yanked.

Here's some elisp I whipped up to do this automatically after yanks:

(dolist (command '(yank yank-pop))
   (eval `(defadvice ,command (after indent-region activate)
            (fill-region (region-beginning) (region-end)))))


@kaushalmodi mentioned that using advices like this could result in unwanted behavior. His suggestion of a wrapper function could be implemented like this:

(defun my-yank-and-fill (&optional arg)
  "Fills the region immediately after yanking."
  (yank arg)
  (fill-region (region-beginning) (region-end)))

Doing the same for yank-pop doesn't work though. It says "last command was not a yank", enough though a normal yank-pop works. But, you can just call fill-region separately after all your yank-poping to fill the final result.

  • 3
    It might be catastrophic to defadvice these commands as these advices will be effective throughout emacs! It would be safe to have wrapper functions which the user can bind in specific mode maps. Commented Feb 27, 2015 at 23:01
  • @kaushalmodi That's true, I didn't think of that. I'll replace the advice with functions.
    – nanny
    Commented Mar 2, 2015 at 13:51

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.