# CommandVariables(4)

[Home] [Commands] [Variables] [Macro-Dev] [Glossary]

## NAME

@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

## SYNOPSIS

@clk
@cl
@cck
@cc
@cgk
@cg
@cqk
@cq

## DESCRIPTION

The Command Variables allow macros to obtain MicroEmacs 2009 input commands and keystrokes from the user. The general format of the command is:-

@c i[k]

Where,

i

Determines the source of the input as follows:-

l

The last input entered.

c

The current input entered.

q

Provides a low level character input mechanism, obtaining a single raw character input from the user. The input fetch 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.

g

Like @cq, @cg[k] gets a single character input, however if the 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. In addition, it honors the users bindings, however bizarre.

k

When, omitted command input is returned to the caller (i.e. the name of the command, such as "`forward-char`"). When present, the raw keystroke is returned to the caller, i.e. "`^F` (control-F).

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.

## Summary

@cl

Get or set the last command.

@clk

Get or set the last key stroke.

@cc

Get or set the current command.

@cck

Get or set the current keystroke.

@cg

Get a command name from the user.

@cgk

Get a keystroke from the user.

@cq

Get a quoted command name from the user.

@cqk

Get a quoted keystroke from the user.

## EXAMPLE

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.

## EXAMPLE

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

## SEE ALSO

@wc(4), &kbind(4), define-macro(2).

(c) Copyright JASSPA 2009
Last Modified: 2009/08/29
Generated On: 2009/10/12

</HMTL>