changeset 73194:1a9d85f409b8

* wid-edit.el (widget-button-click-moves-point): New variable. (widget-button-click): If widget-button-click-moves-point is non-nil, set point after performing the button action * cus-edit.el (custom-mode): Set widget-button-click-moves-point.
author Chong Yidong <cyd@stupidchicken.com>
date Sat, 30 Sep 2006 15:45:35 +0000
parents 445124744ecc
children 8c2c62dede21
files lisp/ChangeLog lisp/cus-edit.el lisp/wid-edit.el
diffstat 3 files changed, 27 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Sat Sep 30 10:03:11 2006 +0000
+++ b/lisp/ChangeLog	Sat Sep 30 15:45:35 2006 +0000
@@ -1,3 +1,11 @@
+2006-09-30  Chong Yidong  <cyd@stupidchicken.com>
+
+	* wid-edit.el (widget-button-click-moves-point): New variable.
+	(widget-button-click): If widget-button-click-moves-point is
+	non-nil, set point after performing the button action
+
+	* cus-edit.el (custom-mode): Set widget-button-click-moves-point.
+
 2006-09-30  Martin Rudalics  <rudalics@gmx.at>
 
 	* files.el (find-file-existing): Modified to not allow wildcards.
--- a/lisp/cus-edit.el	Sat Sep 30 10:03:11 2006 +0000
+++ b/lisp/cus-edit.el	Sat Sep 30 15:45:35 2006 +0000
@@ -4555,6 +4555,13 @@
   (setq widget-documentation-face 'custom-documentation)
   (make-local-variable 'widget-button-face)
   (setq widget-button-face custom-button)
+
+  ;; We need this because of the "More" button on docstrings.
+  ;; Otherwise clicking on "More" can push point offscreen, which
+  ;; causes the window to recenter on point, which pushes the
+  ;; newly-revealed docstring offscreen; which is annoying.  -- cyd.
+  (set (make-local-variable 'widget-button-click-moves-point) t)
+
   (set (make-local-variable 'widget-button-pressed-face) custom-button-pressed)
   (set (make-local-variable 'widget-mouse-face) custom-button-mouse)
 
--- a/lisp/wid-edit.el	Sat Sep 30 10:03:11 2006 +0000
+++ b/lisp/wid-edit.el	Sat Sep 30 15:45:35 2006 +0000
@@ -912,6 +912,10 @@
 ;; backward-compatibility alias
 (put 'widget-button-pressed-face 'face-alias 'widget-button-pressed)
 
+(defvar widget-button-click-moves-point nil
+  "If non-nil, `widget-button-click' moves point to a button after invoking it.
+If nil, point returns to its original position after invoking a button.")
+
 (defun widget-button-click (event)
   "Invoke the button that the mouse is pointing at."
   (interactive "e")
@@ -922,7 +926,8 @@
 	     (start (event-start event))
 	     (button (get-char-property
 		      pos 'button (and (windowp (posn-window start))
-				       (window-buffer (posn-window start))))))
+				       (window-buffer (posn-window start)))))
+	     newpoint)
 	(when (or (null button)
 		  (catch 'button-press-cancelled
 	      ;; Mouse click on a widget button.  Do the following
@@ -974,12 +979,15 @@
 
 			  ;; When mouse is released over the button, run
 			  ;; its action function.
-			  (when (and pos
-				     (eq (get-char-property pos 'button) button))
-			    (widget-apply-action button event)))
+			  (when (and pos (eq (get-char-property pos 'button) button))
+			    (goto-char pos)
+			    (widget-apply-action button event)
+			    (if widget-button-click-moves-point
+				(setq newpoint (point)))))
 		      (overlay-put overlay 'face face)
 		      (overlay-put overlay 'mouse-face mouse-face))))
 
+		(if newpoint (goto-char newpoint))
 		;; This loses if the widget action switches windows. -- cyd
 		;; (unless (pos-visible-in-window-p (widget-event-point event))
 		;;   (mouse-set-point event)