Class key_binding is a subclass of class recogniser. It accepts keyboard events and maps them onto messages.
Class key_binding deals with
<-prefix)
<-argument).
<-saved_column).
Key_binding objects are used by various classes that are sensitive to keyboard events: editor, text, text_item and list_browser.
The following example shows how a key_binding object may be used to make a graphical object editable using the mouse:
send(new(P, picture('Graphical editor')), open),
send(P, display, new(B, box(100,100))), send(B, recogniser,
new(K, key_binding(@nil,
argument))), send(K, function, ’TAB’, message(@receiver,
inverted,
@receiver?inverted?negate)),
send(K, function, ’\C-d’, free), send(K,
function, ’\C-p’, pen).
Typing TAB (= control-I), the box is inverted; typing control-d will
delete the graphical; typing META-3 control-p will make the pen
(thickness) of the line 3. See key_binding<-argument
on how to specify the universal numeric argument.
How a key_binding parses a keyboard event is described with key_binding->typed;
The specification of symbolic key-names is described with key_binding->function;
Resolution of a binding from a symbolic key is described with<-function;
Predefined binding tables are described with key_binding->initialise.
See also
@key_bindings.
The library keybinding.pl defines show_key_bindings/1,
which shows the keys of an object or table in a browser. It is opened
with Settings/Key bindings in the IDE and with Control-H b
in PceEmacs. The keys are grouped by the table that binds them, starting
with the most specific one. Selecting a key shows the documentation of
the method it invokes, and the controls to change it:
->fill_arguments_and_execute).
Built-in methods are offered if their group is one of commands, such as
caret, delete or search; a method
defined in Prolog if it refines such a method or is bound to a key
elsewhere. The functions are listed with their summaries. Typing filters
them on name and summary, the menu next to the filter limits them to the
methods of one class, and selecting one shows its documentation.
Double-click or Bind to bind the selected function, or type the
name of a function that is not listed.
Selecting the header of a table says what the table is and where the keys you change are saved. Add key binds a new key in it: type the key, then choose the function.
Change in selects the table that is changed, by default the one that binds the key. The changes apply at once. Save writes them to the Defaults file, Revert goes back to what the Defaults file says, and Edit defaults file opens it in the editor.
The keys the user binds in a named table are the class variable
key_binding.<table>: a list of Key := Function, where
the function
none unbinds the key. For example:
key_binding.epilog: [ '\C-jq' := paste, \
'<f6>' := none \
]
Keys are written as for key_binding->function,
but with a single backslash: the Defaults file reads text between quotes
as is. A $ in the name of a table is written as _, e.g., key_binding.emacs_prolog
for the table
emacs$prolog. Class key_binding
declares these class variables for the tables it defines, such as editor
and text_item; for other tables key_binding<-user_bindings_variable
creates it when the table asks for it. These bindings are applied by key_binding->apply_preferences,
after those of the style, so they win. The key binding browser of
library keybinding.pl maintains them.
\e0 .. \e9 and \e- are bound
to the function digit_argument the universal argument may be composed by
typing its value with the META-key held down.
universal_argument,
followed by the digits to construct its value.
The predefined key_binding name argument binds \e0
.. \e9 and \e- to
digit_argument and \C-u to universal_argument.
Using this table, the following sequences are examples for entering a
universal_argument:
Sequence Value \e1\e414 \C-u5656
->function.
The function is either a name, in which case the key-binding will invoke
the named method on the
event-receiver,
or a code object.
|code*<-bindings
nor one of the key_binding<-defaults
key_bindings define a binding for the typed key.
A common way to use this facility is to declare key_binding<->default_function
to
alert. Any unknown keys will then be mapped onto the method
graphical->alert.
prefix
this variable is set to this key.
The predefined table emacs_special binds \e, \C-c
and \C-x to the function prefix.
->event.->bind_resources,
which applies modifications from class-variables as defined in the XPCE
Defaults file. The Prolog library refines it: it applies the key binding
style and key_binding->apply_user_bindings,
which reads the same class variables but remembers the bindings it
replaces.name is not
specified the key_binding<-name
of the binding table is used. For example, to bind ^S to save
in editor objects use
the following line in ~/.xpce/Defaults:
key_binding.editor = \
[ '\\C-s' = save \
]
none
unbinds the key; @nil
restores the binding the table had before the user changed it. This does
not save the Defaults file.->user_binding.->event
method.
If the event is a subtype of event-type keyboard this
method invokes
key_binding->typed: event<-id, event<-receiver.
->fill_arguments_and_execute.
It simply invokes the method selector on receiver
with the given arguments. This method may be redefined to take action
before or after invoking a method on the receiver:
execute(KB, Rec:object, Sel:name, Args:any ...) :->
<before-refinement>
send(KB, send_super_vector, execute, Rec, Sel, Args),
<after-refinement>.
See also object->send_super_vector.
->typed.
The key_binding
object should send a message to receiver named selector.
arguments is a partial argument list. This method collects
possible additional arguments:
If an argument of the send-method does not accept @default,
<-receiver defines
the method key_binding<-interactive_argument,
this method will be invoked using the following arguments:
1-st: Behaviour object implementing the method 2-nd: Ordinal number of the argument required
This method should return a value for the argument or fail.
If no argument can be found, the error no_argument is raised.
When all arguments are gathered, key_binding->execute
is activated.
|event_id,
action=name|codeWhen an event_id is passed it will be converted into the corresponding symbolic key-name. The symbolic key-names for the characters
Symbolic name ASCII Description \C-@ ...\C-h0..8 Control-characters TAB 9 The tab-key or control-I LFD 10 The linefeed-key or control-J \C-k ..\C-l11..12 Control-characters RET 13 The return-key or control-M \C-n ...\C-z14..26 Control-characters \e27 The escape-key or control-[ \C-\...\C-_28..31 Control-characters SPC 32 The space-bar @ ... ~33..126 Normal printable characters DEL 127 The delete-key
A key typed with the meta (Alt) key held down is named \e,
followed by the name of the key without meta. The event's key_binding<-id
is the plain character; the meta key is in its key_binding<-buttons.
<-defaults). PCE predefines
some names. If a table with a predefined name is created the table will
be initialised according to this name. Tables that do not have a
predefined name are initially empty.
The predefined table-name are:
insert_self to all printable
characters and the TAB, LFD and RET keys.
digit_argument to \e0 ... \e9
and \e-; assigns
universal_argument to \C-u.
prefix to \e, \C-c and \C-x; ‘keyboard_quit
to \C-g
\C-v; \ev; \C-l
<-receiver to the
argument graphical; key_binding<-prefix
to ” and
key_binding<-argument
to @default.
Defaults: When no graphical is specified, key_binding<-receiver
is set to @nil.
|event_id,
for=[object]event(-id) of a keyboard event
object arrived on the given graphical. It performs the following steps:
graphical is specified and not equal to key_binding<-receiver,
invoke key_binding->reset
and set key_binding<-receiver to graphical.
key by appending the symbolic name of the
typed character to the current key_binding<-prefix.
Determine the binding of this key using key_binding<-function.
<-prefix
with the current key.
->reset
to clear key_binding<-prefix
and key_binding<-argument
next_line, previous_line<-saved_column
equals @default,
set it to the current column by invoking key_binding<-column
on the receiver.
\e0 ... \e9 or \e-,
set the key_binding<-argument.
<-argument.
First time: set
key_binding<-argument
to 4; afterwards: multiply key_binding<-argument
by
<-send_method.
Next specify the arguments according to their argument-type:
<-argument
when specified
Finally, key_binding->typed
invokes key_binding->fill_arguments_and_execute
to fill additional arguments, which in turn calls key_binding->execute
to send a message to the key_binding<-receiver.
If the key-binding is a code
object, key_binding->forward this code
object with the following arguments:
@receiver key_binding <-receiver@arg1 key_binding <-argument@arg2 the argument event -id
Finally on behalf of uniting Emacs and Windows users with the editor,
if a key is bound to the function prefix_or_copy or prefix_or_cut, the
system invokes editor->cua_key_as_prefix
on the receiver. If this method succeeds the key acts as prefix and
otherwise it is mapped to the functions cut or copy.
Defaults: If no graphical is specified, key_binding<-receiver
left unmodified.
If the name cannot be found in @key_bindings
but it is the name of a predefined table (see key_binding<-initialise), key_binding<-convert
will create a table and initialise it.
|name|event_id -> name|code->typed.
It performs the following steps:
<-bindings.
Return the result if found.
<-bindings
of the key_binding<-defaults tables
(recursively). If found somewhere return the result.
<-default_function
when not @nil.
<-default_function
in the key_binding<-defaults tables.
->typed