Skip to content

Commit e744f43

Browse files
dan suttonbbatsov
dan sutton
authored andcommitted
Fix bug in end-of-defun
Going to end of defun would skip over two forms. Needed to pass on the negative prefix that was used by the generic parts of this mechanism. Also fixed an issue with paredit would not insert parens in an empty buffer by handling the `end-of-buffer` condition.
1 parent e6bd584 commit e744f43

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

clojure-mode.el

+7-5
Original file line numberDiff line numberDiff line change
@@ -1955,7 +1955,8 @@ This will skip over sexps that don't represent objects, so that ^hints and
19551955
(clojure-forward-logical-sexp 1)
19561956
(clojure-backward-logical-sexp 1)
19571957
(looking-at-p first-form))
1958-
(scan-error nil)))
1958+
(scan-error nil)
1959+
(end-of-buffer nil)))
19591960

19601961
(defun clojure-sexp-starts-until-position (position)
19611962
"Return the starting points for forms before POSITION.
@@ -1992,10 +1993,11 @@ testing, give an easy way to turn this new behavior off."
19921993
(setq haystack (cdr haystack))))
19931994
found))
19941995

1995-
(defun clojure-beginning-of-defun-function ()
1996+
(defun clojure-beginning-of-defun-function (&optional n)
19961997
"Go to top level form.
19971998
Set as `beginning-of-defun-function' so that these generic
1998-
operators can be used."
1999+
operators can be used. Given a positive N it will do it that
2000+
many times."
19992001
(let ((beginning-of-defun-function nil))
20002002
(if (and clojure-toplevel-inside-comment-form
20012003
(clojure-top-level-form-p "comment"))
@@ -2013,8 +2015,8 @@ operators can be used."
20132015
(clojure-sexp-starts-until-position
20142016
clojure-comment-end))))
20152017
(progn (goto-char sexp-start) t)
2016-
(progn (beginning-of-defun) t))))
2017-
(progn (beginning-of-defun) t))))
2018+
(beginning-of-defun n))))
2019+
(beginning-of-defun n))))
20182020

20192021
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
20202022
;;

test/clojure-mode-sexp-test.el

+15-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,21 @@ and point left there."
6565
(wrong))"
6666
(let ((clojure-toplevel-inside-comment-form t))
6767
(beginning-of-defun))
68-
(should (looking-at-p "(right)"))))
68+
(should (looking-at-p "[[:space:]]*(right)"))))
69+
70+
(ert-deftest test-clojure-end-of-defun-function ()
71+
(clojure-buffer-with-text
72+
"
73+
(first form)
74+
|
75+
(second form)
76+
77+
(third form)"
78+
79+
(end-of-defun)
80+
(backward-char)
81+
(should (looking-back "(second form)"))))
82+
6983

7084
(ert-deftest test-sexp-with-commas ()
7185
(with-temp-buffer

0 commit comments

Comments
 (0)