home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / misc / x-mouse.el < prev    next >
Encoding:
Text File  |  1990-07-22  |  3.3 KB  |  80 lines

  1. ;From ark1!uakari.primate.wisc.edu!samsung!cs.utexas.edu!rice!brazos!rich Fri Apr 20 11:02:19 EDT 1990
  2. ;Article 1809 of comp.emacs:
  3. ;Xref: ark1 comp.emacs:1809 gnu.emacs:1543
  4. ;Path: ark1!uakari.primate.wisc.edu!samsung!cs.utexas.edu!rice!brazos!rich
  5. ;From: rich@Rice.edu (Rich Murphey)
  6. ;Newsgroups: comp.emacs,gnu.emacs
  7. ;Subject: Re: GNU Emacs X Windows cut
  8. ;Message-ID: <RICH.90Apr19231705@kalliope.Rice.edu>
  9. ;Date: 20 Apr 90 04:17:05 GMT
  10. ;References: <1990Apr19.023817.8046@ctr.columbia.edu>
  11. ;    <DAVIDE.90Apr19122828@maverick.cad.mcc.com>
  12. ;Sender: root@rice.edu
  13. ;Reply-To: Rich@Rice.edu (Rich Murphey)
  14. ;Followup-To: comp.emacs
  15. ;Organization: Department of Electrical and Computer Engineering, Rice
  16. ;    University
  17. ;Lines: 60
  18. ;In-reply-to: davide@maverick.cad.mcc.com's message of 19 Apr 90 17:28:28 GMT
  19. ;
  20. ;
  21. ;In article <DAVIDE.90Apr19122828@maverick.cad.mcc.com> davide@maverick.cad.mcc.com (David Eckelkamp) writes:
  22. ;   The
  23. ;   thing that most like is that it makes the emacs mouse work very
  24. ;   similar to xterm. Press mouse-left, drag then release mouse-left to
  25. ;   mark a region and put the region in the cut-buffer. A mouse middle
  26. ;   will paste the cut-buffer *at the Emacs point*, not the mouse cursor
  27. ;   point.
  28. ;
  29. ;
  30. ;David points out cutting text in the xterm style -- point and drag --
  31. ;is useful.  Here's another version of x-cut-text-if-moved which, like
  32. ;xterm, doesn't move the cursor while you are dragging text.  One
  33. ;obvious use is in a shell buffer, where you generally want leave the
  34. ;cursor on the command line and paste text onto it.  Rich@Rice.edu
  35.  
  36.  
  37. ;; Cut and paste text using the mouse without distubing the cursor.
  38. ;; Based on x-mouse.el, part of GNU Emacs.
  39. ;; Copyright (C) 1985, 1987 Free Software Foundation, Inc.
  40.  
  41. (defun x-mouse-get-point-and-window (arg)
  42.   "Get the point and window at the current mouse position."
  43.   (save-window-excursion
  44.     (save-excursion
  45.       (x-mouse-set-point arg)
  46.       (list (point) (selected-window)))))
  47.  
  48. (defvar button-down-point-and-window nil
  49.   "A list containing the point (buffer position) and window where the
  50. button down was saved.  See x-set-button-down-point-and-window.")
  51.  
  52. (defun x-set-button-down-point-and-window (arg)
  53.   "Save the location of mouse the variable `button-down-point-and-window'.
  54. The location is a list containing the point (buffer position) and window."
  55.   (setq button-down-point-and-window (x-mouse-get-point-and-window arg)))
  56.  
  57. (defun x-cut-text-if-moved (arg)
  58.   "If the mouse has moved between button down and button up, copy text
  59. between button down and button up points into the window system cut
  60. buffer.  Save the text in Emacs kill ring also."
  61.   (let* ((button-up-point-and-window (x-mouse-get-point-and-window arg))
  62.     (beg (car button-down-point-and-window))
  63.     (end (car button-up-point-and-window))
  64.     (down-win (car (cdr button-down-point-and-window)))
  65.     (up-win (car (cdr button-up-point-and-window))))
  66.     (if (and (not (equal beg end)))
  67.     (if (equal down-win up-win)
  68.         (progn
  69.           (save-window-excursion
  70.         (save-excursion
  71.           (select-window down-win)
  72.           (x-store-cut-buffer (buffer-substring beg end))
  73.           (copy-region-as-kill beg end))))
  74.       (message "You cannot drag across window boundaries.")))))
  75.  
  76. (define-key mouse-map x-button-left-up 'x-cut-text-if-moved)
  77. (define-key mouse-map x-button-left 'x-set-button-down-point-and-window)
  78. ;--
  79. ;Rich@Rice.edu
  80.