# MacroNumericArguments(4)

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

## NAME

@#, @? - Macro numeric arguments

## SYNOPSIS

@# - The numerical argument to a macro
@? - The truth of the numerical argument to a macro

## DESCRIPTION

All built-in commands and macros are invoked with a numerical argument. The argument is obtained from either the command line when the user invokes a command line such as:

esc 5 esc x forward-char

where the argument is entered after prefix 1 (esc). In this case, causing the cursor to be moved forward 5 characters. Within a macro file the same operation is defined as:-

5 forward-char

In both cases the numerical argument 5 is passed to the command requesting that the resultant operation is performed 5 times in succession before returning. The command itself is invoked once, it is the responsibility of the command to iterate if requested.

The command determines how the numerical argument is interpreted, in the case of spell-word the argument identifies the type of word that is being spelled and NOT the number of words to spell.

The invocation of named macros operate in the same way, the macro may use the variables @? and @# to determine the status of the numerical argument passed to it. The variables are interpreted as follows:

@?

A logical value defined as `TRUE` (1) if a numerical argument has been specified, otherwise `FALSE` (0).

@#

A signed integer value of the supplied numeric argument. If no argument is supplied (i.e. @?==`FALSE`) then @# is set to 1.

The @? and @# are only valid for the current macro invocation. Other macros or commands that are invoked have their own values of @? and @#.

## EXAMPLE

Consider the following example, which sorts lines into alphabetical order using the sort-lines(2) function. A new command sort-lines-ignore-case is created using a macro to sort lines case insensitively regardless of the current buffer mode. The command sort-lines takes an optional argument which determines which column should be used to perform the sort.

    ;
    ; sort-lines-ignore-case
    ; Sort lines case insensitively regardless of the current 'exact' mode
    ; setting.
    define-macro sort-lines-ignore-case
        set-variable #l0 &bmod exact
        -1 buffer-mode "exact"
        !if @?
            @# sort-lines
        !else
            sort-lines
        !endif
        &cond #l0 1 -1 buffer-mode "exact"
    !emacro

@? is used to test the presence of the argument, if it is false sort-lines is invoked without an argument. When true the numeric argument is propagated e.g. @# sort-lines.

This particular macro highlights an important consideration when passing the numerical argument to other functions, had the macro been implemented as:

    ; INCORRECT IMPLEMENTATION
    define-macro sort-lines-ignore-case
        set-variable #l0 &bmod exact
        -1 buffer-mode "exact"
        @# sort-lines
        &cond #l0 1 -1 buffer-mode "exact"
    !emacro

then when sort-lines-ignore-case is invoked with no arguments @# is defined as 1, this is would be incorrectly propagated to sort-lines causing it to sort on column 1 rather than column 0 as expected.

## SEE ALSO

MacroArguments, define-macro(2).

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

</HMTL>