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

Calculate indentation when user presses Enter #14

Open
oakmac opened this issue Nov 9, 2015 · 11 comments
Open

Calculate indentation when user presses Enter #14

oakmac opened this issue Nov 9, 2015 · 11 comments
Assignees

Comments

@oakmac
Copy link
Owner

oakmac commented Nov 9, 2015

We should probably calculate where to put the cursor when the user presses Enter. The cursor should be right at the current indentation threshold.

I'm not sure if Atom is doing this correctly by itself.

@oakmac oakmac self-assigned this Nov 9, 2015
@oakmac oakmac changed the title must calculate indentation when user presses "enter" Calculate indentation when user presses "enter" Nov 14, 2015
@oakmac oakmac changed the title Calculate indentation when user presses "enter" Calculate indentation when user presses Enter Nov 14, 2015
@00dani
Copy link

00dani commented Nov 26, 2015

Indentation-on-enter indeed doesn't seem to be working correctly, at least on my setup, which makes writing even simple code with Parinfer active awfully difficult. For instance:

; | is my cursor
(defun id (x)|)
; enter
(defun id (x))
|
; manual indentation now required to start the function body!

The correct indentation does appear to be applied in this case, where the indent merely must match the previous line exactly:

(define blahs '(a
                b 
                c|))
; enter
(define blahs '(a
                b 
                c))
                |
; cursor's in perfect spot to add extra item to the list, directly under c

But the very common case where the current form must be continued, by increasing indent on Enter, is not successfully supported. Note that the official Parinfer demos produce correct indentation in both of these examples.

I've tested under both language-lisp and language-racket, with exactly the same results - I'm not sure whether the active filetype actually affects Atom's indentation logic anyway, but it didn't help here.

@neverfox
Copy link

Yeah, this is really disappointing trying to use it with Clojure. Has anybody come up with a fix (to what I assume is a problem with Atom's Clojure indentation logic)?

@oakmac
Copy link
Owner Author

oakmac commented Feb 21, 2016

I have been annoyed with this recently too.

@neverfox
Copy link

Does that imply that it wasn't always this way?

@oakmac
Copy link
Owner Author

oakmac commented Feb 21, 2016

I'm not sure.

@neverfox
Copy link

Another indent mode example for the record

(def m {:a 1|})

(def m {:a 1})
  |

Six spaces off from where you need it to continue the map.

@shaunlebron
Copy link
Collaborator

Thanks for the examples @00Davo and @neverfox

The crux of the problem is that Atom does not indent based on language grammars. The python community has been most vocal about this, and they recently created a stopgap package for it. We could follow by taking cues from indentation rules documented for emacs or vim, or do a quick, partial solution using parinfer itself.

@shaunlebron
Copy link
Collaborator

I go this working when pressing enter inside a Paren Trail, but I have to think more about how to do this when pressing enter further inside a line. Tracking at https://github.com/shaunlebron/parinfer/issues/97

@rgdelato
Copy link

rgdelato commented Jul 6, 2017

In the new Atom guide on the ClojureScript site, I pointed people towards the solution on Jason Gilman's opinionated setup page, which is to install the Paredit plugin and only assign the keybinding for the "Enter" key.

If anyone finds a better solution or if Parinfer ends up at a place where it can do this on it's own, please send a PR to the ClojureScript site!

@shaunlebron
Copy link
Collaborator

This is actually fixed in latest Parinfer:
https://runkit.com/shaunlebron/595d8d7fb05c230013f8dd60

dependent on #78 being merged

@rgdelato
Copy link

rgdelato commented Jul 6, 2017

@shaunlebron After playing with it, Parinfer's auto-indentation feels a bit weird. But I can continue that discussion in https://github.com/shaunlebron/parinfer/issues/59 rather than here.

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

No branches or pull requests

5 participants