[racket] Alt/Option key as meta on Mac

From: jab at math.brown.edu (jab at math.brown.edu)
Date: Sun Dec 1 14:44:31 EST 2013

On Fri, Nov 29, 2013 at 5:19 PM, Robby Findler
<robby at eecs.northwestern.edu>wrote:

> On Fri, Nov 29, 2013 at 3:10 PM, <jab at math.brown.edu> wrote:
>
>> On Thu, Nov 28, 2013 at 10:33 PM, Robby Findler <
>> robby at eecs.northwestern.edu> wrote:
>>
>>> Oh, I should have done that long ago. I've pushed something that lets
>>> you use alt as meta.
>>>
>>
>> Just found it at https://github.com/plt/racket/commit/d95a6b02. Thank
>> you for adding this! And so quickly, to boot!
>>
>> Can't wait to be able to use it. Extrapolating based on the release dates
>> of the last few versions, the next release should be out soon, I take it?
>> Is there a way to get Alt as Meta working in the meantime?
>>
>>
> You can build racket (it isn't too hard once you have the dev stuff
> installed), or you can get the latest snapshot which, I believe, has that
> commit: http://plt.eecs.northwestern.edu/snapshots/
>

Just grabbed this<http://plt.eecs.northwestern.edu/snapshots/current/installers/racket-test-6.0.0.1-x86_64-macosx.dmg>
and
sure enough, found "Treat alt key as meta" under Preferences > Editing >
General. Excellent!

Trying it out and so far so good, except for Alt-p/n. Rather than going
backward/forward in command history like Esc-p/n, they're still getting the
standard OS X behavior (printing "π" / attaching ~ to next character,
respectively).

 I've already figured out how to add a user-defined keybindings file to map
>> Ctrl+w to "backward-kill-word", as in the shell. In case it helps anyone
>> else:
>>
>>  #lang s-exp framework/keybinding-lang
>>
>>
>> (define (rebind key command)
>>
>>   (keybinding
>>
>>    key
>>
>>    (λ (ed evt)
>>
>>      (send (send ed get-keymap) call-function command ed evt #t))))
>>
>>
>> (rebind "control:w" "backward-kill-word")
>>
>>
>>
>> Similarly I'd like to map Ctrl-u to "delete-to-beginning-of-line", but it
>> looks like that function doesn't come out of the box, and I haven't yet
>> tried to figure out how to add it.
>>
>>
> You want look at the methods of text% (of which ed is one), specifically
> for the position-paragraph and related methods.
>

Thanks Robby, I'll take a look for this.


>  One last behavior I miss from the shell (as well as other GUI IDEs with
>> REPLs, such as Python's IDLE) is the default mapping of Ctrl-p/Ctrl-n to
>> "previous/next command from history" rather than "move the cursor up/down",
>> which I need much less often. Tried to figure out how to change this, but
>> didn't see where the Meta-p/Meta-n mappings were defined
>> in collects/framework/private/keymap.rkt in the first place.
>>
>>
> The names of various existing key bindings are listed in the
> Edit|Keybindings|Show Active Keybindings... menu item.
>

Thanks for the tip! Looking there I found esc;p bound to put-previous-sexp,
so I added (rebind "c:p" "put-previous-sexp") to my keybindings file and it
worked like a charm. Thanks, Robby!

  Any advice on these would be much appreciated. And I'll start a new
>> thread if this is getting too off-topic for this one.
>>
>>
>>> The docs are wrong, tho, because even with the release version you
>>> should be able to use command as meta (not that you really want to...)
>>>
>>
>> (I didn't see a Command as Meta option in preferences, but you're right
>> that I don't want that anyway.)
>>
>>
> Which OS are you using?
>

Oops, "Treat command key as meta" was there all along, I just missed it.
Sorry about that.

Relatedly, if I ever start hacking on the DrRacket source, I'll look out
for a chance to add search to the Preferences dialog (à la Eclipse, System
Preferences, etc.).

 Thanks again for your help, Robby, and happy Thanksgiving weekend to
>> everyone celebrating.
>>
>>
> Happy Thanksgiving to you too.
>

Thanks, and thanks again for all your help.


> Robby
>
>
>>  Robby
>>>
>>>
>>> On Wed, Nov 27, 2013 at 9:43 PM, <jab at math.brown.edu> wrote:
>>>
>>>> Hey Racket Users,
>>>>
>>>> Just trying Racket for the first time, and very excited to finally be
>>>> learning it! I've been wanting to for years.
>>>>
>>>> Just had my first encounter with DrRacket, and am trying to get
>>>> comfortable with keyboard input. According to
>>>> http://docs.racket-lang.org/drracket/Keyboard_Shortcuts.html,
>>>>
>>>> On Windows and Mac OS X, Meta is only available through the Escape key.
>>>>>
>>>>
>>>> Sorry to see it's not possible to bind the Alt/Option key to Meta, as
>>>> it is with e.g. Terminal.app, as it would be a huge usability win; the
>>>> Escape key on most keyboards is one of the hardest to reach, aggravating
>>>> RSI the world over. In
>>>> http://lists.racket-lang.org/users/archive/2010-August/041085.html, a
>>>> post from 2010, Matthew Flatt alludes to adding support for Option as Meta
>>>> after a soon-coming GUI rewrite, but I found no further mention of it here,
>>>> on GitHub (https://github.com/plt/racket/search?q=meta&type=issues),
>>>> or elsewhere.
>>>>
>>>> Just thought I'd inquire again about the possibility. On the off chance
>>>> it's a matter of submitting a newcomer-friendly patch, I'd be delighted to
>>>> give it a shot.
>>>>
>>>> Thanks for reading, and thanks for the great work on Racket.
>>>>
>>>> ____________________
>>>>   Racket Users list:
>>>>   http://lists.racket-lang.org/users
>>>>
>>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20131201/ace8fd4d/attachment-0001.html>

Posted on the users mailing list.