A rather naive solution - there should be no leading numbers of a paragraph with a different --textual-- meaning:
Edited after request: When starting from an already numbered paragraph, take that value counting on.
(defun number-paragraphs (&optional takefirst)
"Numbers resp. renumber paragraphs.
If starting from already numbered, take that value as offset "
(interactive "*P")
(let ((counter 0)
(last 0))
(when (looking-at "\\([0-9]+\\)\. ")
(setq counter (car (read-from-string (match-string-no-properties 1))))
(forward-paragraph))
(while (and (forward-paragraph) (< last (point)))
(setq last (copy-marker (point)))
(backward-paragraph)
(skip-chars-forward " \t\r\n\f")
(when (looking-at "[0-9]+\. ")
(delete-region (match-beginning 0) (match-end 0)))
(insert (format "%s. " (1+ counter)))
(setq counter (1+ counter))
(goto-char last))))
(ert-deftest number-paragraph-test-OFHIl1 ()
(with-temp-buffer
(switch-to-buffer (current-buffer))
(insert "Emacs is the extensible, customizable, self-documenting real-time
display editor. This manual describes how to edit with Emacs and some
of the ways to customize it; it corresponds to GNU Emacs version 26.2.
If you are reading this in Emacs, type ‘h’ to read a basic
introduction to the Info documentation system.
For information on extending Emacs, see *note Emacs Lisp: (elisp)Top.
This is the ‘GNU Emacs Manual’, updated for Emacs version 26.2.
")
(goto-char (point-min))
(number-paragraphs)
(goto-char (point-min))
(should (looking-at "1. Emacs"))
(forward-paragraph)
(skip-chars-forward " \t\r\n\f")
(should (looking-at "2. If"))))
(ert-deftest number-paragraph-section-test-OFHIl1 ()
(with-temp-buffer
(switch-to-buffer (current-buffer))
(insert "Emacs is the extensible, customizable, self-documenting real-time
display editor. This manual describes how to edit with Emacs and some
of the ways to customize it; it corresponds to GNU Emacs version 26.2.
2. If you are reading this in Emacs, type ‘h’ to read a basic
introduction to the Info documentation system.
5. For information on extending Emacs, see *note Emacs Lisp: (elisp)Top.
6. This is the ‘GNU Emacs Manual’, updated for Emacs version 26.2.
")
(goto-char (point-min))
(search-forward "If")
(narrow-to-region (line-beginning-position) (point-max))
(back-to-indentation)
(number-paragraphs)
(widen)
(goto-char (point-min))
(search-forward "For")
(beginning-of-line)
(should (looking-at " +3. For"))
(search-forward "This")
(beginning-of-line)
(should (looking-at " +4. This"))))
M-x print-buffer
. But what I meant was it would be great if the numbers are part of the document text. I am not able to edit the earlier comment, unfortunately. – deshmukh Jul 15 '19 at 12:54