diff options
Diffstat (limited to 'lisp/wid-edit.el')
-rw-r--r-- | lisp/wid-edit.el | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el index fc64dd5f361..af41424ca75 100644 --- a/lisp/wid-edit.el +++ b/lisp/wid-edit.el @@ -912,6 +912,10 @@ Recommended as a parent keymap for modes using widgets.") ;; 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 @@ Recommended as a parent keymap for modes using widgets.") (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 @@ -959,24 +964,30 @@ Recommended as a parent keymap for modes using widgets.") (push event unread-command-events) (setq event oevent) (throw 'button-press-cancelled t)) - (setq pos (widget-event-point event)) - (if (and pos - (eq (get-char-property pos 'button) - button)) - (when face - (overlay-put overlay 'face pressed-face) - (overlay-put overlay 'mouse-face pressed-face)) - (overlay-put overlay 'face face) - (overlay-put overlay 'mouse-face mouse-face))))) + (unless (or (integerp event) + (memq (car event) '(switch-frame select-window)) + (eq (car event) 'scroll-bar-movement)) + (setq pos (widget-event-point event)) + (if (and pos + (eq (get-char-property pos 'button) + button)) + (when face + (overlay-put overlay 'face pressed-face) + (overlay-put overlay 'mouse-face pressed-face)) + (overlay-put overlay 'face face) + (overlay-put overlay 'mouse-face mouse-face)))))) ;; 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) @@ -1862,7 +1873,7 @@ If END is omitted, it defaults to the length of LIST." "History of field minibuffer edits.") (defun widget-field-prompt-internal (widget prompt initial history) - "Read string for WIDGET promptinhg with PROMPT. + "Read string for WIDGET prompting with PROMPT. INITIAL is the initial input and HISTORY is a symbol containing the earlier input." (read-string prompt initial history)) @@ -2853,7 +2864,7 @@ The first group should be the link itself." (defcustom widget-documentation-link-p 'intern-soft "Predicate used to test if a string is useful as a link. -The value should be a function. The function will be called one +The value should be a function. The function will be called with one argument, a string, and should return non-nil if there should be a link for that string." :type 'function |