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

How to re-order data constructors? #133

Open
negatratoron opened this issue Jul 27, 2016 · 4 comments
Open

How to re-order data constructors? #133

negatratoron opened this issue Jul 27, 2016 · 4 comments

Comments

@negatratoron
Copy link

Hey, suppose I've got a data type with multiple constructors and would like to re-order them:

data JSValue = JSNumber Double
             | JSString String
             | JSNull
             | JSObject [(String, JSValue)]
             | JSArray [JSValue]
             | JSIndexInto JSValue JSValue
             | JSLetIn String JSValue JSValue
             | JSIdentifier String
             | JSLambda [String] JSValue
             | JSApplication JSValue [JSValue]

For example, say I want to move JSIdentifier to the top. Normally I would use C-k to kill the line. However it seems the behavior of (shm/kill-line) is to kill all data constructors to the end of the type. Here that would include JSIdentifier, JSLambda, and JSApplication.

Another way to move the data constructor would be to select it, use kill-region, and yank. (Specifically: place your cursor immediately after the |, select, move down one line, kill region, place your cursor after the =, and then yank.) Following this procedure, killing the line works as expected, but upon yanking, the formatting is not correct:

data JSValue =JSIdentifier String
  | JSNumber Double
             | JSString String
             | JSNull
             | JSObject [(String, JSValue)]
             | JSArray [JSValue]
             | JSIndexInto JSValue JSValue
             | JSLetIn String JSValue JSValue
             | JSLambda [String] JSValue
             | JSApplication JSValue [JSValue]

So, how should one actually re-order data constructors?

@negatratoron
Copy link
Author

One way that works is to kill and yank only the data constructor, none of the whitespace around it.

@chrisdone
Copy link
Member

You can select the whole line and kill it or hit C-S-backspace to kill the whole line.

But I agree, a way to move things up and down in a list, like M-up/M-down in org-mode, would be nice.

@emmanueldenloye
Copy link
Contributor

emmanueldenloye commented Dec 28, 2016

First of all, I want to say thanks Chris for writing this package. It is really convenient to use and has made my forays into Haskell far more pleasant. On to brass tacks:

I think I have a solution to this small problem of reordering data constructors. It has a few hiccups and I don't understand the SHM parsing and overlay mechanism well enough to diagnose the problem to a satisfactory degree. However, since the parser reparses the data constructor of interest if it parses another valid expression, these problems can be resolved by moving the point. I submitted a pull request, so hopefully my previous sentence will become clearer if anyone tests the code.

Regards,

Emmanuel

emmanueldenloye added a commit to emmanueldenloye/structured-haskell-mode that referenced this issue Dec 29, 2016
@emmanueldenloye
Copy link
Contributor

@chrisdone Since I worked on this, do you think the solution that I worked on a couple of years ago is sufficient so that you can close this issue?

Regards,

Emmanuel

incredibles007 pushed a commit to incredibles007/structured_haskell that referenced this issue Oct 26, 2021
incredibles007 pushed a commit to incredibles007/structured_haskell that referenced this issue Dec 14, 2023
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

3 participants