Fork me on GitHub
#emacs
<
2023-04-30
>
teodorlu08:04:34

Sharing a small emacs lisp function that I've come to use several times, latest today:

(defun teod/one-line-per-sentence ()
  (interactive)
  (let* ((s (delete-and-extract-region (mark) (point)))
         (s2 (string-replace ". " ".\n" s)))
    (insert s2)))
Alternative with thread-last, which I learned from @elken today.
(defun teod/one-sentence-per-line ()
  (interactive)
  (thread-last (delete-and-extract-region (mark) (point))
               (string-replace ". " ".\n")
               (insert)))
requires https://github.com/magnars/s.el. Does not require third party libraries thanks to @elken! But must be run on Emacs 28.1 or later. why? I find that writing one sentence per line lets me write better. Each sentence should stand on its own and say something. I usually prefer to write one sentence per line for myself, then join the lines into a paragraph when I share with others. (with evil-join / J in normal-mode for me). Derek Sivers argues for the same thing, if you prefer his opinion: https://sive.rs/1s M-x teod/one-line-per-sentence lets me move back. Perhaps I wrote something somewhere. Then I can mark the text, and run M-x teod/one-line-per-sentence. And continue editing the paragraph as I like. Edit: fix: I wrote N (wrong) instead of J (correct).

👍 2
elken10:04:36

string-replace is built-in since 28.1

👀 2
teodorlu10:04:17

Nice, thanks! 💯

🙌 2
elken10:04:28

(untested) Could probably also write it as

(thread-last
   (delete-and-extract-region (mark) (point)) 
   (string-replace ". " ".\n")
   (insert))

💯 2
teodorlu10:04:17

Tested, works perfectly. Never new about thread-last. Thanks for that too! Great to know coming from Clojure.

elken10:04:37

Nice! 😄 thread-first and thread-last are great additions

💯 2
2
teodorlu10:04:52

stylistically, do you prefer

;; 1
(thread-last (delete-and-extract-region (mark) (point))
             (string-replace ". " ".\n")
             (insert))
or
;; 2
(thread-last
  (delete-and-extract-region (mark) (point))
  (string-replace ". " ".\n")
  (insert))
in Emacs Lisp?

elken10:04:41

I always prefer flow (2) to hang (1) but I know it's a point of contention for some 😛 Pick whichever semantically fits

👍 2
😸 2
teodorlu14:04:19

Nice! Thanks for the reference. Interesting to hear that people were doing this in the 1930s! > We picked up this idea from the writing guide in the https://neo4j.com/docs/2.2.8/community-docs.html#_writing. However, it seems like the idea dates back a discovery by Buckminster Fuller in the 1930s, who called it https://vanemden.wordpress.com/2009/01/01/ventilated-prose/. The technique was also recommended in 2009 by Brandon Rhodes in a blog post about https://rhodesmill.org/brandon/2012/one-sentence-per-line/.

lread14:04:49

Interesting!

lread14:04:21

For AsciiDoc the strategy applies to writing, when rendered for reading, the sentences are joined into normal-looking paragraphs.

👍 2