1 ; file: list-keys-dmn.scm
 2 ; type: lepton-schematic Guile script
 3 ; version: 1.1
 4 ; copyright (c) 2019-2020 dmn <graahnul.grom@gmail.com>
 5 ; license: GPLv2+
 6 ;
 7 ; Prints current lepton-schematic key bindings to stdout
 8 ;
 9 ; Usage:
10 ; Run lepton-schematic in terminal and type in File->REPL:
11 ;   ( primitive-load "/path/to/list-keys-dmn.scm" )
12 ;
13 
14 ( use-modules ( schematic gui keymap ) )
15 ( use-modules ( schematic keymap ) )
16 ( use-modules ( schematic action ) )
17 
18 
19 ; function: print-keymap()
20 ;
21 ( define* ( print-keymap kmap #:optional (indent 0) )
22 
23   ; auxiliary local functions:
24 
25   ( define ( print-indent ind )
26     ( while ( > ind 0 )
27       ( format #t "  " )
28       ( set! ind (1- ind) )
29     )
30   )
31 
32   ( define ( print-key key )
33     ( format #t "~a" (key->display-string key) )
34   )
35 
36   ; NOTE: BLPP: do not pass #:module to eval-string()
37   ;
38   ( define ( print-action action )
39   ( let*
40     (
41     ( action-str     (format #f "~a" action) )
42     ( action-sym-str (format #f "'~a" action-str) )
43     ( action-sym     (eval-string action-sym-str) )
44     ; perform check to avoid "undefined sym" error, e.g.
45     ; if key is bound to undefined action:
46     ( action-obj
47       ( if ( defined? action-sym )
48         ( eval-string action-str ) ; if
49         #f                         ; else
50       )
51     )
52     )
53 
54     ( format #t "~20t= ~a" action )
55     ( if ( action? action-obj )
56       ( format #t " (~a)" ( action-property action-obj 'label ) ) ; if
57       ; debug: ( format #t " ---------- NOT AN ACTION" )          ; else
58     )
59     ( format #t "~%" )
60   )
61   )
62 
63 
64   ; function body:
65 
66   ( format #t "~%" )
67 
68   ( keymap-for-each
69     ( lambda( key action-or-keymap )
70 
71       ( print-indent indent )
72       ( print-key key )
73 
74       ( if ( keymap? action-or-keymap )
75         ( print-keymap action-or-keymap (1+ indent) ) ; if
76         ( print-action action-or-keymap )             ; else
77       )
78 
79     )
80     kmap
81   )
82 
83 ) ; print-keymap()
84 
85 
86 ; top-level code:
87 ;
88 ( print-keymap %global-keymap )
89