help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: the «inverse» function of join-lines


From: Nikolay Kudryavtsev
Subject: Re: the «inverse» function of join-lines
Date: Thu, 23 Nov 2023 18:50:06 +0300
User-agent: Mozilla Thunderbird

Weirdly I have not found unfill-paragraph-or-region anywhere in the org mode.

But there are different unfill paragraph\region functions on EmacsWiki.

None of them had the advanced functionality I was looking for, so I hacked up a better one for myself:

(defun unfill-region (beg end)
  (interactive "*r")
  (replace-regexp-in-region
   "\\([^\.\\!\\?:]\\)\n\s*\\([^-\\*[:digit:][:upper:]\s]+\\)"
                "\\1 \\2" beg end))

This works just about perfectly, since it checks both sides of the line break, before removing it. You know, there's the famous quote by H. L. Mencken that "For every complex problem there is an /answer/ that is clear, /simple/ and wrong." I guess what's also true is that for every complex problem there's a simple and incomprehensible regular expression solution. Me starting to like regexps nowadays also probably means that, I'll end up in a mental asylum soon enough. ;-)

P.S. I don't really understand why do I have to put \s into the second group, but without explicitly doing that it just keeps eating whitespace from the first \s. I guess, sometimes the less you know, the longer you live.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]