Fork me on GitHub
#cider
<
2021-03-05
>
william18:03:12

I'm debugging an issue with clojure indentation in emacs, and I'd like some pointers to continue the debugging. I found, using edebug, that my error

clojure-indent-function: Wrong type argument: number-or-marker-p, nil
comes from trying to do:
((= pos (1+ method))
where method comes from:
(let ((method (clojure--find-indent-spec))
Now, the question: I enabled edebug also for clojure--find-indent-spec, but the debugger doesn't step in that automatically! Why?

william18:03:43

I'd like another pair of eyes to see how method can become nil in this code, from clojure-mode:

william18:03:38

(defun clojure-indent-function (indent-point state)

  ;; Goto to the open-paren.
  (goto-char (elt state 1))
  ;; Maps, sets, vectors and reader conditionals.
  (if (clojure--not-function-form-p)
      (1+ (current-column))
    ;; Function or macro call.
    (forward-char 1)
    (let ((method (clojure--find-indent-spec))
          (last-sexp calculate-lisp-indent-last-sexp)
          (containing-form-column (1- (current-column))))
      (pcase method
        ((or (pred integerp) `(,method))
         (let ((pos -1))
           (condition-case nil
               (while (and (<= (point) indent-point)
                           (not (eobp)))
                 (clojure-forward-logical-sexp 1)
                 (cl-incf pos))
             ;; If indent-point is _after_ the last sexp in the
             ;; current sexp, we detect that by catching the
             ;; `scan-error'. In that case, we should return the
             ;; indentation as if there were an extra sexp at point.
             (scan-error (cl-incf pos)))
           (cond
            ;; The first non-special arg. Rigidly reduce indentation.
            ((= pos (1+ method))
             (+ lisp-body-indent containing-form-column))

william18:03:47

basically, in the last but one line, I have (= pos (1+ method)) and method is nil there, but it wasn't nil in the let block in which it has been defined, and I'm not sure where else it could have changed!

dpsutton19:03:20

i don't have time to look at it atm. and these kinds of things just require stepping through. I doubt anyone has context on this low level stuff except at the time they've worked on it. its quite possible you know the most about it at the current time

dpsutton19:03:46

but if you open an issue on clojure-mode it might get some eyes on it. and be a place for discussion that won't go away when the slack scroll limit is hit

🙌 1
william19:03:37

thanks, yes, I'll probably do that. I stepped through that, hence my disbelief, since the only place in which it could have changed is:

(pcase method
        ((or (pred integerp) `(,method))
and I don't think that modifies method. Anyway, yes, I'll head for github

dpsutton19:03:54

oof. sucks when its a language control flow issue you end up diagnosing

william20:03:31

so, there was a PR here https://github.com/clojure-emacs/clojure-mode/pull/585/files following that discussion, but I tried to modify that locally, and the problem persists

william20:03:30

it doesn't help that I don't understand why pcase (which is pattern matching) should ever overwrite the variable it's matching on. I'm trying to understand the semantics of pcase now that we restricted the problem

william20:03:55

pinging @manuel since he knows more

william20:03:16

ah, no, my bad, it's not literally the same problem 👼

william20:03:48

problem solved 🙂