@clk, @cl - Last key or command name
@cck, @cc - Current key or command name
@cgk, @cg - Get a key or command name from the user
@cqk, @cq - Get a quoted key or command name from the user
The Command Variables allow macros to obtain MicroEmacs '06 input commands and keystrokes from the user. The general format of the command is:-
The @cl, @clk, @cc and @cck variables can also be set, this feature can be used by macros to change the command history. While setting the current command is limited in use, setting the last command can be immensely useful, consider the following macro code:-
kill-line forward-line set-variable @cl kill-line kill-line
Without the setting of the @cl variable, the current kill buffer will contain only the last line. But the setting of @cl to kill-line fools MicroEmacs into thinking the last command was a kill command so the last kill line as appended to the current yank buffer, i.e. the kill buffer will have both lines in it.
This feature can be used for any command whose effect depends on the previous command. Such commands include forward-line(2), kill-region(2), reyank(2) and undo(2). This feature should not be abused as unexpected things may happen.
The following example shows how the @cc and @cl commands are used:-
define-macro current-last-command insert-string &spr "Last key [%s] name [%s]\n" @clk @cl insert-string &spr "Current key [%s] name [%s]\n" @cck @cc !emacro
Pressing the up key and then executing this macro using execute-named-command (esc x) will insert the lines:-
Last key [up] name [backward-line] Current key [esc x] name [execute-named-command]
@cg like @cq gets a single character input, however if the keyboard input is bound to a function then the function name is returned instead of the character e.g. if ^F or <left-arrow> is depressed then forward-char is returned. This has distinct advantages over @cq as the binding becomes device independent and executes on all platforms, additionally it honors the users bindings, however bizarre.
@cq provides a low level character input mechanism, obtaining a single raw character input from the user. This does not interact with the message line and the user is not prompted for input (use ml-write(2) to create your own message). @cq is very low level, it is generally preferable to use @cg which provides a more intelligent binding.
The following example is taken from draw.emf which uses @cg to obtain cursor movements from the user. Note how the input from @cg (stored in variable %dw-comm) is compared with the binding name rather than any keyboard characters.
!repeat 0 screen-update !force set-variable #l0 @cg !if &seq #l0 "abort-command" !if &iseq @mc1 "Really quit [y/n]? " "nNyY" "y" find-buffer :dw-buf 0 delete-buffer "*draw*" -1 buffer-mode "view" !abort !endif !elif &seq #l0 "newline" . . !elif &seq #l0 "forward-line" 1 draw-vert !elif &seq #l0 "backward-line" -1 draw-vert !elif &seq #l0 "forward-char" 1 draw-horz !elif &seq #l0 "backward-char" -1 draw-horz !elif &seq #l0 "osd" .osd.draw-help osd !elif &set #l1 &sin #l0 "mdeu-=" !if &les #l1 5 set-variable :dw-mode &sub #l1 1 set-variable :dw-modes #l0 draw-setmode-line !elif &sin #l0 "-=" set-variable :dw-char #l0 draw-setmode-line !endif !else ml-write "[Invalid command]" !endif !until 0
Copyright (c) 1998-2006 JASSPA
Last Modified: 2002/01/11
Generated On: 2006/10/07