Sublime Forum

Get merged current keymap

#1

I want to write plugin that will automatically generate localized keymaps. e.g. it will create russian [“ctrl+ф”] copy for existing [“ctrl+a”].

Is there exist function/command that return merged current keymap?
Or I need to use find_resources and repeat sublime logic for merge all existing keymaps in correct order?
Or maybe exist other way to do what I need?
Or I don’t need to do this, because localized keymaps can be switched-on from settings?

0 Likes

#2

And what means pattern in sublime.find_resources description? Can I write optional parts in this pattern like this: Default( ${platform})?.sublime-keymap

0 Likes

#3

Not that I’m aware of, no. You would indeed have to manually load the files and merge their contents yourself. However, sublime.decode_value() can turn a loaded keymap file into a JSON object and sublime.find_resources() can find all of the files (and returns them in the order they would be merged).

sublime.find_resources("*.sublime-keymap") would find every keymap, while sublime.find_resources("*(OSX).sublime-keymap") would only find the OSX specific ones, for example.

You can’t provide the variable ${platform} because find_resources() doesn’t expand variables. You could however do the following to find only the files for the current platform (i.e. expand the variable yourself).

spec = "*(${platform}).sublime-keymap"
res_name = sublime.expand_variables(spec, window.extract_variables())
sublime.find_resources(res_name)

However for a proper result you probably need to find all of the resource files and then exclude any of the platform specific ones that aren’t for the current platform as you go through the list, or you may end up merging things in the wrong order.

0 Likes

#4

this is great news! The order of merging is main problem of this plugin. Thank you.

0 Likes