1 ;;; mouse-sel.el --- multi-click selection support for Emacs 19
3 ;; Copyright (C) 1993, 1994, 1995, 2001, 2002, 2004
4 ;; Free Software Foundation, Inc.
6 ;; Author: Mike Williams <mdub@bigfoot.com>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
28 ;; This module provides multi-click mouse support for GNU Emacs versions
29 ;; 19.18 and later. I've tried to make it behave more like standard X
30 ;; clients (eg. xterm) than the default Emacs 19 mouse selection handlers.
33 ;; * Clicking mouse-1 starts (cancels) selection, dragging extends it.
35 ;; * Clicking or dragging mouse-3 extends the selection as well.
37 ;; * Double-clicking on word constituents selects words.
38 ;; Double-clicking on symbol constituents selects symbols.
39 ;; Double-clicking on quotes or parentheses selects sexps.
40 ;; Double-clicking on whitespace selects whitespace.
41 ;; Triple-clicking selects lines.
42 ;; Quad-clicking selects paragraphs.
44 ;; * Selecting sets the region & X primary selection, but does NOT affect
45 ;; the kill-ring. Because the mouse handlers set the primary selection
46 ;; directly, mouse-sel sets the variables interprogram-cut-function
47 ;; and interprogram-paste-function to nil.
49 ;; * Clicking mouse-2 inserts the contents of the primary selection at
50 ;; the mouse position (or point, if mouse-yank-at-point is non-nil).
52 ;; * Pressing mouse-2 while selecting or extending copies selection
53 ;; to the kill ring. Pressing mouse-1 or mouse-3 kills it.
55 ;; * Double-clicking mouse-3 also kills selection.
57 ;; * M-mouse-1, M-mouse-2 & M-mouse-3 work similarly to mouse-1, mouse-2
58 ;; & mouse-3, but operate on the X secondary selection rather than the
59 ;; primary selection and region.
61 ;; This module requires my thingatpt.el module, which it uses to find the
62 ;; bounds of words, lines, sexps, etc.
64 ;; Thanks to KevinB@bartley.demon.co.uk for his useful input.
66 ;;--- Customisation -------------------------------------------------------
68 ;; * You may want to use none or more of following:
70 ;; ;; Enable region highlight
71 ;; (transient-mark-mode 1)
73 ;; ;; But only in the selected window
74 ;; (setq highlight-nonselected-windows nil)
76 ;; ;; Enable pending-delete
77 ;; (delete-selection-mode 1)
79 ;; * You can control the way mouse-sel binds its keys by setting the value
80 ;; of mouse-sel-default-bindings before loading mouse-sel.
82 ;; (a) If mouse-sel-default-bindings = t (the default)
84 ;; Mouse sets and insert selection
85 ;; mouse-1 mouse-select
86 ;; mouse-2 mouse-insert-selection
87 ;; mouse-3 mouse-extend
89 ;; Selection/kill-ring interaction is disabled
90 ;; interprogram-cut-function = nil
91 ;; interprogram-paste-function = nil
93 ;; (b) If mouse-sel-default-bindings = 'interprogram-cut-paste
95 ;; Mouse sets selection, and pastes from kill-ring
96 ;; mouse-1 mouse-select
97 ;; mouse-2 mouse-insert-selection
98 ;; mouse-3 mouse-extend
99 ;; In this mode, mouse-insert-selection just calls mouse-yank-at-click.
101 ;; Selection/kill-ring interaction is retained
102 ;; interprogram-cut-function = x-select-text
103 ;; interprogram-paste-function = x-cut-buffer-or-selection-value
105 ;; What you lose is the ability to select some text in
106 ;; delete-selection-mode and yank over the top of it.
108 ;; (c) If mouse-sel-default-bindings = nil, no bindings are made.
110 ;; * By default, mouse-insert-selection (mouse-2) inserts the selection at
111 ;; the mouse position. You can tell it to insert at point instead with:
113 ;; (setq mouse-yank-at-point t)
115 ;; * I like to leave point at the end of the region nearest to where the
116 ;; mouse was, even though this makes region highlighting mis-leading (the
117 ;; cursor makes it look like one extra character is selected). You can
118 ;; disable this behaviour with:
120 ;; (setq mouse-sel-leave-point-near-mouse nil)
122 ;; * By default, mouse-select cycles the click count after 4 clicks. That
123 ;; is, clicking mouse-1 five times has the same effect as clicking it
124 ;; once, clicking six times has the same effect as clicking twice, etc.
125 ;; Disable this behaviour with:
127 ;; (setq mouse-sel-cycle-clicks nil)
129 ;; * The variables mouse-sel-{set,get}-selection-function control how the
130 ;; selection is handled. Under X Windows, these variables default so
131 ;; that the X primary selection is used. Under other windowing systems,
132 ;; alternate functions are used, which simply store the selection value
135 ;; * You can change the selection highlight face by altering the properties
136 ;; of mouse-drag-overlay, eg.
138 ;; (overlay-put mouse-drag-overlay 'face 'bold)
148 ;;=== User Variables ======================================================
150 (defgroup mouse-sel nil
151 "Mouse selection enhancement."
154 (defcustom mouse-sel-leave-point-near-mouse t
155 "*Leave point near last mouse position.
156 If non-nil, \\[mouse-select] and \\[mouse-extend] will leave point at the end
157 of the region nearest to where the mouse last was.
158 If nil, point will always be placed at the beginning of the region."
162 (defcustom mouse-sel-cycle-clicks t
163 "*If non-nil, \\[mouse-select] cycles the click-counts after 4 clicks."
167 (defcustom mouse-sel-default-bindings t
168 "*Control mouse bindings."
169 :type
'(choice (const :tag
"none" nil
)
170 (const :tag
"cut and paste" interprogram-cut-paste
)
171 (other :tag
"default bindings" t
))
174 ;;=== Key bindings ========================================================
176 (defconst mouse-sel-bound-events
177 '(;; Primary selection bindings.
179 ;; Bind keys to `ignore' instead of unsetting them because modes may
180 ;; bind `down-mouse-1', for instance, without binding `mouse-1'.
181 ;; If we unset `mouse-1', this leads to a bitch_at_user when the
182 ;; mouse goes up because no matching binding is found for that.
184 ([drag-mouse-1
] . ignore
)
186 ([down-mouse-1
] . mouse-select
)
187 ([down-mouse-3
] . mouse-extend
)
188 ([mouse-2
] . mouse-insert-selection
)
189 ;; Secondary selection bindings.
190 ([M-mouse-1
] . ignore
)
191 ([M-drag-mouse-1
] . ignore
)
192 ([M-mouse-3
] . ignore
)
193 ([M-down-mouse-1
] . mouse-select-secondary
)
194 ([M-mouse-2
] . mouse-insert-secondary
)
195 ([M-down-mouse-3
] . mouse-extend-secondary
))
196 "An alist of events that `mouse-sel-mode' binds.")
198 ;;=== User Command ========================================================
200 (defvar mouse-sel-has-been-enabled nil
201 "Non-nil if Mouse Sel mode has been enabled at least once.")
203 (defvar mouse-sel-original-bindings nil
)
204 (defvar mouse-sel-original-interprogram-cut-function nil
)
205 (defvar mouse-sel-original-interprogram-paste-function nil
)
208 (define-minor-mode mouse-sel-mode
209 "Toggle Mouse Sel mode.
210 With prefix ARG, turn Mouse Sel mode on if and only if ARG is positive.
211 Returns the new status of Mouse Sel mode (non-nil means on).
213 When Mouse Sel mode is enabled, mouse selection is enhanced in various ways:
215 - Clicking mouse-1 starts (cancels) selection, dragging extends it.
217 - Clicking or dragging mouse-3 extends the selection as well.
219 - Double-clicking on word constituents selects words.
220 Double-clicking on symbol constituents selects symbols.
221 Double-clicking on quotes or parentheses selects sexps.
222 Double-clicking on whitespace selects whitespace.
223 Triple-clicking selects lines.
224 Quad-clicking selects paragraphs.
226 - Selecting sets the region & X primary selection, but does NOT affect
227 the `kill-ring', nor do the kill-ring functions change the X selection.
228 Because the mouse handlers set the primary selection directly,
229 mouse-sel sets the variables `interprogram-cut-function' and
230 `interprogram-paste-function' to nil.
232 - Clicking mouse-2 inserts the contents of the primary selection at
233 the mouse position (or point, if `mouse-yank-at-point' is non-nil).
235 - Pressing mouse-2 while selecting or extending copies selection
236 to the kill ring. Pressing mouse-1 or mouse-3 kills it.
238 - Double-clicking mouse-3 also kills selection.
240 - M-mouse-1, M-mouse-2 & M-mouse-3 work similarly to mouse-1, mouse-2
241 & mouse-3, but operate on the X secondary selection rather than the
242 primary selection and region."
247 (add-hook 'x-lost-selection-functions
'mouse-sel-lost-selection-hook
)
248 (when mouse-sel-default-bindings
249 ;; Save original bindings and replace them with new ones.
250 (setq mouse-sel-original-bindings
251 (mapcar (lambda (binding)
252 (let ((event (car binding
)))
253 (prog1 (cons event
(lookup-key global-map event
))
254 (global-set-key event
(cdr binding
)))))
255 mouse-sel-bound-events
))
256 ;; Update interprogram functions.
257 (setq mouse-sel-original-interprogram-cut-function
258 interprogram-cut-function
259 mouse-sel-original-interprogram-paste-function
260 interprogram-paste-function
261 mouse-sel-has-been-enabled t
)
262 (unless (eq mouse-sel-default-bindings
'interprogram-cut-paste
)
263 (setq interprogram-cut-function nil
264 interprogram-paste-function nil
))))
266 ;; Restore original bindings
267 (remove-hook 'x-lost-selection-functions
'mouse-sel-lost-selection-hook
)
268 (dolist (binding mouse-sel-original-bindings
)
269 (global-set-key (car binding
) (cdr binding
)))
270 ;; Restore the old values of these variables,
271 ;; only if they were actually saved previously.
272 (if mouse-sel-has-been-enabled
273 (setq interprogram-cut-function
274 mouse-sel-original-interprogram-cut-function
275 interprogram-paste-function
276 mouse-sel-original-interprogram-paste-function
))))
278 ;;=== Internal Variables/Constants ========================================
280 (defvar mouse-sel-primary-thing nil
281 "Type of PRIMARY selection in current buffer.")
282 (make-variable-buffer-local 'mouse-sel-primary-thing
)
284 (defvar mouse-sel-secondary-thing nil
285 "Type of SECONDARY selection in current buffer.")
286 (make-variable-buffer-local 'mouse-sel-secondary-thing
)
288 ;; Ensure that secondary overlay is defined
289 (unless (overlayp mouse-secondary-overlay
)
290 (setq mouse-secondary-overlay
(make-overlay 1 1))
291 (overlay-put mouse-secondary-overlay
'face
'secondary-selection
))
293 (defconst mouse-sel-selection-alist
294 '((PRIMARY mouse-drag-overlay mouse-sel-primary-thing
)
295 (SECONDARY mouse-secondary-overlay mouse-sel-secondary-thing
))
296 "Alist associating selections with variables.
297 Each element is of the form:
299 (SELECTION-NAME OVERLAY-SYMBOL SELECTION-THING-SYMBOL)
301 where SELECTION-NAME = name of selection
302 OVERLAY-SYMBOL = name of variable containing overlay to use
303 SELECTION-THING-SYMBOL = name of variable where the current selection
304 type for this selection should be stored.")
306 (defvar mouse-sel-set-selection-function
307 (if (eq mouse-sel-default-bindings
'interprogram-cut-paste
)
309 (lambda (selection value
)
310 (if (eq selection
'PRIMARY
)
311 (x-select-text value
)
312 (x-set-selection selection value
))))
313 "Function to call to set selection.
314 Called with two arguments:
316 SELECTION, the name of the selection concerned, and
317 VALUE, the text to store.
319 This sets the selection as well as the cut buffer for the older applications,
320 unless `mouse-sel-default-bindings' is `interprogram-cut-paste'.")
322 (defvar mouse-sel-get-selection-function
324 (if (eq selection
'PRIMARY
)
325 (or (x-cut-buffer-or-selection-value)
326 (bound-and-true-p x-last-selected-text
)
327 (bound-and-true-p x-last-selected-text-primary
))
328 (x-get-selection selection
)))
329 "Function to call to get the selection.
330 Called with one argument:
332 SELECTION: the name of the selection concerned.")
334 ;;=== Support/access functions ============================================
336 (defun mouse-sel-determine-selection-thing (nclicks)
337 "Determine what `thing' `mouse-sel' should operate on.
338 The first argument is NCLICKS, is the number of consecutive
339 mouse clicks at the same position.
341 Double-clicking on word constituents selects words.
342 Double-clicking on symbol constituents selects symbols.
343 Double-clicking on quotes or parentheses selects sexps.
344 Double-clicking on whitespace selects whitespace.
345 Triple-clicking selects lines.
346 Quad-clicking selects paragraphs.
348 Feel free to re-define this function to support your own desired
349 multi-click semantics."
350 (let* ((next-char (char-after (point)))
351 (char-syntax (if next-char
(char-syntax next-char
))))
352 (if mouse-sel-cycle-clicks
353 (setq nclicks
(1+ (%
(1- nclicks
) 4))))
356 ((= nclicks
3) 'line
)
357 ((>= nclicks
4) 'paragraph
)
358 ((memq char-syntax
'(?\
( ?\
) ?
\" ?
')) 'sexp
)
359 ((memq next-char
'(?\s ?
\t ?
\n)) 'whitespace
)
360 ((eq char-syntax ?_
) 'symbol
)
361 ((eq char-syntax ?w
) 'word
))))
363 (defun mouse-sel-set-selection (selection value
)
364 "Set the specified SELECTION to VALUE."
365 (if mouse-sel-set-selection-function
366 (funcall mouse-sel-set-selection-function selection value
)
367 (put 'mouse-sel-internal-selection selection value
)))
369 (defun mouse-sel-get-selection (selection)
370 "Get the value of the specified SELECTION."
371 (if mouse-sel-get-selection-function
372 (funcall mouse-sel-get-selection-function selection
)
373 (get 'mouse-sel-internal-selection selection
)))
375 (defun mouse-sel-selection-overlay (selection)
376 "Return overlay corresponding to SELECTION."
377 (let ((symbol (nth 1 (assoc selection mouse-sel-selection-alist
))))
378 (or symbol
(error "No overlay corresponding to %s selection" selection
))
379 (symbol-value symbol
)))
381 (defun mouse-sel-selection-thing (selection)
382 "Return overlay corresponding to SELECTION."
383 (let ((symbol (nth 2 (assoc selection mouse-sel-selection-alist
))))
384 (or symbol
(error "No symbol corresponding to %s selection" selection
))
387 (defun mouse-sel-region-to-primary (orig-window)
388 "Convert region to PRIMARY overlay and deactivate region.
389 Argument ORIG-WINDOW specifies the window the cursor was in when the
390 originating command was issued, and is used to determine whether the
391 region was visible or not."
392 (if transient-mark-mode
393 (let ((overlay (mouse-sel-selection-overlay 'PRIMARY
)))
396 (or highlight-nonselected-windows
397 (eq orig-window
(selected-window))))
398 ;; Region was visible, so convert region to overlay
399 (move-overlay overlay
(region-beginning) (region-end)
401 ((eq orig-window
(selected-window))
402 ;; Point was visible, so set overlay at point
403 (move-overlay overlay
(point) (point) (current-buffer)))
405 ;; Nothing was visible, so remove overlay
406 (delete-overlay overlay
)))
407 (setq mark-active nil
))))
409 (defun mouse-sel-primary-to-region (&optional direction
)
410 "Convert PRIMARY overlay to region.
411 Optional argument DIRECTION specifies the mouse drag direction: a value of
412 1 indicates that the mouse was dragged left-to-right, otherwise it was
413 dragged right-to-left."
414 (let* ((overlay (mouse-sel-selection-overlay 'PRIMARY
))
415 (start (overlay-start overlay
))
416 (end (overlay-end overlay
)))
419 (if start
(goto-char start
))
421 (if (and mouse-sel-leave-point-near-mouse
(eq direction
1))
424 (push-mark start
'nomsg
'active
))
426 (push-mark end
'nomsg
'active
)))
427 (if transient-mark-mode
(delete-overlay overlay
))))
429 (defmacro mouse-sel-eval-at-event-end
(event &rest forms
)
430 "Evaluate forms at mouse position.
431 Move to the end position of EVENT, execute FORMS, and restore original
433 `(let ((posn (event-end ,event
)))
434 (if posn
(mouse-minibuffer-check ,event
))
435 (if (and posn
(not (windowp (posn-window posn
))))
436 (error "Cursor not in text area of window"))
437 (let (orig-window orig-point-marker
)
438 (setq orig-window
(selected-window))
439 (if posn
(select-window (posn-window posn
)))
440 (setq orig-point-marker
(point-marker))
441 (if (and posn
(numberp (posn-point posn
)))
442 (goto-char (posn-point posn
)))
446 (goto-char (marker-position orig-point-marker
))
447 (move-marker orig-point-marker nil
)
448 (select-window orig-window
)))))
450 (put 'mouse-sel-eval-at-event-end
'lisp-indent-hook
1)
452 ;;=== Select ==============================================================
454 (defun mouse-select (event)
455 "Set region/selection using the mouse.
457 Click sets point & mark to click position.
458 Dragging extends region/selection.
460 Multi-clicking selects word/lines/paragraphs, as determined by
461 'mouse-sel-determine-selection-thing.
463 Clicking mouse-2 while selecting copies selected text to the kill-ring.
464 Clicking mouse-1 or mouse-3 kills the selected text.
466 This should be bound to a down-mouse event."
470 (setq direction
(mouse-select-internal 'PRIMARY event
))
471 (mouse-sel-primary-to-region direction
))))
473 (defun mouse-select-secondary (event)
474 "Set secondary selection using the mouse.
476 Click sets the start of the secondary selection to click position.
477 Dragging extends the secondary selection.
479 Multi-clicking selects word/lines/paragraphs, as determined by
480 'mouse-sel-determine-selection-thing.
482 Clicking mouse-2 while selecting copies selected text to the kill-ring.
483 Clicking mouse-1 or mouse-3 kills the selected text.
485 This should be bound to a down-mouse event."
487 (mouse-select-internal 'SECONDARY event
))
489 (defun mouse-select-internal (selection event
)
490 "Set SELECTION using the mouse."
491 (mouse-sel-eval-at-event-end event
492 (let ((thing-symbol (mouse-sel-selection-thing selection
))
493 (overlay (mouse-sel-selection-overlay selection
)))
495 (mouse-sel-determine-selection-thing (event-click-count event
)))
496 (let ((object-bounds (bounds-of-thing-at-point
497 (symbol-value thing-symbol
))))
500 (move-overlay overlay
501 (car object-bounds
) (cdr object-bounds
)
503 (move-overlay overlay
(point) (point) (current-buffer)))))
504 (mouse-extend-internal selection
)))
506 ;;=== Extend ==============================================================
508 (defun mouse-extend (event)
509 "Extend region/selection using the mouse."
511 (let ((orig-window (selected-window))
513 (select-window (posn-window (event-end event
)))
516 (mouse-sel-region-to-primary orig-window
)
517 (setq direction
(mouse-extend-internal 'PRIMARY event
)))
518 (mouse-sel-primary-to-region direction
))))
520 (defun mouse-extend-secondary (event)
521 "Extend secondary selection using the mouse."
523 (save-window-excursion
524 (mouse-extend-internal 'SECONDARY event
)))
526 (defun mouse-extend-internal (selection &optional initial-event
)
527 "Extend specified SELECTION using the mouse.
528 Track mouse-motion events, adjusting the SELECTION appropriately.
529 Optional argument INITIAL-EVENT specifies an initial down-mouse event to
532 See documentation for mouse-select-internal for more details."
533 (mouse-sel-eval-at-event-end initial-event
534 (let ((orig-cursor-type
535 (cdr (assoc 'cursor-type
(frame-parameters (selected-frame))))))
538 (let* ((thing-symbol (mouse-sel-selection-thing selection
))
539 (overlay (mouse-sel-selection-overlay selection
))
540 (orig-window (selected-window))
541 (orig-window-frame (window-frame orig-window
))
542 (top (nth 1 (window-edges orig-window
)))
543 (bottom (nth 3 (window-edges orig-window
)))
544 (mark-active nil
) ; inhibit normal region highlight
545 (echo-keystrokes 0) ; don't echo mouse events
550 ;; Get current bounds of overlay
551 (if (eq (overlay-buffer overlay
) (current-buffer))
552 (setq min
(overlay-start overlay
)
553 max
(overlay-end overlay
))
556 (set thing-symbol nil
))
560 (if (fboundp 'modify-frame-parameters
)
561 (modify-frame-parameters (selected-frame)
562 '((cursor-type . bar
))))
567 (while (if initial-event
; Use initial event
569 (setq event initial-event
)
570 (setq initial-event nil
))
571 (setq event
(read-event))
573 (memq (car event
) '(mouse-movement switch-frame
))))
575 (let ((selection-thing (symbol-value thing-symbol
))
576 (end (event-end event
)))
580 ;; Ignore any movement outside the frame
581 ((eq (car-safe event
) 'switch-frame
) nil
)
582 ((and (posn-window end
)
583 (not (eq (let ((posn-w (posn-window end
)))
585 (window-frame posn-w
)
587 (window-frame orig-window
)))) nil
)
589 ;; Different window, same frame
590 ((not (eq (posn-window end
) orig-window
))
591 (let ((end-row (cdr (cdr (mouse-position)))))
593 ((and end-row
(not (bobp)) (< end-row top
))
594 (mouse-scroll-subr orig-window
(- end-row top
)
596 ((and end-row
(not (eobp)) (>= end-row bottom
))
597 (mouse-scroll-subr orig-window
(1+ (- end-row bottom
))
602 ((eq (posn-point end
) 'mode-line
)
603 (mouse-scroll-subr orig-window
1 overlay min
))
605 ;; In original window
606 (t (goto-char (posn-point end
)))
610 ;; Determine direction of drag
612 ((and (not direction
) (not (eq min max
)))
613 (setq direction
(if (< (point) (/ (+ min max
) 2)) -
1 1)))
614 ((and (not (eq direction -
1)) (<= (point) min
))
616 ((and (not (eq direction
1)) (>= (point) max
))
619 (if (not selection-thing
) nil
621 ;; If dragging forward, goal is next character
622 (if (and (eq direction
1) (not (eobp))) (forward-char 1))
624 ;; Move to start/end of selected thing
625 (let ((goal (point)))
626 (goto-char (if (eq 1 direction
) min max
))
629 (while (> (* direction
(- goal
(point))) 0)
630 (forward-thing selection-thing direction
))
632 (forward-thing selection-thing
(- direction
))
634 (if (> (* direction
(- goal
(point))) 0)
639 (move-overlay overlay
640 (if (eq 1 direction
) min
(point))
641 (if (eq -
1 direction
) max
(point))
644 ))) ; end track-mouse
646 ;; Finish up after dragging
647 (let ((overlay-start (overlay-start overlay
))
648 (overlay-end (overlay-end overlay
)))
651 (if (not (eq overlay-start overlay-end
))
652 (mouse-sel-set-selection
654 (buffer-substring overlay-start overlay-end
)))
659 ((eq (event-basic-type last-input-event
) 'mouse-2
)
660 (copy-region-as-kill overlay-start overlay-end
)
661 (read-event) (read-event))
662 ((and (memq (event-basic-type last-input-event
)
664 (memq 'down
(event-modifiers last-input-event
)))
665 (kill-region overlay-start overlay-end
)
666 (move-overlay overlay overlay-start overlay-start
)
667 (read-event) (read-event))
668 ((and (eq (event-basic-type last-input-event
) 'mouse-3
)
669 (memq 'double
(event-modifiers last-input-event
)))
670 (kill-region overlay-start overlay-end
)
671 (move-overlay overlay overlay-start overlay-start
)))))
676 (if (fboundp 'modify-frame-parameters
)
677 (modify-frame-parameters
678 (selected-frame) (list (cons 'cursor-type orig-cursor-type
))))
682 ;;=== Paste ===============================================================
684 (defun mouse-insert-selection (event arg
)
685 "Insert the contents of the PRIMARY selection at mouse click.
686 If `mouse-yank-at-point' is non-nil, insert at point instead."
688 (if (eq mouse-sel-default-bindings
'interprogram-cut-paste
)
689 (mouse-yank-at-click event arg
)
690 (mouse-insert-selection-internal 'PRIMARY event
)))
692 (defun mouse-insert-secondary (event)
693 "Insert the contents of the SECONDARY selection at mouse click.
694 If `mouse-yank-at-point' is non-nil, insert at point instead."
696 (mouse-insert-selection-internal 'SECONDARY event
))
698 (defun mouse-insert-selection-internal (selection event
)
699 "Insert the contents of the named SELECTION at mouse click.
700 If `mouse-yank-at-point' is non-nil, insert at point instead."
701 (unless mouse-yank-at-point
702 (mouse-set-point event
))
703 (when mouse-sel-get-selection-function
704 (push-mark (point) 'nomsg
)
705 (insert (or (funcall mouse-sel-get-selection-function selection
) ""))))
707 ;;=== Handle loss of selections ===========================================
709 (defun mouse-sel-lost-selection-hook (selection)
710 "Remove the overlay for a lost selection."
711 (let ((overlay (mouse-sel-selection-overlay selection
)))
712 (delete-overlay overlay
)))
716 ;; arch-tag: 86e6c73f-deaa-48d3-a24e-c565fda1f7d7
717 ;;; mouse-sel.el ends here