Function: use-region-p

use-region-p is a byte-compiled function defined in simple.el.gz.

Signature

(use-region-p)

Documentation

Return t if the region is active and it is appropriate to act on it.

This is used by commands that act specially on the region under Transient Mark mode.

The return value is t if Transient Mark mode is enabled and the mark is active; furthermore, if use-empty-active-region is nil, the region must not be empty. Otherwise, the return value is nil.

If use-empty-active-region is non-nil, there is one further caveat: If the user has used \mouse-1 to set point, but used the mouse to move point to a different character yet, this function returns nil.

For some commands, it may be appropriate to ignore the value of use-empty-active-region; in that case, use region-active-p.

You can use the interactive code letter R when writing commands that act specially on an active region. For interactive specs that evaluate Lisp forms to produce a list of arguments, see the functions use-region-beginning and use-region-end.

View in manual

Probably introduced at or before Emacs version 23.1.

Aliases

reftex-region-active-p (obsolete since 28.1) idlwave-region-active-p (obsolete since 28.1)

Source Code

;; Defined in /usr/src/emacs/lisp/simple.el.gz
(defun use-region-p ()
  "Return t if the region is active and it is appropriate to act on it.
This is used by commands that act specially on the region under
Transient Mark mode.

The return value is t if Transient Mark mode is enabled and the
mark is active; furthermore, if `use-empty-active-region' is nil,
the region must not be empty.  Otherwise, the return value is nil.

If `use-empty-active-region' is non-nil, there is one further
caveat: If the user has used \\`mouse-1' to set point, but used
the mouse to move point to a different character yet, this
function returns nil.

For some commands, it may be appropriate to ignore the value of
`use-empty-active-region'; in that case, use `region-active-p'.

You can use the `interactive' code letter `R' when writing commands that
act specially on an active region.  For `interactive' specs that
evaluate Lisp forms to produce a list of arguments, see the functions
`use-region-beginning' and `use-region-end'."
  (and (region-active-p)
       (or (> (region-end) (region-beginning))
           (and use-empty-active-region
                (not (eq (car-safe last-input-event) 'down-mouse-1))
                (not (mouse-movement-p last-input-event))))))