]> git.eshelyaron.com Git - emacs.git/commitdiff
(region-active-p): New function.
authorRichard M. Stallman <rms@gnu.org>
Sun, 23 Dec 2007 21:46:25 +0000 (21:46 +0000)
committerRichard M. Stallman <rms@gnu.org>
Sun, 23 Dec 2007 21:46:25 +0000 (21:46 +0000)
(use-empty-active-region): New variable.

etc/NEWS
lisp/ChangeLog
lisp/simple.el

index fb51744bab68e52f8cdb4521bc559b743d0ca8b6..d7e7f0f93c6df657557138df47240d9473697683 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -149,6 +149,9 @@ word at point.
 ** TAB now indents the region if the region is active and
 `transient-mark-mode' is turned on.
 
+** `use-empty-active-region' controls whether an empty active region
+in Transient Mark mode should make commands operate on that empty region.
+
 ** C-z now invokes `suspend-frame', C-x C-c now invokes
 `save-buffers-kill-terminal'.
 
@@ -439,6 +442,9 @@ variable as having been made within Custom.
 ** `frame-inherited-parameters' lets new frames inherit parameters from
 the selected frame.
 
+** Commands should use `region-active-p' to test whether there is
+an active region that they should operate on.
+
 ** New keymap `input-decode-map' overrides like key-translation-map, but
 applies before function-key-map.  Also it is terminal-local contrary to
 key-translation-map.  Terminal-specific key-sequences are generally added to
index 9fb73a60a1c8ef99e7ae680142fd1141b1ee491b..76dfeb27f0512a7995672769018a389acfd3281e 100644 (file)
@@ -1,5 +1,8 @@
 2007-12-23  Richard Stallman  <rms@gnu.org>
 
+       * simple.el (region-active-p): New function.
+       (use-empty-active-region): New variable.
+
        * dired-aux.el (dired): Load dired.el at run time too.
 
 2007-12-23  Juri Linkov  <juri@jurta.org>
index 22f29ab04643c116d3b18df300c8ce4d1b5e1ac0..2750fc8577789ecd0be1061bd4e0a3e6c658e1cb 100644 (file)
@@ -3329,6 +3329,28 @@ store it in a Lisp variable.  Example:
     (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)