(defun mouse--down-1-maybe-follows-link (&optional _prompt)
"Turn `mouse-1' events into `mouse-2' events if follows-link.
Expects to be bound to `down-mouse-1' in `key-translation-map'."
- (if (or (null mouse-1-click-follows-link)
- (not (eq (if (eq mouse-1-click-follows-link 'double)
- 'double-down-mouse-1 'down-mouse-1)
- (car-safe last-input-event)))
- (not (mouse-on-link-p (event-start last-input-event)))
- (and (not mouse-1-click-in-non-selected-windows)
- (not (eq (selected-window)
- (posn-window (event-start last-input-event))))))
- nil
+ (when (and mouse-1-click-follows-link
+ (eq (if (eq mouse-1-click-follows-link 'double)
+ 'double-down-mouse-1 'down-mouse-1)
+ (car-safe last-input-event))
+ (mouse-on-link-p (event-start last-input-event))
+ (or mouse-1-click-in-non-selected-windows
+ (eq (selected-window)
+ (posn-window (event-start last-input-event)))))
(let ((this-event last-input-event)
(timedout
(sit-for (if (numberp mouse-1-click-follows-link)
'double-mouse-1 'mouse-1))
;; Turn the mouse-1 into a mouse-2 to follow links.
(let ((newup (if (eq mouse-1-click-follows-link 'double)
- 'double-mouse-2 'mouse-2))
- (newdown (if (eq mouse-1-click-follows-link 'double)
- 'double-down-mouse-2 'down-mouse-2)))
+ 'double-mouse-2 'mouse-2)))
;; If mouse-2 has never been done by the user, it doesn't have
;; the necessary property to be interpreted correctly.
- (put newup 'event-kind (get (car event) 'event-kind))
- (put newdown 'event-kind (get (car this-event) 'event-kind))
+ (unless (get newup 'event-kind)
+ (put newup 'event-kind (get (car event) 'event-kind)))
(push (cons newup (cdr event)) unread-command-events)
- ;; Modify the event in place, so read-key-sequence doesn't
- ;; generate a second fake prefix key (see fake_prefixed_keys in
- ;; src/keyboard.c).
- (setcar this-event newdown)
- (vector this-event))
+ ;; Don't change the down event, only the up-event (bug#18212).
+ nil)
(push event unread-command-events)
nil))))))
(or (eq frame oframe)
(set-mouse-position (selected-frame) (1- (frame-width)) 0))))
-(defun mouse-tear-off-window (click)
- "Delete the window clicked on, and create a new frame displaying its buffer."
+(define-obsolete-function-alias 'mouse-tear-off-window 'tear-off-window "24.4")
+(defun tear-off-window (click)
+ "Delete the selected window, and create a new frame displaying its buffer."
(interactive "e")
(mouse-minibuffer-check click)
(let* ((window (posn-window (event-start click)))
(buf (window-buffer window))
- (frame (make-frame)))
+ (frame (make-frame))) ;FIXME: Use pop-to-buffer.
(select-frame frame)
(switch-to-buffer buf)
(delete-window window)))
(window (posn-window start))
(frame (window-frame window))
(minibuffer-window (minibuffer-window frame))
- (on-link (and mouse-1-click-follows-link
- (mouse-on-link-p start)))
(side (and (eq line 'vertical)
(or (cdr (assq 'vertical-scroll-bars
(frame-parameters frame)))
;; Check whether header-line can be dragged at all.
(if (window-at-side-p window 'top)
(setq draggable nil)
- (setq height (/ (window-header-line-height window) 2))
+ ;; window-pixel-edges includes the header and mode lines, so
+ ;; we need to account for that when calculating window growth.
+ ;; On GUI frames, assume the mouse is approximately in the
+ ;; middle of the header/mode line, so we need only half the
+ ;; height in pixels.
+ (setq height
+ (cond
+ ((display-graphic-p frame)
+ (/ (window-header-line-height window) 2))
+ (t (window-header-line-height window))))
(setq window (window-in-direction 'above window t))))
((eq line 'mode)
;; Check whether mode-line can be dragged at all.
(eq minibuffer-window
(active-minibuffer-window))))))
(setq draggable nil)
- (setq height (/ (window-mode-line-height window) 2))))
+ (setq height
+ (cond
+ ((display-graphic-p frame)
+ (/ (window-mode-line-height window) 2))
+ (t (window-mode-line-height window))))))
((eq line 'vertical)
;; Get the window to adjust for the vertical case. If the scroll
;; bar is on the window's right or we drag a vertical divider,
(unless (zerop growth)
(setq dragged t)
(adjust-window-trailing-edge
- window (if (eq line 'mode) growth (- growth)) nil t))))))
- ;; Process the terminating event.
- (when (and (mouse-event-p event) on-link (not dragged)
- (mouse--remap-link-click-p start-event event))
- ;; If mouse-2 has never been done by the user, it doesn't have
- ;; the necessary property to be interpreted correctly.
- (put 'mouse-2 'event-kind 'mouse-click)
- (setcar event 'mouse-2)
- (push event unread-command-events))))
+ window (if (eq line 'mode) growth (- growth)) nil t))))))))
(defun mouse-drag-mode-line (start-event)
"Change the height of a window by dragging on the mode line."
(defun mouse-set-region-1 ()
;; Set transient-mark-mode for a little while.
(unless (eq (car-safe transient-mark-mode) 'only)
- (setq transient-mark-mode
- (cons 'only
- (unless (eq transient-mark-mode 'lambda)
- transient-mark-mode))))
+ (setq-local transient-mark-mode
+ (cons 'only
+ (unless (eq transient-mark-mode 'lambda)
+ transient-mark-mode))))
(setq mouse-last-region-beg (region-beginning))
(setq mouse-last-region-end (region-end))
(setq mouse-last-region-tick (buffer-modified-tick)))
(str (posn-string pos)))
(or (and str
(get-text-property (cdr str) property (car str)))
- (and pt
+ ;; Mouse clicks in the fringe come with a position in
+ ;; (nth 5). This is useful but is not exactly where we clicked, so
+ ;; don't look up that position's properties!
+ (and pt (not (memq (posn-area pos) '(left-fringe right-fringe
+ left-margin right-margin)))
(get-char-property pt property w))))
(get-char-property pos property)))
;; Activate the region, using `mouse-start-end' to determine where
;; to put point and mark (e.g., double-click will select a word).
- (setq transient-mark-mode
- (if (eq transient-mark-mode 'lambda)
- '(only)
- (cons 'only transient-mark-mode)))
+ (setq-local transient-mark-mode
+ (if (eq transient-mark-mode 'lambda)
+ '(only)
+ (cons 'only transient-mark-mode)))
(let ((range (mouse-start-end start-point start-point click-count)))
(push-mark (nth 0 range) t t)
(goto-char (nth 1 range)))
(let (select-active-regions)
(deactivate-mark)))
(or mouse-yank-at-point (mouse-set-point click))
- (let ((primary
- (if (fboundp 'x-get-selection-value)
- (if (eq (framep (selected-frame)) 'w32)
- ;; MS-Windows emulates PRIMARY in x-get-selection, but not
- ;; in x-get-selection-value (the latter only accesses the
- ;; clipboard). So try PRIMARY first, in case they selected
- ;; something with the mouse in the current Emacs session.
- (or (x-get-selection 'PRIMARY)
- (x-get-selection-value))
- ;; Else MS-DOS or X.
- ;; On X, x-get-selection-value supports more formats and
- ;; encodings, so use it in preference to x-get-selection.
- (or (x-get-selection-value)
- (x-get-selection 'PRIMARY)))
- ;; FIXME: What about xterm-mouse-mode etc.?
- (x-get-selection 'PRIMARY))))
- (unless primary
- (error "No selection is available"))
+ (let ((primary (gui-get-primary-selection)))
(push-mark (point))
- (insert primary)))
+ (insert-for-yank primary)))
(defun mouse-kill-ring-save (click)
"Copy the region between point and the mouse click in the kill ring.
(if (numberp (posn-point posn))
(setq beg (posn-point posn)))
(move-overlay mouse-secondary-overlay beg (posn-point end))
- (x-set-selection
+ (gui-set-selection
'SECONDARY
(buffer-substring (overlay-start mouse-secondary-overlay)
(overlay-end mouse-secondary-overlay))))))
(if (marker-position mouse-secondary-start)
(save-window-excursion
(delete-overlay mouse-secondary-overlay)
- (x-set-selection 'SECONDARY nil)
+ (gui-set-selection 'SECONDARY nil)
(select-window start-window)
(save-excursion
(goto-char mouse-secondary-start)
(sit-for 1)
nil))
- (x-set-selection
+ (gui-set-selection
'SECONDARY
(buffer-substring (overlay-start mouse-secondary-overlay)
(overlay-end mouse-secondary-overlay)))))))))
(or mouse-yank-at-point (mouse-set-point click))
(let ((secondary (x-get-selection 'SECONDARY)))
(if secondary
- (insert secondary)
+ (insert-for-yank secondary)
(error "No secondary selection"))))
(defun mouse-kill-secondary ()
(setq str (buffer-substring (overlay-start mouse-secondary-overlay)
(overlay-end mouse-secondary-overlay)))
(> (length str) 0)
- (x-set-selection 'SECONDARY str))))
+ (gui-set-selection 'SECONDARY str))))
\f
(defcustom mouse-buffer-menu-maxlen 20