emacs-devel
[Top][All Lists]
Advanced

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

Re: master 78fc49407b8 1/3: Improve filling of ChangeLog entries


From: João Távora
Subject: Re: master 78fc49407b8 1/3: Improve filling of ChangeLog entries
Date: Wed, 31 Jan 2024 16:46:42 +0000

On Wed, Jan 31, 2024 at 3:32 PM Alan Mackenzie <acm@muc.de> wrote:

> > Was there a way to write it more succinctly, using some higher-level
> > constructs? That is the subject.

Dmitry, sometimes you don't even need higher-level constructs.  You just
need not to freak out over cl-loop, breathe slowly, and expand it
to see what you get.

> I think the discussion is over the advantages and disadvantages of
> replacing obscure concise code with its equivalent in plain Lisp.

Alan, here's a version of log-edit--insert-filled-defuns derived from the one
we had a few days ago, and which really didn't have "countless bugs".
All "plain elisp" as far as I can tell.  Spans one fourth of Po's.  I got
it by simply cleaning up the macroexpansion.

(defun log-edit--insert-filled-defuns (func-names)
  "Insert FUNC-NAMES, following ChangeLog formatting."
  (if (not func-names)
      (insert ":")
    (unless (or (memq (char-before) '(?\n ?\s))
                (> (current-column) fill-column))
      (insert " "))
    (let* ((first-fun t) (def nil))
      (while (consp func-names)
        (setq def (pop func-names))
        (when (>
               (+ (current-column) (string-width def) (if first-fun 1 2)
                  (if (null func-names) 1 0))
               fill-column)
          (unless first-fun (insert ")"))
          (unless (eq (char-before) ?\n) (insert "\n"))
          (setq first-fun t))
        (insert (if first-fun "(" ", ") def)
        (setq first-fun nil)))
    (insert "):")))

Even if in Po's version the comments are not counted, this version is
still less than half the length, less variables, less 'if', no
'delete-char', no 'format', doesn't 'cons', and much more
closely resembles the original, passing all of Po's tests.  Probably
could use a comment to explain the line measuring arithmetic, or
made even simpler if one really wanted to, but I think it's just
short enough to be fine.

Uses 'pop' and 'unless'.  Dunno if that is "plain elisp" to you.
I've never seen that defined anywhere, don't know why you
get to say what it is, or why it's even a useful working concept.

For the other rewritten function it's much of the same
I've already shown how a one-line change would have fixed its bug
(taking for granted that is was even a bug):

-                  (beg (progn (goto-char beg) (line-beginning-position))))
+                  (beg (progn (goto-char beg) (skip-chars-backward "^
\n") (point))))



reply via email to

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