mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-22 19:11:40 +03:00
b2cff3f420
Parse entries out of the cmds array in normal.cc, then generate a sorted list of key bindings as an HTML table.
62 lines
1.3 KiB
Ruby
Executable File
62 lines
1.3 KiB
Ruby
Executable File
#!/usr/bin/env ruby
|
|
|
|
# Generate a reference sheet for Kakoune's normal mode
|
|
# Use: ./kakmap.rb ../src/normal.cc
|
|
|
|
require 'markaby'
|
|
|
|
# Relies on the cmds array assignment ending with };
|
|
raw = ARGF.read.split( /cmds\[\] =\s+{\s*/m ).last.split( /^};$/ ).first
|
|
|
|
commands = {}
|
|
|
|
# break code into lines
|
|
raw.split( /\n+/ ).each{ |line|
|
|
line.gsub!( /(^\s*{\s*|\s*},?\*$)/, '' ) # discard wrapping for array elements
|
|
|
|
mod = (line.scan( /^alt|^ctrl/ ).first || 'none').to_sym
|
|
key = line.scan(/(?:^Key::(\w+)|(?<!\\)'\\?(.*?)(?<!\\)')/).flatten.compact.first
|
|
des = line.scan(/(?<!\\)"(?<desc>.*?)(?<!\\)"/).flatten.first
|
|
|
|
key = 'Space' if key == ' '
|
|
|
|
commands[key] ||= {}
|
|
commands[key][mod] = des
|
|
}
|
|
|
|
# sort, showing single characters first, symbols next and spelled out keys last
|
|
commands = commands.sort_by{ |key, _|
|
|
case key
|
|
when /^\w$/
|
|
key.upcase + key.swapcase
|
|
when /^\W$/
|
|
'_' + key
|
|
else
|
|
'~~' + key
|
|
end
|
|
}
|
|
|
|
puts Markaby::Builder.new {
|
|
table do
|
|
thead do
|
|
tr do
|
|
th "Key"
|
|
th "Description"
|
|
th "ALT + key"
|
|
th "CTRL + key"
|
|
end
|
|
end
|
|
tbody do
|
|
for key, binding in commands
|
|
tr do
|
|
th key
|
|
td binding[:none]
|
|
td binding[:alt]
|
|
td binding[:ctrl]
|
|
end
|
|
end
|
|
end
|
|
end
|
|
}
|
|
|