Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve support for multiple forms in single lines by replacing beginning-of-defun fn #663

Merged
merged 3 commits into from
Sep 6, 2023

Conversation

p4v4n
Copy link
Contributor

@p4v4n p4v4n commented Sep 5, 2023

This change will improve overall support when multiple forms are present on the same line.

  • beginning-of-defun by default moves the cursor to the beginning of line instead of stopping at the opening paren. This can lead to many edge cases when multiple forms are present in the same line.
  • To control this behaviour and stop the cursor at opening paren we need use beginning-of-defun-function and beginning-of-defun-raw together.

This change replaces all calls to beginning-of-defun with beginning-of-defun-raw.
(beginning-of-defun-raw calls beginning-of-defun-function internally which in our case is clojure-beginning-of-defun-function)

To see the improvement I have tried M-x cider-eval-defun-at-point(C-c C-c) inside (+ 1 2) in the below example.

(defn f1 [x] (inc x)) (+ 1 2)

(defn f2 [x] (str x))

Before the change the output is #'user/f2. After this change it correctly evaluates to 3.

@p4v4n p4v4n mentioned this pull request Sep 5, 2023
@bbatsov
Copy link
Member

bbatsov commented Sep 5, 2023

The proposed change looks good to me. Let's just add a couple of unit tests and a changelog entry before we merge it.

@bbatsov bbatsov merged commit a6a688d into clojure-emacs:master Sep 6, 2023
@p4v4n p4v4n deleted the replace-beginning-of-defun-fn branch September 6, 2023 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants