Index: lisp/simple.el =================================================================== RCS file: /sources/emacs/emacs/lisp/simple.el,v retrieving revision 1.899 diff -u -r1.899 simple.el --- lisp/simple.el 1 Feb 2008 16:01:05 -0000 1.899 +++ lisp/simple.el 5 Feb 2008 06:53:10 -0000 @@ -3316,6 +3316,7 @@ "Deactivate the mark by setting `mark-active' to nil. \(That makes a difference only in Transient Mark mode.) Also runs the hook `deactivate-mark-hook'." + (cancel-function-timers 'maybe-select-for-select-active-regions) (cond ((eq transient-mark-mode 'lambda) (setq transient-mark-mode nil)) @@ -3323,11 +3324,39 @@ (setq mark-active nil) (run-hooks 'deactivate-mark-hook)))) + (defcustom select-active-regions nil "If non-nil, an active region automatically becomes the window selection." :type 'boolean :group 'killing - :version "23.1") + :version "23.1" + :risky t) + +(defvar select-active-regions-last-region nil + "record of last propagated region for comparison.") + +(defun maybe-select-for-select-active-regions () + "Implements `select-active-regions'. Called by timer +`select-active-regions-timer' and `set-mark'" + (and select-active-regions + (region-active-p) + (let ((current-region-text + (buffer-substring (region-beginning) (region-end)))) + (if (or (null select-active-regions-last-region) + (not (string= select-active-regions-last-region + current-region-text))) + (if (or (null current-region-text) + (string= "" current-region-text)) + ;; don't propagate if this region is empty, but this + ;; region being empty means future nonempty regions + ;; need repropagation + (setq select-active-regions-last-region nil) + ;; this should be a call to interprogram-highlight-function + ;; if/when that is introduced. + (x-set-selection nil current-region-text) + (setq select-active-regions-last-region + current-region-text)))))) + (defun set-mark (pos) "Set this buffer's mark to POS. Don't use this function! @@ -3350,9 +3379,13 @@ (progn (setq mark-active t) (run-hooks 'activate-mark-hook) - (and select-active-regions - (x-set-selection - nil (buffer-substring (region-beginning) (region-end)))) + (when select-active-regions + (cancel-function-timers 'maybe-select-for-select-active-regions) + (run-with-idle-timer + 0 t 'maybe-select-for-select-active-regions) + ;; force repropagate if mark is reset + (progn (setq select-active-regions-last-region nil) + (maybe-select-for-select-active-regions))) (set-marker (mark-marker) pos (current-buffer))) ;; Normally we never clear mark-active except in Transient Mark mode. ;; But when we actually clear out the mark value too, Index: lisp/loadup.el =================================================================== RCS file: /sources/emacs/emacs/lisp/loadup.el,v retrieving revision 1.160 diff -u -r1.160 loadup.el --- lisp/loadup.el 1 Feb 2008 22:43:10 -0000 1.160 +++ lisp/loadup.el 5 Feb 2008 06:53:11 -0000 @@ -82,6 +82,8 @@ (message "%s" (garbage-collect)) (load "loaddefs.el") ;Don't get confused if someone compiled this by mistake. (message "%s" (garbage-collect)) + +(load "emacs-lisp/timer") ; select-active-region in simple.el needs timer. (load "simple") (load "help") @@ -145,7 +147,6 @@ (and (boundp 'x-toolkit-scroll-bars) (load "scroll-bar")) (load "select"))) -(load "emacs-lisp/timer") (load "isearch") (load "rfn-eshadow")