Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why don't Shift+arrow bindings work in clojure-mode in emacs terminal?

If I runs emacs in a terminal (i.e start emacs in iTerm2 with emacs -nw) using windmove and it's default bindings, I should be able to navigate between windows using various combinations of Shift + , Also paredit has bindings that involve Ctrl/Meta + , these all work fine in (say) an elisp mode buffer.

Looks like the arrow keys functionality relies on emacs decoding terminal escape sequences, via (I think) the input-decode-map

However, if I set the major mode as clojure-mode then the decoding of the escape sequences appears to be disabled (or overwritten). When I execute those bindings I just get the escape sequence instead.

What's going on with the bindings in clojure-mode ?

Versions:

  • emacs 24.3.1 (have tried maxosxforemacs.com version and homebrew)
  • clojure-mode 20131117.2306 (have tried other versions)
  • OSX 10.8.5
  • iTerm2 1.0.0.20131124

(disclaimer: I raised this as an issue on clojure-mode, but no solution is forthcoming)

UPDATE 2013/12/10: To be absolutely clear: this problem is specific to clojure-mode. emacs -nw in iTerm + arrow keys works fine in other major modes. I'm sure I'm doing something silly that is causing this, I'd like to know what.

like image 976
sw1nn Avatar asked Dec 08 '13 22:12

sw1nn


2 Answers

Almost identical setup here, but no similar problem. Here's what I would do anyway. First, evaluate the following emacs-lisp code in the scratch buffer.

(progn
(define-key input-decode-map "\e[1;2D" [S-left])  
(define-key input-decode-map (kbd "M-[ 1 ; 2 C") [S-right])  
(define-key input-decode-map (kbd "M-[ 1 ; 2 B")[S-down])  
(define-key input-decode-map "\e[1;2A" [S-up])  
(define-key input-decode-map "\e[1;6A" [S-C-up])
(define-key input-decode-map "\e[1;6B" [S-C-down]))

Try the windmove bindings when clojure-mode is activated. If this fixes your problem, and assuming your TERM environment variable is set to xterm-256color, put the following in your init.el

(if (equal "xterm-256color" (tty-type)) 
(progn
(define-key input-decode-map "\e[1;2D" [S-left])  
(define-key input-decode-map (kbd "M-[ 1 ; 2 C") [S-right])  
(define-key input-decode-map (kbd "M-[ 1 ; 2 B")[S-down])  
(define-key input-decode-map "\e[1;2A" [S-up])  
(define-key input-decode-map "\e[1;6A" [S-C-up])
(define-key input-decode-map "\e[1;6B" [S-C-down])))

Hope this helps.

like image 134
Daniel Szmulewicz Avatar answered Oct 01 '22 13:10

Daniel Szmulewicz


Check your settings in Iterm, more specifically the "Global shortcut keys". Those will take precedence over what is sent to emacs. C-Shift-Arrow is used to switch tabs in Iterm I believe and may be interfering with emacs.

like image 45
gvickers Avatar answered Oct 01 '22 14:10

gvickers