changeset 87377:1b576fc3020d

(region-active-p): New function. (use-empty-active-region): New variable.
author Richard M. Stallman <rms@gnu.org>
date Sun, 23 Dec 2007 21:45:35 +0000
parents c3656622dbff
children 6be99f7927ac
files lisp/simple.el
diffstat 1 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/simple.el	Sun Dec 23 19:14:55 2007 +0000
+++ b/lisp/simple.el	Sun Dec 23 21:45:35 2007 +0000
@@ -3329,6 +3329,28 @@
     (run-hooks 'deactivate-mark-hook)
     (set-marker (mark-marker) nil)))
 
+(defcustom use-empty-active-region nil
+  "If non-nil, an active region takes control even if empty.
+This applies to certain commands which, in Transient Mark mode,
+apply to the active region if there is one.  If the setting is t,
+these commands apply to an empty active region if there is one.
+If the setting is nil, these commands treat an empty active
+region as if it were not active."
+  :type 'boolean
+  :version "23.1"
+  :group 'editing-basics)
+
+(defun region-active-p ()
+  "Return t if certain commands should apply to the region.
+Certain commands normally apply to text near point,
+but in Transient Mark mode when the mark is active they apply
+to the region instead.  Such commands should use this subroutine to
+test whether to do that.
+
+This function also obeys `use-empty-active-region'."
+  (and transient-mark-mode mark-active
+       (or use-empty-active-region (> (region-end) (region-beginning)))))
+
 (defvar mark-ring nil
   "The list of former marks of the current buffer, most recent first.")
 (make-variable-buffer-local 'mark-ring)