💾 Archived View for idiomdrottning.org › hardening-newlines captured on 2024-08-31 at 14:11:29. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2024-05-26)

-=-=-=-=-=-=-

Hardening newlines

Sometimes I just want all newlines in a region to become hardened, for example when writing code or poetry.

Markdown

I have this brev snippet that I run with shell-command-on-region:

(make-sloppy-tree-accessor scadr)

(define (poetry-md)
  (pair-fold
    (fn (if (any empty? (list (car x) (scadr x)))
          (print (car x))
          (print (car x) "  ")))
    (void)
    ((over (strse x " +$" "")) (read-lines))))

use-hard-newlines mode

Here’s a function to harden all newlines in the region:

(defun harden-region (start end)
  (interactive "r")
  (when use-hard-newlines
    (save-excursion
      (goto-char start)
      (while (< (point) (min (point-max) end))
        (end-of-line)
        (forward-char)
        (set-hard-newline-properties
         (- (point) 1) (point))))))