MiroHibler / sublime-keymaps

Find a keymap for... and show all enabled keymaps in a Cheat Sheet.
143 stars 9 forks source link

Update Keymaps.py - issue #5 #6

Closed vegar closed 10 years ago

vegar commented 11 years ago

A simple attempt from an python-illiterate to use the ´args´ parameters to make a more descriptive caption. ref. issue #5

I guess the code could be a lot better, and things like 'not forward' could be substituted with 'backward'... but at least it's a possible improvement.

Only tested in SublimeText 3.

MiroHibler commented 11 years ago

With this being my first ever python project, I'm not much more literate than you ;)

Consider these (part of "move" commands from your issue #4):

{ "keys": ["ctrl+left"], "command": "move", "args": {"by": "subwords", "forward": false} },
{ "keys": ["ctrl+right"], "command": "move", "args": {"by": "subword_ends", "forward": true} },
{ "keys": ["ctrl+shift+left"], "command": "move", "args": {"by": "subwords", "forward": false, "extend": true} },
{ "keys": ["ctrl+shift+right"], "command": "move", "args": {"by": "subword_ends", "forward": true, "extend": true} },

Now, how would one go about making these more "descriptive"? ;)

vegar commented 11 years ago

With the changes in this pull request, it would be rendered like this:

                       [ CTRL LEFT ]: Move, By Words, Not Forward
                      [ CTRL RIGHT ]: Move, By Word Ends, Forward
                 [ CTRL SHIFT LEFT ]: Move, By Words, Extend, Not Forward
                [ CTRL SHIFT RIGHT ]: Move, By Word Ends, Extend, Forward

As I said: "Not Forward" could perfectly well be rendered "Backward". You would need a dictionary with 'negated arguments'. I'm not sure the title-casing is that good when including arguments. Maybe a sentence casing would read better.

If you are already working on this, how where you about to solve this? Do you have an alternative idea?

MiroHibler commented 11 years ago

Well, in this particular case, with some "guess-work" you'd come to some acceptable results, but in many other cases - not (IMHO). just take a look in /Packages/Default/ folder for various *.sublime-keymaps files...

When I said "working on it", I meant "thinking about the best approach" really ;)

At the moment, I decided to live the "guess-work" to the user, but if you want to take a piece of it - please do, be my guest :)

vegar commented 11 years ago

Do you have examples where this guess-work does not come up with acceptable results?

It's by no measure perfect, but as long as it doesn't make wrong guesses, I would argue that it's a lot better at guessing then I am. I can't see examples where the guess-work is wrong.

If there is context involved, you will still end up with multiple lines of "same key, same caption"-cases. Or different keys with the same caption, or same keys, but different captions and so on.

MiroHibler commented 11 years ago

Just to illustrate what "args" can contain, how about this for an example (from Sublime Text Unofficial Documentation):

{ "keys": ["shift+enter"], "command": "insert_snippet", "args": {"contents": "\n\t$0\n"}, "context":
    [
        { "key": "setting.auto_indent", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "preceding_text", "operator": "regex_contains", "operand": "\\{$", "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^\\}", "match_all": true }
    ]
}

How would you interpret that in context of multiple commands with similar "command" and variations of "args"?

vegar commented 11 years ago

Today that particular case will be rendered the same, with or without my pull request.

                     [ SHIFT ENTER ]: Insert Snippet

I'm not sure why the args want render for this one. I would have expected something like "Insert Snippet, Contents \n\t..."

I'm not sure context is that relevant anyway. It enables different shortcuts for the same command in different settings - or different commands for the same shortcut in different settings. It could be nice to show some context information in the cheatsheet - like ´[SHIFT ENTER]: Insert Snippet (if auto indent, no selection and cursor inside word)´ but I'm not sure how that should be realized. I'm not sure it would be that helpful either.