step towards cheat sheet generation

This commit is contained in:
Jean-Philippe Bernardy 2016-11-13 14:45:10 +01:00
parent 0ebc0658ca
commit 54e9e3b8e3
3 changed files with 35 additions and 7 deletions

1
.gitignore vendored
View file

@ -12,3 +12,4 @@ TAGS
/.stack-work /.stack-work
/boon.elc /boon.elc
/Colemak.hs

View file

@ -11,6 +11,13 @@ cheat.pdf: cheat-sheet.hs
test: test:
$(emacs) -batch --script boon-test.el $(emacs) -batch --script boon-test.el
Colemak.hs:
$(emacs) -batch \
--eval "(add-to-list 'load-path (expand-file-name \".\"))" \
--eval "(package-initialize)" \
-l boon-tutorial.el \
--eval '(boon-dump-cheatsheet "colemak")'
clean: clean:
rm -f *.elc rm -f *.elc

View file

@ -11,11 +11,12 @@
(require 'dash) (require 'dash)
(defun boon-dump-map (map) (defun boon-dump-map (map)
"Dump the MAP in a format usable to generate a cheat sheet. "Dump the MAP in a format usable to generate a cheat sheet."
Currently unused." (apply
(apply 'concat 'concat
(--map (format "('%c',\"%S\"):" it (--map (let* ((b (lookup-key map (make-vector 1 it)))
(let ((b (lookup-key map (make-vector 1 it)))) (mn (boon-mnemonic-noformat b map)))
(format "(%d,%S,\"%S\"):" it mn
(cond ((symbolp b) b) (cond ((symbolp b) b)
((eq b boon-x-map) 'x-map) ((eq b boon-x-map) 'x-map)
((eq b boon-goto-map) 'goto-map)) ((eq b boon-goto-map) 'goto-map))
@ -26,6 +27,20 @@ Currently unused."
'(?\; ?: ?- ?' ?, ?. ?< ?>) '(?\; ?: ?- ?' ?, ?. ?< ?>)
)))) ))))
(defun boon-dump-cheatsheet (flavour)
"Dump cheatcheat info for FLAVOUR."
(let ((module (capitalize flavour))
(el (concat "boon-" flavour ".el")))
(require 'boon)
(load el)
(with-temp-buffer
(insert (format "module %s where \n " module))
(insert (format "nil = \"\"\n"))
(insert (format "commandMap = %s:[]\n" (boon-dump-map boon-command-map)))
(insert (format "movesMap = %s:[]\n" (boon-dump-map boon-moves-map)))
(insert (format "selectMap = %s:[]\n" (boon-dump-map boon-select-map)))
(write-region nil nil (concat module ".hs")))))
(defun boon-keymap-rev-look (sub map) (defun boon-keymap-rev-look (sub map)
"Return an event yielding SUB from the keymap MAP." "Return an event yielding SUB from the keymap MAP."
(let (res) (let (res)
@ -35,7 +50,7 @@ Currently unused."
map) map)
(key-description (vector res)))) (key-description (vector res))))
(defun boon-mnemonic (sub &optional map) (defun boon-mnemonic-noformat (sub &optional map)
"Return the mnemonic for SUB from the keymap MAP." "Return the mnemonic for SUB from the keymap MAP."
(let (res) (let (res)
(map-keymap (lambda (_event b) (when (and (consp b) (map-keymap (lambda (_event b) (when (and (consp b)
@ -43,7 +58,12 @@ Currently unused."
(eq (cdr b) sub)) (eq (cdr b) sub))
(setq res (car b)))) (setq res (car b))))
(or map boon-command-map)) (or map boon-command-map))
(format "(mnemonic: %s)" res))) res))
(defun boon-mnemonic (sub &optional map)
"Return the formatted mnemonic for SUB from the keymap MAP."
(format "(mnemonic: %s)" (boon-mnemonic-noformat sub map)))
;; utilities to create the tutorial ;; utilities to create the tutorial