[plt-scheme] How to remap keybinding "(c:j)" from "newline" to "newline-and-indent"?

From: Benjamin L.Russell (DekuDekuplex at Yahoo.com)
Date: Wed Apr 1 06:07:44 EDT 2009

While editing a file in the Definitions panel in DrScheme, version
4.1.5 [3m], english, I discovered that the keybinding for "C-j" (in
Emacs-style notation, the control key held while the 'j' key is
pressed) did not indent the following line, but merely created a
newline.

Previously, in order to activate Emacs-style keybindings, I had
navigated to the "Edit -> Preferences" menu item -> "Editing ->
General" tab, and unchecked "Enable keybindings in menus."  This
allowed many Emacs-style keybindings to override the keybindings
normally set in the menus in DrScheme.  However, this particular
keybinding had apparently been mapped to just "newline", instead of to
"newline-and-indent".

According to the "Edit -> Keybindings -> Show Active Keybindings" menu
item, indeed, the keybinding "(c:j)" (in DrScheme-style notation,
again, the control key held while the 'j' key is pressed) was, by
default, mapped to "newline" instead of "newline-and-indent", unlike
in Emacs.

Navigating to the "Edit -> Keybindings -> Add User-defined Keybindings
..." menu item displayed a file navigator dialog box prompting to
select a file.

Mystified, in order to figure out how to override the above-mentioned
keybinding, I then went to the "Help -> Help Desk" menu item, and
found a very cryptic entry for "keymap:add-user-keybindings-file
provided from framework" (see
file:///c:/bin/PLT-4.1.5/doc/framework/Keymap.html#(def._((lib._framework/main..ss)._keymap~3aadd-user-keybindings-file))",
but was unable to figure out exactly what sequence of commands to use
to override this keybinding.

Then, I search using Google with the keywords "DrScheme
"keybindings"", and found a reference to "PLT Scheme Blog: Adjusting
DrScheme's Keybindings" (see
http://blog.plt-scheme.org/2007/05/adjusting-drschemes-keybindings.html),
which in turn provided a reference to "Scheme from the Florida Keys:
Keybinding in DrScheme Explained" (see
http://schemekeys.blogspot.com/2007/05/keybinding-101-in-drscheme.html).

According to this blog, in DrScheme, version 369.100-svn5may2007 [3m],
it is possible to create a single file, say, mykeys.ss, containing
keybindings using the special keybindings language, (lib
"keybinding-lang.ss" "framework"), in which, to override a single
keybinding, an incantation similar to the following is used:

(module mykeys (lib "keybinding-lang.ss" "framework") (require (lib
"tool-lib.ss" "drscheme")) (keybinding keybinding-string-expr
keybinding-proc-expr))

in which the "keybinding-string-expr" and the "keybinding-proc-expr"
expressions are to be substituted with appropriate definitions for the
overriding keybindings.

Based on the information in the blog, I constructed the following
mykeys.ss file:

--
(module mykeys
(lib "keybinding-lang.ss" "framework")

; Adds DrScheme Specific functions to the
; available functions we can bind to.
(require (lib "tool-lib.ss" "drscheme"))

(keybinding "c:j"
(lambda (editor event)
  (begin
    (newline)
    (tabify-at-caret)))))
--

However, loading it into the "Edit -> Keybindings -> Add User-defined
Keybindings ..." menu item resulted in the following error message:

--
Error when installing the keybindings C:\Documents and
Settings\Benjamin\My Documents\DrScheme\User-defined
Keybindings\mykeys.ss:

C:\Documents and Settings\Benjamin\My Documents\DrScheme\User-defined
Keybindings\mykeys.ss:12:5: compile: unbound identifier in module in:
tabify-at-caret
--

But "tabify-at-caret" is a legal command listed in both the list
displayed by the "Edit -> Keybindings -> Show Active Keybindings" menu
item and the above-mentioned blog entry!

How should I rewrite the code for mykeys.ss file to remap the
keybinding "(c:j)" from "newline" to "newline-and-indent", as in
Emacs?

-- Benjamin L. Russell
-- 
Benjamin L. Russell  /   DekuDekuplex at Yahoo dot com
http://dekudekuplex.wordpress.com/
Translator/Interpreter / Mobile:  +011 81 80-3603-6725
"Furuike ya, kawazu tobikomu mizu no oto." 
-- Matsuo Basho^ 



Posted on the users mailing list.