all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: help with what should have been a very simple defun
Date: Sat, 22 Jan 2022 14:39:47 +0100	[thread overview]
Message-ID: <878rv7q47w.fsf@zoho.eu> (raw)
In-Reply-To: m24k5w3p8h.fsf@vanoostrum.org

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	other threads:[~2022-01-22 13:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <e941a882-e952-432a-852b-63fd368b23c4n@googlegroups.com>
2022-01-22 12:54 ` help with what should have been a very simple defun Pieter van Oostrum
2022-01-22 13:39   ` Emanuel Berg via Users list for the GNU Emacs text editor [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878rv7q47w.fsf@zoho.eu \
    --to=help-gnu-emacs@gnu.org \
    --cc=moasenwood@zoho.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.