Function: mark-word

mark-word is an interactive and byte-compiled function defined in simple.el.gz.

Signature

(mark-word &optional ARG ALLOW-EXTEND)

Documentation

Set mark ARG words from point or move mark one word.

When called from Lisp with ALLOW-EXTEND omitted or nil, mark is set ARG words from point. With ARG and ALLOW-EXTEND both non-nil (interactively, with prefix argument), the place to which mark goes is the same place M-f (forward-word) would move to with the same argument; if the mark is active, it moves ARG words from its current position, otherwise it is set ARG words from point. When invoked interactively without a prefix argument and no active region, mark moves one word forward. When invoked interactively without a prefix argument, and region is active, mark moves one word away of point (i.e., forward if mark is at or after point, back if mark is before point), thus extending the region by one word. Since the direction of region extension depends on the relative position of mark and point, you can change the direction by C-x C-x (exchange-point-and-mark).

View in manual

Probably introduced at or before Emacs version 22.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/simple.el.gz
(defun mark-word (&optional arg allow-extend)
  "Set mark ARG words from point or move mark one word.
When called from Lisp with ALLOW-EXTEND omitted or nil, mark is
set ARG words from point.
With ARG and ALLOW-EXTEND both non-nil (interactively, with prefix
argument), the place to which mark goes is the same place \\[forward-word]
would move to with the same argument; if the mark is active, it moves
ARG words from its current position, otherwise it is set ARG words
from point.
When invoked interactively without a prefix argument and no active
region, mark moves one word forward.
When invoked interactively without a prefix argument, and region
is active, mark moves one word away of point (i.e., forward
if mark is at or after point, back if mark is before point), thus
extending the region by one word.  Since the direction of region
extension depends on the relative position of mark and point, you
can change the direction by \\[exchange-point-and-mark]."
  (interactive "P\np")
  (cond ((and allow-extend
	      (or (and (eq last-command this-command) (mark t))
		  (region-active-p)))
	 (setq arg (if arg (prefix-numeric-value arg)
		     (if (< (mark) (point)) -1 1)))
	 (set-mark
	  (save-excursion
	    (goto-char (mark))
	    (forward-word arg)
	    (point))))
	(t
	 (push-mark
	  (save-excursion
	    (forward-word (prefix-numeric-value arg))
	    (point))
	  nil t))))