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

  1. ;From ark1!uakari.primate.wisc.edu!aplcen!uunet!brunix!tac Sat Mar  3 17:13:27 EST 1990
  2. ;Article 1510 of comp.emacs:
  3. ;Path: ark1!uakari.primate.wisc.edu!aplcen!uunet!brunix!tac
  4. ;From: tac@cs.brown.edu (Theodore A. Camus)
  5. ;Newsgroups: comp.emacs
  6. ;Subject: mouse scrolling
  7. ;Message-ID: <30868@brunix.UUCP>
  8. ;Date: 27 Feb 90 23:09:59 GMT
  9. ;Sender: news@brunix.UUCP
  10. ;Reply-To: tac@cs.brown.edu (Theodore A. Camus)
  11. ;Organization: Brown University Department of Computer Science
  12. ;Lines: 50
  13. ;
  14. ;
  15. ;Here's a fast way to scroll in a large file.
  16. ;Just position mouse in the window you wish to scroll,
  17. ;and shift right click.  The file in that window will
  18. ;scroll to a position in the file that is the same 
  19. ;percentage as the mouse's position horizontally in the
  20. ;window in question.
  21. ;
  22. ;Btw, you may not be able to put it in your .emacs.
  23. ;Just put the define-key's or global-set-mouse's in some
  24. ;other function and call it at the eval prompt after you
  25. ;start up emacs.
  26. ;
  27. ;X version:
  28. ;==========
  29.  
  30. (define-key mouse-map x-button-s-right 'x-col-jump)
  31.  
  32. (defun x-col-jump (arg)
  33.   "Will move cursor to pos in buffer as a mouse % of window width.
  34.    Will work for any window mouse is in, not just current-buffer."
  35.   (let ((OriginallySelectedWindow (selected-window))
  36.         (line ())
  37.         (old-perc ())) 
  38.     (unwind-protect 
  39.       (progn (x-mouse-set-point arg)
  40.         (let* ((wd  (1- (window-width)))
  41.                (size (buffer-size))
  42.                (perc (perc (- (car arg) (car (window-edges))) wd))
  43.                (new-pos (perc-of perc size)))
  44.            (goto-char new-pos)
  45.            (setq old-perc perc line (what-line))))
  46.       (select-window OriginallySelectedWindow))
  47.       (message " %s = %s%s" line old-perc '%)))
  48.  
  49. ;Suntool version:
  50. ;================
  51.  
  52. (global-set-mouse '(text shift right)  'mouse-fast-col-jump)
  53.  
  54. (defun mouse-fast-col-jump (w x y)
  55.   (if (not (eq last-command 'mouse-fast-col-jump))
  56.       (setq *column* (current-column)))
  57.   (mouse-scroll-proportional w x y)
  58.   (move-to-column *column*))
  59.  
  60. ;  CSnet:     tac@cs.brown.edu                          Ted Camus  
  61. ;  ARPAnet:   tac%cs.brown.edu@relay.cs.net             Box 1910 CS Dept
  62. ;  BITnet:    tac@browncs.BITNET                        Brown University
  63. ;  "An ounce of example is worth a pound of theory."    Providence, RI 02912
  64.  
  65.  
  66.