Hacker News new | past | comments | ask | show | jobs | submit login

Fine, here you go, with the line breaks

;; one sentence per line

(defun wrap-at-sentences ()

  "Fills the current paragraph, but starts each sentence on a new line."

  (interactive)

  (save-excursion

    ;; Select the entire paragraph.

    (mark-paragraph)

    ;; Move to the start of the paragraph.

    (goto-char (region-beginning))

    ;; Record the location of the end of the paragraph.

    (setq end-of-paragraph (region-end))

    ;; Wrap lines with 'hard' newlines (i.e., real line breaks).

    (let ((use-hard-newlines 't))

      ;; Loop over each sentence in the paragraph.

      (while (< (point) end-of-paragraph)

        ;; Determine the region spanned by the sentence.

        (setq start-of-sentence (point))

        (forward-sentence)

        ;; Wrap the sentence with hard newlines.

        (fill-region start-of-sentence (point))

        ;; Delete the whitespace following the period, if any.

        (while (char-equal (char-syntax (preceding-char)) ?\s)

          (delete-char -1))

        ;; Insert a newline before the next sentence.

        (insert "\n")))))

(global-set-key (kbd "M-j") 'wrap-at-sentences)



Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: