chrisdone/structured-haskell-mode — pull request #79 by phenguin (2014-09-01 01:22:35+00:00)
Title: Add features to shm-case-split

Now, you can case split based on the type of the expression at point (in
particular, the expression corresponding to the currently selected shm node)

I was re-browsing the structured haskell mode documentation and noticed the shm/case-split feature which I hadn't seen before. I was excited to try it out but then I noticed it didn't exactly do what it advertised. Instead of performing a case split based on the name at point like it said, it actually prompted for a type and then did a case split based on that.

I tried to add the feature that was missing (as far as I could tell). The function shm/case-split-shm-node uses the haskell process to get the type of the whole current node, processes the type it gets back a bit, then replaces the node with the output of shm/case-split.

I also modified shm/case-split to take an additional optional parameter to be used as the "case variable" string instead of undefined, as well as updating documentation. Additionally I added a wrapper function, shm/do-case-split, that wraps both my new behavior, and the behavior of shm/case-split, conditional on a prefix argument. I have this bound to C-c C-s in my configuration, but didn't want to alter the default bindings of SHM.

As an example of the feature, if you have the cursor here:
```
x = [J]ust 5
```
, and the current node is "Just 5", then calling shm/do-case-split with no prefix argument will replace this with:
```
x = case Just 5 of
Nothing -> undefined
Just _ -> undefined
```

Please note that this is my first open source contribution, so I'm more than open to critique if I'm doing this whole pull request thing wrong or something. I also haven't written very much elisp, and none so public, so I'm open to critique there as well.

One possible improvement I'd like to make is integrating this with ghc-mod. Currently, only top level expressions can be evaluated and replaced this way, but with ghc-mod integration, this could work with expressions including local variables of functions, let bound variables, etc..