t9md / atom-keystroke

define multi keystroke commands easily
https://atom.io/packages/keystroke
MIT License
17 stars 2 forks source link

Expose function buildCommandSpecsFromKeyBindings #9

Closed jdanbrown closed 6 years ago

jdanbrown commented 6 years ago
t9md commented 6 years ago

OK, btw, how do you call? Can you share me the repo and code where you call buildCommandSpecsFromKeyBindings?

jdanbrown commented 6 years ago

Sure, but beware that the repo is still super hacky and not yet published as a proper atom package:

jdanbrown commented 6 years ago

And here's how I call it (copied from the link in the previous comment):

      // 'keystroke ...' keymaps automatically work only for the user's ~/.atom/keymap.cson keymaps. We have to manually
      // register them for our own package keymap/*.cson keymaps.
      keystroke.main.registerCommands(keystroke.main.buildCommandSpecsFromKeyBindings(
        atom.keymaps.getKeyBindings().filter(k =>
          // Check exists because builtin sources aren't valid paths, e.g. 'core:...'
          fs.existsSync(k.source) &&
          // Use realpath in case any ~/.atom/packages/foo are symlinks
          fs.realpathSync(k.source).startsWith(`${atom.packages.resolvePackagePath('hydrogen-extras')}/keymaps/`)
        )
      )),
t9md commented 6 years ago

After checking your package and usage of buildCommandSpecsFromKeyBindings, what you want is service provided by keystroke pkg. I don't want keystroke pkg's function directly imported and used by outer-pkg. It will be break when I forget it is used in other place.

So I will provide service function which you can depend on from your pkg. Give me one or two days for that.

To be clear. I won't merge this PR, but will keep open until I implement service feature.

jdanbrown commented 6 years ago

Sounds great! This definitely felt like a brittle hack, and I'd be happy to rely on a proper service instead.

t9md commented 6 years ago

Will close, and see changes in #10 and updated readme to check how to use.