Using the Keypad

Xah Lee has an interesting post on defining keys to open frequently used files (search for 2012-11-21). The idea is that you add lines like

(global-set-key (kbd "<kp-7> <kp-3>") (lambda () "" (interactive) (find-file "~/web/ergoemacs_org/emacs/blog.html")))

for each of the files that you access frequently. That way, you can open the file quickly by pressing just 2 keys.

It’s a cute idea but not one I’d use. That’s because Lee and I have slightly different Emacs work flows. Lee says he likes to close files when he’s finished with them. I, on the other hand, tend to leave files open and occasionally cull files that I’m no longer using. Lee’s idea makes sense for him because he is always opening those files. I rarely have to open the files I use all the time because I keep them open—even across Emacs invocations—so I don’t really need a super efficient way to open them.

Still, I found the post useful because it reminded me that using the keypad is a way to get access to about 15 unused keys for binding to commands. I’ve never thought too much about that because I’m almost always on one of my Macs and their keyboards don’t have a separate keypad. What they do have is a virtual keypad on the regular keyboard that is accessed by the function key. Thus, <kp-2> is accessed by pressing 【fn+k】 and that’s not much harder than, say, 【Ctrl+k】 other than for a slightly longer reach for the 【fn】 key.

So, there are two takeaways from Lee’s post:

  1. If you have a work flow like Lee’s, you might find it useful to add a list of keybindings to open frequently accessed files to your .emacs or init.el file.
  2. Don’t forget about the keypad (even if you’re on a Mac) as a source of keys suitable for binding to frequently used commands.
This entry was posted in General and tagged . Bookmark the permalink.

5 Responses to Using the Keypad

  1. Magnar Sveen says:

    If you’re on OS X you can also simply bind fn to, say, hyper. That’s what I’ve done. Voila, a new modifier key that’s real easy to hit. :-)

    • jcs jcs says:

      Hi Magnar,

      Thanks for stopping by. I love the videos and am absolutely addicted to expand-region and multiple-cursors.

      I’ve thought about mapping fn to hyper but I sometimes want to adjust the volume or start/stop music while I’m in Emacs so I’ve resisted doing it so far. Right now I use right-command as hyper but that’s less convenient than fn so perhaps I’ll change.

      • Magnar Sveen says:

        Cool, glad to hear it. :-)

        On my Mac at least, I can still use fn to change volume, and start/stop music. It’s pretty nifty!

        • Magnar Sveen says:

          And to be a little more helpful, this is how I did it:

          (setq ns-function-modifier ‘hyper)

        • jcs jcs says:

          Wow. Thanks. I just assumed either fn would act as a function key or as a remapped key. It turns out, as you say, that you can make fn work as hyper except when you type fn and a function key. Then it does the right thing (such as adjust volume). It also disappears the virtual keypad keys: so fn+k is mapped to hyper+k instead of <kp-2>. I can live with that since my iMac keyboard doesn’t have the virtual keypad anyway.

          I’ve already changed my init.el. Thanks again.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>