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

Structural navigation doesn't work as expected within strings and comments #2097

Closed
tanzoniteblack opened this issue Dec 14, 2018 · 14 comments
Closed
Labels
changed Marks issues describing changes to existing features released Marks issues which have had the fixes released in a stable build
Milestone

Comments

@tanzoniteblack
Copy link

tanzoniteblack commented Dec 14, 2018

When the cursor is within a string or comment, ctrl+<left/right> don't work as I'd expect. I'd expect that these keys would jump to the beginning/end of the word I'm at within the strin

example where | represents the current point of the cursor: I would expect that this: (count "dog eats |food)", type ctrl+left, goes to (count "dog |eats food"), instead I get (count |"dog eats food")

The same type of thing occurs within comments.

@ourkwest
Copy link

This is particularly annoying as it violates expectations built up across not just IntelliJ outside of Cursive, but other text editors as well. Even here in this GitHub comment editing block, Ctrl + Left/Right allows me to move one word at a time through prose.

I'm aware that there must be plenty of issues competing for development time, but breaking standardised navigation commands feels fairly fundamental. Of course it wouldn't seem so frustrating if Cursive didn't seem to be obviously the best Clojure editing solution available. :-D

@crispinb
Copy link

crispinb commented Jun 2, 2020

Similarly with emacs keybindings, Alt-f/b jumps out of comments & strings to the next/previous sexp.

I've no idea if Idea's plugin architecture permits movement actions to work differently depending on context, but it would be really nice if it was possible to change this. I find myself tripped up by this all the time, especially within comment blocks. Muscle-memory for wordwise movement does become very deeply engrained ;)

@cursive-ide cursive-ide added this to the 1.10.1 milestone Jan 26, 2021
@cursive-ide cursive-ide modified the milestones: 1.10.1, 1.10.1-eap2 Jan 29, 2021
@cursive-ide cursive-ide added the changed Marks issues describing changes to existing features label Jan 29, 2021
@imrekoszo
Copy link

I kinda feel that the way this was fixed doesn't work for me. Previously when I was inside a longer string I could move forward/back to get out of it, but now that's gone 😞 I tried move forward out of sexp but that put me outside the sexp that contained the string. Any chance I could either get the old behaviour back (make this a config setting) or add more structural support for strings?

@cursive-ide
Copy link
Owner

@imrekoszo Thanks for the feedback. What you're missing is basically the change that was requested in this issue, unless I'm misunderstanding something. Assuming that others are happy with how it works now, the only way I can see to allow both would be a config switch.

@tanzoniteblack
Copy link
Author

I'm definitely happy with the new behavior! Thanks for implementing it.

This seems relevant: https://xkcd.com/1172/

@cursive-ide
Copy link
Owner

Haha, yes, I put that in the slack comments discussing this :). Thanks for the feedback too, that's good to know.

@imrekoszo
Copy link

Thanks @cursive-ide, a config setting would be perfect for me.

However, I'd take the opportunity to try and learn more about this topic. Here are a few related commands:

  1. Cursive command Structural Movement - Move Backward/Forward, bound (on a Mac) by default to cmd+left/right and option(alt)+left/right
  2. Idea default command Move Caret to Previous/Next Word, bound (on a Mac) by default to option(alt)+left/right (clashes with the above, Cursive command takes precedence in Clojure files)
  3. Cursive commands Structural Editing - Slurp/Barf Backward/Forward
  4. Cursive commands Structural Movement - Move Backward/Forward Out of Sexp

Prior to this fix one could achieve moving word-by-word inside a string/comment by removing the clashing binding from 1. and using command 2., while leaving 1. to work based on Clojure forms (a string is atomic in this sense as far as I'm aware).

However, 3. already worked on strings so I do see people wanting to have more structural movement/editing support for the added convenience. I'm wondering then, why shouldn't 4. work on strings? Or commands like Splice sexp or Raise? For those of us who want 1. to work the way it is now (post-fix) surely 4. would be helpful.

@cursive-ide
Copy link
Owner

Yes, I think it definitely makes sense for more commands to work on strings, @PEZ mentioned in Slack that in Calva strings are treated as lists of words, so that all the paredit commands just work on them. Cursive special cased slurp and barf for strings, and now also does for movement, but a more definitive fix would be to generally treat strings the same way that Calva does.

One thing - I think that in the default keybindings, Move Back/Forward should only be bound to a single key, not multiple ones. This should be option left/right in both the "Mac OS X 10.5+" and the legacy "Mac OS X" keymaps. I'm using a modified "Mac OS X 10.5+" and I only see that key bound.

@PEZ
Copy link

PEZ commented Feb 8, 2021

With Calva there are people who want it to behave even more structural within strings (basically treat the string fully as structured text) and others who want it to behave more like how editors otherwise define words. None of these option are particularly hard to implement, but pleasing both these user groups as well as the group who is happy with how it works today is challenging, if I put it that way.

VS Code offers some mechanism where I can give the users the option to disable paredit sexpr movement within strings. I think this is what I will do when I find some time for it.

Generally, the trade-offs are a bit like so:

  • It is not possible to have defaults that please everyone
  • It is not feasible to create settings for everything

I generally say no to add settings, because of the maintenance and communication cost they carry. But sometimes a setting makes sense and can even make something else easier to maintain.

Sorry for running away on a tangent with this. 😄

@cursive-ide
Copy link
Owner

Agreed, I definitely try to minimise the amount of config flags too for the reasons you describe. I think most of the settings I would prefer not to have sneak in through this same process. It's generally when I fix a problem that should have been done a different way from the start but users are now used to the previous way things were done when I finally fix it.

@imrekoszo
Copy link

I'm in the less-structural-in-strings camp but I definitely want a way to escape from the middle of a long string, which is currently missing unfortunately.

The double keybind might certainly be something I added sometime, perhaps not fully knowing what I was doing. But the point is that prior to this change there was a way to go word by word within a string and there was a way to quickly go to the beginning or the end of it.

@cursive-ide
Copy link
Owner

I guess if we're treating strings essentially as if they were lists of words, then "Move Forward/Backward out of Sexp" would be what you'd use. If it did work like that would that suffice, do you think?

@imrekoszo
Copy link

@cursive-ide I'd be happy either with that or the old way, as long as I can get out of a string quickly :) I don't use "Move Forward/Backward out of Sexp" too much now, perhaps this would make me develop the muscle memory.

Mind that this could in turn break some other folks' workflow who rely on the current behaviour of the command when standing in a string, but at least they'd be able to give the command again once out of the string to get to where they used to get.

@imrekoszo
Copy link

@cursive-ide I noticed that while "Move Forward/Backward out of Sexp" works in strings (thank you again for adding that), it doesn't appear to work in line comments (;)
("Structural Movement - Move Backward/Forward" work)

@cursive-ide cursive-ide added the released Marks issues which have had the fixes released in a stable build label Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changed Marks issues describing changes to existing features released Marks issues which have had the fixes released in a stable build
Projects
None yet
Development

No branches or pull requests

6 participants