Skip to content

Commit 71b32ee

Browse files
dan suttonbbatsov
dan sutton
authored andcommitted
Handle unbalanced parens in custom beginning of defun fn
Paredit has some strange logic. It inserts its opening "(" and then tasks itself with discovering whether it is in a comment or string before inserting its closing ")". But this means that paredit _by design_ calls functions on unbalanced parens states and I don't know why they do this. If we find a scan-error, this bails and lets the default beginning of defun function shoulder that logic.
1 parent dd8a193 commit 71b32ee

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

clojure-mode.el

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,22 +2028,24 @@ many times."
20282028
(let ((beginning-of-defun-function nil))
20292029
(if (and clojure-toplevel-inside-comment-form
20302030
(clojure-top-level-form-p "comment"))
2031-
(save-match-data
2032-
(let ((original-position (point))
2033-
clojure-comment-start clojure-comment-end)
2034-
(beginning-of-defun)
2035-
(setq clojure-comment-start (point))
2036-
(end-of-defun)
2037-
(setq clojure-comment-end (point))
2038-
(beginning-of-defun)
2039-
(forward-char 1) ;; skip paren so we start at comment
2040-
(clojure-forward-logical-sexp) ;; skip past the comment form itself
2041-
(if-let ((sexp-start (clojure-find-first (lambda (beg-pos)
2042-
(< beg-pos original-position))
2043-
(clojure-sexp-starts-until-position
2044-
clojure-comment-end))))
2045-
(progn (goto-char sexp-start) t)
2046-
(beginning-of-defun n))))
2031+
(condition-case nil
2032+
(save-match-data
2033+
(let ((original-position (point))
2034+
clojure-comment-start clojure-comment-end)
2035+
(beginning-of-defun)
2036+
(setq clojure-comment-start (point))
2037+
(end-of-defun)
2038+
(setq clojure-comment-end (point))
2039+
(beginning-of-defun)
2040+
(forward-char 1) ;; skip paren so we start at comment
2041+
(clojure-forward-logical-sexp) ;; skip past the comment form itself
2042+
(if-let ((sexp-start (clojure-find-first (lambda (beg-pos)
2043+
(< beg-pos original-position))
2044+
(clojure-sexp-starts-until-position
2045+
clojure-comment-end))))
2046+
(progn (goto-char sexp-start) t)
2047+
(beginning-of-defun n))))
2048+
(scan-error (beginning-of-defun n)))
20472049
(beginning-of-defun n))))
20482050

20492051
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

0 commit comments

Comments
 (0)