• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10.1/emacs-93/emacs/lisp/

Lines Matching defs:mouse

0 ;;; mouse-sel.el --- multi-click selection support for Emacs 19
7 ;; Keywords: mouse
28 ;; This module provides multi-click mouse support for GNU Emacs versions
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.
45 ;; the kill-ring. Because the mouse handlers set the primary selection
46 ;; directly, mouse-sel sets the variables interprogram-cut-function
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
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)
85 ;; mouse-1 mouse-select
86 ;; mouse-2 mouse-insert-selection
87 ;; mouse-3 mouse-extend
93 ;; (b) If mouse-sel-default-bindings = 'interprogram-cut-paste
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.
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)
116 ;; mouse was, even though this makes region highlighting mis-leading (the
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
127 ;; (setq mouse-sel-cycle-clicks nil)
129 ;; * The variables mouse-sel-{set,get}-selection-function control how the
136 ;; of mouse-drag-overlay, eg.
138 ;; (overlay-put mouse-drag-overlay 'face 'bold)
142 (require 'mouse)
150 (defgroup mouse-sel nil
152 :group 'mouse)
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.
160 :group 'mouse-sel)
162 (defcustom mouse-sel-cycle-clicks t
163 "*If non-nil, \\[mouse-select] cycles the click-counts after 4 clicks."
165 :group 'mouse-sel)
167 (defcustom mouse-sel-default-bindings t
168 "*Control mouse bindings."
172 :group 'mouse-sel)
176 (defconst mouse-sel-bound-events
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.
183 ([mouse-1] . ignore)
184 ([drag-mouse-1] . ignore)
185 ([mouse-3] . ignore)
186 ([down-mouse-1] . mouse-select)
187 ([down-mouse-3] . mouse-extend)
188 ([mouse-2] . mouse-insert-selection)
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.")
200 (defvar mouse-sel-has-been-enabled nil
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
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.
228 Because the mouse handlers set the primary selection directly,
229 mouse-sel sets the variables `interprogram-cut-function' and
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
244 :group 'mouse-sel
245 (if mouse-sel-mode
247 ;; If mouse-2 has never been done by the user, initialize the
250 (put 'mouse-2 'event-kind 'mouse-click)
251 (add-hook 'x-lost-selection-functions 'mouse-sel-lost-selection-hook)
252 (when mouse-sel-default-bindings
254 (setq mouse-sel-original-bindings
259 mouse-sel-bound-events))
261 (setq mouse-sel-original-interprogram-cut-function
263 mouse-sel-original-interprogram-paste-function
265 mouse-sel-has-been-enabled t)
266 (unless (eq mouse-sel-default-bindings 'interprogram-cut-paste)
271 (remove-hook 'x-lost-selection-functions 'mouse-sel-lost-selection-hook)
272 (dolist (binding mouse-sel-original-bindings)
276 (if mouse-sel-has-been-enabled
278 mouse-sel-original-interprogram-cut-function
280 mouse-sel-original-interprogram-paste-function))))
284 (defvar mouse-sel-primary-thing nil
286 (make-variable-buffer-local 'mouse-sel-primary-thing)
288 (defvar mouse-sel-secondary-thing nil
290 (make-variable-buffer-local 'mouse-sel-secondary-thing)
293 (unless (overlayp mouse-secondary-overlay)
294 (setq mouse-secondary-overlay (make-overlay 1 1))
295 (overlay-put mouse-secondary-overlay 'face 'secondary-selection))
297 (defconst mouse-sel-selection-alist
298 '((PRIMARY mouse-drag-overlay mouse-sel-primary-thing)
299 (SECONDARY mouse-secondary-overlay mouse-sel-secondary-thing))
310 (defvar mouse-sel-set-selection-function
311 (if (eq mouse-sel-default-bindings 'interprogram-cut-paste)
324 unless `mouse-sel-default-bindings' is `interprogram-cut-paste'.")
326 (defvar mouse-sel-get-selection-function
340 (defun mouse-sel-determine-selection-thing (nclicks)
341 "Determine what `thing' `mouse-sel' should operate on.
343 mouse clicks at the same position.
356 (if mouse-sel-cycle-clicks
367 (defun mouse-sel-set-selection (selection value)
369 (if mouse-sel-set-selection-function
370 (funcall mouse-sel-set-selection-function selection value)
371 (put 'mouse-sel-internal-selection selection value)))
373 (defun mouse-sel-get-selection (selection)
375 (if mouse-sel-get-selection-function
376 (funcall mouse-sel-get-selection-function selection)
377 (get 'mouse-sel-internal-selection selection)))
379 (defun mouse-sel-selection-overlay (selection)
381 (let ((symbol (nth 1 (assoc selection mouse-sel-selection-alist))))
385 (defun mouse-sel-selection-thing (selection)
387 (let ((symbol (nth 2 (assoc selection mouse-sel-selection-alist))))
391 (defun mouse-sel-region-to-primary (orig-window)
397 (let ((overlay (mouse-sel-selection-overlay 'PRIMARY)))
413 (defun mouse-sel-primary-to-region (&optional direction)
415 Optional argument DIRECTION specifies the mouse drag direction: a value of
416 1 indicates that the mouse was dragged left-to-right, otherwise it was
418 (let* ((overlay (mouse-sel-selection-overlay 'PRIMARY))
425 (if (and mouse-sel-leave-point-near-mouse (eq direction 1))
433 (defmacro mouse-sel-eval-at-event-end (event &rest forms)
434 "Evaluate forms at mouse position.
438 (if posn (mouse-minibuffer-check ,event))
454 (put 'mouse-sel-eval-at-event-end 'lisp-indent-hook 1)
458 (defun mouse-select (event)
459 "Set region/selection using the mouse.
465 'mouse-sel-determine-selection-thing.
467 Clicking mouse-2 while selecting copies selected text to the kill-ring.
468 Clicking mouse-1 or mouse-3 kills the selected text.
470 This should be bound to a down-mouse event."
474 (setq select (mouse-select-internal 'PRIMARY event))
476 (push (cons 'mouse-2 (cdr event)) unread-command-events)
477 (mouse-sel-primary-to-region select)))))
479 (defun mouse-select-secondary (event)
480 "Set secondary selection using the mouse.
486 'mouse-sel-determine-selection-thing.
488 Clicking mouse-2 while selecting copies selected text to the kill-ring.
489 Clicking mouse-1 or mouse-3 kills the selected text.
491 This should be bound to a down-mouse event."
493 (mouse-select-internal 'SECONDARY event))
495 (defun mouse-select-internal (selection event)
496 "Set SELECTION using the mouse, with EVENT as the initial down-event.
498 made: a value of 1 indicates that the mouse was dragged
501 However, if `mouse-1-click-follows-link' is non-nil and the
502 subsequent mouse events specify following a link, this returns
503 the final mouse-event. In that case, the selection is not set."
504 (mouse-sel-eval-at-event-end event
505 (let ((thing-symbol (mouse-sel-selection-thing selection))
506 (overlay (mouse-sel-selection-overlay selection)))
508 (mouse-sel-determine-selection-thing (event-click-count event)))
518 (mouse-extend-internal selection event t))))
522 (defun mouse-extend (event)
523 "Extend region/selection using the mouse."
530 (mouse-sel-region-to-primary orig-window)
531 (setq direction (mouse-extend-internal 'PRIMARY event)))
532 (mouse-sel-primary-to-region direction))))
534 (defun mouse-extend-secondary (event)
535 "Extend secondary selection using the mouse."
538 (mouse-extend-internal 'SECONDARY event)))
540 (defun mouse-extend-internal (selection &optional initial-event no-process)
541 "Extend specified SELECTION using the mouse.
542 Track mouse-motion events, adjusting the SELECTION appropriately.
543 Optional argument INITIAL-EVENT specifies an initial down-mouse event.
547 See documentation for mouse-select-internal for more details."
548 (mouse-sel-eval-at-event-end initial-event
553 (let* ((thing-symbol (mouse-sel-selection-thing selection))
554 (overlay (mouse-sel-selection-overlay selection))
560 (echo-keystrokes 0) ; don't echo mouse events
580 (track-mouse
589 (memq (car event) '(mouse-movement switch-frame))))
607 (let ((end-row (cdr (cdr (mouse-position)))))
610 (mouse-scroll-subr orig-window (- end-row top)
613 (mouse-scroll-subr orig-window (1+ (- end-row bottom))
619 (mouse-scroll-subr orig-window 1 overlay min))
660 ))) ; end track-mouse
663 (when (mouse-sel-follow-link-p initial-event event)
672 (mouse-sel-set-selection
679 ((eq (event-basic-type last-input-event) 'mouse-2)
683 '(mouse-1 mouse-3))
688 ((and (eq (event-basic-type last-input-event) 'mouse-3)
702 (defun mouse-sel-follow-link-p (initial final)
703 "Return t if we should follow a link, given INITIAL and FINAL mouse events.
704 See `mouse-1-click-follows-link' for details. Currently, Mouse
707 (and initial final mouse-1-click-follows-link
708 (eq (car initial) 'down-mouse-1)
709 (mouse-on-link-p (event-start initial))
713 (or (not (integerp mouse-1-click-follows-link))
717 (if (> mouse-1-click-follows-link 0)
718 (<= (- t1 t0) mouse-1-click-follows-link)
719 (< (- t0 t1) mouse-1-click-follows-link)))))))
723 (defun mouse-insert-selection (event arg)
724 "Insert the contents of the PRIMARY selection at mouse click.
725 If `mouse-yank-at-point' is non-nil, insert at point instead."
727 (if (eq mouse-sel-default-bindings 'interprogram-cut-paste)
728 (mouse-yank-at-click event arg)
729 (mouse-insert-selection-internal 'PRIMARY event)))
731 (defun mouse-insert-secondary (event)
732 "Insert the contents of the SECONDARY selection at mouse click.
733 If `mouse-yank-at-point' is non-nil, insert at point instead."
735 (mouse-insert-selection-internal 'SECONDARY event))
737 (defun mouse-insert-selection-internal (selection event)
738 "Insert the contents of the named SELECTION at mouse click.
739 If `mouse-yank-at-point' is non-nil, insert at point instead."
740 (unless mouse-yank-at-point
741 (mouse-set-point event))
742 (when mouse-sel-get-selection-function
745 (or (funcall mouse-sel-get-selection-function selection) ""))))
749 (defun mouse-sel-lost-selection-hook (selection)
751 (let ((overlay (mouse-sel-selection-overlay selection)))
754 (provide 'mouse-sel)
757 ;;; mouse-sel.el ends here