0

How can I get scrollbars with exact positioning?

To illustrate what I mean:

  1. C-h C-f (Read the The GNU Emacs FAQ)

  2. Now try to position the buffer content such that the paragraph starting with This is the version ... is on top. With the default scrollbar you need several redraws to do this. Or you left-click for cursor positioning then C-lC-l

  3. Now go back to where you have been before. This is impossible with regular scrollbars.

What I would like to have is to just click in the scrollbar at the height of This is the version ... to position this line on top for step 2. And to go back where I came from, I rightclick (without having moved the mouse, indeed).

In the past, I have always installed Emacs with the Athena widgets-like option to get such scrollbars, see a description of them. But I wonder if there is now a better or more modern way to do this. After all, I'd rather like to use standard distributions.

Maybe, it is not even necessary to change the scrollbars at all but to use rather the left-fringe for it. After all, mouse clicking in the fringe is recognized as <left-fringe>

M-x emacs-version
GNU Emacs 23.3.1 (x86_64-pc-linux-gnu, GTK+ Version 2.24.10) of 2012-09-21 on batsu, modified by Debian

false
  • 10,264
  • 13
  • 101
  • 209
  • Emacs's source code includes its own version of scrollbars, which work kind of like Athena, but they're only used if Emacs is compiled without toolkit support. OTOH it shouldn't be too difficult to change the code so that we support both toolkit and non-toolkit scrollbars and choose between them at run-time. I'd be very happy to accept such a patch. – Stefan Jan 11 '13 at 02:00
  • @Stefan: you're right the configure option gives Athena-like scrollbars. But actually, left- and right-mouse in Athena are very simple, no dragging and the like, only down-key/ButtonPress ; for this reason I more and more favour to leave the scrollbars as they are and rather consider to overload the fringe. This gives less surprises. – false Jan 11 '13 at 02:08

2 Answers2

1

Maybe a change of usage habits could help? Some Emacs user recommend disabling the scrollbars completely and navigate Emacs exclusively with the keyboard. (This habit is also beneficial for using Emacs inside a shell.)

Emacs provides a large number of navigation shortcuts. For instance, for jumping up and down large amounts of buffer space, you have:

C-v scroll-up

M-v scroll-down

M-} forward-paragraph

M-{ backward-paragaph

C-x ] forward-page

C-x [ backward-page

However, I would argue that by far the most useful navigation commands are:

C-s isearch-forward

C-r isearch-backward

In Emacs, search is so cheap, it is such an integral part of the work flow that it's often times much faster to get to a different point in the buffer by using a reference word as an anchor for a quick search, rather than leaving the home row to reach for the mouse. Hitting C-s or C-r repeatedly will move the point to consecutive matches. (You can even switch to regular expression search by hitting M-r while searching to make search even more powerful.)

You already mentioned C-l C-l to view the current line at the top of the buffer.

Now, if you want to go back to the previous location, you could use

C-u C-x

which jumps back to the mark. All the above commands for navigation push their start position on a "mark-ring" which means you can not only jump back one position, repeatedly hitting C-u C-x will take you back to many previous positions.

Thomas
  • 17,016
  • 4
  • 46
  • 70
  • No thanks. This is not what I asked for. I am myself very reluctant to rodents of all kind, but there are situation where this is useful. In particular, if you only have the mouse and the keyboard is controlled by someone else... – false Jan 10 '13 at 22:58
  • Sure, for a situation like that using the scrollbar would be useful, although I find it a bit hard to imagine (Couldn't the person in control of the keyboard do the scrolling? Wouldn't s/he be annoyed if someone else scrolled for them?) Other than that, the situation you outlined originally could be performed by `C-s ver C-l C-l` followed by `C-u C-x`. I am not aware of any "scrollbar replacements" for Emacs (or any kind of application for that matter), but good luck anyway for finding a solution more suitable for your needs. – Thomas Jan 10 '13 at 23:11
  • oral exams; sitting to the left close to the scrollbar :-) But that is not the *only* situation – false Jan 10 '13 at 23:13
  • By the way - under X, you could open a second frame on a different `Display` so you could edit simultaneously on two machines. That might be helpful for your situation as well... – Thomas Jan 10 '13 at 23:16
  • Sharing the same screens makes the exam less stressful. And ... how does this work for the keyboard... Maybe X or Emacs has improved here... – false Jan 10 '13 at 23:19
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/22549/discussion-between-thomas-and-false) – Thomas Jan 10 '13 at 23:22
1

For this task I press C-l once, twice, three times.They will switch between middle-top-bottom.

alinsoar
  • 15,386
  • 4
  • 57
  • 74
  • This I use too and `[S-down] (lambda () (interactive) (scroll-up 1)))` etc. But here, I have only a mouse in my hand :-) – false Jan 11 '13 at 02:50