diff options
| author | Kim F. Storm | 2005-05-11 12:33:44 +0000 |
|---|---|---|
| committer | Kim F. Storm | 2005-05-11 12:33:44 +0000 |
| commit | 3f00c08b2ba845fc53fb0cb10886ed28c294ddb3 (patch) | |
| tree | 2b133245c9f60b8852b97576bb1f6538d810cea9 | |
| parent | 1f9d439a45d8d36a65c067bc34f6e97633e2589d (diff) | |
| download | emacs-3f00c08b2ba845fc53fb0cb10886ed28c294ddb3.tar.gz emacs-3f00c08b2ba845fc53fb0cb10886ed28c294ddb3.zip | |
From Chong Yidong <cyd@stupidchicken.com>
(mouse-sel-follow-link-p): New function.
(mouse-select, mouse-select-internal, mouse-extend-internal):
Use it to implement mouse-1-click-follows-link functionality.
| -rw-r--r-- | lisp/mouse-sel.el | 53 |
1 files changed, 44 insertions, 9 deletions
diff --git a/lisp/mouse-sel.el b/lisp/mouse-sel.el index 4f3741a5213..4cabafe737d 100644 --- a/lisp/mouse-sel.el +++ b/lisp/mouse-sel.el | |||
| @@ -465,10 +465,12 @@ Clicking mouse-1 or mouse-3 kills the selected text. | |||
| 465 | 465 | ||
| 466 | This should be bound to a down-mouse event." | 466 | This should be bound to a down-mouse event." |
| 467 | (interactive "@e") | 467 | (interactive "@e") |
| 468 | (let (direction) | 468 | (let (select) |
| 469 | (unwind-protect | 469 | (unwind-protect |
| 470 | (setq direction (mouse-select-internal 'PRIMARY event)) | 470 | (setq select (mouse-select-internal 'PRIMARY event)) |
| 471 | (mouse-sel-primary-to-region direction)))) | 471 | (if (and select (listp select)) |
| 472 | (push (cons 'mouse-2 (cdr event)) unread-command-events) | ||
| 473 | (mouse-sel-primary-to-region select))))) | ||
| 472 | 474 | ||
| 473 | (defun mouse-select-secondary (event) | 475 | (defun mouse-select-secondary (event) |
| 474 | "Set secondary selection using the mouse. | 476 | "Set secondary selection using the mouse. |
| @@ -487,7 +489,14 @@ This should be bound to a down-mouse event." | |||
| 487 | (mouse-select-internal 'SECONDARY event)) | 489 | (mouse-select-internal 'SECONDARY event)) |
| 488 | 490 | ||
| 489 | (defun mouse-select-internal (selection event) | 491 | (defun mouse-select-internal (selection event) |
| 490 | "Set SELECTION using the mouse." | 492 | "Set SELECTION using the mouse, with EVENT as the initial down-event. |
| 493 | Normally, this returns the direction in which the selection was | ||
| 494 | made: a value of 1 indicates that the mouse was dragged | ||
| 495 | left-to-right, otherwise it was dragged right-to-left. | ||
| 496 | |||
| 497 | However, if `mouse-1-click-follows-link' is non-nil and the | ||
| 498 | subsequent mouse events specify following a link, this returns | ||
| 499 | the final mouse-event. In that case, the selection is not set." | ||
| 491 | (mouse-sel-eval-at-event-end event | 500 | (mouse-sel-eval-at-event-end event |
| 492 | (let ((thing-symbol (mouse-sel-selection-thing selection)) | 501 | (let ((thing-symbol (mouse-sel-selection-thing selection)) |
| 493 | (overlay (mouse-sel-selection-overlay selection))) | 502 | (overlay (mouse-sel-selection-overlay selection))) |
| @@ -501,7 +510,8 @@ This should be bound to a down-mouse event." | |||
| 501 | (car object-bounds) (cdr object-bounds) | 510 | (car object-bounds) (cdr object-bounds) |
| 502 | (current-buffer))) | 511 | (current-buffer))) |
| 503 | (move-overlay overlay (point) (point) (current-buffer))))) | 512 | (move-overlay overlay (point) (point) (current-buffer))))) |
| 504 | (mouse-extend-internal selection))) | 513 | (catch 'follow-link |
| 514 | (mouse-extend-internal selection event t)))) | ||
| 505 | 515 | ||
| 506 | ;;=== Extend ============================================================== | 516 | ;;=== Extend ============================================================== |
| 507 | 517 | ||
| @@ -523,11 +533,12 @@ This should be bound to a down-mouse event." | |||
| 523 | (save-window-excursion | 533 | (save-window-excursion |
| 524 | (mouse-extend-internal 'SECONDARY event))) | 534 | (mouse-extend-internal 'SECONDARY event))) |
| 525 | 535 | ||
| 526 | (defun mouse-extend-internal (selection &optional initial-event) | 536 | (defun mouse-extend-internal (selection &optional initial-event no-process) |
| 527 | "Extend specified SELECTION using the mouse. | 537 | "Extend specified SELECTION using the mouse. |
| 528 | Track mouse-motion events, adjusting the SELECTION appropriately. | 538 | Track mouse-motion events, adjusting the SELECTION appropriately. |
| 529 | Optional argument INITIAL-EVENT specifies an initial down-mouse event to | 539 | Optional argument INITIAL-EVENT specifies an initial down-mouse event. |
| 530 | process. | 540 | Optional argument NO-PROCESS means not to process the initial |
| 541 | event. | ||
| 531 | 542 | ||
| 532 | See documentation for mouse-select-internal for more details." | 543 | See documentation for mouse-select-internal for more details." |
| 533 | (mouse-sel-eval-at-event-end initial-event | 544 | (mouse-sel-eval-at-event-end initial-event |
| @@ -564,7 +575,8 @@ See documentation for mouse-select-internal for more details." | |||
| 564 | ;; Handle dragging | 575 | ;; Handle dragging |
| 565 | (track-mouse | 576 | (track-mouse |
| 566 | 577 | ||
| 567 | (while (if initial-event ; Use initial event | 578 | (while (if (and initial-event (not no-process)) |
| 579 | ;; Use initial event | ||
| 568 | (prog1 | 580 | (prog1 |
| 569 | (setq event initial-event) | 581 | (setq event initial-event) |
| 570 | (setq initial-event nil)) | 582 | (setq initial-event nil)) |
| @@ -643,6 +655,10 @@ See documentation for mouse-select-internal for more details." | |||
| 643 | 655 | ||
| 644 | ))) ; end track-mouse | 656 | ))) ; end track-mouse |
| 645 | 657 | ||
| 658 | ;; Detect follow-link events | ||
| 659 | (when (mouse-sel-follow-link-p initial-event event) | ||
| 660 | (throw 'follow-link event)) | ||
| 661 | |||
| 646 | ;; Finish up after dragging | 662 | ;; Finish up after dragging |
| 647 | (let ((overlay-start (overlay-start overlay)) | 663 | (let ((overlay-start (overlay-start overlay)) |
| 648 | (overlay-end (overlay-end overlay))) | 664 | (overlay-end (overlay-end overlay))) |
| @@ -679,6 +695,25 @@ See documentation for mouse-select-internal for more details." | |||
| 679 | 695 | ||
| 680 | )))) | 696 | )))) |
| 681 | 697 | ||
| 698 | (defun mouse-sel-follow-link-p (initial final) | ||
| 699 | "Return t if we should follow a link, given INITIAL and FINAL mouse events. | ||
| 700 | See `mouse-1-click-follows-link' for details. Currently, Mouse | ||
| 701 | Sel mode does not support using a `double' value to follow links | ||
| 702 | using double-clicks." | ||
| 703 | (and initial final mouse-1-click-follows-link | ||
| 704 | (eq (car initial) 'down-mouse-1) | ||
| 705 | (mouse-on-link-p (posn-point (event-start initial))) | ||
| 706 | (= (posn-point (event-start initial)) | ||
| 707 | (posn-point (event-end final))) | ||
| 708 | (= (event-click-count initial) 1) | ||
| 709 | (or (not (integerp mouse-1-click-follows-link)) | ||
| 710 | (let ((t0 (posn-timestamp (event-start initial))) | ||
| 711 | (t1 (posn-timestamp (event-end final)))) | ||
| 712 | (and (integerp t0) (integerp t1) | ||
| 713 | (if (> mouse-1-click-follows-link 0) | ||
| 714 | (<= (- t1 t0) mouse-1-click-follows-link) | ||
| 715 | (< (- t0 t1) mouse-1-click-follows-link))))))) | ||
| 716 | |||
| 682 | ;;=== Paste =============================================================== | 717 | ;;=== Paste =============================================================== |
| 683 | 718 | ||
| 684 | (defun mouse-insert-selection (event arg) | 719 | (defun mouse-insert-selection (event arg) |