Function: forward-word

forward-word is an interactive function defined in syntax.c.

Signature

(forward-word &optional ARG)

Documentation

Move point forward ARG words (backward if ARG is negative).

If ARG is omitted or nil, move point forward one word. Normally returns t. If an edge of the buffer or a field boundary is reached, point is left there and the function returns nil. Field boundaries are not noticed if inhibit-field-text-motion is non-nil.

The word boundaries are normally determined by the buffer's syntax table and character script (according to char-script-table), but find-word-boundary-function-table, such as set up by subword-mode(var)/subword-mode(fun), can change that. If a Lisp program needs to move by words determined strictly by the syntax table, it should use forward-word-strictly instead. See Info node (elisp) Word Motion for details.

Probably introduced at or before Emacs version 20.1.

Key Bindings

Source Code

// Defined in /usr/src/emacs/src/syntax.c
{
  Lisp_Object tmp;
  ptrdiff_t orig_val, val;

  if (NILP (arg))
    XSETFASTINT (arg, 1);
  else
    CHECK_FIXNUM (arg);

  val = orig_val = scan_words (PT, XFIXNUM (arg));
  if (! orig_val)
    val = XFIXNUM (arg) > 0 ? ZV : BEGV;

  /* Avoid jumping out of an input field.  */
  tmp = Fconstrain_to_field (make_fixnum (val), make_fixnum (PT),
			     Qnil, Qnil, Qnil);
  val = XFIXNAT (tmp);

  SET_PT (val);
  return val == orig_val ? Qt : Qnil;
}