This is a short post to leave here a piece of knowledge that often escapes me: flush-lines.
flush-lines
flush-lines is a simple tool that has been around for quite some time now (since version 20), and that I always seem to forget. It’s mission is very simple: to eliminate the lines that match a given regex. flush-lines can be used in region, or it will be executed from point to the end of the buffer.
I normally use it to eliminate empty lines:
M-x flush-lines RET
;; it asks for the regex
^$ RET
All empty lines are gone!
(I often try to C-M-% ^$ RET, but it doesn’t work, flush-lines is the right tool for the job).