3

What the title says: I want to switch to using an emacs-server / emacs-client model instead of using the GUI for Mac OS X. I use iTerm2. I would like to map the function key (fn) to super or hyper.

I tried using KeyRemap4MacBook - but no luck.

Update:

It looks like I can use event-apply-super-modifier or event-apply-hyper-modifier, defined by function-key-map.

I can probably make the Fn key emit an an used key code, like KeyCode::F18, and have iTerm2 translate that to some escape characters, like:

Esc+[+J or something like that.

UPDATE (April 13th, 2015):

I think this https://apple.stackexchange.com/questions/144481/sending-controlalt-char-to-terminal-in-iterm2 is very interesting. There might be a way to configure iterm2 to send the appropriate control keys, similar to @toolbear74's answer.

3
  • 1
    Consider this port, which has native Fn key support; if you build emacsclient from that port as well, you'll be able to get the benefit of a graphical client for the Emacs daemon, without needing to run an X server, and with fairly extensive Aqua support. (It's worked extremely well for me, at any rate.) Aug 27, 2013 at 18:57
  • What did you end up going with? Jan 7, 2015 at 23:36
  • @Tricon haven't been able to figure this out and it's been my main blocker to switching directly to a terminal-based Emacs experience. Let me know if you do find something. Jan 8, 2015 at 2:27

1 Answer 1

1

Unsatisfactory Workaround

The sequence C-x @ s-… is equivalent to s-…, e.g. C-x @ s-t is equivalent to s-t. Combined with iTerm2 shortcuts:

  1. Create a global or profile shortcut for ⌘… set to Send hex code, e.g. ⌘t => Send hex code
  2. Specify hex code of the form: 0x18 0x40 MOD KEY where MOD is either 0x68 or 0x73 for h and s respectively and KEY is the key you want modified with hyper or super. E.g. mapping ⌘t to s-t:

    ⌘t => 0x18 0x40 0x73 0x74
    
  3. Repeat for every shortcut you want…meh…

Failed Experiment #1

In iTerm:

  1. Globally configure Left & Right Option keys as Left Option
  2. Globally configure Left & Right Command keys as Right Option
  3. In a profile, configure Left Option as +ESC and Right Option as Meta

Remapping this way effectively disables all iTerm keyboard shortcuts…meh…

In Emacs:

Using Right Option (R⌥) results in characters with 8th bit set, which as I understand it, is the old way of representing the META key press (back when keyboards had an actual META key).

However, I've failed to get Emacs to do something useful with this distinction. Given that META-t => t with its 8th bit on => octal 364 I've tried:

(global-set-key (kbd "[R⌥-t]") (lambda () (interactive) (message "woot #1")))
(global-set-key (kbd "\364") (lambda () (interactive) (message "woot #2")))

Where [R⌥-t] is the individual character that shows up in my buffer when I press that key sequence, represented graphically as \364 but behaving as a single character.

Worth noting that with our without the key binding, whenever I press R⌥-t nothing is displayed in emacs until I press another key upon which emacs displays the \364 character followed by interpreting the second keypress. For instance, R⌥-t a => \364a<point> and R⌥-t LEFT => <point>\364, but only after a or left arrow has been pressed.

You can experiment by only doing Step 3 above and using R⌥ directly.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .