comparison lisp/wid-edit.el @ 41763:541b53a03028

(widget-button-click): Don't move point permanently: Avoid mouse-set-point--instead select the window, then do save-excursion, then move point. Specify the buffer for get-char-property. Don't use `@' in interactive.
author Richard M. Stallman <rms@gnu.org>
date Sun, 02 Dec 2001 04:49:43 +0000
parents faa52db1ed51
children 6a1a8da1ad47
comparison
equal deleted inserted replaced
41762:9ebf70e688cd 41763:541b53a03028
854 "Face used for pressed buttons." 854 "Face used for pressed buttons."
855 :group 'widget-faces) 855 :group 'widget-faces)
856 856
857 (defun widget-button-click (event) 857 (defun widget-button-click (event)
858 "Invoke the button that the mouse is pointing at." 858 "Invoke the button that the mouse is pointing at."
859 (interactive "@e") 859 (interactive "e")
860 (if (widget-event-point event) 860 (if (widget-event-point event)
861 (let* ((pos (widget-event-point event)) 861 (let* ((pos (widget-event-point event))
862 (button (get-char-property pos 'button))) 862 (start (event-start event))
863 (button (get-char-property
864 pos 'button (and (windowp (posn-window start))
865 (window-buffer (posn-window start))))))
863 (if button 866 (if button
864 ;; Mouse click on a widget button. Do the following 867 ;; Mouse click on a widget button. Do the following
865 ;; in a save-excursion so that the click on the button 868 ;; in a save-excursion so that the click on the button
866 ;; doesn't change point. 869 ;; doesn't change point.
867 (save-selected-window 870 (save-selected-window
871 (select-window (posn-window (event-start event)))
868 (save-excursion 872 (save-excursion
869 (mouse-set-point event) 873 (goto-char (posn-point (event-start event)))
870 (let* ((overlay (widget-get button :button-overlay)) 874 (let* ((overlay (widget-get button :button-overlay))
871 (face (overlay-get overlay 'face)) 875 (face (overlay-get overlay 'face))
872 (mouse-face (overlay-get overlay 'mouse-face))) 876 (mouse-face (overlay-get overlay 'mouse-face)))
873 (unwind-protect 877 (unwind-protect
874 ;; Read events, including mouse-movement events 878 ;; Read events, including mouse-movement events
905 (eq (get-char-property pos 'button) button)) 909 (eq (get-char-property pos 'button) button))
906 (widget-apply-action button event)))) 910 (widget-apply-action button event))))
907 (overlay-put overlay 'face face) 911 (overlay-put overlay 'face face)
908 (overlay-put overlay 'mouse-face mouse-face)))) 912 (overlay-put overlay 'mouse-face mouse-face))))
909 913
910 (unless (pos-visible-in-window-p (widget-event-point event)) 914 (unless (pos-visible-in-window-p (widget-event-point event))
911 (mouse-set-point event) 915 (mouse-set-point event)
912 (beginning-of-line) 916 (beginning-of-line)
913 (recenter))) 917 (recenter))
918 )
914 919
915 (let ((up t) command) 920 (let ((up t) command)
916 ;; Mouse click not on a widget button. Find the global 921 ;; Mouse click not on a widget button. Find the global
917 ;; command to run, and check whether it is bound to an 922 ;; command to run, and check whether it is bound to an
918 ;; up event. 923 ;; up event.