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

lispy: New layer that puts lispy-mode toggle on M-m k #4596

Closed
wants to merge 1 commit into from
Closed

lispy: New layer that puts lispy-mode toggle on M-m k #4596

wants to merge 1 commit into from

Conversation

justbur
Copy link
Contributor

@justbur justbur commented Jan 13, 2016

This layer adds the lispy package and makes it available as a toggle on M-m k.The intention is to provide users of holy-mode (and possibly hybrid-mode) with an alternative to evil-lisp-state for editing lisp in spacemacs.

@syl20bnr
Copy link
Owner

Why only for emacs style users ? :-)

Since it is a layer, I guess you can make it exclude evil-lisp-state and remove the condition on the editing style, so anybody can try lispy. We may have some key binding tweaks in vim style, like for helm and ivy but we'll find out by using it.

Excellent and so simple, I love that 💜

@nixmaniack
Copy link
Contributor

This is awesome if it's landing in spacemacs! I'm using this with hybrid style and feels amazing when writing lisp.
Couple of issues which I faced:

  • If lispy/hydra gets updated, it breaks lispy and you need to reinstall both(lispy and hydra) as lispy does some compiling stuff (which I didn't dig into much)
  • Some of the important keys are shadowed with default config, most prominently M-m for lispy-mark-symbol.
  • If it's for hybrid, it makes sense to only enable in hybrid state, making it available in other states might override important keybindings causing confusion.

@justbur
Copy link
Contributor Author

justbur commented Jan 13, 2016

Since it is a layer, I guess you can make it exclude evil-lisp-state and remove the condition on the editing style, so anybody can try lispy.

There's no need to remove evil-lisp-state as this effectively removes all of the evil-lisp-state entry points.

If lispy/hydra gets updated, it breaks lispy and you need to reinstall both(lispy and hydra) as lispy does some compiling stuff (which I didn't dig into much)

I think I ran into that already, but I didn't understand what was happening. Has it been reported?

Some of the important keys are shadowed with default config, most prominently M-m for lispy-mark-symbol.

Ok I'll fix that.

If it's for hybrid, it makes sense to only enable in hybrid state, making it available in other states might override important keybindings causing confusion.

I can do that too.

@nixmaniack
Copy link
Contributor

@justbur I didn't report the issue. Based on this comment I installed hydra and got it working. Which tells us we might need hydra as a direct dependency of lispy in layer packages and needs to be installed prior to lispy initialization.

@justbur
Copy link
Contributor Author

justbur commented Jan 13, 2016

@nixmaniack That should be reported. hydra is not currently listed as a dependency of lispy in melpa

@justbur
Copy link
Contributor Author

justbur commented Jan 13, 2016

@syl20bnr Check it now. I think this should work fine for all editing styles now

@nixmaniack
Copy link
Contributor

@justbur I created issue abo-abo/lispy#180 but looking at discussion over here abo-abo/lispy#74 it seems it's unlikely. If that isn't resolved, you'll need to add it to layers packages.

Also, is it alright to make lispy available in hybrid state everywhere? I had an issue with org mode previously(abo-abo/lispy#141, fixed as of now). So it might make sense to enable it in lisp related modes to avoid such issues.

@justbur
Copy link
Contributor Author

justbur commented Jan 13, 2016

Also, is it alright to make lispy available in hybrid state everywhere? I had an issue with org mode previously(abo-abo/lispy#141, fixed as of now). So it might make sense to enable it in lisp related modes to avoid such issues.

Good point. I intended to make it only available in the buffer you toggled it in, but these hooks don't do that.

@justbur
Copy link
Contributor Author

justbur commented Jan 13, 2016

@nixmaniack It's fixed now. The toggle only applies to the current buffer.

(defun lispy/init-lispy ()
(use-package lispy
:config
(defun spacemacs/lispy-off () (lispy-mode -1))
Copy link
Contributor

Choose a reason for hiding this comment

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

If someone turns off lispy mode, exiting the (state)hook will cause this to fire off and based on this comment, it's better to guard it to avoid unintended issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess that's right. Although the situation you linked to cannot happen here, because the hooks are buffer-local. I'll add the guard anyway thanks

@ryepesg
Copy link

ryepesg commented Jan 16, 2016

Would it be possible to use together Lispy layer with evil-cleverparens layer? Related issue:
#4337

@justbur
Copy link
Contributor Author

justbur commented Jan 16, 2016

With this yes
On Sat, Jan 16, 2016 at 10:41 AM ryepesg notifications@github.com wrote:

Would it be possible to use together Lispy layer with evil-cleverparens
layer? Related issue:
#4337 #4337


Reply to this email directly or view it on GitHub
#4596 (comment).

@ryepesg
Copy link

ryepesg commented Jan 16, 2016

Great! Thank you.

@justbur
Copy link
Contributor Author

justbur commented Jan 17, 2016

Some of the important keys are shadowed with default config, most prominently M-m for lispy-mark-symbol.

@nixmaniack Any suggestions for a new binding?

@nixmaniack
Copy link
Contributor

@justbur That's a tough question! I struggled to find a good spacemacsy alternative while writing that comment hence didn't suggest. Almost everything with two keypress seems to be bound to something.
As for me, I'm using s-m but I am sure it's not right for spacemacs.

We should ask others I think. @syl20bnr @StreakyCobra @TheBB @tuhdo do you have any suggestion for keybinding for lispy-mark-symbol (marks the symbol under point) as the default is M-m which is used by spacemacs. (We're mostly concerned about 'emacs and 'hybrid style)

In my case, I use it quite often hence two keypress key should be better.

@nixmaniack
Copy link
Contributor

@justbur hydra is added as dependency of lispy now.

@justbur
Copy link
Contributor Author

justbur commented Jan 17, 2016

@justbur hydra is added as dependency of lispy now.

Thank you!

@syl20bnr
Copy link
Owner

@nixmaniack can you give a key sequence for a use case using lispy-mark-symbol ? It will allow me to quickly see how you use it and hopefully come with an appropriate key binding suggestion. Thank you.

@nixmaniack
Copy link
Contributor

@syl20bnr
After marking the symbol you can perform all sorts of operations on it. Also it activates lispy's special mode where almost all keybindings of lispy become available. To name a few of them.

  • evaluate the symbol with e
  • navigating up/down using jk
  • moving symbol up/down using ws
  • moving symbol out of the current sexp using o``lh
  • teleporting symbol to some other form
  • extending selection like expand-region with <> and performing operation on it.

As an example my cursor is somewhere(denoted by |) between function name

(defun test-so|mething ()
 ...
)

I could do M-m col(e to copy the function name (c) under the function definition(ol), put parens(() around it and evaluate it(e).

(defun test-something ()
 ...
)
(test-something)|

Another use case would be transforming symbol under point to let bound variable using M-m xb``foo

And other would be while browsing through code, select variable under point and evaluate it with M-m e to check its value.

The possibilities are endless once you know these commands, and I find it as one of the core bindings of lispy.

A thing to note, currently with default spacemacs bindings and hybrid style, you could use M-m v to mark thing at point but it doesn't mark full thing if it's something like some-long-variable-name, and you end up pressing M-m vv whereas lispy-mark-symbol takes care of this.

@justbur
Copy link
Contributor Author

justbur commented Jan 19, 2016

@nixmaniack Here are some ideas

  1. M-s "select"
  2. M-n next to M-m and similar to pulling the symbol under the point into the minibuffer
  3. M-m M-m

@nixmaniack
Copy link
Contributor

M-n sounds good. If it doesn't conflict much/anywhere then I would vote for it. 👍
M-s would override default bindings(I think isearch related), although I don't use them, just pointing out.
M-m M-m I had this previously, but had switched to s-m because of frequency and was easier to hit.

@justbur
Copy link
Contributor Author

justbur commented Jan 20, 2016

@nixmaniack Added the M-n binding

@nixmaniack
Copy link
Contributor

@justbur 👍 Thanks!

(pcase (list (bound-and-true-p holy-mode)
(bound-and-true-p hybrid-mode)
spacemacs-lispy-mode)
(`(t ,x ,y)
Copy link
Contributor

Choose a reason for hiding this comment

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

_ is usally used as a pattern to match anything :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean?

Copy link
Contributor

Choose a reason for hiding this comment

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

(t ,_ ,_)` matches the same as (t ,x ,y)but doesn't bindxandy`.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, thanks. I changed it

The toggle works with all editing styles but behaves slightly
differently depending on which one is used. In emacs editing style
(holy-mode on), the mode is simply toggled. In hybrid (hybrid-mode on)
or vim, the mode is on in insert/hybrid state and off otherwise.
@syl20bnr
Copy link
Owner

I tried it but it does not seem to work or I missed something.
Pressing SPC k echoes messages like:

Lispy-mode enabled in insert state for this buffer.
Lispy-mode disabled in insert state for this buffer.

@Andre0991
Copy link
Contributor

I agree that the idea of "implicit states" can cause some confusion, but using an extra key would completely defeat Lispy's purpose.

If what we want is to make it more clear that he is using Lispy state, what about just changing the colour of the spaceline?

As it was mentioned, an user that install this layer should by aware of how Lispy works, we shouldn't modify it, IMO.

I agree that if this layer were shipped with Spacemacs replacing the current evil lisp state, then it would be very confusing for users, as they don't know how to use Lispy which is much less intuitive. But it's not the case so I don't think we need to worry about that.

@syl20bnr
Copy link
Owner

syl20bnr commented Feb 5, 2016

Lispy is not about its implicit state, the implicit state is to introduce some kind of Vim state in the Emacs paradigm, think about a state without a state, and it is OK in Emacs way.

Lispy is about the functions it provides to manipulate sexp.

I will reformulate what I want this way: Spacemacs is an evil distribution and to add a lispy layer officially it (the layer) has to support lispy as a replacement for evil-lisp-state which means what I repeat over and over again since someone mentioned lispy on this repo. I won't repeat it one more time ;-)

@syl20bnr
Copy link
Owner

syl20bnr commented Feb 5, 2016

Initial request here: #1955 (comment)

@Andre0991
Copy link
Contributor

I understand what you want, I think. You want consistency and basically the same interface for evil-lisp-state and lispy.

This makes sense for some kind of packages. Let's say there's a syntax checking package called x and another called y. This would be abstracted by Spacemacs just using the name "Syntax checking", and regardless of what package is being used, SPC m e <letter> would cover all syntax checking functions.

You want the same thing with Lisp manipulation. The problem is that the implicit state is important in Lispy and using the same interface as SPC k would make it much, much less convenient for little gain. You would like to adapt Lispy to the current Spacemacs way but that would cripple it. Lispy is a complete different beast.

Sorry if I misunderstood what you want @syl20bnr , but anyway, this discussion is going nowhere.

@syl20bnr
Copy link
Owner

syl20bnr commented Feb 5, 2016

Lispy and using the same interface as SPC k would make it much, much less convenient for little gain.

I don't care, it has to fit the Vim style as well! A layer variable can allow to control this behavior, seriously do I have to repeat the same thing again ?

Vim users feel basically naked in insert state when it comes to navigation and manipulation of text, a state is needed for this!

No lispy state --> no official layer in Spacemacs. I won't comment on this thread again.

@tuhdo
Copy link
Contributor

tuhdo commented Feb 5, 2016

Can we just pretend VIm users do not exist and don't care about this layer i.e. mark it Emacs only layer?

@Andre0991
Copy link
Contributor

Cam we just pretend VIm users do not exist and don't care about this layer i.e. mark it Emacs only layer?

Spacemacs, as syl20bnr said, is an Evil distribution. I use it with Evil and I'm very interested in using Lispy, as many Evil users are.

@nixmaniack
Copy link
Contributor

Does that mean you want to replace smartparens (current backend of evil-lisp-state) with lispy for vim style?

And the same keybinding which enables evil-lisp-state for vim style, will enable lispy for emacs style without switch of the explicit state?

For hybrid style, I prefer going emacs style way, no switch of state.

@syl20bnr
Copy link
Owner

syl20bnr commented Feb 5, 2016

Spacemacs, as syl20bnr said, is an Evil distribution.

Thank you, my fear about Spacemacs loosing its identity is real.

I'll see what I can do to put back the project on the right track.

@tuhdo
Copy link
Contributor

tuhdo commented Feb 5, 2016

Spacemacs, as syl20bnr said, is an Evil distribution. I use it with Evil and I'm very interested in using Lispy, as many Evil users are.

If this is the case, and the way that Lispy has to fit in Spacemacs, there's no value in adding Lispy to Spacemacs because essentially Lispy is just another version of evil-lisp-state with more fancy commands.

@nixmaniack
Copy link
Contributor

Cam we just pretend VIm users do not exist and don't care about this layer i.e. mark it Emacs only layer?

I assumed this since start that lispy is only for emacs style(hybrid for me).

@syl20bnr
Copy link
Owner

syl20bnr commented Feb 5, 2016

Lispy is just another version of evil-lisp-state with more fancy commands

This is why I want it! As I said lispy is about the commands to manipulate sexps, not the way we activate its state. The activation method can be a layer variable, OMG do I have to repeat again ? :-)

@Andre0991
Copy link
Contributor

Well, actually the current solution is not bad. Evil users that want to use Lispy in a Emacs editing style way can temporarily switch to hybrid state - this is what I would do. Otherwise they use the familiarSPC k 👍

@nixmaniack
Copy link
Contributor

I would appreciate if you answer this @syl20bnr. This would make it more clear in case someone wants to go ahead and implement.

Does that mean you want to replace smartparens (current backend of evil-lisp-state) with lispy for vim style?

And the same keybinding which enables evil-lisp-state for vim style, will enable lispy for emacs style without switch of the explicit state?

@tuhdo
Copy link
Contributor

tuhdo commented Feb 5, 2016

@syl20bnr so, you just want Lispy to be an enhanced version of evil-lisp-state i.e. completely replace evil-lisp-state package with lispy? I guess that's fine though we lose half of its power, one of the selling point of Lispy.

Probably, a better approach is to enable the implicit state by default in holy-mode, and disable otherwise?

@syl20bnr
Copy link
Owner

syl20bnr commented Feb 5, 2016

Does that mean you want to replace smartparens (current backend of evil-lisp-state) with lispy for vim style?

@nixmaniack Not really, it means we can replace the whole evil-lisp-state by a lispy evil state activated on SPC k. From there we can tweak lispy key bindings in Vim style if required.

Probably, a better approach is to enable the implicit state by default in holy-mode, and disable otherwise?

@tuhdo Actually both could leave together in holy-mode, implicit and explicit.

@syl20bnr
Copy link
Owner

syl20bnr commented Feb 5, 2016

@tuhdo This is the Emacs paradigm which lacks states in conventional insertion of text, not Vim where states are at the root of the paradigm so your idea of half its power is a lot biased. As I said, the activation method is not important both types of users are equaly efficient to manage either implicit state or explicit state. Explicitly switching state for a Vim user == no op, and having an explicit state to manipulate text is what a Vim user expects.

EDIT: what I meant here is that in holy mode both way to activate the state can live together because after all Emacs has no notion of state in the first place. But in Vim this is not the case, the state are already part of the game, we have to be compliant with this.

@syl20bnr
Copy link
Owner

syl20bnr commented Feb 5, 2016

Truth is I don't even notice I press SPC k when manipulating sexps.

@tuhdo
Copy link
Contributor

tuhdo commented Feb 5, 2016

@syl20bnr the thing is, for an Emacs user, it's very annoying to handle editing states explicitly, and that's why Lispy was created to activate automatically. And I like it much better than mentally switch to LIsp state with a long sequence of key strokes. With Lispy, you need 0 key stroke to get in and out of its editing state. And this is why it was created. If Emacs users want to have modal editing the Emacs way, they can simply use god-mode, not Evil.

@Andre0991
Copy link
Contributor

@tuhdo Actually both could leave together in holy-mode, implicit and explicit.

So Evil users that prefer SPC k can continue using it, and users that want to use it with the implicit state thing can use hybrid state.

SPC k would get a very powerful backend and everyone would be able to use Lispy the way they prefer 👍

@syl20bnr
Copy link
Owner

syl20bnr commented Feb 5, 2016

And I like it much better than mentally switch to LIsp state with a long sequence of key strokes

@tuhdo I hear you and this is totally fine. Lispy may be the ultimate sexp manipulation backend for Spacemacs thanks to this but it has to fit the Vim way as well.

@syl20bnr
Copy link
Owner

syl20bnr commented Feb 5, 2016

With Lispy, you need 0 key stroke to get in and out of its editing state.

@tuhdo Not exactly, actually both methods cancel each other on this particular point. To be in lispy state you have to move the point on the right position first, which is not 0 keystroke ;-)

@tuhdo
Copy link
Contributor

tuhdo commented Feb 5, 2016

it has to fit the Vim way as well.

That's why I suggest we should leave the way lispy is for holy-mode and adjust whatever it is to fit a Vim user's mental model.

To be in lispy state you have to move the point on the right position first, which is not 0 keystroke ;-)

Well, that's true but as an Emacs user, explicitly manage editing state is unbearable, so that's the reason Lispy does it for them. In the case of an Emacs user, they might want to use other commands in conjunction with Lisp-specific commands i.e. use C-f to move outside of the context to enter some text. With the way of evil-lisp-state, they have to exit the state first, and this is just unusable for them.

That's why I suggest to leave Lispy as is in holy-mode and adjust to fit in other styles.

@nixmaniack
Copy link
Contributor

That's why I suggest to leave Lispy as is in holy-mode and adjust to fit in other styles.

👍

vim - explicit ( with SPC k)
holy - implicit (leave as it is)
hybrid - both! explicit (with SPC k) and implicit (because hybrid state has emacs bindings already)

@syl20bnr
Copy link
Owner

syl20bnr commented Feb 5, 2016

Actually more this:

  • vim SPC k
  • hybrid SPC k with explicit opt-in to the layer variable to enable implicit state
  • holy-mode both (no impact what so ever)

More on what I said about cancelling each other, from Lispy README (see at the end of this post) we can go to a special place from anywhere, so basically I press SPC k I'm in Lispy state then ] or any other non location specific navigation command (which could be tweaked for Vim users, maybe an evil-lispy like evil-magit ?).


You can use plain Emacs navigation commands to get into special, or you can use
some of the dedicated commands:

Key Binding Description
] lispy-forward - move to the end of the closest list, analogous to C-M-n (forward-list)
[ lispy-backward - move to the start of the closest list, analogous to C-M-p (backward-list)
C-3 lispy-right - exit current list forwards, analogous to up-list
) lispy-right-nostring exit current list forwards, but self-insert in strings and comments

These are the few lispy commands that don't care whether the point is
special or not. Other such bindings are DEL, C-d, C-k.

@syl20bnr
Copy link
Owner

syl20bnr commented Feb 5, 2016

Maybe something like this could be pretty handy:

  • SPC k switch to lispy state and move point to closest open parens backward (effectively doing SPC k [ in one shot).
  • SPC K switch to lispy state and move point to closest closing parens forward (effectively doing SPC k ] in one shot).

@AlejandroCatalina
Copy link
Contributor

Actually, an evil-lispy package is what is being suggested here, and I think it may work pretty well.

@syl20bnr
Copy link
Owner

syl20bnr commented Feb 5, 2016

Can be part of the layer before being a stand alone package.

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

Successfully merging this pull request may close these issues.

10 participants