File: keymapping.tex

package info (click to toggle)
geda-doc 20020209-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 112 kB
  • ctags: 12
  • sloc: makefile: 27
file content (193 lines) | stat: -rw-r--r-- 6,838 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
% gEDA - GNU Electronic Design Automation
% keymapping.tex - Key mapping documentation
% Copyright (C) 1999-2000 Stefan Petersen
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

\documentclass[a4paper]{article}

\usepackage{tabularx}

\setlength{\parindent}{0pt}
\setlength{\parskip}{1ex plus 0.5ex minus 0.2ex}

\title{How To Setup Keymapping In gschem}
\author{Stefan Petersen, spe@geda.seul.org\\
	{\tiny This document is released under GPL 
	(http://www.fsf.org/copyleft/gpl.html)}}
\date{1999-07-24}


\begin{document}

\maketitle

\section*{About this document}
The purpose of this document is to try to explain how key mapping 
works in gEDA/gschem schematic entry program. It uses the langauge
Scheme a lot, which is a Lisp-dialect and is used in gschem as a
scripting language. If you're not familiar with this language, please
see the dictionary (see appendix \ref{dict}, page \pageref{dict},
for a short description of common data structures used in Scheme.


\section{Functionality}
When you press a button in gschem, a Scheme function is called.
This function (\texttt{press-key}) accepts one argument, the name of 
the pressed key. Then there are Scheme routines to evaluate which key 
you pressed and call the appropriate action.

Since the evaluation routines are written in Scheme it's simple to change
the behaviour of what happens when you presses a key. You can 
implement macros or do several things at each key press. For example,
the ``repeat-last-key command is implemented completly in Scheme.


\section{Keymaps}
The current implementation is built-up around ``keymaps''. A keymap is
a list with pairs. Each pairs first element (the car-element) is which 
key to react on, and the second element (cdr) is a ``what-to-do-next''. 
This can either be an action, a function to call or another keymap.


\subsection{An example on keymaps}
Two simple examples of keymaps is seen in figure \ref{example1} and
figure \ref{example2}.

\begin{figure}[ht]
\begin{verbatim}
(define global-keymap
  '(("Escape" . cancel)
    ("a" . add-keymap)))
\end{verbatim}
\caption{First example of an simple keymap}
\label{example1}
\end{figure}

In figure \ref{example1} is the keymap called \texttt{global-keymap}. 
This keymap is the first keymap used. If you for example press the 'a'-key,
\texttt{global-keymap} tells us that next key pressed will be interpreted
by \texttt{add-keymap} (see figure \ref{example2}).

\begin{figure}[ht]
\begin{verbatim}
(define add-keymap
  '(("c" . add-component)
    ("a" . add-attribute)
    ("n" . add-net-hotkey)))
\end{verbatim}
\caption{Second example of an simple keymap}
\label{example2}
\end{figure}


If you, after you pressed 'a', press a 'c' the built-in action 
\texttt{add-component} comes to live. This is exactly what had happend
if you had selected Add, Component\ldots in the menubar.

When an action has been performed the current keymap is reset back to\\
\texttt{global-keymap}.

Available built-in actions are listed in appendix \ref{builtins}.


\subsection{Description of keys}
The key are described as:

\begin{tabular}{lcl}
For a & -- & ``a''\\
For Shift-A & -- & ``Shift A''\\
For Control-a & -- & ``Control a''\\
For Alt-a &-- & ``Alt a''\\
\end{tabular}

There are a few simple rules to follow when keys for a new keymap is
defined:
\begin{itemize}
\item Everything is case sensitive
\item  At this point in time you can only have one modifier 
       (shift, control, alt) at a time.
\item Keys must be unique in each keymap, especially the global one 
\item Strings (without any modifers) are the same strings specified
      for the keys in the file /usr/lib/X11/XKeysymDB (at least on 
      a linux box)
\end{itemize}


\subsection{Actions}
The built-in actions that can be called are listed in appendix 
\ref{builtins}.

Sometimes you may notice that there are similar actions, like
\texttt{ edit-rotate-90} and \texttt{ edit-rotate-90-hotkey}.
They do the same thing, just that the \texttt{-hotkey} actions is
run immediately, while the other wait for you to select 
something.


\subsection{Function calls}
If the cdr-element is an ordinary Scheme function that function is called. 
The function can't receive any arguments.

This can be used if you want to do complex tasks, like several actions
in a row or do some calculation. You can do rather advanced actions since
the Guile dialect of Scheme used in gschem is extended from plain Scheme.
For further information on Guile, please see the Guile documentation.

\subsection{Another keymap}
If the cdr-element is another keymap then that command is a multi-key command,
ie you need to press at least two keys to cause an action. The first key is
desribed in the first keymap, which points to the next keymap. The 
second keymap describes what should happen when the second key is pressed.


\section{Where are the key mappings stored}
The keymap is stored in the startup file for gschem, namely\\
\texttt{<startpath, typically /usr/local>/share/gEDA/system-gschemrc}.

You can then redefine or add keymaps as you like (I think) in your local
setup file for gschem,\\
\texttt{\~{}/.gEDA/gschemrc}

The Scheme functions used to resolve keypresses to actions are stored at\\
\texttt{<startpath, typically /usr/local>/share/gEDA/scheme/gschem.scm}.\\
This is configurable in the \texttt{gschemrc} files.


\newpage

\appendix

\section{Dictionary\label{dict}}

\begin{tabularx}{\linewidth}{lX}
\textbf{function} & A subprogram in Scheme, C or other programming 
languages. \\
\textbf{action} & What gschem (in this case) does when you press a key or a set
of keys. \\
\textbf{list} &  A data structure very common in Lisp-looking languages like 
Scheme. Simply put, a long list of values.\\
\textbf{pair} & (also dotted pair) A datstructure also very common in 
Lisp-looking languages.\\
\textbf{car element} & First element in a pair. Since lists are decendents 
from pairs, \texttt{car} is also the first element in a list. \\
\textbf{cdr element} & (pronounced \emph{cudr}) The second element in a pair. 
In the list case it denotes the rest of list.\\
\end{tabularx}

\newpage
\section{Built-in actions in gschem\label{builtins}}
\input{available-keys}
\end{document}