*** empty log message ***
[bpt/emacs.git] / lisp / mouse.el
index 145eb76..a5f208b 100644 (file)
@@ -556,7 +556,7 @@ resized by dragging their header-line."
         (echo-keystrokes 0)
         (start-event-frame (window-frame (car (car (cdr start-event)))))
         (start-event-window (car (car (cdr start-event))))
-        event mouse x left right edges wconfig growth
+        event mouse x left right edges growth
         (which-side
          (or (cdr (assq 'vertical-scroll-bars (frame-parameters start-event-frame)))
              'right)))
@@ -775,10 +775,28 @@ If the click is in the echo area, display the `*Messages*' buffer."
       (mouse-drag-track start-event t))))
 
 
+(defun mouse-posn-property (pos property)
+  "Look for a property at click position.
+POS may be either a buffer position or a click position like
+those returned from `event-start'.  If the click position is on
+a string, the text property PROPERTY is examined.
+If this is nil or the click is not on a string, then
+the corresponding buffer position is searched for PROPERTY.
+If PROPERTY is encountered in one of those places,
+its value is returned."
+  (if (consp pos)
+      (let ((w (posn-window pos)) (pt (posn-point pos))
+           (str (posn-string pos)))
+       (or (and str
+                (get-text-property (cdr str) property (car str)))
+           (and pt
+                (get-char-property pt property w))))
+    (get-char-property pos property)))
+
 (defun mouse-on-link-p (pos)
   "Return non-nil if POS is on a link in the current buffer.
-POS must be a buffer position in the current buffer or an mouse
-event location in the selected window, see `event-start'.
+POS must be a buffer position in the current buffer or a mouse
+event location in the selected window (see `event-start').
 However, if `mouse-1-click-in-non-selected-windows' is non-nil,
 POS may be a mouse event location in any window.
 
@@ -798,7 +816,7 @@ is a non-nil `mouse-face' property at POS.  Return t in this case.
 
 - If the value is a function, FUNC, POS is inside a link if
 the call \(FUNC POS) returns non-nil.  Return the return value
-from that call.  Arg is \(posn-point POS) if POS is a mouse event,
+from that call.  Arg is \(posn-point POS) if POS is a mouse event.
 
 - Otherwise, return the value itself.
 
@@ -814,24 +832,23 @@ click is the local or global binding of that event.
 
 - Otherwise, the mouse-1 event is translated into a mouse-2 event
 at the same position."
-  (let ((w (and (consp pos) (posn-window pos))))
-    (if (consp pos)
-       (setq pos (and (or mouse-1-click-in-non-selected-windows
-                          (eq (selected-window) w))
-                      (posn-point pos))))
-    (when pos
-      (with-current-buffer (window-buffer w)
-       (let ((action
-              (or (get-char-property pos 'follow-link)
-                  (save-excursion
-                    (goto-char pos)
-                    (key-binding [follow-link] nil t)))))
-         (cond
-          ((eq action 'mouse-face)
-           (and (get-char-property pos 'mouse-face) t))
-          ((functionp action)
-           (funcall action pos))
-          (t action)))))))
+  (let ((action
+        (and (or (not (consp pos))
+                 mouse-1-click-in-non-selected-windows
+                 (eq (selected-window) (posn-window pos)))
+             (or (mouse-posn-property pos 'follow-link)
+                 (key-binding [follow-link] nil t pos)))))
+    (cond
+     ((eq action 'mouse-face)
+      (and (mouse-posn-property pos 'mouse-face) t))
+     ((functionp action)
+      ;; FIXME: This seems questionable if the click is not in a buffer.
+      ;; Should we instead decide that `action' takes a `posn'?
+      (if (consp pos)
+         (with-current-buffer (window-buffer (posn-window pos))
+           (funcall action (posn-point pos)))
+       (funcall action pos)))
+     (t action))))
 
 (defun mouse-fixup-help-message (msg)
   "Fix help message MSG for `mouse-1-click-follows-link'."
@@ -872,7 +889,7 @@ at the same position."
   (let ((range (mouse-start-end start end mode)))
     (move-overlay ol (car range) (nth 1 range))))
 
-(defun mouse-drag-track (start-event  &optional 
+(defun mouse-drag-track (start-event  &optional
                                      do-mouse-drag-region-post-process)
     "Track mouse drags by highlighting area between point and cursor.
 The region will be defined with mark and point, and the overlay
@@ -904,7 +921,7 @@ should only be used by mouse-drag-region."
                        ;; Use start-point before the intangibility
                        ;; treatment, in case we click on a link inside an
                        ;; intangible text.
-                       (mouse-on-link-p start-point)))
+                       (mouse-on-link-p start-posn)))
         (click-count (1- (event-click-count start-event)))
         (remap-double-click (and on-link
                                  (eq mouse-1-click-follows-link 'double)
@@ -966,8 +983,8 @@ should only be used by mouse-drag-region."
          (let* ((fun (key-binding (vector (car event))))
                 (do-multi-click   (and (> (event-click-count event) 0)
                                        (functionp fun)
-                                       (not (memq fun 
-                                                  '(mouse-set-point 
+                                       (not (memq fun
+                                                  '(mouse-set-point
                                                     mouse-set-region))))))
            ;; Run the binding of the terminating up-event, if possible.
            (if (and (not (= (overlay-start mouse-drag-overlay)
@@ -2360,7 +2377,7 @@ and selects that window."
   "X fonts suitable for use in Emacs.")
 
 (defun mouse-set-font (&rest fonts)
-  "Select an emacs font from a list of known good fonts and fontsets."
+  "Select an Emacs font from a list of known good fonts and fontsets."
   (interactive
    (progn (unless (display-multi-font-p)
            (error "Cannot change fonts on this display"))
@@ -2398,6 +2415,8 @@ and selects that window."
 (global-set-key [right-fringe mouse-1] 'mouse-set-point)
 
 (global-set-key [mouse-2]      'mouse-yank-at-click)
+;; Allow yanking also when the corresponding cursor is "in the fringe".
+(global-set-key [right-fringe mouse-2] [mouse-2])
 (global-set-key [mouse-3]      'mouse-save-then-kill)
 
 ;; By binding these to down-going events, we let the user use the up-going