aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2006-09-08 14:15:02 +0000
committerChong Yidong2006-09-08 14:15:02 +0000
commit612c16f1307be001af8fac7df6e35b5c7fe21502 (patch)
tree7d8a5bbd6d9f10b79ee4596e7f788065c4c318ec
parent92b2332318a23f84c60088380d4c0ea07e17d1bb (diff)
downloademacs-612c16f1307be001af8fac7df6e35b5c7fe21502.tar.gz
emacs-612c16f1307be001af8fac7df6e35b5c7fe21502.zip
* window.el (mouse-autoselect-window-timer)
(mouse-autoselect-window-position) (mouse-autoselect-window-window) (mouse-autoselect-window-now): New vars. (mouse-autoselect-window-cancel) (mouse-autoselect-window-select) (mouse-autoselect-window-start): New functions. (handle-select-window): Call `mouse-autoselect-window-start' when delayed window autoselection is enabled. * cus-start.el (mouse-autoselect-window): Handle delayed window autoselection. * emacs-lisp/eldoc.el: Add `handle-select-window' to the set of commands after which it is allowed to print in the echo area.
-rw-r--r--lisp/ChangeLog18
-rw-r--r--lisp/cus-start.el6
-rw-r--r--lisp/emacs-lisp/eldoc.el2
-rw-r--r--lisp/window.el133
4 files changed, 147 insertions, 12 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index efcc3aab37e..8229d0871ce 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,21 @@
12006-08-27 Martin Rudalics <rudalics@gmx.at>
2
3 * window.el (mouse-autoselect-window-timer)
4 (mouse-autoselect-window-position)
5 (mouse-autoselect-window-window)
6 (mouse-autoselect-window-now): New vars.
7 (mouse-autoselect-window-cancel)
8 (mouse-autoselect-window-select)
9 (mouse-autoselect-window-start): New functions.
10 (handle-select-window): Call `mouse-autoselect-window-start' when
11 delayed window autoselection is enabled.
12
13 * cus-start.el (mouse-autoselect-window): Handle delayed window
14 autoselection.
15
16 * emacs-lisp/eldoc.el: Add `handle-select-window' to the set of
17 commands after which it is allowed to print in the echo area.
18
12006-09-08 Richard Stallman <rms@gnu.org> 192006-09-08 Richard Stallman <rms@gnu.org>
2 20
3 * textmodes/fill.el (adaptive-fill-regexp): Don't match `(1)' or `1.' 21 * textmodes/fill.el (adaptive-fill-regexp): Don't match `(1)' or `1.'
diff --git a/lisp/cus-start.el b/lisp/cus-start.el
index 906b2e51a1d..77980d726e5 100644
--- a/lisp/cus-start.el
+++ b/lisp/cus-start.el
@@ -361,6 +361,11 @@ since it could result in memory overflow and make Emacs crash."
361 (unibyte-display-via-language-environment mule boolean) 361 (unibyte-display-via-language-environment mule boolean)
362 (blink-cursor-alist cursor alist "22.1") 362 (blink-cursor-alist cursor alist "22.1")
363 (overline-margin display integer "22.1") 363 (overline-margin display integer "22.1")
364 (mouse-autoselect-window
365 display (choice
366 (const :tag "Off (nil)" :value nil)
367 (const :tag "Immediate" :value t)
368 (number :tag "Delay by secs" :value 0.5)) "22.1")
364 ;; xfaces.c 369 ;; xfaces.c
365 (scalable-fonts-allowed display boolean) 370 (scalable-fonts-allowed display boolean)
366 ;; xfns.c 371 ;; xfns.c
@@ -370,7 +375,6 @@ since it could result in memory overflow and make Emacs crash."
370 (x-gtk-show-hidden-files menu boolean "22.1") 375 (x-gtk-show-hidden-files menu boolean "22.1")
371 (x-gtk-whole-detached-tool-bar x boolean "22.1") 376 (x-gtk-whole-detached-tool-bar x boolean "22.1")
372 ;; xterm.c 377 ;; xterm.c
373 (mouse-autoselect-window display boolean "22.1")
374 (x-use-underline-position-properties display boolean "22.1") 378 (x-use-underline-position-properties display boolean "22.1")
375 (x-underline-at-descent-line display boolean "22.1") 379 (x-underline-at-descent-line display boolean "22.1")
376 (x-stretch-cursor display boolean "21.1"))) 380 (x-stretch-cursor display boolean "21.1")))
diff --git a/lisp/emacs-lisp/eldoc.el b/lisp/emacs-lisp/eldoc.el
index 805184e15de..98d778f1507 100644
--- a/lisp/emacs-lisp/eldoc.el
+++ b/lisp/emacs-lisp/eldoc.el
@@ -432,7 +432,7 @@ Emacs Lisp mode) that support Eldoc.")
432;; Prime the command list. 432;; Prime the command list.
433(eldoc-add-command-completions 433(eldoc-add-command-completions
434 "backward-" "beginning-of-" "move-beginning-of-" "delete-other-windows" 434 "backward-" "beginning-of-" "move-beginning-of-" "delete-other-windows"
435 "delete-window" 435 "delete-window" "handle-select-window"
436 "end-of-" "move-end-of-" "exchange-point-and-mark" "forward-" 436 "end-of-" "move-end-of-" "exchange-point-and-mark" "forward-"
437 "indent-for-tab-command" "goto-" "mark-page" "mark-paragraph" 437 "indent-for-tab-command" "goto-" "mark-page" "mark-paragraph"
438 "mouse-set-point" "move-" "pop-global-mark" "next-" "other-window" 438 "mouse-set-point" "move-" "pop-global-mark" "next-" "other-window"
diff --git a/lisp/window.el b/lisp/window.el
index 7810ba4c5be..0c50bc63a08 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -777,21 +777,134 @@ and the buffer that is killed or buried is the one in that window."
777 ;; Maybe get rid of the window. 777 ;; Maybe get rid of the window.
778 (and window (not window-handled) (not window-solitary) 778 (and window (not window-handled) (not window-solitary)
779 (delete-window window)))) 779 (delete-window window))))
780
781(defvar mouse-autoselect-window-timer nil
782 "Timer used by delayed window autoselection.")
783
784(defvar mouse-autoselect-window-position nil
785 "Last mouse position recorded by delayed window autoselection.")
786
787(defvar mouse-autoselect-window-window nil
788 "Last window recorded by delayed window autoselection.")
789
790(defvar mouse-autoselect-window-now nil
791 "When non-nil don't delay autoselection in `handle-select-window'.")
792
793(defun mouse-autoselect-window-cancel (&optional force)
794 "Cancel delayed window autoselection.
795Optional argument FORCE means cancel unconditionally."
796 (unless (and (not force)
797 ;; Don't cancel while the user drags a scroll bar.
798 (eq this-command 'scroll-bar-toolkit-scroll)
799 (memq (nth 4 (event-end last-input-event))
800 '(handle end-scroll)))
801 (setq mouse-autoselect-window-now nil)
802 (when (timerp mouse-autoselect-window-timer)
803 (cancel-timer mouse-autoselect-window-timer))
804 (remove-hook 'pre-command-hook 'mouse-autoselect-window-cancel)))
805
806(defun mouse-autoselect-window-start (window)
807 "Start delayed window autoselection.
808Called when Emacs detects that the mouse has moved to the non-selected
809window WINDOW and the variable `mouse-autoselect-window' has a numeric,
810non-zero value. The return value is non-nil iff delayed autoselection
811started successfully. Delayed window autoselection is canceled when the
812mouse position has stabilized or a command is executed."
813 ;; Cancel any active window autoselection.
814 (mouse-autoselect-window-cancel t)
815 ;; Record current mouse position in `mouse-autoselect-window-position' and
816 ;; WINDOW in `mouse-autoselect-window-window'.
817 (setq mouse-autoselect-window-position (mouse-position))
818 (setq mouse-autoselect-window-window window)
819 ;; Install timer which runs `mouse-autoselect-window-select' every
820 ;; `mouse-autoselect-window' seconds.
821 (setq mouse-autoselect-window-timer
822 (run-at-time
823 (abs mouse-autoselect-window) (abs mouse-autoselect-window)
824 'mouse-autoselect-window-select))
825 ;; Executing a command cancels window autoselection.
826 (add-hook 'pre-command-hook 'mouse-autoselect-window-cancel))
827
828(defun mouse-autoselect-window-select ()
829 "Select window with delayed window autoselection.
830If the mouse position has stabilized in a non-selected window, select
831that window. The minibuffer window is selected iff the minibuffer is
832active. This function is run by `mouse-autoselect-window-timer'."
833 (condition-case nil
834 (let* ((mouse-position (mouse-position))
835 (window (window-at (cadr mouse-position) (cddr mouse-position)
836 (car mouse-position))))
837 (cond
838 ((and window (not (eq window (selected-window)))
839 (or (not (numberp mouse-autoselect-window))
840 (and (> mouse-autoselect-window 0)
841 ;; If `mouse-autoselect-window' is positive, select
842 ;; window if the window is the same as before.
843 (eq window mouse-autoselect-window-window))
844 ;; Otherwise select window iff the mouse is at the same
845 ;; position as before. Observe that the first test after
846 ;; `mouse-autoselect-window-start' usually fails since the
847 ;; value of `mouse-autoselect-window-position' recorded there
848 ;; is the position where the mouse has entered the new window
849 ;; and not necessarily where the mouse has stopped moving.
850 (equal mouse-position mouse-autoselect-window-position))
851 ;; The minibuffer is a candidate window iff it's active.
852 (or (not (window-minibuffer-p window))
853 (eq window (active-minibuffer-window))))
854 ;; Mouse position has stabilized in non-selected window: Cancel window
855 ;; autoselection and try to select that window.
856 (mouse-autoselect-window-cancel t)
857 ;; Select window where mouse appears unless the selected window is the
858 ;; minibuffer. Use `unread-command-events' in order to execute pre-
859 ;; and post-command hooks and trigger idle timers. To avoid delaying
860 ;; autoselection again, temporarily set `mouse-autoselect-window-now'
861 ;; to t.
862 (unless (window-minibuffer-p (selected-window))
863 (setq mouse-autoselect-window-now t)
864 (setq unread-command-events
865 (cons (list 'select-window (list window))
866 unread-command-events))))
867 ((or (and window (eq window (selected-window)))
868 (not (numberp mouse-autoselect-window))
869 (equal mouse-position mouse-autoselect-window-position))
870 ;; Mouse position has either stabilized in the selected window or at
871 ;; `mouse-autoselect-window-position': Cancel window autoselection.
872 (mouse-autoselect-window-cancel t))
873 (t
874 ;; Mouse position has not stabilized yet, record new mouse position in
875 ;; `mouse-autoselect-window-position' and any window at that position
876 ;; in `mouse-autoselect-window-window'.
877 (setq mouse-autoselect-window-position mouse-position)
878 (setq mouse-autoselect-window-window window))))
879 (error nil)))
780 880
781(defun handle-select-window (event) 881(defun handle-select-window (event)
782 "Handle select-window events." 882 "Handle select-window events."
783 (interactive "e") 883 (interactive "e")
784 (let ((window (posn-window (event-start event)))) 884 (let ((window (posn-window (event-start event))))
785 (if (and (window-live-p window) 885 (when (and (window-live-p window)
786 ;; Don't switch if we're currently in the minibuffer. 886 ;; Don't switch if we're currently in the minibuffer.
787 ;; This tries to work around problems where the minibuffer gets 887 ;; This tries to work around problems where the minibuffer gets
788 ;; unselected unexpectedly, and where you then have to move 888 ;; unselected unexpectedly, and where you then have to move
789 ;; your mouse all the way down to the minibuffer to select it. 889 ;; your mouse all the way down to the minibuffer to select it.
790 (not (window-minibuffer-p (selected-window))) 890 (not (window-minibuffer-p (selected-window)))
791 ;; Don't switch to a minibuffer window unless it's active. 891 ;; Don't switch to a minibuffer window unless it's active.
792 (or (not (window-minibuffer-p window)) 892 (or (not (window-minibuffer-p window))
793 (minibuffer-window-active-p window))) 893 (minibuffer-window-active-p window)))
794 (select-window window)))) 894 (unless (and (numberp mouse-autoselect-window)
895 (not (zerop mouse-autoselect-window))
896 (not mouse-autoselect-window-now)
897 ;; When `mouse-autoselect-window' has a numeric, non-zero
898 ;; value, delay window autoselection by that value.
899 ;; `mouse-autoselect-window-start' returns non-nil iff it
900 ;; successfully installed a timer for this purpose.
901 (mouse-autoselect-window-start window))
902 ;; Re-enable delayed window autoselection.
903 (setq mouse-autoselect-window-now nil)
904 (when mouse-autoselect-window
905 ;; Run `mouse-leave-buffer-hook' when autoselecting window.
906 (run-hooks 'mouse-leave-buffer-hook))
907 (select-window window)))))
795 908
796(define-key ctl-x-map "2" 'split-window-vertically) 909(define-key ctl-x-map "2" 'split-window-vertically)
797(define-key ctl-x-map "3" 'split-window-horizontally) 910(define-key ctl-x-map "3" 'split-window-horizontally)