Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Create a Cocoa keyboard map for single-line scrolling System
As an emacs user, I've long had custom keybindings to scroll one line up or down. In my case, they're bound to ctrl-period and ctrl-semicolon for scrolling down and up, respectively.

(defun scroll-up-one-line ()
      (interactive)
      (scroll-up 1))
(defun scroll-down-one-line ()
      (interactive)
      (scroll-down 1))
(global-set-key [(control ?.)]  'scroll-up-one-line) ; C-.
(global-set-key [(control ?;)] 'scroll-down-one-line) ; C-;
In emacs, the cursor always stays in view, but in Mac apps, the cursor stays put so that scrolling and then typing will bounce you right back to where you were. I'd like to scroll and then type without ever taking my hands off the keyboard. To provide the same functionality as emacs, I chose to edit the Cocoa key bindings so that the cursor moves a line for each line scrolled. In that way, the cursor stays usually pretty close to the same relative window position. Moreover, the cursor stays in view, so it's easy to position the cursor using the keyboard once you've scrolled to the desired location.

Here's what to do:

Add emacs key bindings to all of your Cocoa apps by saving this file into ~/Library -> KeyBindings -> DefaultKeyBinding.dict. Adding keybindings to Cocoa is a great hint by itself, in case you missed it. Cocoa comes with some basic emacs keybindings, but the above file adds more. Then edit the file, and add the following lines within the dict:
     <key>^.</key>
        <array>
              <string>scrollLineDown:</string>
          <string>moveDown:</string>
        </array>
        <key>^;</key>
        <array>
              <string>scrollLineUp:</string>
            <string>moveUp:</string>
        </array>
[robg adds: This works as described. Note that you'll have to create the KeyBindings directory if you haven't done so previously.]
    •    
  • Currently 2.60 / 5
  You rated: 3 / 5 (5 votes cast)
 
[9,444 views]  

Create a Cocoa keyboard map for single-line scrolling | 4 comments | Create New Account
Click here to return to the 'Create a Cocoa keyboard map for single-line scrolling' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Create a Cocoa keyboard map for single-line scrolling
Authored by: interlard on Aug 29, '05 10:49:53AM

I'm sorry that this is a stupid question, but I'm going to ask anyway:

Is this an emacs-only hint, or will it keep my cursor on the screen, so that when I page down in ANY application, the cursor will not get left behind?

I love Macs (I switched-back a few years ago) but I find the leaving-the-curor-behind approach to be of no value. I need to use the keyboard a fair bit to avoid wrist and finger stress from too much mouse use, and my Mac isn't helping me as much as it could.

Thanks!



[ Reply to This | # ]
Having page up/down move the cursor
Authored by: sabi on Aug 29, '05 11:09:58AM
It looks like the default Cocoa text bindings to keep the insertion point with the scroll position are option-page up/down. If you want to bind these to ordinary page up/down, you can do so with:

        "\UF72C" = "pageUp:";
        "\UF72D" = "pageDown:";


[ Reply to This | # ]
Having page up/down move the cursor
Authored by: sabi on Aug 29, '05 11:09:58AM
It looks like the default Cocoa text bindings to keep the insertion point with the scroll position are option-page up/down. If you want to bind these to ordinary page up/down, you can do so with:

        "\UF72C" = "pageUp:";
        "\UF72D" = "pageDown:";


[ Reply to This | # ]
Create a Cocoa keyboard map for single-line scrolling
Authored by: kenahoo on Aug 29, '05 12:52:52PM

I'm actually more interested in the Emacs hint than in the Cocoa hint. :-) I pasted that lisp code into my ~/.xemacs/init.el file, but for some reason I'm unable to bind to control-. and control-; . The two functions do get defined, though, as I can invoke them manually by name, and they work as expected. But when I hit control-. or control-;, I just get the terminal bell (and no scrolling). In the *Messages* buffer I see that my init.el file is indeed being loaded, and when I put gobbledygook into it I do get an error.

The same code seems to work fine for xemacs on linux, i.e. the scrolling actually happens with the bound keys.

Any ideas for what I've got wrong?

-Ken



[ Reply to This | # ]