[comp.emacs] Mouse scrolling

tac@cs.brown.edu (Theodore A. Camus) (02/27/90)

This may be useful to some of you.
Place the mouse one line below the cursor and shift left click;
everything moves up one. Place it two below the cursor, and it 
moves two, etc.  

X version :
-----------

(define-key mouse-map x-button-s-left 'x-scroll-to-cursor)

(defun x-scroll-to-cursor (arg)
  (let* ((cursor-y (current-row))
         (mouse-y (progn (x-mouse-set-point arg) (current-row)))
         (pos (point))
         (ok (cond ((< mouse-y cursor-y)
                    (move-to-window-line 0)
                    (/= (point) 1))
                   (t (/= (point) (point-max))))))
    (cond (ok (goto-char pos)
              (scroll-up (- mouse-y cursor-y))
              (move-to-window-line 0)
              (next-line cursor-y)
              (move-to-column (- (car arg) (car (window-edges)))))
          (t  (goto-char pos)))))

Suntool version :
-----------------

(global-set-mouse '(text shift left)   'mouse-scroll-to-cursor)

(defun mouse-scroll-to-cursor (w x y)
  (let* ((offset  (current-row)) 
         (pos (point))  
         (ok (cond ((< y offset) 
                    (move-to-window-line 0)
                    (/= (point) 1))
                   (t (/= (point) (point-max))))))
        (cond (ok (goto-char pos)
                  (scroll-up (- y offset))
                  (cursor-to-window-top)
                  (next-line offset)
                  (move-to-column x))
              (t  (goto-char pos)))))


Needed for both :
-----------------

(defun current-row ()
  "Returns current row #, from screen top, from 0."
  (let* ((pos (point))
         (top (window-start))
         (count 0))
    (beginning-of-line)
    (while (/= (point) top)
        (forward-line -1)
        (setq count (1+ count)))
    (goto-char pos)
    count))
  CSnet:     tac@cs.brown.edu                          Ted Camus  
  ARPAnet:   tac%cs.brown.edu@relay.cs.net             Box 1910 CS Dept
  BITnet:    tac@browncs.BITNET                        Brown University
  "An ounce of example is worth a pound of theory."    Providence, RI 02912

tac@cs.brown.edu (Theodore A. Camus) (02/28/90)

Here's a fast way to scroll in a large file.
Just position mouse in the window you wish to scroll,
and shift right click.  The file in that window will
scroll to a position in the file that is the same 
percentage as the mouse's position horizontally in the
window in question.

Btw, you may not be able to put it in your .emacs.
Just put the define-key's or global-set-mouse's in some
other function and call it at the eval prompt after you
start up emacs.

X version:
==========

(define-key mouse-map x-button-s-right 'x-col-jump)

(defun x-col-jump (arg)
  "Will move cursor to pos in buffer as a mouse % of window width.
   Will work for any window mouse is in, not just current-buffer."
  (let ((OriginallySelectedWindow (selected-window))
        (line ())
        (old-perc ())) 
    (unwind-protect 
      (progn (x-mouse-set-point arg)
        (let* ((wd  (1- (window-width)))
               (size (buffer-size))
               (perc (perc (- (car arg) (car (window-edges))) wd))
               (new-pos (perc-of perc size)))
           (goto-char new-pos)
           (setq old-perc perc line (what-line))))
      (select-window OriginallySelectedWindow))
      (message " %s = %s%s" line old-perc '%)))

Suntool version:
================

(global-set-mouse '(text shift right)  'mouse-fast-col-jump)

(defun mouse-fast-col-jump (w x y)
  (if (not (eq last-command 'mouse-fast-col-jump))
      (setq *column* (current-column)))
  (mouse-scroll-proportional w x y)
  (move-to-column *column*))

  CSnet:     tac@cs.brown.edu                          Ted Camus  
  ARPAnet:   tac%cs.brown.edu@relay.cs.net             Box 1910 CS Dept
  BITnet:    tac@browncs.BITNET                        Brown University
  "An ounce of example is worth a pound of theory."    Providence, RI 02912

jr@bbn.com (John Robinson) (02/28/90)

In article <30868@brunix.UUCP>, tac@cs (Theodore A. Camus) writes:
>Here's a fast way to scroll in a large file.
>Just position mouse in the window you wish to scroll,
>and shift right click.  The file in that window will
>scroll to a position in the file that is the same 
>percentage as the mouse's position horizontally in the
>window in question.

This idea found its way into the BitGraph mouse package.  Someone
suggested it to me whose name is lost in the mists of time:

  (defun bg-move-by-percentage ()
    "Go to location in buffer that is the same percentage of the
  way through the buffer as the BitGraph mouse's X position in the window."

I'd still like to see all the mouse support (bg, sun, x) integrated
better - there ought to be one mouse library (there sort of is) with
all the mouse functions, and one dispatch method, etc.  Volunteers?

>Btw, you may not be able to put it in your .emacs.
>Just put the define-key's or global-set-mouse's in some
>other function and call it at the eval prompt after you
>start up emacs.

... or hang the function on term-setup-hook, which is evaluated after
the terminal-dependent initialization is done.

  term-setup-hook's value is my-x-button-init

  Documentation:
  Function to be called after loading terminal-specific lisp code.
  It is called with no arguments.  You can use this to override the
  definitions made by the terminal-specific file.
--
/jr, nee John Robinson     Life did not take over the globe by combat,
jr@bbn.com or bbn!jr          but by networking -- Lynn Margulis

jv@mh.nl (Johan Vromans) (03/06/90)

I would like to have hot-spots (pseudo-buttons) in my window (or on
the associated status line) which, when clicked with the left button,
will perform scroll-down and scroll-up (maybe also beginning-of-buffer
and end-of-buffer).
Possible place for the hot spots are top-right and botton-right.

Has anyone already built a function to do this?

Johan
--
Johan Vromans				       jv@mh.nl via internet backbones
Multihouse Automatisering bv		       uucp: ..!{uunet,hp4nl}!mh.nl!jv
Doesburgweg 7, 2803 PL Gouda, The Netherlands  phone/fax: +31 1820 62944/62500
------------------------ "Arms are made for hugging" -------------------------