(while (> n 0) (unless (re-search-forward "\\(\\=\\|[^\\\\]\\)\\(\\\\\\\\\\)*\\([{}]\\)" nil t) (debug)) (message "N0.3") (if (string= (match-string 3) "{") (setq i (1+ i)) (message "N0.4") (setq i (1- i)) (message "N0.5 %s" i) (when (<= i 0) (message "N0.5.1") (setq n (1- n)) (message "N0.2")))) (message "N0.6") (message "N1.1") (setq result (buffer-substring-no-properties point (point))) gives N0.3 N0.4 N0.5 1 Not enough arguments for format string