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

Paredit: delete # character before opening delimiter #1122

Closed
yuhan0 opened this issue Apr 16, 2021 · 6 comments
Closed

Paredit: delete # character before opening delimiter #1122

yuhan0 opened this issue Apr 16, 2021 · 6 comments
Labels
paredit Paredit and structural editing

Comments

@yuhan0
Copy link

yuhan0 commented Apr 16, 2021

Calva treats #( and #{ as single units and refuses to delete the # character alone.
This can be annoying when eg. refactoring a #(..) into a (fn ..) or when deleting the #_ ignore macro one character at a time.

#_ (ignore me) ;;  delete the _
# (ignore me)  ;; oops, can't delete the #  

#:same{:thing :here} ;; try removing the namespace tag

@PEZ suggested Alt-backspace as a temporary workaround which ignores paredit and forces deletion.

@PEZ PEZ added the paredit Paredit and structural editing label Apr 17, 2021
@PEZ
Copy link
Collaborator

PEZ commented Apr 17, 2021

So translating this to Paredit tests, one way to solve this would be to make these tests pass (without breaking any existing tests, naturally).

            it('Deletes open paren prefix characters', () => {
                // https://github.com/BetterThanTomorrow/calva/issues/1122
                const a = docFromTextNotation('#|(foo)');
                const b = docFromTextNotation('|(foo)');
                paredit.backspace(a);
                expect(textAndSelection(a)).toEqual(textAndSelection(b));
            });
            it('Deletes open map curly prefix/ns characters', () => {
                const a = docFromTextNotation('#:same|{:thing :here}');
                const b = docFromTextNotation('#:sam|{:thing :here}');
                paredit.backspace(a);
                expect(textAndSelection(a)).toEqual(textAndSelection(b));
            });
            it('Deletes open set hash characters', () => {
                // https://github.com/BetterThanTomorrow/calva/issues/1122
                const a = docFromTextNotation('#|{:thing :here}');
                const b = docFromTextNotation('|{:thing :here}');
                paredit.backspace(a);
                expect(textAndSelection(a)).toEqual(textAndSelection(b));
            });
            it('Moves cursor past entire open paren, including prefix characters', () => {
                const a = docFromTextNotation('#(|foo)');
                const b = docFromTextNotation('|#(foo)');
                paredit.backspace(a);
                expect(textAndSelection(a)).toEqual(textAndSelection(b));
            });

Note that of these, the _ Deletes open map curly prefix/ns characters_ already passes.

My rationale behind this particular solution is that if you place the cursor somewhere ”in” a multi-character open token it is OK for backspace to delete things. While if the cursor is inside the list and you hit backspace twice, you get protection against accidentally removing the prefix, if the first backspace takes outside the whole open token.

@yuhan0
Copy link
Author

yuhan0 commented Apr 17, 2021

Hmm, then I guess the same thing should happen with any other prefix character, like

'(quotes) 
~@(splicing unquotes) 
~'#?@(:clj [un-syntax-quoted splicing reader conditional])  ; 💥 

I didn't notice this before but all these prefixes currently behave the same as # and you can't delete them individually.
In the last case your proposal would jump over 6 characters when hitting backspace from within a nonempty form?

And should it distinguish the sequence #_ such that you can delete it like such:

#_(|foo)
#_|(foo) 
#|(foo) 
|(foo) 

@PEZ
Copy link
Collaborator

PEZ commented Apr 17, 2021

@PEZ
Copy link
Collaborator

PEZ commented Apr 17, 2021

Yes, Calva lumps together all sorts of opening ”prefix” characters. So the VSIX should now behave consistently in the new way. 😄 And the ignore marker is not considered an opening prefix so also that should work as you suggest there.

@yuhan0
Copy link
Author

yuhan0 commented Apr 17, 2021

Yup, it handles all those cases exactly how I'd expect them too 👍
Thanks for the quick fix!

@PEZ
Copy link
Collaborator

PEZ commented Apr 17, 2021

Thanks for being super quick in testing and responding here. It helps tons!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
paredit Paredit and structural editing
Projects
None yet
Development

No branches or pull requests

2 participants