Skip to content

Commit 16a889a

Browse files
dpsuttonbbatsov
authored andcommitted
[Fix clojure-emacs#489] Inserting parens before comment form doesn't move point (clojure-emacs#490)
In a form like ``` | (comment (stuff)) ``` Entering parens with paredit would put the parens right before the comment block. Paredit determines if it is in a comment to insert parens so it doesn't automatically enter a closing when in a comment or a string. Part of this called beginning-of-defun which we have modified. The error here was that rater than just going to the beginning of the form, we went to the end and then back one logical form to be at the beginning. This is identical behavior _unless_ you are between two forms. Going straight to the beginning put you in the first form, going to the end and then the beginning puts you in the second form. I.e., ``` (formA) | (formB) ``` Our beginning of form went to formB but it should go to formA.
1 parent 249af94 commit 16a889a

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
* [#481](https://github.com/clojure-emacs/clojure-mode/issues/481): Support vertical alignment even in the presence of blank lines, with the new `clojure-align-separator` user option.
88
* [#483](https://github.com/clojure-emacs/clojure-mode/issues/483): Support alignment for reader conditionals, with the new `clojure-align-reader-conditionals` user option.
99

10+
### Bugs fixed
11+
12+
* [#489](https://github.com/clojure-emacs/clojure-mode/issues/489) Inserting parens before comment form doesn't move point
13+
1014
## 5.9.1 (2018-08-27)
1115

1216
* [#485](https://github.com/clojure-emacs/clojure-mode/issues/485): Fix a regression in `end-f-defun`.

clojure-mode.el

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,8 +1977,7 @@ This will skip over sexps that don't represent objects, so that ^hints and
19771977
"Return truthy if the first form matches FIRST-FORM."
19781978
(condition-case nil
19791979
(save-excursion
1980-
(end-of-defun)
1981-
(clojure-backward-logical-sexp 1)
1980+
(beginning-of-defun)
19821981
(forward-char 1)
19831982
(clojure-forward-logical-sexp 1)
19841983
(clojure-backward-logical-sexp 1)
@@ -2032,10 +2031,11 @@ many times."
20322031
(save-match-data
20332032
(let ((original-position (point))
20342033
clojure-comment-start clojure-comment-end)
2034+
(beginning-of-defun)
2035+
(setq clojure-comment-start (point))
20352036
(end-of-defun)
20362037
(setq clojure-comment-end (point))
2037-
(clojure-backward-logical-sexp 1) ;; beginning of comment form
2038-
(setq clojure-comment-start (point))
2038+
(beginning-of-defun)
20392039
(forward-char 1) ;; skip paren so we start at comment
20402040
(clojure-forward-logical-sexp) ;; skip past the comment form itself
20412041
(if-let ((sexp-start (clojure-find-first (lambda (beg-pos)

test/clojure-mode-sexp-test.el

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,15 @@ and point left there."
6565
(wrong))"
6666
(let ((clojure-toplevel-inside-comment-form t))
6767
(beginning-of-defun))
68-
(should (looking-at-p "[[:space:]]*(right)"))))
68+
(should (looking-at-p "[[:space:]]*(right)")))
69+
(clojure-buffer-with-text
70+
"
71+
(formA)
72+
|
73+
(formB)"
74+
(let ((clojure-toplevel-inside-comment-form t))
75+
(beginning-of-defun)
76+
(should (looking-at-p "(formA)")))))
6977

7078
(ert-deftest test-clojure-end-of-defun-function ()
7179
(clojure-buffer-with-text

0 commit comments

Comments
 (0)