Re: small indentation inside with-html from spinneret (Common Lisp)

Michael Heerdegen via Users list for the GNU Emacs text editor <[email protected]> Fri, 19 Jun 2026 04:16:49 +0200
Newsgroups gmane.emacs.help
Message-ID <[email protected]>
Peter Münster <[email protected]> writes:

> > #+begin_src emacs-lisp
> > (advice-add
> >  'common-lisp-indent-function :after-until
> >  (defun my-common-lisp-indent-function--offset-fallback (indent-point state)
> >    (save-excursion
> >      (goto-char (elt state 1))
> >      (+ (current-column) 2))))
> > #+end_src
> >
> > This would change the algorithm to always do what you want for
> > `with-clog-create'.
>
> Ok, unfortunately it seems, that it’s not really *always*:
> [...]
>
> (defun my-func ()
>   (with-clog-create body
>     (okokok ()
>             (NOT-OK ()
>               (okokok ()
>                 (okokok ()))))))

Hmm, correct:

| (throw 'exit (if (and (= n 0) (null p)) (+ sexp-column lisp-body-indent) normal-indent))
| (cond ((and tail (not (or (consp tem) (symbolp tem)))) (throw 'exit normal-indent)) ((eq tem '&body) (throw 'exit (if (and (= n 0) (null p)) (+ sexp-column lisp-body-indent) normal-indent))) ((eq tem '&rest) (progn (setq tail (> n 0)) (setq n 0) (setq method (cdr method)))) ((> n 0) (progn (setq n (1- n)) (setq method (cdr method))) (if (< n 0) (throw 'exit normal-indent))) ((eq tem 'nil) (throw 'exit (if (consp normal-indent) normal-indent (list normal-indent containing-form-start)))) ((eq tem '&lambda) (throw 'exit (cond ((null p) (list (+ sexp-column 4) containing-form-start)) ((null (cdr p)) (list (lisp-indent-lambda-list indent-point sexp-column containing-form-start) containing-form-start)) (t normal-indent)))) ((integerp tem) (throw 'exit (if (null p) (list (+ sexp-column tem) containing-form-start) normal-indent))) ((symbolp tem) (throw 'exit (funcall tem path state indent-point sexp-column normal-indent))) (t (if (not (null p)) (progn (setq method (cdr (cdr tem))) (setq n nil)) (setq tem (car (cdr tem))) (throw 'exit (cond (tail normal-indent) ((eq tem 'nil) (list normal-indent containing-form-start)) ((integerp tem) (list (+ sexp-column tem) containing-form-start)) (t (funcall tem path state indent-point sexp-column normal-indent)))))))
| (while n (setq tem (car method)) (or (eq tem 'nil) (eq tem '&lambda) (and (eq tem '&body) (null (cdr method))) (and (eq tem '&rest) (consp (cdr method)) (null (cdr (cdr method)))) (integerp tem) (and (consp tem) (eq (car tem) '&whole) (or (symbolp (car (cdr tem))) (integerp (car (cdr tem))))) (and (symbolp tem) (null (cdr method))) (lisp-indent-report-bad-format method)) (cond ((and tail (not (or (consp tem) (symbolp tem)))) (throw 'exit normal-indent)) ((eq tem '&body) (throw 'exit (if (and (= n 0) (null p)) (+ sexp-column lisp-body-indent) normal-indent))) ((eq tem '&rest) (progn (setq tail (> n 0)) (setq n 0) (setq method (cdr method)))) ((> n 0) (progn (setq n (1- n)) (setq method (cdr method))) (if (< n 0) (throw 'exit normal-indent))) ((eq tem 'nil) (throw 'exit (if (consp normal-indent) normal-indent (list normal-indent containing-form-start)))) ((eq tem '&lambda) (throw 'exit (cond ((null p) (list (+ sexp-column 4) containing-form-start)) ((null (cdr p)) (list (lisp-indent-lambda-list indent-point sexp-column containing-form-start) containing-form-start)) (t normal-indent)))) ((integerp tem) (throw 'exit (if (null p) (list (+ sexp-column tem) containing-form-start) normal-indent))) ((symbolp tem) (throw 'exit (funcall tem path state indent-point sexp-column normal-indent))) (t (if (not (null p)) (progn (setq method (cdr (cdr tem))) (setq n nil)) (setq tem (car (cdr tem))) (throw 'exit (cond (tail normal-indent) ((eq tem ...) (list normal-indent containing-form-start)) ((integerp tem) (list ... containing-form-start)) (t (funcall tem path state indent-point sexp-column normal-indent))))))))
| (while p (if (not (consp method)) (lisp-indent-report-bad-format method)) (progn (setq n (1- (car p))) (setq p (cdr p)) (setq tail nil)) (while n (setq tem (car method)) (or (eq tem 'nil) (eq tem '&lambda) (and (eq tem '&body) (null (cdr method))) (and (eq tem '&rest) (consp (cdr method)) (null (cdr (cdr method)))) (integerp tem) (and (consp tem) (eq (car tem) '&whole) (or (symbolp (car (cdr tem))) (integerp (car (cdr tem))))) (and (symbolp tem) (null (cdr method))) (lisp-indent-report-bad-format method)) (cond ((and tail (not (or (consp tem) (symbolp tem)))) (throw 'exit normal-indent)) ((eq tem '&body) (throw 'exit (if (and (= n 0) (null p)) (+ sexp-column lisp-body-indent) normal-indent))) ((eq tem '&rest) (progn (setq tail (> n 0)) (setq n 0) (setq method (cdr method)))) ((> n 0) (progn (setq n (1- n)) (setq method (cdr method))) (if (< n 0) (throw 'exit normal-indent))) ((eq tem 'nil) (throw 'exit (if (consp normal-indent) normal-indent (list normal-indent containing-form-start)))) ((eq tem '&lambda) (throw 'exit (cond ((null p) (list ... containing-form-start)) ((null ...) (list ... containing-form-start)) (t normal-indent)))) ((integerp tem) (throw 'exit (if (null p) (list (+ sexp-column tem) containing-form-start) normal-indent))) ((symbolp tem) (throw 'exit (funcall tem path state indent-point sexp-column normal-indent))) (t (if (not (null p)) (progn (setq method (cdr ...)) (setq n nil)) (setq tem (car (cdr tem))) (throw 'exit (cond (tail normal-indent) (... ...) (... ...) (t ...))))))))
| (let ((p path) (containing-form-start (elt state 1)) n tem tail) (while p (if (not (consp method)) (lisp-indent-report-bad-format method)) (progn (setq n (1- (car p))) (setq p (cdr p)) (setq tail nil)) (while n (setq tem (car method)) (or (eq tem 'nil) (eq tem '&lambda) (and (eq tem '&body) (null (cdr method))) (and (eq tem '&rest) (consp (cdr method)) (null (cdr (cdr method)))) (integerp tem) (and (consp tem) (eq (car tem) '&whole) (or (symbolp (car ...)) (integerp (car ...)))) (and (symbolp tem) (null (cdr method))) (lisp-indent-report-bad-format method)) (cond ((and tail (not (or ... ...))) (throw 'exit normal-indent)) ((eq tem '&body) (throw 'exit (if (and ... ...) (+ sexp-column lisp-body-indent) normal-indent))) ((eq tem '&rest) (progn (setq tail (> n 0)) (setq n 0) (setq method (cdr method)))) ((> n 0) (progn (setq n (1- n)) (setq method (cdr method))) (if (< n 0) (throw 'exit normal-indent))) ((eq tem 'nil) (throw 'exit (if (consp normal-indent) normal-indent (list normal-indent containing-form-start)))) ((eq tem '&lambda) (throw 'exit (cond (... ...) (... ...) (t normal-indent)))) ((integerp tem) (throw 'exit (if (null p) (list ... containing-form-start) normal-indent))) ((symbolp tem) (throw 'exit (funcall tem path state indent-point sexp-column normal-indent))) (t (if (not (null p)) (progn (setq method ...) (setq n nil)) (setq tem (car ...)) (throw 'exit (cond ... ... ... ...))))))))
| (catch 'exit (let ((p path) (containing-form-start (elt state 1)) n tem tail) (while p (if (not (consp method)) (lisp-indent-report-bad-format method)) (progn (setq n (1- (car p))) (setq p (cdr p)) (setq tail nil)) (while n (setq tem (car method)) (or (eq tem 'nil) (eq tem '&lambda) (and (eq tem '&body) (null (cdr method))) (and (eq tem '&rest) (consp (cdr method)) (null (cdr ...))) (integerp tem) (and (consp tem) (eq (car tem) '&whole) (or (symbolp ...) (integerp ...))) (and (symbolp tem) (null (cdr method))) (lisp-indent-report-bad-format method)) (cond ((and tail (not ...)) (throw 'exit normal-indent)) ((eq tem '&body) (throw 'exit (if ... ... normal-indent))) ((eq tem '&rest) (progn (setq tail ...) (setq n 0) (setq method ...))) ((> n 0) (progn (setq n ...) (setq method ...)) (if (< n 0) (throw ... normal-indent))) ((eq tem 'nil) (throw 'exit (if ... normal-indent ...))) ((eq tem '&lambda) (throw 'exit (cond ... ... ...))) ((integerp tem) (throw 'exit (if ... ... normal-indent))) ((symbolp tem) (throw 'exit (funcall tem path state indent-point sexp-column normal-indent))) (t (if (not ...) (progn ... ...) (setq tem ...) (throw ... ...))))))))
| (lisp-indent-259 (4 &lambda &body) (3 2 2) (3 251 259 nil nil nil 0 nil nil (204 224 251) nil) 262 4 12)
| [...]
| (common-lisp-indent-call-method "defun" (4 &lambda &body) (3 2 2) (3 251 259 nil nil nil 0 nil nil (204 224 251) nil) 262 4 12)
| (setq calculated (common-lisp-indent-call-method function method path state indent-point sexp-column normal-indent))
| [...]
| (common-lisp-indent-function-1 262 (3 251 259 nil nil nil 0 nil nil (204 224 251) nil))
| [...]
| (common-lisp-indent-function 262 (3 251 259 nil nil nil 0 nil nil (204 224 251) nil))
| (calculate-lisp-indent (3 251 259 nil nil nil 0 nil nil (204 224 251) nil))
| (lisp-indent-line)
| (indent--funcall-widened lisp-indent-line)
| (indent-for-tab-command nil)

In this case there is no fallback, instead, what we see here is the
behavior of "&body" (associated with `defun') which is used at this
point.  Yes, it's a bit weird (more than a bit) because the
`with-clog-create' call is two levels above, and the `defun' three.  But
this is how it works, and the behavior is even hardcoded.

I see three solutions: (1) lower `lisp-indent-maximum-backtracking' to 2
(if you don't need the 3 levels anywhere) or (2) we could try to
install another advice on `common-lisp-indent-call-method', overwriting
the NORMAL-INDENT argument, and hope that this gives always good
results (I can't guarantee that).  Or (3) you try tpeplt's solution.

"I can't guarantee" means it could work perfectly, but it could also be
that we waste some more time and still don't get it work.


Michael.