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?
M-q which is the command
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." (interactive) (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.