Merge remote-tracking branch 'kawas44/fix-kakmap-script'

This commit is contained in:
Maxime Coste 2017-08-29 07:58:33 +07:00
commit a06dbfac7d

View File

@ -5,23 +5,35 @@
require 'markaby'
# Relies on the cmds array assignment ending with };
raw = ARGF.read.split( /cmds\[\] =\s+{\s*/m ).last.split( /^};$/ ).first
# Relies on the keymap HashMap assignment ending with };
raw = ARGF.read.split( /const\s+HashMap<Key,\s*NormalCmd>\s+keymap\s*{/ ).last.split( /^};$/ ).first
commands = {}
# break code into lines
raw.split( /\n+/ ).each{ |line|
line.gsub!( /(^\s*{\s*|\s*},?\*$)/, '' ) # discard wrapping for array elements
# skip empty or comment line
line = line.strip
if line.empty? or /^\/\// =~ line
next
end
mod = (line.scan( /^alt|^ctrl/ ).first || 'none').to_sym
key = line.scan(/(?:^Key::(\w+)|(?<!\\)'\\?(.*?)(?<!\\)')/).flatten.compact.first
des = line.scan(/(?<!\\)"(?<desc>.*?)(?<!\\)"/).flatten.first
# match key mapping line
/^\{\s*\{(?<mdky>[^}]+)\}\s*,\s*\{\s*"(?<dsc>[^"]+)"/.match(line) do |m|
modAndKey = m['mdky']
des = m['dsc']
modAndKey.gsub!(/\s*\/\*[^*]+\*\/\s*/, '') # remove comment in key definition
# match key and modifier
/Key::(?<key>\w+)|(?<mod>alt|ctrl)\('\\?(?<key>.+?)'\)|'\\?(?<key>.+?)'$/.match(modAndKey) do |sm|
key = sm['key']
mod = (sm['mod'] || 'none').to_sym
key = 'Space' if key == ' '
commands[key] ||= {}
commands[key][mod] = des
end
end
}
# sort, showing single characters first, symbols next and spelled out keys last
@ -37,7 +49,12 @@ commands = commands.sort_by{ |key, _|
}
puts Markaby::Builder.new {
table do
html do
head do
title "Kakoune default keymap"
end
body do
table :style => "border-collapse: collapse" do
thead do
tr do
th "Key"
@ -48,7 +65,7 @@ puts Markaby::Builder.new {
end
tbody do
for key, binding in commands
tr do
tr :style => "border-bottom: 1px solid #fbfbfb" do
th key
td binding[:none]
td binding[:alt]
@ -57,5 +74,7 @@ puts Markaby::Builder.new {
end
end
end
end
end
}