0

Every time, I press 'Enter' in org docs it prompts

Debugger entered--Lisp error: (wrong-type-argument wholenump -47)
  make-list(-47 nil)
  lisp-indent-initial-state()
  indent-sexp()
  paredit-newline()
  funcall-interactively(paredit-newline)
  call-interactively(paredit-newline nil nil)
  command-execute(paredit-newline)

google search returns few answer to the debugger error.

What's the problem?

  • 1
    Might it be that you have lisp or emacs-lisp code blocks in your org file? The lisp parser causes the problems in connection with paredit. If you switch paredit off the problem should be gone. – Tobias Jun 26 at 7:41
  • inform us about emacs-version, org-version, and the version of paredit. Can you reproduce the problem with emacs -Q after M-x package-initialize <RET>? – Tobias Jun 26 at 7:48
  • 1
    This might be Bug#35286 or Bug#30891 – npostavs Jun 26 at 12:27
  • org-version 9.1.9 emacs-version 26.1. cannot reproduce the problem with emacs -Q @Tobias – Algebra Jun 27 at 1:03
  • 1
    @Tobias I don't really see the point in copying your answer; you've already credited me in the text, and my name is on the patches in the Emacs git repo. Digesting the bug report patch into an easy-to-use init file snippet is what you get credit for, which seems fine to me. – npostavs Jun 27 at 11:35
1

Npostavs referenced Bug#35286 and Bug#30891 in his comment.

Note: I do not want to take credit for Noam Postavky's findings. The hard task is to find the bug. I just "copied" his patch here. So, please try the proposed bugfix.

You told us that your emacs-version is 26.1. That leaves us only with Bug#30891.

There are two indicators that your problem is Bug#30891:

  • The problem deals with negative depths.
  • The problem is found in Emacs 26.1 and fixed in Emacs 26.2.

This problem should be fixed with the following code in your init file:

(defun lisp-indent-calc-next-patch (state)
  "Move to next line and return calculated indent for it.
STATE is updated by side effect, the first state should be
created by `lisp-indent-initial-state'.  This function may move
by more than one line to cross a string literal."
  (pcase-let* (((cl-struct lisp-indent-state
                           (stack indent-stack) ppss ppss-point)
                state)
               (indent-depth (car ppss)) ; Corresponding to indent-stack.
               (depth indent-depth))
    ;; Parse this line so we can learn the state to indent the
    ;; next line.
    (while (let ((last-sexp (nth 2 ppss)))
             (setq ppss (parse-partial-sexp
                         ppss-point (progn (end-of-line) (point))
                         nil nil ppss))
             ;; Preserve last sexp of state (position 2) for
             ;; `calculate-lisp-indent', if we're at the same depth.
             (if (and (not (nth 2 ppss)) (= depth (car ppss)))
                 (setf (nth 2 ppss) last-sexp)
               (setq last-sexp (nth 2 ppss)))
             (setq depth (car ppss))
             ;; Skip over newlines within strings.
             (nth 3 ppss))
      (let ((string-start (nth 8 ppss)))
        (setq ppss (parse-partial-sexp (point) (point-max)
                                       nil nil ppss 'syntax-table))
        (setf (nth 2 ppss) string-start) ; Finished a complete string.
        (setq depth (car ppss)))
      (setq ppss-point (point)))
    (setq ppss-point (point))
    (let* ((depth-delta (- depth indent-depth)))
      (cond ((< depth-delta 0)
             (setq indent-stack (nthcdr (- depth-delta) indent-stack)))
            ((> depth-delta 0)
             (setq indent-stack (nconc (make-list depth-delta nil)
                                       indent-stack)))))
    (prog1
        (let (indent)
          (cond ((= (forward-line 1) 1) nil)
                ;; Negative depth, probably some kind of syntax error.
                ((null indent-stack)
                 ;; Reset state.
                 (setq ppss (parse-partial-sexp (point) (point))))
                ((car indent-stack))
                ((integerp (setq indent (calculate-lisp-indent ppss)))
                 (setf (car indent-stack) indent))
                ((consp indent)       ; (COLUMN CONTAINING-SEXP-START)
                 (car indent))
                ;; This only happens if we're in a string.
                (t (error "This shouldn't happen"))))
      (setf (lisp-indent-state-stack state) indent-stack)
      (setf (lisp-indent-state-ppss-point state) ppss-point)
      (setf (lisp-indent-state-ppss state) ppss))))

(with-eval-after-load 'lisp-mode
  (if (version<= "26.2" emacs-version)
      (warn "If you exclusively use Emacs >= 26.2 you can remove `lisp-indent-calc-next-patch'")
    (advice-add 'lisp-indent-calc-next :override #'lisp-indent-calc-next-patch)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.