Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

emacs xterm bindings

By: a guest on Oct 26th, 2012  |  syntax: None  |  size: 1.42 KB  |  hits: 31  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ;; http://www.reddit.com/r/emacs/comments/123lbu/there_must_be_a_better_way_to_switch_between/c6rzl48
  2. ;; As of this writing, emacs does not correctly recognize some xterm
  3. ;; key sequences.  Add code to deal with these.
  4. (defun add-escape-key-mapping-alist (escape-prefix key-prefix
  5.                                                    suffix-alist)
  6.   "Add mappings for up, down, left and right keys for a given list
  7.  of escape sequences and list of keys."
  8.   (while suffix-alist
  9.     (let ((escape-suffix (car (car suffix-alist)))
  10.           (key-suffix (cdr (car suffix-alist))))
  11.       (define-key input-decode-map (concat escape-prefix escape-suffix)
  12.         (read-kbd-macro (concat key-prefix key-suffix))))
  13.     (setq suffix-alist (cdr suffix-alist))))
  14.  
  15. (setq nav-key-pair-alist
  16.       '(("A" . "<up>") ("B" . "<down>") ("C" . "<right>") ("D" . "<left>")
  17.         ("H" . "<home>") ("F" . "<end>") ("I" . "<tab>") ("s" . "\"")
  18.         ("l" . ",") ("n" . ";") ("^" . "<return>")))
  19.  
  20. (add-escape-key-mapping-alist "\e[1;2" "S-" nav-key-pair-alist)
  21. (add-escape-key-mapping-alist "\e[1;3" "M-" nav-key-pair-alist)
  22. (add-escape-key-mapping-alist "\e[1;4" "M-S-" nav-key-pair-alist)
  23. (add-escape-key-mapping-alist "\e[1;5" "C-" nav-key-pair-alist)
  24. (add-escape-key-mapping-alist "\e[1;6" "C-S-" nav-key-pair-alist)
  25. (add-escape-key-mapping-alist "\e[1;7" "M-C-" nav-key-pair-alist)
  26. (add-escape-key-mapping-alist "\e[1;8" "M-C-S-" nav-key-pair-alist)