1 ;;; mouse-sel.el --- multi-click selection support for Emacs 19
3 ;; Copyright (C) 1993,1994,1995,2001,2002 Free Software Foundation, Inc.
5 ;; Author: Mike Williams <mdub@bigfoot.com>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; This module provides multi-click mouse support for GNU Emacs versions
28 ;; 19.18 and later. I've tried to make it behave more like standard X
29 ;; clients (eg. xterm) than the default Emacs 19 mouse selection handlers.
32 ;; * Clicking mouse-1 starts (cancels) selection, dragging extends it.
34 ;; * Clicking or dragging mouse-3 extends the selection as well.
36 ;; * Double-clicking on word constituents selects words.
37 ;; Double-clicking on symbol constituents selects symbols.
38 ;; Double-clicking on quotes or parentheses selects sexps.
39 ;; Double-clicking on whitespace selects whitespace.
40 ;; Triple-clicking selects lines.
41 ;; Quad-clicking selects paragraphs.
43 ;; * Selecting sets the region & X primary selection, but does NOT affect
44 ;; the kill-ring. Because the mouse handlers set the primary selection
45 ;; directly, mouse-sel sets the variables interprogram-cut-function
46 ;; and interprogram-paste-function to nil.
48 ;; * Clicking mouse-2 inserts the contents of the primary selection at
49 ;; the mouse position (or point, if mouse-yank-at-point is non-nil).
51 ;; * Pressing mouse-2 while selecting or extending copies selection
52 ;; to the kill ring. Pressing mouse-1 or mouse-3 kills it.
54 ;; * Double-clicking mouse-3 also kills selection.
56 ;; * M-mouse-1, M-mouse-2 & M-mouse-3 work similarly to mouse-1, mouse-2
57 ;; & mouse-3, but operate on the X secondary selection rather than the
58 ;; primary selection and region.
60 ;; This module requires my thingatpt.el module, which it uses to find the
61 ;; bounds of words, lines, sexps, etc.
63 ;; Thanks to KevinB@bartley.demon.co.uk for his useful input.
65 ;;--- Customisation -------------------------------------------------------
67 ;; * You may want to use none or more of following:
69 ;; ;; Enable region highlight
70 ;; (transient-mark-mode 1)
72 ;; ;; But only in the selected window
73 ;; (setq highlight-nonselected-windows nil)
75 ;; ;; Enable pending-delete
76 ;; (delete-selection-mode 1)
78 ;; * You can control the way mouse-sel binds its keys by setting the value
79 ;; of mouse-sel-default-bindings before loading mouse-sel.
81 ;; (a) If mouse-sel-default-bindings = t (the default)
83 ;; Mouse sets and insert selection
84 ;; mouse-1 mouse-select
85 ;; mouse-2 mouse-insert-selection
86 ;; mouse-3 mouse-extend
88 ;; Selection/kill-ring interaction is disabled
89 ;; interprogram-cut-function = nil
90 ;; interprogram-paste-function = nil
92 ;; (b) If mouse-sel-default-bindings = 'interprogram-cut-paste
94 ;; Mouse sets selection, and pastes from kill-ring
95 ;; mouse-1 mouse-select
96 ;; mouse-2 mouse-insert-selection
97 ;; mouse-3 mouse-extend
98 ;; In this mode, mouse-insert-selection just calls mouse-yank-at-click.
100 ;; Selection/kill-ring interaction is retained
101 ;; interprogram-cut-function = x-select-text
102 ;; interprogram-paste-function = x-cut-buffer-or-selection-value
104 ;; What you lose is the ability to select some text in
105 ;; delete-selection-mode and yank over the top of it.
107 ;; (c) If mouse-sel-default-bindings = nil, no bindings are made.
109 ;; * By default, mouse-insert-selection (mouse-2) inserts the selection at
110 ;; the mouse position. You can tell it to insert at point instead with:
112 ;; (setq mouse-yank-at-point t)
114 ;; * I like to leave point at the end of the region nearest to where the
115 ;; mouse was, even though this makes region highlighting mis-leading (the
116 ;; cursor makes it look like one extra character is selected). You can
117 ;; disable this behaviour with:
119 ;; (setq mouse-sel-leave-point-near-mouse nil)
121 ;; * By default, mouse-select cycles the click count after 4 clicks. That
122 ;; is, clicking mouse-1 five times has the same effect as clicking it
123 ;; once, clicking six times has the same effect as clicking twice, etc.
124 ;; Disable this behaviour with:
126 ;; (setq mouse-sel-cycle-clicks nil)
128 ;; * The variables mouse-sel-{set,get}-selection-function control how the
129 ;; selection is handled. Under X Windows, these variables default so
130 ;; that the X primary selection is used. Under other windowing systems,
131 ;; alternate functions are used, which simply store the selection value
134 ;; * You can change the selection highlight face by altering the properties
135 ;; of mouse-drag-overlay, eg.
137 ;; (overlay-put mouse-drag-overlay 'face 'bold)
147 ;;=== User Variables ======================================================
149 (defgroup mouse-sel nil
150 "Mouse selection enhancement."
153 (defcustom mouse-sel-leave-point-near-mouse t
154 "*Leave point near last mouse position.
155 If non-nil, \\[mouse-select] and \\[mouse-extend] will leave point at the end
156 of the region nearest to where the mouse last was.
157 If nil, point will always be placed at the beginning of the region."
161 (defcustom mouse-sel-cycle-clicks t
162 "*If non-nil, \\[mouse-select] cycles the click-counts after 4 clicks."
166 (defcustom mouse-sel-default-bindings t
167 "*Control mouse bindings."
168 :type
'(choice (const :tag
"none" nil
)
169 (const :tag
"cut and paste" interprogram-cut-paste
)
170 (other :tag
"default bindings" t
))
173 ;;=== Key bindings ========================================================
175 (defconst mouse-sel-bound-events
176 '(;; Primary selection bindings.
178 ;; Bind keys to `ignore' instead of unsetting them because modes may
179 ;; bind `down-mouse-1', for instance, without binding `mouse-1'.
180 ;; If we unset `mouse-1', this leads to a bitch_at_user when the
181 ;; mouse goes up because no matching binding is found for that.
183 ([drag-mouse-1
] . ignore
)
185 ([down-mouse-1
] . mouse-select
)
186 ([down-mouse-3
] . mouse-extend
)
187 ([mouse-2
] . mouse-insert-selection
)
188 ;; Secondary selection bindings.
189 ([M-mouse-1
] . ignore
)
190 ([M-drag-mouse-1
] . ignore
)
191 ([M-mouse-3
] . ignore
)
192 ([M-down-mouse-1
] . mouse-select-secondary
)
193 ([M-mouse-2
] . mouse-insert-secondary
)
194 ([M-down-mouse-3
] . mouse-extend-secondary
))
195 "An alist of events that `mouse-sel-mode' binds.")
197 ;;=== User Command ========================================================
199 (defvar mouse-sel-has-been-enabled nil
200 "Non-nil if Mouse Sel mode has been enabled at least once.")
202 (defvar mouse-sel-original-bindings nil
)
203 (defvar mouse-sel-original-interprogram-cut-function nil
)
204 (defvar mouse-sel-original-interprogram-paste-function nil
)
207 (define-minor-mode mouse-sel-mode
208 "Toggle Mouse Sel mode.
209 With prefix ARG, turn Mouse Sel mode on if and only if ARG is positive.
210 Returns the new status of Mouse Sel mode (non-nil means on).
212 When Mouse Sel mode is enabled, mouse selection is enhanced in various ways:
214 - Clicking mouse-1 starts (cancels) selection, dragging extends it.
216 - Clicking or dragging mouse-3 extends the selection as well.
218 - Double-clicking on word constituents selects words.
219 Double-clicking on symbol constituents selects symbols.
220 Double-clicking on quotes or parentheses selects sexps.
221 Double-clicking on whitespace selects whitespace.
222 Triple-clicking selects lines.
223 Quad-clicking selects paragraphs.
225 - Selecting sets the region & X primary selection, but does NOT affect
226 the `kill-ring', nor do the kill-ring functions change the X selection.
227 Because the mouse handlers set the primary selection directly,
228 mouse-sel sets the variables `interprogram-cut-function' and
229 `interprogram-paste-function' to nil.
231 - Clicking mouse-2 inserts the contents of the primary selection at
232 the mouse position (or point, if `mouse-yank-at-point' is non-nil).
234 - Pressing mouse-2 while selecting or extending copies selection
235 to the kill ring. Pressing mouse-1 or mouse-3 kills it.
237 - Double-clicking mouse-3 also kills selection.
239 - M-mouse-1, M-mouse-2 & M-mouse-3 work similarly to mouse-1, mouse-2
240 & mouse-3, but operate on the X secondary selection rather than the
241 primary selection and region."
246 (add-hook 'x-lost-selection-hooks
'mouse-sel-lost-selection-hook
)
247 (when mouse-sel-default-bindings
248 ;; Save original bindings and replace them with new ones.
249 (setq mouse-sel-original-bindings
250 (mapcar (lambda (binding)
251 (let ((event (car binding
)))
252 (prog1 (cons event
(lookup-key global-map event
))
253 (global-set-key event
(cdr binding
)))))
254 mouse-sel-bound-events
))
255 ;; Update interprogram functions.
256 (setq mouse-sel-original-interprogram-cut-function
257 interprogram-cut-function
258 mouse-sel-original-interprogram-paste-function
259 interprogram-paste-function
260 mouse-sel-has-been-enabled t
)
261 (unless (eq mouse-sel-default-bindings
'interprogram-cut-paste
)
262 (setq interprogram-cut-function nil
263 interprogram-paste-function nil
))))
265 ;; Restore original bindings
266 (remove-hook 'x-lost-selection-hooks
'mouse-sel-lost-selection-hook
)
267 (dolist (binding mouse-sel-original-bindings
)
268 (global-set-key (car binding
) (cdr binding
)))
269 ;; Restore the old values of these variables,
270 ;; only if they were actually saved previously.
271 (if mouse-sel-has-been-enabled
272 (setq interprogram-cut-function
273 mouse-sel-original-interprogram-cut-function
274 interprogram-paste-function
275 mouse-sel-original-interprogram-paste-function
))))
277 ;;=== Internal Variables/Constants ========================================
279 (defvar mouse-sel-primary-thing nil
280 "Type of PRIMARY selection in current buffer.")
281 (make-variable-buffer-local 'mouse-sel-primary-thing
)
283 (defvar mouse-sel-secondary-thing nil
284 "Type of SECONDARY selection in current buffer.")
285 (make-variable-buffer-local 'mouse-sel-secondary-thing
)
287 ;; Ensure that secondary overlay is defined
288 (unless (overlayp mouse-secondary-overlay
)
289 (setq mouse-secondary-overlay
(make-overlay 1 1))
290 (overlay-put mouse-secondary-overlay
'face
'secondary-selection
))
292 (defconst mouse-sel-selection-alist
293 '((PRIMARY mouse-drag-overlay mouse-sel-primary-thing
)
294 (SECONDARY mouse-secondary-overlay mouse-sel-secondary-thing
))
295 "Alist associating selections with variables.
296 Each element is of the form:
298 (SELECTION-NAME OVERLAY-SYMBOL SELECTION-THING-SYMBOL)
300 where SELECTION-NAME = name of selection
301 OVERLAY-SYMBOL = name of variable containing overlay to use
302 SELECTION-THING-SYMBOL = name of variable where the current selection
303 type for this selection should be stored.")
305 (defvar mouse-sel-set-selection-function
306 (if (eq mouse-sel-default-bindings
'interprogram-cut-paste
)
308 (lambda (selection value
)
309 (if (eq selection
'PRIMARY
)
310 (x-select-text value
)
311 (x-set-selection selection value
))))
312 "Function to call to set selection.
313 Called with two arguments:
315 SELECTION, the name of the selection concerned, and
316 VALUE, the text to store.
318 This sets the selection as well as the cut buffer for the older applications,
319 unless `mouse-sel-default-bindings' is `interprogram-cut-paste'.")
321 (defvar mouse-sel-get-selection-function
323 (if (eq selection
'PRIMARY
)
324 (or (x-cut-buffer-or-selection-value)
325 (bound-and-true-p x-last-selected-text
)
326 (bound-and-true-p x-last-selected-text-primary
))
327 (x-get-selection selection
)))
328 "Function to call to get the selection.
329 Called with one argument:
331 SELECTION: the name of the selection concerned.")
333 ;;=== Support/access functions ============================================
335 (defun mouse-sel-determine-selection-thing (nclicks)
336 "Determine what `thing' `mouse-sel' should operate on.
337 The first argument is NCLICKS, is the number of consecutive
338 mouse clicks at the same position.
340 Double-clicking on word constituents selects words.
341 Double-clicking on symbol constituents selects symbols.
342 Double-clicking on quotes or parentheses selects sexps.
343 Double-clicking on whitespace selects whitespace.
344 Triple-clicking selects lines.
345 Quad-clicking selects paragraphs.
347 Feel free to re-define this function to support your own desired
348 multi-click semantics."
349 (let* ((next-char (char-after (point)))
350 (char-syntax (if next-char
(char-syntax next-char
))))
351 (if mouse-sel-cycle-clicks
352 (setq nclicks
(1+ (%
(1- nclicks
) 4))))
355 ((= nclicks
3) 'line
)
356 ((>= nclicks
4) 'paragraph
)
357 ((memq char-syntax
'(?\
( ?\
) ?
\" ?
')) 'sexp
)
358 ((memq next-char
'(?\s ?
\t ?
\n)) 'whitespace
)
359 ((eq char-syntax ?_
) 'symbol
)
360 ((eq char-syntax ?w
) 'word
))))
362 (defun mouse-sel-set-selection (selection value
)
363 "Set the specified SELECTION to VALUE."
364 (if mouse-sel-set-selection-function
365 (funcall mouse-sel-set-selection-function selection value
)
366 (put 'mouse-sel-internal-selection selection value
)))
368 (defun mouse-sel-get-selection (selection)
369 "Get the value of the specified SELECTION."
370 (if mouse-sel-get-selection-function
371 (funcall mouse-sel-get-selection-function selection
)
372 (get 'mouse-sel-internal-selection selection
)))
374 (defun mouse-sel-selection-overlay (selection)
375 "Return overlay corresponding to SELECTION."
376 (let ((symbol (nth 1 (assoc selection mouse-sel-selection-alist
))))
377 (or symbol
(error "No overlay corresponding to %s selection" selection
))
378 (symbol-value symbol
)))
380 (defun mouse-sel-selection-thing (selection)
381 "Return overlay corresponding to SELECTION."
382 (let ((symbol (nth 2 (assoc selection mouse-sel-selection-alist
))))
383 (or symbol
(error "No symbol corresponding to %s selection" selection
))
386 (defun mouse-sel-region-to-primary (orig-window)
387 "Convert region to PRIMARY overlay and deactivate region.
388 Argument ORIG-WINDOW specifies the window the cursor was in when the
389 originating command was issued, and is used to determine whether the
390 region was visible or not."
391 (if transient-mark-mode
392 (let ((overlay (mouse-sel-selection-overlay 'PRIMARY
)))
395 (or highlight-nonselected-windows
396 (eq orig-window
(selected-window))))
397 ;; Region was visible, so convert region to overlay
398 (move-overlay overlay
(region-beginning) (region-end)
400 ((eq orig-window
(selected-window))
401 ;; Point was visible, so set overlay at point
402 (move-overlay overlay
(point) (point) (current-buffer)))
404 ;; Nothing was visible, so remove overlay
405 (delete-overlay overlay
)))
406 (setq mark-active nil
))))
408 (defun mouse-sel-primary-to-region (&optional direction
)
409 "Convert PRIMARY overlay to region.
410 Optional argument DIRECTION specifies the mouse drag direction: a value of
411 1 indicates that the mouse was dragged left-to-right, otherwise it was
412 dragged right-to-left."
413 (let* ((overlay (mouse-sel-selection-overlay 'PRIMARY
))
414 (start (overlay-start overlay
))
415 (end (overlay-end overlay
)))
418 (if start
(goto-char start
))
420 (if (and mouse-sel-leave-point-near-mouse
(eq direction
1))
423 (push-mark start
'nomsg
'active
))
425 (push-mark end
'nomsg
'active
)))
426 (if transient-mark-mode
(delete-overlay overlay
))))
428 (defmacro mouse-sel-eval-at-event-end
(event &rest forms
)
429 "Evaluate forms at mouse position.
430 Move to the end position of EVENT, execute FORMS, and restore original
432 `(let ((posn (event-end ,event
)))
433 (if posn
(mouse-minibuffer-check ,event
))
434 (if (and posn
(not (windowp (posn-window posn
))))
435 (error "Cursor not in text area of window"))
436 (let (orig-window orig-point-marker
)
437 (setq orig-window
(selected-window))
438 (if posn
(select-window (posn-window posn
)))
439 (setq orig-point-marker
(point-marker))
440 (if (and posn
(numberp (posn-point posn
)))
441 (goto-char (posn-point posn
)))
445 (goto-char (marker-position orig-point-marker
))
446 (move-marker orig-point-marker nil
)
447 (select-window orig-window
)))))
449 (put 'mouse-sel-eval-at-event-end
'lisp-indent-hook
1)
451 ;;=== Select ==============================================================
453 (defun mouse-select (event)
454 "Set region/selection using the mouse.
456 Click sets point & mark to click position.
457 Dragging extends region/selection.
459 Multi-clicking selects word/lines/paragraphs, as determined by
460 'mouse-sel-determine-selection-thing.
462 Clicking mouse-2 while selecting copies selected text to the kill-ring.
463 Clicking mouse-1 or mouse-3 kills the selected text.
465 This should be bound to a down-mouse event."
469 (setq direction
(mouse-select-internal 'PRIMARY event
))
470 (mouse-sel-primary-to-region direction
))))
472 (defun mouse-select-secondary (event)
473 "Set secondary selection using the mouse.
475 Click sets the start of the secondary selection to click position.
476 Dragging extends the secondary selection.
478 Multi-clicking selects word/lines/paragraphs, as determined by
479 'mouse-sel-determine-selection-thing.
481 Clicking mouse-2 while selecting copies selected text to the kill-ring.
482 Clicking mouse-1 or mouse-3 kills the selected text.
484 This should be bound to a down-mouse event."
486 (mouse-select-internal 'SECONDARY event
))
488 (defun mouse-select-internal (selection event
)
489 "Set SELECTION using the mouse."
490 (mouse-sel-eval-at-event-end event
491 (let ((thing-symbol (mouse-sel-selection-thing selection
))
492 (overlay (mouse-sel-selection-overlay selection
)))
494 (mouse-sel-determine-selection-thing (event-click-count event
)))
495 (let ((object-bounds (bounds-of-thing-at-point
496 (symbol-value thing-symbol
))))
499 (move-overlay overlay
500 (car object-bounds
) (cdr object-bounds
)
502 (move-overlay overlay
(point) (point) (current-buffer)))))
503 (mouse-extend-internal selection
)))
505 ;;=== Extend ==============================================================
507 (defun mouse-extend (event)
508 "Extend region/selection using the mouse."
510 (let ((orig-window (selected-window))
512 (select-window (posn-window (event-end event
)))
515 (mouse-sel-region-to-primary orig-window
)
516 (setq direction
(mouse-extend-internal 'PRIMARY event
)))
517 (mouse-sel-primary-to-region direction
))))
519 (defun mouse-extend-secondary (event)
520 "Extend secondary selection using the mouse."
522 (save-window-excursion
523 (mouse-extend-internal 'SECONDARY event
)))
525 (defun mouse-extend-internal (selection &optional initial-event
)
526 "Extend specified SELECTION using the mouse.
527 Track mouse-motion events, adjusting the SELECTION appropriately.
528 Optional argument INITIAL-EVENT specifies an initial down-mouse event to
531 See documentation for mouse-select-internal for more details."
532 (mouse-sel-eval-at-event-end initial-event
533 (let ((orig-cursor-type
534 (cdr (assoc 'cursor-type
(frame-parameters (selected-frame))))))
537 (let* ((thing-symbol (mouse-sel-selection-thing selection
))
538 (overlay (mouse-sel-selection-overlay selection
))
539 (orig-window (selected-window))
540 (orig-window-frame (window-frame orig-window
))
541 (top (nth 1 (window-edges orig-window
)))
542 (bottom (nth 3 (window-edges orig-window
)))
543 (mark-active nil
) ; inhibit normal region highlight
544 (echo-keystrokes 0) ; don't echo mouse events
549 ;; Get current bounds of overlay
550 (if (eq (overlay-buffer overlay
) (current-buffer))
551 (setq min
(overlay-start overlay
)
552 max
(overlay-end overlay
))
555 (set thing-symbol nil
))
559 (if (fboundp 'modify-frame-parameters
)
560 (modify-frame-parameters (selected-frame)
561 '((cursor-type . bar
))))
566 (while (if initial-event
; Use initial event
568 (setq event initial-event
)
569 (setq initial-event nil
))
570 (setq event
(read-event))
572 (memq (car event
) '(mouse-movement switch-frame
))))
574 (let ((selection-thing (symbol-value thing-symbol
))
575 (end (event-end event
)))
579 ;; Ignore any movement outside the frame
580 ((eq (car-safe event
) 'switch-frame
) nil
)
581 ((and (posn-window end
)
582 (not (eq (let ((posn-w (posn-window end
)))
584 (window-frame posn-w
)
586 (window-frame orig-window
)))) nil
)
588 ;; Different window, same frame
589 ((not (eq (posn-window end
) orig-window
))
590 (let ((end-row (cdr (cdr (mouse-position)))))
592 ((and end-row
(not (bobp)) (< end-row top
))
593 (mouse-scroll-subr orig-window
(- end-row top
)
595 ((and end-row
(not (eobp)) (>= end-row bottom
))
596 (mouse-scroll-subr orig-window
(1+ (- end-row bottom
))
601 ((eq (posn-point end
) 'mode-line
)
602 (mouse-scroll-subr orig-window
1 overlay min
))
604 ;; In original window
605 (t (goto-char (posn-point end
)))
609 ;; Determine direction of drag
611 ((and (not direction
) (not (eq min max
)))
612 (setq direction
(if (< (point) (/ (+ min max
) 2)) -
1 1)))
613 ((and (not (eq direction -
1)) (<= (point) min
))
615 ((and (not (eq direction
1)) (>= (point) max
))
618 (if (not selection-thing
) nil
620 ;; If dragging forward, goal is next character
621 (if (and (eq direction
1) (not (eobp))) (forward-char 1))
623 ;; Move to start/end of selected thing
624 (let ((goal (point)))
625 (goto-char (if (eq 1 direction
) min max
))
628 (while (> (* direction
(- goal
(point))) 0)
629 (forward-thing selection-thing direction
))
631 (forward-thing selection-thing
(- direction
))
633 (if (> (* direction
(- goal
(point))) 0)
638 (move-overlay overlay
639 (if (eq 1 direction
) min
(point))
640 (if (eq -
1 direction
) max
(point))
643 ))) ; end track-mouse
645 ;; Finish up after dragging
646 (let ((overlay-start (overlay-start overlay
))
647 (overlay-end (overlay-end overlay
)))
650 (if (not (eq overlay-start overlay-end
))
651 (mouse-sel-set-selection
653 (buffer-substring overlay-start overlay-end
)))
658 ((eq (event-basic-type last-input-event
) 'mouse-2
)
659 (copy-region-as-kill overlay-start overlay-end
)
660 (read-event) (read-event))
661 ((and (memq (event-basic-type last-input-event
)
663 (memq 'down
(event-modifiers last-input-event
)))
664 (kill-region overlay-start overlay-end
)
665 (move-overlay overlay overlay-start overlay-start
)
666 (read-event) (read-event))
667 ((and (eq (event-basic-type last-input-event
) 'mouse-3
)
668 (memq 'double
(event-modifiers last-input-event
)))
669 (kill-region overlay-start overlay-end
)
670 (move-overlay overlay overlay-start overlay-start
)))))
675 (if (fboundp 'modify-frame-parameters
)
676 (modify-frame-parameters
677 (selected-frame) (list (cons 'cursor-type orig-cursor-type
))))
681 ;;=== Paste ===============================================================
683 (defun mouse-insert-selection (event arg
)
684 "Insert the contents of the PRIMARY selection at mouse click.
685 If `mouse-yank-at-point' is non-nil, insert at point instead."
687 (if (eq mouse-sel-default-bindings
'interprogram-cut-paste
)
688 (mouse-yank-at-click event arg
)
689 (mouse-insert-selection-internal 'PRIMARY event
)))
691 (defun mouse-insert-secondary (event)
692 "Insert the contents of the SECONDARY selection at mouse click.
693 If `mouse-yank-at-point' is non-nil, insert at point instead."
695 (mouse-insert-selection-internal 'SECONDARY event
))
697 (defun mouse-insert-selection-internal (selection event
)
698 "Insert the contents of the named SELECTION at mouse click.
699 If `mouse-yank-at-point' is non-nil, insert at point instead."
700 (unless mouse-yank-at-point
701 (mouse-set-point event
))
702 (when mouse-sel-get-selection-function
703 (push-mark (point) 'nomsg
)
704 (insert (or (funcall mouse-sel-get-selection-function selection
) ""))))
706 ;;=== Handle loss of selections ===========================================
708 (defun mouse-sel-lost-selection-hook (selection)
709 "Remove the overlay for a lost selection."
710 (let ((overlay (mouse-sel-selection-overlay selection
)))
711 (delete-overlay overlay
)))
715 ;;; arch-tag: 86e6c73f-deaa-48d3-a24e-c565fda1f7d7
716 ;;; mouse-sel.el ends here