1 ;;; gEDA - GPL Electronic Design Automation
2 ;;; gschem - gEDA Schematic Capture
3 ;;; Copyright (C) 1998-2007 Ales Hvezda
4 ;;; Copyright (C) 1998-2007 gEDA Contributors (see ChangeLog for details)
6 ;;; This program is free software; you can redistribute it and/or modify
7 ;;; it under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 2 of the License, or
9 ;;; (at your option) any later version.
11 ;;; This program is distributed in the hope that it will be useful,
12 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with this program; if not, write to the Free Software
18 ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 ; guile 1.4/1.6 compatibility: Define an eval-in-currentmodule procedure
22 ; If this version of guile has an R5RS-compatible eval (that requires a
23 ; second argument specfying the environment), and a current-module function
24 ; (like 1.6) use them to define eval-cm. else define eval-cm to eval (for 1.4)
25 (if (false-if-exception (eval 'display (current-module)))
26 (define (eval-cm exp) (eval exp (current-module)))
27 (define eval-cm eval))
29 (define last-command-sequence #f)
30 (define current-command-sequence '())
40 (define (press-key key)
41 (eval-pressed-key current-keymap key))
43 (define (eval-pressed-key keymap key)
45 (let ((lookup (assoc key keymap)))
47 (if (not (equal? 'repeat-last-command (cdr lookup)))
48 (set! current-command-sequence
49 (cons key current-command-sequence)))
50 (perform-action (cdr lookup)))
52 (set! current-keymap global-keymap)
53 ;(display "No keymap found")
58 (define (perform-action action)
59 (let ((local-action (eval-cm action)))
60 (cond ((list? local-action)
61 (set! current-keymap local-action))
62 ((equal? 'repeat-last-command action)
63 (repeat-last-command))
65 (set! last-command-sequence current-command-sequence)
66 (set! current-command-sequence '())
68 (set! current-keymap global-keymap)))))
70 (define (repeat-last-command)
71 ;; need to `reverse' because the sequence was "push"ed initially
72 ;(display last-command-sequence)
74 (and last-command-sequence
75 (not (null? last-command-sequence))
76 (for-each press-key (reverse last-command-sequence))))
78 (define (eval-stroke stroke)
79 (let ((action (assoc stroke strokes)))
81 ; (display "No such stroke\n")
85 ; (display "Scheme found action ")
88 ((eval-cm (cdr action)))
92 ;; Search the keymap for a particular scheme function and return the keys
93 ;; which execute this hotkey
97 (define find-key-lowlevel
99 (lambda (keymap function)
101 (lambda (mapped-key) ; Receives a pair
102 (if (list? (eval-cm (cdr mapped-key)))
104 (set! temp (car mapped-key))
105 (find-key-lowlevel (eval-cm (cdr mapped-key)) function)
108 (if (eq? (cdr mapped-key) function)
109 (set! foundkey (string-append temp (car mapped-key)))
120 ;; (display function) (newline)
121 (find-key-lowlevel global-keymap function)
122 (if (eq? (string-length foundkey) 0)
128 ;; Printing out current key bindings for gEDA (gschem)
130 (define (dump-current-keymap)
131 (dump-keymap global-keymap))
133 (use-modules (srfi srfi-13))
134 (define (dump-keymap keymap)
135 (let loop ((keymap keymap)
139 (let* ((entry (car keymap))
141 (action (eval-cm (cdr entry))))
142 (cond ((list? action)
143 (append (loop action (cons key keys))
144 (loop (cdr keymap) keys)))
146 (cons (cons (cdr entry)
147 (string-join (reverse (cons key keys)) " "))
148 (loop (cdr keymap) keys))))))))