I would like to write a function that counts the number of nested parentheses while moving the cursor to the innermost bracket without throwing an error.
(defun count-and-move () (interactive) (setq c 0) (while t (down-list) (incf c)))
If we run this code, the cursor would eventually reach the innermost bracket.
|「「「「」」」」 --> 「「「「|」」」」
After which it throws an error:
down-list: Scan error: "Containing expression ends prematurely", 254, 255
What should the condition for
while be so that the movement stops automatically when the cursor has reached the innermost point?
In human language, it would be something like:
(down-list) and increase counter by 1 until the cursor is stuck." OR
"Break out of loop if
(down-list) is going to throw an error!"