(defun number-pgraphs (start end) ;; alias M-npg "insert paragraph-numbers of chapters at paragraphs' start in region. Blank lines have been guaranteed to consist of only a single C-j" (interactive "r") (let ((par-number 1)) (save-excursion (goto-char start) (while (< (point) end) (while (and (bolp) (eolp)) (forward-line)) ;; skip blank line(s) with only linefeed chars (if (= (following-char) ?*) ;; * character, start of new chapter - reset paragraph number (setq par-number 1) ;; Check if there is already a paragraph number, remove it first (if (looking-at "[0-9]+\. ") (replace-match "")) (insert (concat (number-to-string par-number) "." " ")) (setq par-number (1+ par-number))) (forward-line)))) ) ;; defun