Next: , Previous: , Up: Buffers   [Index]


7.4.2 Interactive Commands for Creating and Selecting Buffers

list-buffers &optional ARG (‘C-x C-b’)

Invoke the Buffer Menu. Display a list of existing buffers. With prefix argument ARG, show only buffers that are visiting files.

buffer-menu &optional ARG
buffer-menu-other-window

Switch to the Buffer Menu.

CRMBufferSizeModeFile
. the current buffer% read-only* modifiednamesizemajor modevisited file
> marked for displayS marked for saving
D marked for deletion
Icompleteglobal minor mode (‘M-x icomplete-mode’)

provides a convenient way to quickly select an element among the possible completions in a minibuffer. When enabled, typing in the minibuffer continuously displays a list of possible completions that match the string you have typed. At any time, you can type ‘C-j’ to select the first completion in the list. There are two ways to make an item first:

  1. You can type more of the completion name and thus narrow down the list;
  2. You can use ‘C-.’ and ‘C-,’ to rotate the list until the desired buffer is first.

‘M-<TAB>’ will select the first completion in the list, like ‘C-j’ but without exiting the minibuffer, so you can edit it further. This is typically used when entering a file name, where ‘M-<TAB>’ can be used a few times to descend in the hierarchy of directories.

icomplete-mode variable

nil to deselect; t to select.

ibuffer

Begin using Ibuffer to edit a list of buffers. Make a list of buffers and operate on them in Dired-like fashion. Type ‘h’ after entering ibuffer for more information.

switch-to-buffer BUFFER-OR-NAME (‘C-x b BUFFER’)

If called interactively, read the buffer name using ‘read-buffer’. The variable confirm-nonexistent-file-or-buffer determines whether to request confirmation before creating a new buffer. If BUFFER-OR-NAME is a string that does not identify an existing buffer, create a buffer with that name. If BUFFER-OR-NAME is ‘nil’, switch to the buffer returned by other-buffer (Return most recently selected buffer other than BUFFER).

WARNING: This is NOT the way to work on another buffer temporarily within a Lisp program! Use set-buffer instead. That avoids messing with the window-buffer correspondences.

switch-to-buffer-other-window (‘C-x 4 b BUFFER’)
switch-to-buffer-other-frame (‘C-x 5 b BUFFER’)
previous-buffer (‘C-x <LEFT>’)
next-buffer (‘C-x <RIGHT>’)
beginning-of-buffer (‘M-<’)

This function is for interactive use only; move point to the beginning of the buffer. With numeric arg N, put point N/10 of the way from the beginning.

end-of-buffer (‘M->’)

This function is for interactive use only; move point to the end of the buffer. With numeric arg N, put point N/10 of the way from the end. If the buffer is narrowed, this command uses the end of the accessible part of the buffer.

goto-char (‘M-g c’)
Function: goto-char position

Set point to POSITION. The beginning of the buffer is (point-min), and the end is (point-max).

POSITION

a number or marker indicating buffer position.

RETURN VALUE

POSITION

If narrowing is in effect, position still counts from the beginning of the buffer, but point cannot go outside the accessible portion. If position is out of range, goto-char moves point to the beginning or the end of the accessible portion.

To move point to the beginning (end) of the buffer, write:

(goto-char (point-min))
(goto-char (point-max))
forward-char backward-char
Function: forward-char &optional count

Move point COUNT characters forward (backward if COUNT is negative). Signal error if the beginning or ending of the buffer is reached.

COUNT

if nil, use a default value of 1.

forward-word backward-word
Function: forward-word &optional count

Move point forward (backward) COUNT words.

COUNT

if nil, default is 1.

RETURN VALUE

t; but if an edge of the buffer or a field boundary is reached, point is left there and the function returns nil.

forward-word-strictly backward-word-strictly

See above

goto-line LINE &optional BUFFER (‘M-g g’)

This function is for interactive use only (because it sets mark); in Lisp code use forward-line instead.

Go to LINE, counting from line 1 at beginning of buffer. If called interactively, a numeric prefix argument specifies LINE; without a numeric prefix argument, read LINE from the minibuffer.

If optional argument BUFFER is non-nil, switch to that buffer and move to line LINE there. If called interactively with C-u as argument, BUFFER is the most recently selected other buffer.

This function is usually the wrong thing to use in a Lisp program. What you probably want instead is something like:

(goto-char (point-min))
(forward-line (1- N))

If at all possible, an even better solution is to use char counts rather than line counts.

goto-line (‘C-u M-g M-g’)

reads a number N using the minibuffer, selects the most recently selected buffer other than the current buffer in another window, and then moves point to the beginning of line number N in that buffer.

This is mainly useful in a buffer that refers to line numbers in another buffer: if point is on or just after a number, ‘goto-line’ uses that number as the default for N.

Note that prefix arguments other than just ‘C-u’ behave differently. ‘C-u 4 M-g M-g’ goes to line 4 in the current buffer, without reading a number from the minibuffer.

forward-line &optional N
Function: forward-line &optional n

Move N lines forward (backward if N is negative). Precisely, if point is on line I, move to the start of line I + N. If there isn’t room, go as far as possible (no error).

N

number of lines to move;

RETURN VALUE

Returns the count of lines left to move. If moving forward, that is N minus number of lines moved; if backward, N plus number moved.

beginning-of-line

Move point to the beginning of current line. With argument N > 1, move forward ‘N - 1’ lines first. Stop when reaching the beginning or ending of the buffer without error.

line-beginning-position

Return the position that (beginning-of-line count) would move to.

RETURN VALUE

Return the character position of the first character on the current line. With optional argument N, scan forward N - 1 lines first. If the scan reaches the end of the buffer, return that position.

end-of-line

Move point to end of current line (in the logical order). With argument N not nil or 1, move forward N - 1 lines first. If point reaches the beginning or end of buffer, it stops there.

line-end-position

Return the character position of the last character on the current line. With argument N not nil or 1, move forward N - 1 lines first. If scan reaches end of buffer, return that position.

forward-line

Move N lines forward (backward if N is negative). If point is on line I, move to the start of line I + N. If there isn’t room, go as far as possible (no error).

Returns the count of lines left to move. That is, N minus moved lines.

count-lines start end

Return number of lines between START and END. This is usually the number of newlines between them.

count-words start end

Count words between START and END.

line-number-at-pos

Return buffer line number at position POS. If POS is nil, use current buffer location.

bobp

Return t if point is at the beginning of the buffer.

eobp

Return t if point is at the end of the buffer.


Next: Current Buffer, Previous: About Buffers, Up: Buffers   [Index]