diff options
| author | Stefan Monnier | 2005-09-21 20:26:49 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2005-09-21 20:26:49 +0000 |
| commit | aaf15b8b6faa98dbf2d49fc3036178e346890919 (patch) | |
| tree | 73d6bfab79fbf70a04fbbe40a728a84930a0df3d | |
| parent | b778ed18b633229024335b50efec72497a7c6e9b (diff) | |
| download | emacs-aaf15b8b6faa98dbf2d49fc3036178e346890919.tar.gz emacs-aaf15b8b6faa98dbf2d49fc3036178e346890919.zip | |
(mouse-move-drag-overlay): New function.
(mouse-drag-region-1): Use it.
Try to simplify a bit the state handling. Handle clicks on links
inside intangible areas.
(mouse-save-then-kill): Minor simplification.
(mouse-secondary-overlay): Make it always non-nil instead of
recreating it each time.
(mouse-start-secondary, mouse-set-secondary, mouse-drag-secondary)
(mouse-kill-secondary, mouse-secondary-save-then-kill):
Simplify accordingly.
| -rw-r--r-- | lisp/ChangeLog | 40 | ||||
| -rw-r--r-- | lisp/mouse.el | 293 |
2 files changed, 171 insertions, 162 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index c61ea679cd9..b58c90b3dc9 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,34 +1,48 @@ | |||
| 1 | 2005-09-21 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * mouse.el (mouse-move-drag-overlay): New function. | ||
| 4 | (mouse-drag-region-1): Use it. | ||
| 5 | Try to simplify a bit the state handling. Handle clicks on links | ||
| 6 | inside intangible areas. | ||
| 7 | (mouse-save-then-kill): Minor simplification. | ||
| 8 | (mouse-secondary-overlay): Make it always non-nil instead of | ||
| 9 | recreating it each time. | ||
| 10 | (mouse-start-secondary, mouse-set-secondary, mouse-drag-secondary) | ||
| 11 | (mouse-kill-secondary, mouse-secondary-save-then-kill): | ||
| 12 | Simplify accordingly. | ||
| 13 | |||
| 1 | 2005-09-21 Dan Nicolaescu <dann@ics.uci.edu> | 14 | 2005-09-21 Dan Nicolaescu <dann@ics.uci.edu> |
| 2 | 15 | ||
| 3 | * term/rxvt.el (rxvt-standard-colors): Fix some colors. | 16 | * term/rxvt.el (rxvt-standard-colors): Fix some colors. |
| 4 | 17 | ||
| 5 | 2005-09-20 Michael Kifer <kifer@cs.stonybrook.edu> | 18 | 2005-09-20 Michael Kifer <kifer@cs.stonybrook.edu> |
| 6 | 19 | ||
| 7 | * ediff-ptch.el (ediff-prompt-for-patch-file): More intuitive prompt. | 20 | * ediff-ptch.el (ediff-file-name-sans-prefix): Treat nil as an empty |
| 8 | (ediff-file-name-sans-prefix): Treat nil as an empty string. | 21 | string. |
| 9 | (ediff-fixup-patch-map): Better heuristic for intuiting the file | 22 | (ediff-fixup-patch-map): Better heuristic for intuiting the file names |
| 10 | names to patch. | 23 | to patch. |
| 24 | (ediff-prompt-for-patch-file): More intuitive prompt. | ||
| 11 | 25 | ||
| 12 | * ediff-util.el: Use insert-buffer-substring. | 26 | * ediff-util.el: use insert-buffer-substring. |
| 13 | 27 | ||
| 14 | * ediff-vers.el (cvs-run-ediff-on-file-descriptor): Bug fix. | 28 | * ediff-vers.el (cvs-run-ediff-on-file-descriptor): Bug fix. |
| 15 | 29 | ||
| 16 | * viper-cmd.el (viper-change-state): Don't move over the field | 30 | * emulation/viper-cmd.el (viper-change-state): Don't move over the |
| 17 | boundaries in the minibuffer. | 31 | field boundaries in the minibuffer. |
| 18 | (viper-set-minibuffer-style): Add viper-minibuffer-post-command-hook. | 32 | (viper-set-minibuffer-style): Add viper-minibuffer-post-command-hook. |
| 19 | (viper-minibuffer-post-command-hook): New hook. | 33 | (viper-minibuffer-post-command-hook): New hook. |
| 20 | (viper-line): Don't move cursor at bolp. | 34 | (viper-line): Don't move cursor at bolp. |
| 21 | 35 | ||
| 22 | * viper-ex.el (ex-pwd, viper-info-on-file): Fix message. | 36 | * emulation/viper-ex.el (ex-pwd, viper-info-on-file): Fix message. |
| 23 | 37 | ||
| 24 | * viper-init.el: Add alias to make-variable-buffer-local to avoid | 38 | * emulation/viper-init.el: add alias to make-variable-buffer-local to |
| 25 | compiler warnings. | 39 | avoid compiler warnings. |
| 26 | 40 | ||
| 27 | * viper-macs.el (ex-map): Better messages. | 41 | * emulation/viper-macs.el (ex-map): Better messages. |
| 28 | 42 | ||
| 29 | * viper-utils.el (viper-beginning-of-field): New function. | 43 | * emulation/viper-utils.el (viper-beginning-of-field): New function. |
| 30 | 44 | ||
| 31 | * viper.el: Replace make-variable-buffer-local with | 45 | * emulation/viper.el: replace make-variable-buffer-local with |
| 32 | viper-make-variable-buffer-local everywhere, to avoid warnings. | 46 | viper-make-variable-buffer-local everywhere, to avoid warnings. |
| 33 | 47 | ||
| 34 | 2005-09-19 Stefan Monnier <monnier@iro.umontreal.ca> | 48 | 2005-09-19 Stefan Monnier <monnier@iro.umontreal.ca> |
diff --git a/lisp/mouse.el b/lisp/mouse.el index c570c1a2e43..0723bc1b7c0 100644 --- a/lisp/mouse.el +++ b/lisp/mouse.el | |||
| @@ -743,9 +743,11 @@ Upon exit, point is at the far edge of the newly visible text." | |||
| 743 | (goto-char opoint)))) | 743 | (goto-char opoint)))) |
| 744 | 744 | ||
| 745 | ;; Create an overlay and immediately delete it, to get "overlay in no buffer". | 745 | ;; Create an overlay and immediately delete it, to get "overlay in no buffer". |
| 746 | (defvar mouse-drag-overlay (make-overlay 1 1)) | 746 | (defconst mouse-drag-overlay |
| 747 | (delete-overlay mouse-drag-overlay) | 747 | (let ((ol (make-overlay (point-min) (point-min)))) |
| 748 | (overlay-put mouse-drag-overlay 'face 'region) | 748 | (delete-overlay ol) |
| 749 | (overlay-put ol 'face 'region) | ||
| 750 | ol)) | ||
| 749 | 751 | ||
| 750 | (defvar mouse-selection-click-count 0) | 752 | (defvar mouse-selection-click-count 0) |
| 751 | 753 | ||
| @@ -856,9 +858,29 @@ at the same position." | |||
| 856 | "mouse-1" (substring msg 7))))))) | 858 | "mouse-1" (substring msg 7))))))) |
| 857 | msg) | 859 | msg) |
| 858 | 860 | ||
| 861 | (defun mouse-move-drag-overlay (ol start end mode) | ||
| 862 | (unless (= start end) | ||
| 863 | ;; Go to START first, so that when we move to END, if it's in the middle | ||
| 864 | ;; of intangible text, point jumps in the direction away from START. | ||
| 865 | ;; Don't do it if START=END otherwise a single click risks selecting | ||
| 866 | ;; a region if it's on intangible text. This exception was originally | ||
| 867 | ;; only applied on entry to mouse-drag-region, which had the problem | ||
| 868 | ;; that a tiny move during a single-click would cause the intangible | ||
| 869 | ;; text to be selected. | ||
| 870 | (goto-char start) | ||
| 871 | (goto-char end)) | ||
| 872 | (let ((range (mouse-start-end start (point) mode))) | ||
| 873 | (move-overlay ol (car range) (nth 1 range)))) | ||
| 874 | |||
| 859 | (defun mouse-drag-region-1 (start-event) | 875 | (defun mouse-drag-region-1 (start-event) |
| 860 | (mouse-minibuffer-check start-event) | 876 | (mouse-minibuffer-check start-event) |
| 861 | (let* ((echo-keystrokes 0) | 877 | (setq mouse-selection-click-count-buffer (current-buffer)) |
| 878 | (let* ((original-window (selected-window)) | ||
| 879 | ;; We've recorded what we needed from the current buffer and | ||
| 880 | ;; window, now let's jump to the place of the event, where things | ||
| 881 | ;; are happening. | ||
| 882 | (_ (mouse-set-point start-event)) | ||
| 883 | (echo-keystrokes 0) | ||
| 862 | (start-posn (event-start start-event)) | 884 | (start-posn (event-start start-event)) |
| 863 | (start-point (posn-point start-posn)) | 885 | (start-point (posn-point start-posn)) |
| 864 | (start-window (posn-window start-posn)) | 886 | (start-window (posn-window start-posn)) |
| @@ -873,36 +895,34 @@ at the same position." | |||
| 873 | (1- (nth 3 bounds)))) | 895 | (1- (nth 3 bounds)))) |
| 874 | (on-link (and mouse-1-click-follows-link | 896 | (on-link (and mouse-1-click-follows-link |
| 875 | (or mouse-1-click-in-non-selected-windows | 897 | (or mouse-1-click-in-non-selected-windows |
| 876 | (eq start-window (selected-window))))) | 898 | (eq start-window original-window)) |
| 877 | remap-double-click | 899 | ;; Use start-point before the intangibility |
| 878 | (click-count (1- (event-click-count start-event)))) | 900 | ;; treatment, in case we click on a link inside an |
| 901 | ;; intangible text. | ||
| 902 | (mouse-on-link-p start-point))) | ||
| 903 | (click-count (1- (event-click-count start-event))) | ||
| 904 | (remap-double-click (and on-link | ||
| 905 | (eq mouse-1-click-follows-link 'double) | ||
| 906 | (= click-count 1)))) | ||
| 879 | (setq mouse-selection-click-count click-count) | 907 | (setq mouse-selection-click-count click-count) |
| 880 | (setq mouse-selection-click-count-buffer (current-buffer)) | ||
| 881 | (mouse-set-point start-event) | ||
| 882 | ;; In case the down click is in the middle of some intangible text, | 908 | ;; In case the down click is in the middle of some intangible text, |
| 883 | ;; use the end of that text, and put it in START-POINT. | 909 | ;; use the end of that text, and put it in START-POINT. |
| 884 | (if (< (point) start-point) | 910 | (if (< (point) start-point) |
| 885 | (goto-char start-point)) | 911 | (goto-char start-point)) |
| 886 | (setq start-point (point)) | 912 | (setq start-point (point)) |
| 887 | (setq on-link (and on-link | 913 | (if remap-double-click ;; Don't expand mouse overlay in links |
| 888 | (mouse-on-link-p start-point))) | ||
| 889 | (setq remap-double-click (and on-link | ||
| 890 | (eq mouse-1-click-follows-link 'double) | ||
| 891 | (= click-count 1))) | ||
| 892 | (if remap-double-click ;; Don't expand mouse overlay in links | ||
| 893 | (setq click-count 0)) | 914 | (setq click-count 0)) |
| 894 | (let ((range (mouse-start-end start-point start-point click-count))) | 915 | (mouse-move-drag-overlay mouse-drag-overlay start-point start-point |
| 895 | (move-overlay mouse-drag-overlay (car range) (nth 1 range) | 916 | click-count) |
| 896 | (window-buffer start-window)) | 917 | (overlay-put mouse-drag-overlay 'window start-window) |
| 897 | (overlay-put mouse-drag-overlay 'window (selected-window))) | ||
| 898 | (deactivate-mark) | 918 | (deactivate-mark) |
| 899 | (let (event end end-point last-end-point) | 919 | (let (event end end-point last-end-point) |
| 900 | (track-mouse | 920 | (track-mouse |
| 901 | (while (progn | 921 | (while (progn |
| 902 | (setq event (read-event)) | 922 | (setq event (read-event)) |
| 903 | (or (mouse-movement-p event) | 923 | (or (mouse-movement-p event) |
| 904 | (memq (car-safe event) '(switch-frame select-window)))) | 924 | (memq (car-safe event) '(switch-frame select-window)))) |
| 905 | (if (memq (car-safe event) '(switch-frame select-window)) | 925 | (if (memq (car-safe event) '(switch-frame select-window)) |
| 906 | nil | 926 | nil |
| 907 | (setq end (event-end event) | 927 | (setq end (event-end event) |
| 908 | end-point (posn-point end)) | 928 | end-point (posn-point end)) |
| @@ -913,45 +933,33 @@ at the same position." | |||
| 913 | ;; Are we moving within the original window? | 933 | ;; Are we moving within the original window? |
| 914 | ((and (eq (posn-window end) start-window) | 934 | ((and (eq (posn-window end) start-window) |
| 915 | (integer-or-marker-p end-point)) | 935 | (integer-or-marker-p end-point)) |
| 916 | ;; Go to START-POINT first, so that when we move to END-POINT, | 936 | (mouse-move-drag-overlay mouse-drag-overlay start-point end-point click-count)) |
| 917 | ;; if it's in the middle of intangible text, | ||
| 918 | ;; point jumps in the direction away from START-POINT. | ||
| 919 | (goto-char start-point) | ||
| 920 | (goto-char end-point) | ||
| 921 | (let ((range (mouse-start-end start-point (point) click-count))) | ||
| 922 | (move-overlay mouse-drag-overlay (car range) (nth 1 range)))) | ||
| 923 | 937 | ||
| 924 | (t | 938 | (t |
| 925 | (let ((mouse-row (cdr (cdr (mouse-position))))) | 939 | (let ((mouse-row (cdr (cdr (mouse-position))))) |
| 926 | (cond | 940 | (cond |
| 927 | ((null mouse-row)) | 941 | ((null mouse-row)) |
| 928 | ((< mouse-row top) | 942 | ((< mouse-row top) |
| 929 | (mouse-scroll-subr start-window (- mouse-row top) | 943 | (mouse-scroll-subr start-window (- mouse-row top) |
| 930 | mouse-drag-overlay start-point)) | 944 | mouse-drag-overlay start-point)) |
| 931 | ((>= mouse-row bottom) | 945 | ((>= mouse-row bottom) |
| 932 | (mouse-scroll-subr start-window (1+ (- mouse-row bottom)) | 946 | (mouse-scroll-subr start-window (1+ (- mouse-row bottom)) |
| 933 | mouse-drag-overlay start-point))))))))) | 947 | mouse-drag-overlay start-point))))))))) |
| 934 | 948 | ||
| 935 | ;; In case we did not get a mouse-motion event | 949 | ;; In case we did not get a mouse-motion event |
| 936 | ;; for the final move of the mouse before a drag event | 950 | ;; for the final move of the mouse before a drag event |
| 937 | ;; pretend that we did get one. | 951 | ;; pretend that we did get one. |
| 938 | (when (and (memq 'drag (event-modifiers (car-safe event))) | 952 | (when (and (memq 'drag (event-modifiers (car-safe event))) |
| 939 | (setq end (event-end event) | 953 | (setq end (event-end event) |
| 940 | end-point (posn-point end)) | 954 | end-point (posn-point end)) |
| 941 | (eq (posn-window end) start-window) | 955 | (eq (posn-window end) start-window) |
| 942 | (integer-or-marker-p end-point)) | 956 | (integer-or-marker-p end-point)) |
| 943 | ;; Go to START-POINT first, so that when we move to END-POINT, | 957 | (mouse-move-drag-overlay mouse-drag-overlay start-point end-point click-count)) |
| 944 | ;; if it's in the middle of intangible text, | ||
| 945 | ;; point jumps in the direction away from START-POINT. | ||
| 946 | (goto-char start-point) | ||
| 947 | (goto-char end-point) | ||
| 948 | (let ((range (mouse-start-end start-point (point) click-count))) | ||
| 949 | (move-overlay mouse-drag-overlay (car range) (nth 1 range)))) | ||
| 950 | 958 | ||
| 951 | (if (consp event) | 959 | (if (consp event) |
| 952 | (let ((fun (key-binding (vector (car event))))) | 960 | (let ((fun (key-binding (vector (car event))))) |
| 953 | ;; Run the binding of the terminating up-event, if possible. | 961 | ;; Run the binding of the terminating up-event, if possible. |
| 954 | ;; In the case of a multiple click, it gives the wrong results, | 962 | ;; In the case of a multiple click, it gives the wrong results, |
| 955 | ;; because it would fail to set up a region. | 963 | ;; because it would fail to set up a region. |
| 956 | (if (not (= (overlay-start mouse-drag-overlay) | 964 | (if (not (= (overlay-start mouse-drag-overlay) |
| 957 | (overlay-end mouse-drag-overlay))) | 965 | (overlay-end mouse-drag-overlay))) |
| @@ -962,74 +970,75 @@ at the same position." | |||
| 962 | ;; The end that comes from where we ended the drag. | 970 | ;; The end that comes from where we ended the drag. |
| 963 | ;; Point goes here. | 971 | ;; Point goes here. |
| 964 | (region-termination | 972 | (region-termination |
| 965 | (if (and stop-point (< stop-point start-point)) | 973 | (if (and stop-point (< stop-point start-point)) |
| 966 | (overlay-start mouse-drag-overlay) | 974 | (overlay-start mouse-drag-overlay) |
| 967 | (overlay-end mouse-drag-overlay))) | 975 | (overlay-end mouse-drag-overlay))) |
| 968 | ;; The end that comes from where we started the drag. | 976 | ;; The end that comes from where we started the drag. |
| 969 | ;; Mark goes there. | 977 | ;; Mark goes there. |
| 970 | (region-commencement | 978 | (region-commencement |
| 971 | (- (+ (overlay-end mouse-drag-overlay) | 979 | (- (+ (overlay-end mouse-drag-overlay) |
| 972 | (overlay-start mouse-drag-overlay)) | 980 | (overlay-start mouse-drag-overlay)) |
| 973 | region-termination)) | 981 | region-termination)) |
| 974 | last-command this-command) | 982 | last-command this-command) |
| 975 | (push-mark region-commencement t t) | 983 | (push-mark region-commencement t t) |
| 976 | (goto-char region-termination) | 984 | (goto-char region-termination) |
| 977 | ;; Don't let copy-region-as-kill set deactivate-mark. | 985 | ;; Don't let copy-region-as-kill set deactivate-mark. |
| 978 | (when mouse-drag-copy-region | 986 | (when mouse-drag-copy-region |
| 979 | (let (deactivate-mark) | 987 | (let (deactivate-mark) |
| 980 | (copy-region-as-kill (point) (mark t)))) | 988 | (copy-region-as-kill (point) (mark t)))) |
| 981 | (let ((buffer (current-buffer))) | 989 | (let ((buffer (current-buffer))) |
| 982 | (mouse-show-mark) | 990 | (mouse-show-mark) |
| 983 | ;; mouse-show-mark can call read-event, | 991 | ;; mouse-show-mark can call read-event, |
| 984 | ;; and that means the Emacs server could switch buffers | 992 | ;; and that means the Emacs server could switch buffers |
| 985 | ;; under us. If that happened, | 993 | ;; under us. If that happened, |
| 986 | ;; avoid trying to use the region. | 994 | ;; avoid trying to use the region. |
| 987 | (and (mark t) mark-active | 995 | (and (mark t) mark-active |
| 988 | (eq buffer (current-buffer)) | 996 | (eq buffer (current-buffer)) |
| 989 | (mouse-set-region-1)))) | 997 | (mouse-set-region-1)))) |
| 990 | (delete-overlay mouse-drag-overlay) | 998 | (delete-overlay mouse-drag-overlay) |
| 991 | ;; Run the binding of the terminating up-event. | 999 | ;; Run the binding of the terminating up-event. |
| 992 | (when (and (functionp fun) | 1000 | (when (and (functionp fun) |
| 993 | (= start-hscroll (window-hscroll start-window)) | 1001 | (= start-hscroll (window-hscroll start-window)) |
| 994 | ;; Don't run the up-event handler if the | 1002 | ;; Don't run the up-event handler if the |
| 995 | ;; window start changed in a redisplay after | 1003 | ;; window start changed in a redisplay after |
| 996 | ;; the mouse-set-point for the down-mouse | 1004 | ;; the mouse-set-point for the down-mouse |
| 997 | ;; event at the beginning of this function. | 1005 | ;; event at the beginning of this function. |
| 998 | ;; When the window start has changed, the | 1006 | ;; When the window start has changed, the |
| 999 | ;; up-mouse event will contain a different | 1007 | ;; up-mouse event will contain a different |
| 1000 | ;; position due to the new window contents, | 1008 | ;; position due to the new window contents, |
| 1001 | ;; and point is set again. | 1009 | ;; and point is set again. |
| 1002 | (or end-point | 1010 | (or end-point |
| 1003 | (= (window-start start-window) | 1011 | (= (window-start start-window) |
| 1004 | start-window-start))) | 1012 | start-window-start))) |
| 1005 | (if (and on-link | 1013 | (if (and on-link |
| 1006 | (or (not end-point) (= end-point start-point)) | 1014 | (or (not end-point) (= end-point start-point)) |
| 1007 | (consp event) | 1015 | (consp event) |
| 1008 | (or remap-double-click | 1016 | (or remap-double-click |
| 1009 | (and | 1017 | (and |
| 1010 | (not (eq mouse-1-click-follows-link 'double)) | 1018 | (not (eq mouse-1-click-follows-link 'double)) |
| 1011 | (= click-count 0) | 1019 | (= click-count 0) |
| 1012 | (= (event-click-count event) 1) | 1020 | (= (event-click-count event) 1) |
| 1013 | (not (input-pending-p)) | 1021 | (not (input-pending-p)) |
| 1014 | (or (not (integerp mouse-1-click-follows-link)) | 1022 | (or (not (integerp mouse-1-click-follows-link)) |
| 1015 | (let ((t0 (posn-timestamp (event-start start-event))) | 1023 | (let ((t0 (posn-timestamp (event-start start-event))) |
| 1016 | (t1 (posn-timestamp (event-end event)))) | 1024 | (t1 (posn-timestamp (event-end event)))) |
| 1017 | (and (integerp t0) (integerp t1) | 1025 | (and (integerp t0) (integerp t1) |
| 1018 | (if (> mouse-1-click-follows-link 0) | 1026 | (if (> mouse-1-click-follows-link 0) |
| 1019 | (<= (- t1 t0) mouse-1-click-follows-link) | 1027 | (<= (- t1 t0) mouse-1-click-follows-link) |
| 1020 | (< (- t0 t1) mouse-1-click-follows-link))))) | 1028 | (< (- t0 t1) mouse-1-click-follows-link))))) |
| 1021 | (or (not double-click-time) | 1029 | (or (not double-click-time) |
| 1022 | (sit-for 0 (if (integerp double-click-time) | 1030 | (sit-for 0 (if (integerp double-click-time) |
| 1023 | double-click-time 500) t))))) | 1031 | double-click-time 500) t))))) |
| 1024 | (if (or (vectorp on-link) (stringp on-link)) | 1032 | (if (or (vectorp on-link) (stringp on-link)) |
| 1025 | (setq event (aref on-link 0)) | 1033 | (setq event (aref on-link 0)) |
| 1026 | (setcar event 'mouse-2))) | 1034 | (setcar event 'mouse-2))) |
| 1027 | (setq unread-command-events | 1035 | (push event unread-command-events)))) |
| 1028 | (cons event unread-command-events))))) | 1036 | |
| 1037 | ;; Case where the end-event is not a cons cell (it's just a boring | ||
| 1038 | ;; char-key-press). | ||
| 1029 | (delete-overlay mouse-drag-overlay))))) | 1039 | (delete-overlay mouse-drag-overlay))))) |
| 1030 | 1040 | ||
| 1031 | ;; Commands to handle xterm-style multiple clicks. | 1041 | ;; Commands to handle xterm-style multiple clicks. |
| 1032 | |||
| 1033 | (defun mouse-skip-word (dir) | 1042 | (defun mouse-skip-word (dir) |
| 1034 | "Skip over word, over whitespace, or over identical punctuation. | 1043 | "Skip over word, over whitespace, or over identical punctuation. |
| 1035 | If DIR is positive skip forward; if negative, skip backward." | 1044 | If DIR is positive skip forward; if negative, skip backward." |
| @@ -1338,8 +1347,8 @@ If you do this twice in the same position, the selection is killed." | |||
| 1338 | ;; Don't let a subsequent kill command append to this one: | 1347 | ;; Don't let a subsequent kill command append to this one: |
| 1339 | ;; prevent setting this-command to kill-region. | 1348 | ;; prevent setting this-command to kill-region. |
| 1340 | (this-command this-command)) | 1349 | (this-command this-command)) |
| 1341 | (if (and (save-excursion | 1350 | (if (and (with-current-buffer |
| 1342 | (set-buffer (window-buffer (posn-window (event-start click)))) | 1351 | (window-buffer (posn-window (event-start click))) |
| 1343 | (and (mark t) (> (mod mouse-selection-click-count 3) 0) | 1352 | (and (mark t) (> (mod mouse-selection-click-count 3) 0) |
| 1344 | ;; Don't be fooled by a recent click in some other buffer. | 1353 | ;; Don't be fooled by a recent click in some other buffer. |
| 1345 | (eq mouse-selection-click-count-buffer | 1354 | (eq mouse-selection-click-count-buffer |
| @@ -1402,15 +1411,14 @@ If you do this twice in the same position, the selection is killed." | |||
| 1402 | (goto-char new) | 1411 | (goto-char new) |
| 1403 | (set-mark new)) | 1412 | (set-mark new)) |
| 1404 | (setq deactivate-mark nil))) | 1413 | (setq deactivate-mark nil))) |
| 1405 | (kill-new (buffer-substring (point) (mark t)) t) | 1414 | (kill-new (buffer-substring (point) (mark t)) t)) |
| 1406 | (mouse-show-mark)) | ||
| 1407 | ;; Set the mark where point is, then move where clicked. | 1415 | ;; Set the mark where point is, then move where clicked. |
| 1408 | (mouse-set-mark-fast click) | 1416 | (mouse-set-mark-fast click) |
| 1409 | (if before-scroll | 1417 | (if before-scroll |
| 1410 | (goto-char before-scroll)) | 1418 | (goto-char before-scroll)) |
| 1411 | (exchange-point-and-mark) | 1419 | (exchange-point-and-mark) ;Why??? --Stef |
| 1412 | (kill-new (buffer-substring (point) (mark t))) | 1420 | (kill-new (buffer-substring (point) (mark t)))) |
| 1413 | (mouse-show-mark)) | 1421 | (mouse-show-mark) |
| 1414 | (mouse-set-region-1) | 1422 | (mouse-set-region-1) |
| 1415 | (setq mouse-save-then-kill-posn | 1423 | (setq mouse-save-then-kill-posn |
| 1416 | (list (car kill-ring) (point) click-posn))))))) | 1424 | (list (car kill-ring) (point) click-posn))))))) |
| @@ -1421,10 +1429,13 @@ If you do this twice in the same position, the selection is killed." | |||
| 1421 | (global-set-key [M-mouse-3] 'mouse-secondary-save-then-kill) | 1429 | (global-set-key [M-mouse-3] 'mouse-secondary-save-then-kill) |
| 1422 | (global-set-key [M-mouse-2] 'mouse-yank-secondary) | 1430 | (global-set-key [M-mouse-2] 'mouse-yank-secondary) |
| 1423 | 1431 | ||
| 1424 | ;; An overlay which records the current secondary selection | 1432 | (defconst mouse-secondary-overlay |
| 1425 | ;; or else is deleted when there is no secondary selection. | 1433 | (let ((ol (make-overlay (point-min) (point-min)))) |
| 1426 | ;; May be nil. | 1434 | (delete-overlay ol) |
| 1427 | (defvar mouse-secondary-overlay nil) | 1435 | (overlay-put ol 'face 'secondary-selection) |
| 1436 | ol) | ||
| 1437 | "An overlay which records the current secondary selection. | ||
| 1438 | It is deleted when there is no secondary selection.") | ||
| 1428 | 1439 | ||
| 1429 | (defvar mouse-secondary-click-count 0) | 1440 | (defvar mouse-secondary-click-count 0) |
| 1430 | 1441 | ||
| @@ -1439,11 +1450,9 @@ and complete the secondary selection." | |||
| 1439 | (interactive "e") | 1450 | (interactive "e") |
| 1440 | (mouse-minibuffer-check click) | 1451 | (mouse-minibuffer-check click) |
| 1441 | (let ((posn (event-start click))) | 1452 | (let ((posn (event-start click))) |
| 1442 | (save-excursion | 1453 | (with-current-buffer (window-buffer (posn-window posn)) |
| 1443 | (set-buffer (window-buffer (posn-window posn))) | ||
| 1444 | ;; Cancel any preexisting secondary selection. | 1454 | ;; Cancel any preexisting secondary selection. |
| 1445 | (if mouse-secondary-overlay | 1455 | (delete-overlay mouse-secondary-overlay) |
| 1446 | (delete-overlay mouse-secondary-overlay)) | ||
| 1447 | (if (numberp (posn-point posn)) | 1456 | (if (numberp (posn-point posn)) |
| 1448 | (progn | 1457 | (progn |
| 1449 | (or mouse-secondary-start | 1458 | (or mouse-secondary-start |
| @@ -1458,14 +1467,10 @@ This must be bound to a mouse drag event." | |||
| 1458 | (let ((posn (event-start click)) | 1467 | (let ((posn (event-start click)) |
| 1459 | beg | 1468 | beg |
| 1460 | (end (event-end click))) | 1469 | (end (event-end click))) |
| 1461 | (save-excursion | 1470 | (with-current-buffer (window-buffer (posn-window posn)) |
| 1462 | (set-buffer (window-buffer (posn-window posn))) | ||
| 1463 | (if (numberp (posn-point posn)) | 1471 | (if (numberp (posn-point posn)) |
| 1464 | (setq beg (posn-point posn))) | 1472 | (setq beg (posn-point posn))) |
| 1465 | (if mouse-secondary-overlay | 1473 | (move-overlay mouse-secondary-overlay beg (posn-point end))))) |
| 1466 | (move-overlay mouse-secondary-overlay beg (posn-point end)) | ||
| 1467 | (setq mouse-secondary-overlay (make-overlay beg (posn-point end)))) | ||
| 1468 | (overlay-put mouse-secondary-overlay 'face 'secondary-selection)))) | ||
| 1469 | 1474 | ||
| 1470 | (defun mouse-drag-secondary (start-event) | 1475 | (defun mouse-drag-secondary (start-event) |
| 1471 | "Set the secondary selection to the text that the mouse is dragged over. | 1476 | "Set the secondary selection to the text that the mouse is dragged over. |
| @@ -1485,20 +1490,16 @@ The function returns a non-nil value if it creates a secondary selection." | |||
| 1485 | ;; Don't count the mode line. | 1490 | ;; Don't count the mode line. |
| 1486 | (1- (nth 3 bounds)))) | 1491 | (1- (nth 3 bounds)))) |
| 1487 | (click-count (1- (event-click-count start-event)))) | 1492 | (click-count (1- (event-click-count start-event)))) |
| 1488 | (save-excursion | 1493 | (with-current-buffer (window-buffer start-window) |
| 1489 | (set-buffer (window-buffer start-window)) | ||
| 1490 | (setq mouse-secondary-click-count click-count) | 1494 | (setq mouse-secondary-click-count click-count) |
| 1491 | (or mouse-secondary-overlay | ||
| 1492 | (setq mouse-secondary-overlay | ||
| 1493 | (make-overlay (point) (point)))) | ||
| 1494 | (overlay-put mouse-secondary-overlay 'face 'secondary-selection) | ||
| 1495 | (if (> (mod click-count 3) 0) | 1495 | (if (> (mod click-count 3) 0) |
| 1496 | ;; Double or triple press: make an initial selection | 1496 | ;; Double or triple press: make an initial selection |
| 1497 | ;; of one word or line. | 1497 | ;; of one word or line. |
| 1498 | (let ((range (mouse-start-end start-point start-point click-count))) | 1498 | (let ((range (mouse-start-end start-point start-point click-count))) |
| 1499 | (set-marker mouse-secondary-start nil) | 1499 | (set-marker mouse-secondary-start nil) |
| 1500 | (move-overlay mouse-secondary-overlay 1 1 | 1500 | ;; Why the double move? --Stef |
| 1501 | (window-buffer start-window)) | 1501 | ;; (move-overlay mouse-secondary-overlay 1 1 |
| 1502 | ;; (window-buffer start-window)) | ||
| 1502 | (move-overlay mouse-secondary-overlay (car range) (nth 1 range) | 1503 | (move-overlay mouse-secondary-overlay (car range) (nth 1 range) |
| 1503 | (window-buffer start-window))) | 1504 | (window-buffer start-window))) |
| 1504 | ;; Single-press: cancel any preexisting secondary selection. | 1505 | ;; Single-press: cancel any preexisting secondary selection. |
| @@ -1583,13 +1584,12 @@ is to prevent accidents." | |||
| 1583 | (current-buffer))) | 1584 | (current-buffer))) |
| 1584 | (error "Select or click on the buffer where the secondary selection is"))) | 1585 | (error "Select or click on the buffer where the secondary selection is"))) |
| 1585 | (let (this-command) | 1586 | (let (this-command) |
| 1586 | (save-excursion | 1587 | (with-current-buffer (overlay-buffer mouse-secondary-overlay) |
| 1587 | (set-buffer (overlay-buffer mouse-secondary-overlay)) | ||
| 1588 | (kill-region (overlay-start mouse-secondary-overlay) | 1588 | (kill-region (overlay-start mouse-secondary-overlay) |
| 1589 | (overlay-end mouse-secondary-overlay)))) | 1589 | (overlay-end mouse-secondary-overlay)))) |
| 1590 | (delete-overlay mouse-secondary-overlay) | 1590 | (delete-overlay mouse-secondary-overlay) |
| 1591 | ;;; (x-set-selection 'SECONDARY nil) | 1591 | ;;; (x-set-selection 'SECONDARY nil) |
| 1592 | (setq mouse-secondary-overlay nil)) | 1592 | ) |
| 1593 | 1593 | ||
| 1594 | (defun mouse-secondary-save-then-kill (click) | 1594 | (defun mouse-secondary-save-then-kill (click) |
| 1595 | "Save text to point in kill ring; the second time, kill the text. | 1595 | "Save text to point in kill ring; the second time, kill the text. |
| @@ -1612,13 +1612,11 @@ again. If you do this twice in the same position, it kills the selection." | |||
| 1612 | ;; prevent setting this-command to kill-region. | 1612 | ;; prevent setting this-command to kill-region. |
| 1613 | (this-command this-command)) | 1613 | (this-command this-command)) |
| 1614 | (or (eq (window-buffer (posn-window posn)) | 1614 | (or (eq (window-buffer (posn-window posn)) |
| 1615 | (or (and mouse-secondary-overlay | 1615 | (or (overlay-buffer mouse-secondary-overlay) |
| 1616 | (overlay-buffer mouse-secondary-overlay)) | ||
| 1617 | (if mouse-secondary-start | 1616 | (if mouse-secondary-start |
| 1618 | (marker-buffer mouse-secondary-start)))) | 1617 | (marker-buffer mouse-secondary-start)))) |
| 1619 | (error "Wrong buffer")) | 1618 | (error "Wrong buffer")) |
| 1620 | (save-excursion | 1619 | (with-current-buffer (window-buffer (posn-window posn)) |
| 1621 | (set-buffer (window-buffer (posn-window posn))) | ||
| 1622 | (if (> (mod mouse-secondary-click-count 3) 0) | 1620 | (if (> (mod mouse-secondary-click-count 3) 0) |
| 1623 | (if (not (and (eq last-command 'mouse-secondary-save-then-kill) | 1621 | (if (not (and (eq last-command 'mouse-secondary-save-then-kill) |
| 1624 | (equal click-posn | 1622 | (equal click-posn |
| @@ -1697,10 +1695,7 @@ again. If you do this twice in the same position, it kills the selection." | |||
| 1697 | ;; so put the other end here. | 1695 | ;; so put the other end here. |
| 1698 | (let ((start (+ 0 mouse-secondary-start))) | 1696 | (let ((start (+ 0 mouse-secondary-start))) |
| 1699 | (kill-ring-save start click-posn) | 1697 | (kill-ring-save start click-posn) |
| 1700 | (if mouse-secondary-overlay | 1698 | (move-overlay mouse-secondary-overlay start click-posn)))) |
| 1701 | (move-overlay mouse-secondary-overlay start click-posn) | ||
| 1702 | (setq mouse-secondary-overlay (make-overlay start click-posn))) | ||
| 1703 | (overlay-put mouse-secondary-overlay 'face 'secondary-selection)))) | ||
| 1704 | (setq mouse-save-then-kill-posn | 1699 | (setq mouse-save-then-kill-posn |
| 1705 | (list (car kill-ring) (point) click-posn)))) | 1700 | (list (car kill-ring) (point) click-posn)))) |
| 1706 | (if (overlay-buffer mouse-secondary-overlay) | 1701 | (if (overlay-buffer mouse-secondary-overlay) |