GNU Emacs Manual. Node: Position Info

PREVContinuation Lines UPBasic NEXTArguments

3.9: Cursor Position Information

Here are commands to get information about the size and position of parts of the buffer, and to count lines.

M-x what-page

Print page number of point, and line number within page.

M-x what-line Print line number of point in the buffer.
M-x line-number-mode Toggle automatic display of current line number.
M-= Print number of lines in the current region (count-lines-region). See Mark, for information about the region.
C-x = Print character code of character after point, character position of point, and column of point (what-cursor-position).

There are two commands for working with line numbers. M-x what-line computes the current line number and displays it in the echo area. To go to a given line by number, use M-x goto-line; it prompts you for the number. These line numbers count from one at the beginning of the buffer.

You can also see the current line number in the mode line; See Mode Line. If you narrow the buffer, then the line number in the mode line is relative to the accessible portion (see Narrowing). By contrast, what-line shows both the line number relative to the narrowed region and the line number relative to the whole buffer.

By contrast, M-x what-page counts pages from the beginning of the file, and counts lines within the page, printing both numbers. See Pages.

While on this subject, we might as well mention M-= (count-lines-region), which prints the number of lines in the region (see Mark). See Pages, for the command C-x l which counts the lines in the current page.

The command C-x = (what-cursor-position) can be used to find out the column that the cursor is in, and other miscellaneous information about point. It prints a line in the echo area that looks like this:

Char: c (0143, 99, 0x63)  point=21044 of 26883(78%)  column 53 

(In fact, this is the output produced when point is before the `column' in the example.)

The four values after `Char:' describe the character that follows point, first by showing it and then by giving its character code in octal, decimal and hex. For a non-ASCII multibyte character, these are followed by `ext' and the character's representation, in hex, in the buffer's coding system, if that coding system encodes the character safely and with a single byte (see Coding Systems). If the character's encoding is longer than one byte, Emacs shows `ext ...'.

`point=' is followed by the position of point expressed as a character count. The front of the buffer counts as position 1, one character later as 2, and so on. The next, larger, number is the total number of characters in the buffer. Afterward in parentheses comes the position expressed as a percentage of the total size.

`column' is followed by the horizontal position of point, in columns from the left edge of the window.

If the buffer has been narrowed, making some of the text at the beginning and the end temporarily inaccessible, C-x = prints additional text describing the currently accessible range. For example, it might display this:

Char: C (0103, 67, 0x43)  point=252 of 889(28%) <231 - 599>  column 0 

where the two extra numbers give the smallest and largest character position that point is allowed to assume. The characters between those two positions are the accessible ones. See Narrowing.

If point is at the end of the buffer (or the end of the accessible part), the C-x = output does not describe a character after point. The output might look like this:

point=26957 of 26956(100%)  column 0 

C-u C-x = displays additional information about a character, in place of the buffer coordinates and column: the character set name and the codes that identify the character within that character set; ASCII characters are identified as belonging to the ASCII character set. In addition, the full character encoding, even if it takes more than a single byte, is shown after `ext'. Here's an example for a Latin-1 character A with a grave accent in a buffer whose coding system is iso-2022-7bit[1]:

Char: Á (04300, 2240, 0x8c0, ext ESC , A @) (latin-iso8859-1 64)


[1] On terminals that support Latin-1 characters, the character shown after `Char:' is displayed as the actual glyph of A with grave accent.

PREVContinuation Lines UPBasic NEXTArguments