[gnu.emacs.bug] More on X mouse rebind?

mike@dart.cs.byu.edu (Mike Burbidge) (07/07/89)

It was pointed out that the .emacs file is run before emacs figures out it
is running on X. The solution was to tie a function to term-setup-hook.
Which worked. I am now having a problem using the function scroll-up. It is
supposed to have one parameter. The first attempt I used was:

(setq term-setup-hook
   '(lambda () (define-key mouse-map x-button-m-right 'scroll-up)))

This is when I discovered that scroll-up must take a parameter, because this
had the effect of scrolling some arbitrary number of lines, more than a
page. I then tryed:

(setq term-setup-hook
    '(lambda () (define-key mouse-map x-button-m-right (scroll-up nil))))

and

(setq term-setup-hook
    '(lambda () (define-key mouse-map x-button-m-right '(scroll-up nil))))

both of which complained of one sort or another.  I then looked at some of
the e-lisp code that comes with emacs and did the following:

(defun scroll-page-up ()
    (scroll-up nil))

(setq term-setup-hook
    '(lambda () (define-key mouse-map x-button-m-right 'scroll-up-page)))

This should work from examples I looked at. Can anyone offer any help?

A. Michael Burbidge.
mike@cs.byu.edu

jr@bbn.com (John Robinson) (07/10/89)

In article <8907071602.AA02986@dart.cs.byu.edu>, mike@dart (Mike Burbidge) writes:
>This is when I discovered that scroll-up must take a parameter, because this
>had the effect of scrolling some arbitrary number of lines, more than a
>page.

scroll-up takes an optional parameter (nil when none is present).
This allows it to do the "right thing" (i.e., (scroll-up nil)) when it
is called after you type ^V.


> I then tryed:
>
>(setq term-setup-hook
>    '(lambda () (define-key mouse-map x-button-m-right (scroll-up nil))))

keymap entries are symbols that name functions.  fancier forms don't
work, as you found.

>  I then looked at some of
>the e-lisp code that comes with emacs and did the following:
>
>(defun scroll-page-up ()
>    (scroll-up nil))
>
>(setq term-setup-hook
>    '(lambda () (define-key mouse-map x-button-m-right 'scroll-up-page)))
>
>This should work from examples I looked at. Can anyone offer any help?

[Assuming for the moment this were a function to be called from a]
[function key or a main keyboard control-key...]

 You ought to make scroll-page-up an interactive function.  To
 do this, make its first form (interactive).  Also, you ought to
 document it so that ^H k and ^H c can tell the user something useful
 (you expect to share your code, right?).  So this should be:

 (defun scroll-up-page ()
     "Scroll text of current window upward nearly one full screen."
     (interactive)
     (scroll-up nil))

 (setq term-setup-hook
     '(lambda () (define-key mouse-map x-button-m-right 'scroll-up-page)))

 ... Note you also jumbled the names scroll-page-up and scroll-up-page.

[end assumption]

Now, most things that are called from keystrokes or function keys are
happy to be called with no arguments, or else will prompt for them in
the minibuffer.

mouse-map functions are special, though.  They are passed the mouse
coordinates as arguments.  Thus, they can't use the fancier
(interactive ...) forms to get arguments through the minibuffer (they
would have to open-code things with functions like read-buffer or
read-file).  It doesn't hurt to put an (interactive) call there,
however, and the documentation is good practice.

But the real killer is that you can bind x-button-m-right to
'scroll-up and have a proportional scroll-up.  Mouse near the left
window edge and go up one line.  Near the right edge you go far (a
number of lines equal to the column width of the window).

So it's a feature, not a bug!!  :-)
--
/jr, nee John Robinson     Life did not take over the globe by combat,
jr@bbn.com or bbn!jr          but by networking -- Lynn Margulis