summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZak Greant <zak@greant.com>2015-08-15 12:45:10 +0200
committerZak Greant <zak@greant.com>2015-08-15 12:45:10 +0200
commitb2cff3f42086e3ab63f8d2d8df7dd48d42e25938 (patch)
tree4ae686a6c2cfdf8a33956e3bbb7ab887169312fe
parent821143968581bbdfee5ddae20b58d77cc202ea7f (diff)
Generate normal mode reference
Parse entries out of the cmds array in normal.cc, then generate a sorted list of key bindings as an HTML table.
-rwxr-xr-xcontrib/kakmap.rb61
1 files changed, 61 insertions, 0 deletions
diff --git a/contrib/kakmap.rb b/contrib/kakmap.rb
new file mode 100755
index 00000000..33b61639
--- /dev/null
+++ b/contrib/kakmap.rb
@@ -0,0 +1,61 @@
+#!/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
+}
+