Skip to content

Handle newlines between forms for inf-clojure-eval-buffer #188

New issue

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

By clicking “No 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? No Sign in to your account

Merged
merged 2 commits into from
Mar 17, 2021

Conversation

dpsutton
Copy link
Contributor

This sends the contents of the buffer. However, newlines cause the
prompt to be returned. You can see this with even a regular clojure
repl:

❯❯❯ clojure
Clojure 1.10.2
user=>
user=>
user=>

(note using clj has rlwrap which hides a bit of this so make sure to
use clojure).

But what we can do is make sure to transform

(defn foo [] ...)

(defn bar [] ...)

into

(defn foo [] ...)
(defn bar [] ...)

So that the newlines don't trigger more repl prompts. Real world usage below:

Before:

parse=>
nil
parse=> parse=> nil
parse=> parse=> #'parse/data
parse=> parse=> #'parse/parse-where
parse=> parse=> #'parse/keywords
parse=> parse=> #'parse/tokenize
parse=>
parse=> #'parse/parse
parse=> parse=> #'parse/translate-where
parse=> parse=> nil
parse=> parse=> #'parse/query
parse=> parse=> #'parse/query-test
parse=> parse=> #'parse/bonus-points-test
parse=>

After:

user=>
nil
parse=> nil
parse=> #'parse/data
parse=> #'parse/parse-where
parse=> #'parse/keywords
parse=>
parse=> #'parse/parse
parse=> #'parse/translate-where
parse=> nil
parse=> #'parse/query
parse=> #'parse/query-test
parse=> #'parse/bonus-points-test
parse=>

inf-clojure.el Outdated
;; newlines over a socket repl between top level forms cause
;; a prompt to be returned. so here we dump the region into a
;; temp buffer, and delete all newlines between the forms
(formatted (condition-case nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's seems a bit too complicated to me. Can't we just use the built-in delete-blank-lines or something like this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I see you tried to kill the blank lines only between top-level forms. That seems reasonable, but we should probably move this to some helper function, so it's clearer what it does (and we can add a test or two about it).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do tonight thanks!

@dpsutton
Copy link
Contributor Author

@bbatsov the change is pretty big but look at the last commit. There were a bunch of poorly formatted tests so i just knocked those out.

This sends the contents of the buffer. However, newlines cause the
prompt to be returned. You can see this with even a regular clojure
repl:
```bash
❯❯❯ clojure
Clojure 1.10.2
user=>
user=>
user=>
```
(note using `clj` has rlwrap which hides a bit of this so make sure to
use `clojure`).

But what we can do is make sure to transform
```clojure
(defn foo [] ...)

(defn bar [] ...)
```

into

```clojure
(defn foo [] ...)
(defn bar [] ...)
```

So that the newlines don't trigger more repl prompts. Real world usage below:

Before:
```clojure
parse=>
nil
parse=> parse=> nil
parse=> parse=> #'parse/data
parse=> parse=> #'parse/parse-where
parse=> parse=> #'parse/keywords
parse=> parse=> #'parse/tokenize
parse=>
parse=> #'parse/parse
parse=> parse=> #'parse/translate-where
parse=> parse=> nil
parse=> parse=> #'parse/query
parse=> parse=> #'parse/query-test
parse=> parse=> #'parse/bonus-points-test
parse=>
```

After:
```clojure
user=>
nil
parse=> nil
parse=> #'parse/data
parse=> #'parse/parse-where
parse=> #'parse/keywords
parse=>
parse=> #'parse/parse
parse=> #'parse/translate-where
parse=> nil
parse=> #'parse/query
parse=> #'parse/query-test
parse=> #'parse/bonus-points-test
parse=>
```
@bbatsov bbatsov merged commit 675e9be into clojure-emacs:master Mar 17, 2021
@bbatsov
Copy link
Member

bbatsov commented Mar 17, 2021

Looks good. Thanks!

No Sign up for free to join this conversation on GitHub. Already have an account? No Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants