diff --git a/dotfiles/emacs.d/init.el b/dotfiles/emacs.d/init.el index 0be9387..d458d12 100644 --- a/dotfiles/emacs.d/init.el +++ b/dotfiles/emacs.d/init.el @@ -42,6 +42,20 @@ (setq inhibit-splash-screen t) ;;-------------------------------------------------------------------------------------- +;; Conditionally load urxvt files to fix weird bindings +;;-------------------------------------------------------------------------------------- + +;; This code doesn't fix anything related to emacs -nw not allowing C-) in terminal +;; mode. Currently looking for solutions so I don't have to keep using C- +;; and C- +;; +;; (when (string= (getenv "TERM") "rxvt") +;; (load "term/rxvt") +;; (terminal-init-rxvt) +;; (load "~/.emacs.d/urxvt-bindings.el") +;; ) + +;;-------------------------------------------------------------------------------------- ;; Enable auto-refresh to keep buffers up to date when git or another program ;; modifies them ;;-------------------------------------------------------------------------------------- diff --git a/dotfiles/emacs.d/urxvt-bindings.el b/dotfiles/emacs.d/urxvt-bindings.el new file mode 100644 index 0000000..eea6b9a --- /dev/null +++ b/dotfiles/emacs.d/urxvt-bindings.el @@ -0,0 +1,38 @@ +;; This file adds the missing escape sequences for urxvt so emacs -nw +;; will work with Ctrl+Shift, Ctrl+Meta, etc sequences. +;; +;; Credit for the original code goes to Gilles on emacs.stackexchange.com +;; + +(defun character-apply-modifiers (c &rest modifiers) + "Apply modifiers to the character C. +MODIFIERS must be a list of symbols amongst (meta control shift). +Return an event vector." + (if (memq 'control modifiers) (setq c (if (or (and (<= ?@ c) (<= c ?_)) + (and (<= ?a c) (<= c ?z))) + (logand c ?\x1f) + (logior (lsh 1 26) c)))) + (if (memq 'meta modifiers) (setq c (logior (lsh 1 27) c))) + (if (memq 'shift modifiers) (setq c (logior (lsh 1 25) c))) + (vector c)) +(defun eval-after-load-urxvt () + (when (and (boundp 'rxvt-alternatives-map) (boundp 'rxvt-function-map)) + (let ((c 32)) + (while (<= c 126) + (mapc (lambda (x) + (define-key rxvt-function-map (format (car x) c) + (apply 'character-apply-modifiers c (cdr x)))) + '( + ("\e\[27;3;%d~" meta) + ("\e\[27;5;%d~" control) + ("\e\[27;6;%d~" control shift) + ("\e\[27;7;%d~" control meta) + ("\e\[27;8;%d~" control meta shift) + + ("\e\[%d;3~" meta) + ("\e\[%d;5~" control) + ("\e\[%d;6~" control shift) + ("\e\[%d;7~" control meta) + ("\e\[%d;8~" control meta shift))) + (setq c (1+ c)))))) +(eval-after-load "rxvt" '(eval-after-load-urxvt))