xah emacs lisp live coding 2020-06-10. join lines in a text block

xah emacs lisp live coding 2020-06-10. join lines in a text block
(defun my-join-lines-region ()
  "transform the text block, by joining lines
that do not contain colon to the previous line.

For example:

- Sponsor Org:    ACEE
- Department of Engineering
- Initial Amendment Date:    2010-06-10
- Latest Amendment Date:    2012-04-10
- ID Number:    2298908007
- Grant Type:    Cooperative Agreement
- Top Manager:    Paul Nathen Moore
- ACEE Department of Engineering
- ENG Director Of Science
- Start Date:    2011-06-01
- End Date:    2021-12-10 (Estimated)

becomes

- Sponsor Org:    ACEE, Department of Engineering
- Initial Amendment Date:    2010-06-10
- Latest Amendment Date:    2012-04-10
- ID Number:    2298908007
- Grant Type:    Cooperative Agreement
- Top Manager:    Paul Nathen Moore , ACEE Department of Engineering , ENG Director Of Science
- Start Date:    2011-06-01
- End Date:    2021-12-10 (Estimated)

Version: 2020-06-10"
  (interactive)
  (let (begin end)
    (save-excursion
      (if (re-search-backward "\n[ \t]*\n" nil "move")
          (progn (re-search-forward "\n[ \t]*\n")
                 (setq begin (point)))
        (setq begin (point)))
      (if (re-search-forward "\n[ \t]*\n" nil "move")
          (progn (re-search-backward "\n[ \t]*\n")
                 (setq end (point)))
        (setq end (point))))
    (save-excursion
      (save-restriction
        (narrow-to-region begin end)
        (goto-char (point-max))
        (insert "\n")
        (goto-char (point-min))
        (while (< (point) (point-max))
          (if (search-forward ":" (line-end-position) t )
              (progn
                (beginning-of-line)
                (forward-line 1))
            (progn
              (beginning-of-line)
              (delete-char -1)
              (delete-char 1)
              (insert ",")
              (end-of-line )
              (forward-char 1)))))))
  ;;
  )

If you have a question, put $5 at patreon and message me.