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

Ways to bound C-g to set_mark(False) only #67

Closed
haji-ali opened this issue Mar 30, 2020 · 3 comments
Closed

Ways to bound C-g to set_mark(False) only #67

haji-ali opened this issue Mar 30, 2020 · 3 comments

Comments

@haji-ali
Copy link

First of all, let me express my absolute gratitude for this package. I have been looking for something like this for the longest time and your package is absolutely amazing.

I am using the default configuration and I noticed that C-g is bound to esc followed by set_mark(False). This works as intended in most cases. However, in some cases this has undesirable effects. For example, in Firefox when editing the location bar if I select some text using C-SPC then press C-g to unset the mark, esc is pressed which cancels all editing.

I would like to bound C-g to set_mark(False) if a mark is set and esc otherwise. Or, if not possible, maybe bound C-g to set_mark(False) and C-g C-g to esc. Would that be doable?

@Lenbok
Copy link
Contributor

Lenbok commented Mar 30, 2020

In your config, before where you define the keymap containing c-g, put something like this:

def clear_mark_or(combo):
    if isinstance(combo, Key):
        combo = Combo(None, combo)

    def _clear_mark_or():
        if transform._mark_set:
            transform._mark_set = False
        else:
            return combo

    return _clear_mark_or

Now in the keymap define c-g like this:

    K("C-g"): clear_mark_or(K("esc")),

It seems to work as your first request (although like M-w, the selection is still visible until you subsequently move).

(edit: btw, I pretty much just copy-pasta'd that from the functions in transform.py)

@haji-ali
Copy link
Author

haji-ali commented Mar 30, 2020

Brilliant!!

I changed your code to return K("right") when the mark is reset. This becomes almost identical to Emacs behaviour, except for the fact that the cursor is always to the right of the selection even when the point should be to the left. I would have to somehow return K("left") when the "mark" is to the right of the "point" and K("right") otherwise, but I am not sure how to accomplish this.

This is also related to another thing that I wish I could change. In Emacs when C-SPC is pressed on an active selection, the previous selection is undone and the "mark" is at the "point". This would be easy to accomplish if I could figure out where the "point" is by sending the appropriate "left" or "right" keys.

@joshgoebel
Copy link

joshgoebel commented Jun 4, 2022

What is this "selection" or "point" that you're referring to? All we know is what keys you hit - we know nothing about what you're editing, what is selected, where your cursor is or isn't at... so it's impossible to make decision based on such info.

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

No branches or pull requests

3 participants