help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: help with what should have been a very simple defun


From: Emanuel Berg
Subject: Re: help with what should have been a very simple defun
Date: Sat, 22 Jan 2022 14:39:47 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Pieter van Oostrum wrote:

>> (defun number-pgraphs (start end) ;; alias M-npg
>> "insert paragraph-numbers of chapters at paragraphs'

Well ... there is an obvious problem with this that you should
be aware of, and it is that it changes the material
it analyzes ...

That makes for difficult implementation.

But worse, often the idea itself isn't good, either - better
keep them apart ...

What about a "flash mode", when you fire it off it shows the
digits for x seconds and then the data shows as it was before.
Because it never changed, and only what was displayed to the
user did!

It's the "MVC". Or as I like to think about it, just keep
everything apart that don't belong naturally, like vodka and
cranberry, perhaps.

> (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

You can clean that up a lot ...

Byte-compile and do (checkdoc-current-buffer t) ...

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]