]> code.delx.au - gnu-emacs/blobdiff - lisp/mouse.el
lisp/gnus/gnus-start.el: Optionally check the newsrc.eld file's timestamp before...
[gnu-emacs] / lisp / mouse.el
index 7beea8e26e6e518567e0c4729f24ae49d41463d5..f569ec3577d26ac3918ce51eee2c758f220a5263 100644 (file)
@@ -94,15 +94,14 @@ point at the click position."
 (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)
@@ -118,19 +117,14 @@ Expects to be bound to `down-mouse-1' in `key-translation-map'."
                                        '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))))))
 
@@ -313,13 +307,14 @@ This command must be bound to a mouse click."
     (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)))
@@ -401,7 +396,16 @@ must be one of the symbols `header', `mode', or `vertical'."
       ;; 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.
@@ -416,7 +420,11 @@ must be one of the symbols `header', `mode', or `vertical'."
                             (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,
@@ -1060,26 +1068,9 @@ regardless of where you click."
     (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.
@@ -1264,7 +1255,7 @@ This must be bound to a mouse drag event."
       (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))))))
@@ -1339,13 +1330,13 @@ The function returns a non-nil value if it creates a secondary selection."
            (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)))))))))
@@ -1361,7 +1352,7 @@ regardless of where you click."
   (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 ()
@@ -1478,7 +1469,7 @@ CLICK position, kill the secondary selection."
         (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