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

vim-sexp-mappings-for-regular-people additional binds #10

Open
blaenk opened this issue May 31, 2016 · 3 comments
Open

vim-sexp-mappings-for-regular-people additional binds #10

blaenk opened this issue May 31, 2016 · 3 comments

Comments

@blaenk
Copy link

blaenk commented May 31, 2016

You mentioned that you were going to be implementing vim-sexp-mappings-for-regular-people binds at some point, which is awesome. I ended up having to do it myself manually with the smartparens api because I didn't find existing packages that did it.

I'm gonna take a look at this package because I had seen other similar packages and also lispy, but lispy seemed like its own separate thing and the other packages I found for interfacing with it didn't seem all that enticing. I want to write down my ideas first though before I forget to, so it's likely that some of these things you already have covered in your package.

By the way, I found that I had to make use of the on-parens package for certain functions I created so that they would work well in evil normal mode, which is where I have these binds setup. See its readme for the rationale, which may or may not affect you. Here's an excerpt:

In vi/vim/evil-mode in normal-state, the cursor is viewed as being ON a character rather than BETWEEN characters. This breaks smartparens particularly when it tries to put you past the last character of the line, since normal-state will push point back one character so it can be viewed as on the last character rather than past it. Additionally, most vim/evil movements go to the beginning of a text object, with an alternative version that goes to the end. Emacs tends to go past the end of things when it goes forward, but to the beginning when it goes back.

I added a few additional bindings for operations that I think are useful, though you can be the judge on which keys to actually bind them on. You can find the full source for this here.

I have something like:

    "< u" 'sp-splice-sexp-killing-backward
    "> u" 'sp-splice-sexp-killing-forward

I actually use these a lot. Say I have (func |param thing other), then < u would make it param thing other and > u makes it func.

There's also sp-splice-sexp-killing-around which is useful so that it becomes just param. I wasn't sure what to bind this variant too though, and I do use it a lot, so I was just using the default smartparens bind for it which is C-S-Backspace. Perhaps something like ^u but I guess ^ is already taken.

I bound them to the letter "u" because it feels like I'm "unwrapping" the sexp in a certain direction. Then again smartparens already has a sp-unwrap-sexp which literally just removes the sexp delimiters, so perhaps it may be better to go with < s and > s for "splice".

I also have ones for deleting in a certain direction up to the sexp delimiter:

    "< d" 'blaenk/delete-sexp-backward
    "> d" 'blaenk/delete-sexp-forward

The definition of the -backward one for example is just:

      (defun blaenk/delete-sexp-backward ()
        (interactive)
        (sp-kill-sexp '(-4)))

It's very useful. So if I have (func |param thing other), < d makes it (param thing other) and > d makes it (func).

One other minor thing is that my binds for inserting at the beginning or end are < i and > i, i.e. not < I and > I. It's not a big deal and I'm fine with either, just a difference I noticed.

Also for < i I made it so that it auto-creates a space, so like if you have (one two |three) and you do < i, it'll leave you at (| one two three) instead of just (|one two three). I'm not sure that's all that useful though or even something that one would desire all the time, but it's an idea you might want to pursue for other bindings perhaps. Then again it's not that difficult to just type out a space manually.

I also created bindings for splitting sexps and joining them, M-S and M-J respectively, but I guess that doesn't really go well with the whole > and < binds anymore so that's perhaps not all that relevant.

@noctuid
Copy link
Owner

noctuid commented May 31, 2016

I'm gonna take a look at this package because I had seen other similar packages and also lispy, but lispy seemed like its own separate thing and the other packages I found for interfacing with it didn't seem all that enticing.

I personally use lispy as much as possible, but this package can be used without lispy-mode too.

As for the "on parens" thing, the commands provided by this package are consistent with evil and will put the point before/on parens (e.g. see the additional movement key theme).

I actually use these a lot. Say I have (func |param thing other), then < u would make it param thing other and > u makes it func.

I'll probably just add your extra keybindings to the vim-sexp-mappings-for-regular-people key theme since there aren't any conflicts. I think I like < s and > s (or < x since lispyville's x will splice on an opening paren). As for the killing around one, maybe < S, < X, or < a (replicated on > as well)?

It's very useful. So if I have (func |param thing other), < d makes it (param thing other) and > d makes it (func).

Sure I can add this as well. One thing to note is that you could also do this with lispyville's delete operator (d ( or d ) with the additional movement key theme bound in operator state). I'm planning on adding a "delete by splice" operator, so you could also replicate < u with that the same way. Regardless, I'll add your < u and < d.

One other minor thing is that my binds for inserting at the beginning or end are < i and > i, i.e. not < I and > I. It's not a big deal and I'm fine with either, just a difference I noticed.

I don't think < i is bound right? I'll just use < i instead of < I then.

Also for < i I made it so that it auto-creates a space

I'll probably make this an option. Inserting a space usually makes sense (various lispy commands do this, like the wrapping ones).

I also created bindings for splitting sexps and joining them, M-S and M-J respectively

I'm planning on adding joining/splitting keybindings in a separate key theme.

I'll look at the rest of your keybindings as well.

@blaenk
Copy link
Author

blaenk commented May 31, 2016

Ah okay! Yeah I'm gonna look into lispy and your bindings some more. I've noticed that many things are already possible other ways, I'm just so used to this style of binding, so it'd be nice if we could have them around as well.

Yeah the ones for killing around sound like good ideas all of them. I think < a and > a would be easiest to remember but soon enough I'd remember the other ones you proposed so if you'd rather save < a for other potential bindings then that's fine.

Yeah < i isn't bound by vim-sexp.

@sooheon
Copy link
Contributor

sooheon commented Aug 12, 2016

BTW a nice binding for sp-splice-sexp-killing-around is M-r, mnemonic for "raise"-ing the sexp at point to the above level. If you're not opposed to using meta binding, it's easier than a two key binding like < a or something.

And it mirrors just plain r from special in lispy.

noctuid added a commit that referenced this issue Apr 8, 2018
- Add more commands to the additional key theme (addresses #5)
- Add the additional insert key theme
- Add initial keybindings for the arrows key theme (address #10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants