8

I've recently set up a Common Lisp programming environment in Mac OS X Leopard. One emacs module which I've found to be indispensable is paredit. Paredit is doing its part to help me wrangle my Lisp code more easily, but I've ran into a bit of a snare.

C-), bound to paredit-forward-slurp-sexp, is not forward slurping sexps but instead echoing the number 0. I'm using a Mac, alternating between iTerm and Terminal. The same problem is present in both apps.

I tried the same key combination in GNU Emacs' GUI version, and lo, it worked. Unfortunately the graphical version of Emacs does not satisfy my needs; I would like to keep using my iTerm based rig.

So I ask you, stackoverflow: what do I have to do to get the C-) combo to register with iTerm?

Joe Taylor
  • 638
  • 6
  • 12
  • Why? Why do you want to keep using your iTerm based rig? – klang Jun 07 '11 at 05:08
  • @klang (1) Better consistency across SSH sessions, (2) I can use standard emacs from screen, (3) I find the hybrid window/buffer in GUI emacs confusing, (4) I prefer bash to eshell, and finally, (5) with a dark theme, and especially at full screen, emacs in iTerm feels more polished than the graphical app with its clunky scroll bars and menu. If I'm to use a GUI I much prefer TextMate's interface to GNU Emacs. – Joe Taylor Jun 07 '11 at 05:45
  • You can type `C-c C-)` to make sure, but since you're getting a `0`, it's apparent that your terminal emulators (iTerm and Terminal) are transmitting a `0` when you press `Ctrl+)`. You need to do two things: convince each of iTerm and Terminal to send an escape sequence when you press `Ctrl+)`, and declare to Emacs that this escape sequence corresponds to `Ctrl+)` (in `function-key-map` or `local-function-key-map`). – Gilles 'SO- stop being evil' Jun 07 '11 at 09:14
  • You can plug in any shell you like, on windows I use cygwin from within emacs. You can change the theme to what you like and you can just remove the menu+scroll-bars with luddite-mode https://gist.github.com/539783 .. the consistency across SSH sessions I can't figure out. I usually leave emacs running for weeks with the ssh sessions dropping with my vpn once in a while. Emacs will re-connect when it can and I can keep working on the files. In shell mode I would have to start over. Oh, well, different strokes I guess. – klang Jun 07 '11 at 13:47

5 Answers5

8

For what is worth, on my Mac C-<right> and C-<left> are bound to Mission Control and move to the right and left spaces.

Having said that, C-Shift-<right> and C-Shift-<left> seem to do the trick and I can slurp and barf nicely on emacs with paredit.

Jose B
  • 2,030
  • 2
  • 19
  • 17
5

IIRC, the modifier combination of Control and Shift cannot be sent to Emacs in a terminal. C-) requires the shift key, so it's out of bounds. I'm not convinced that any amount of terminal tweaking will change this.

I believe paredit-forward-slurp-sexp also gets bound to C-<right> by default, which should work fine in a terminal, so perhaps you can train your fingers to use that key instead.

sanityinc
  • 15,002
  • 2
  • 49
  • 43
  • 1
    Terminal tweaking can definitely change this (if the terminal allows such tweaking). Emacs isn't the blocking point. If the terminal can be persuaded to send a distinct escape sequence, you're good. – Gilles 'SO- stop being evil' Jun 07 '11 at 18:44
  • @Gilles: that's good to know. Nonetheless, I presume the difficulty of making commonly available terminals handle ctrl+shift has historically been a factor in Emacs' choice of key bindings. – sanityinc Jun 07 '11 at 21:02
  • 1
    It has, but that was largely at a time when hardware terminals (often not configurable to send these escape sequences) were the norm. Another consequence of this historical fact is that there is not standardized escape sequence, like there is (mostly) for function and cursor keys. – Gilles 'SO- stop being evil' Jun 07 '11 at 21:12
  • 4
    I wrote a post a while back on how to fix these issues with the common OS X terminals (Terminal.app, iTerm and iTerm 2) http://offbytwo.com/2012/01/15/emacs-plus-paredit-under-terminal.html – Cosmin Stejerean Oct 26 '12 at 15:28
4

Based on Cosmin's blog I got this to work in iTerm2.

  1. Open Preferences > Profiles > Keys. (You may want to copy the default profile and change the copy.)
  2. Click the + under the Profile Shortcut Keys:.
  3. Type Ctrl+) (ctrl+shift+leftparen).
  4. For the Action select Send Escape Character and
  5. put [1;5C in the text-box.
boz jennings
  • 327
  • 2
  • 6
2

I was running into the same kind of trouble with paredit's alternate C-<right> binding, and found tmux was causing my trouble - basically tmux was subsuming the C- and just passing along a <right>.

I found the solution at https://unix.stackexchange.com/a/34484, and it comprised adding

set-window-option -g xterm-keys on

to my ~/.tmux.conf.

Community
  • 1
  • 1
Ian
  • 977
  • 8
  • 14
2

I have a hunch your iTerm / Terminal programs are not actually able to send C-), because there is no such character in ASCII and I am pretty sure there is no sequence for it on the VT100.

You can verify this for yourself, though. Run emacs in your terminal emulator. Type C-). Then type C-h l ("view-lossage"). This will show you the last few hundred keys that Emacs saw you type. Try the same thing after typing a non-control ) to see if they are different. If not, you are out of luck unless you can configure iTerm / Terminal to send them to Emacs in distinct ways.

That said, you can always bind some other key to paredit-forward-slurp-sexp.

Nemo
  • 70,042
  • 10
  • 116
  • 153