5

This might have an obvious answer but I've been trying to fix this issue with no luck. (I'm new to Emacs)

Whenever I start Emacs within a Tmux pane, it ignores some of my .emacs settings. These are the contents of the .emacs file:

(custom-set-variables
;; custom-set-variables was added by Custom.                                                                                                                                             
;; If you edit it by hand, you could mess it up, so be careful.                                                                                                                          
;; Your init file should contain only one such instance.                                                                                                                                 
;; If there is more than one, they won't work right.                                                                                                                                     
'(ansi-color-faces-vector
[default default default italic underline success warning error])
'(cua-mode t nil (cua-base))
'(show-paren-mode t)
'(tool-bar-mode nil))

(custom-set-faces
;; custom-set-faces was added by Custom.                                                                                                                                                 
;; If you edit it by hand, you could mess it up, so be careful.                                                                                                                          
;; Your init file should contain only one such instance.                                                                                                                                 
;; If there is more than one, they won't work right.                                                                                                                                     
)

;;Initial GUI frame size and position                                                                                                                                                     
(when window-system (set-frame-size (selected-frame) 160 50))

;; Resizing window quick shortcuts                                                                                                                                                        
(global-set-key (kbd "S-C-<left>") 'shrink-window-horizontally)
(global-set-key (kbd "S-C-<right>") 'enlarge-window-horizontally)
(global-set-key (kbd "S-C-<down>") 'shrink-window)
(global-set-key (kbd "S-C-<up>") 'enlarge-window)

;;Kill buffer without prompt unless there are unsaved changes                                                                                                                             
(global-set-key (kbd "C-x k") 'kill-this-buffer)

;;Interactively-do-mode, improves file and interface navigation                                                                                                                           
(require 'ido)
(ido-mode t)

Settings like IDO mode and kill-this-buffer work fine. But the syntax color scheme and S-C-arrows for resizing the window don't work.

Inside Tmux: enter image description here Outside Tmux (still in gnome-terminal): enter image description here

*Also, is running Emacs inside Tmux a bad idea in general?

Rtsne42
  • 489
  • 5
  • 13
  • How do you know it ignores the configuration? – choroba Dec 19 '16 at 15:09
  • The only thing that seems to be working from my configuration mode is Ido mode. Other than that my syntax theme doesn't work, my custom keybindings don't work and changing settings in the init file like menu-bar-mode -1 doesn't work. It does work in a regular terminal though. – Rtsne42 Dec 19 '16 at 15:26
  • Does `M-: (getenv "HOME")` point to your user's home directory? – wvxvw Dec 19 '16 at 15:31
  • Yes, it does. I killed all the Tmux sessions and some of the new keybinds seem to work now. – Rtsne42 Dec 19 '16 at 15:34
  • But things like my window resize keybinds and syntax theme don't work: `(global-set-key (kbd "S-C-") 'shrink-window-horizontally) (global-set-key (kbd "S-C-") 'enlarge-window-horizontally) (global-set-key (kbd "S-C-") 'shrink-window) (global-set-key (kbd "S-C-") 'enlarge-window)` – Rtsne42 Dec 19 '16 at 15:35
  • I do realise that i just discovered that some of them do work. I'll update the post. If I start emacs in the terminal I can resize windows with S-C-arrows and syntax highlighting is different. When I start it in Tmux these settings don't work. – Rtsne42 Dec 19 '16 at 15:38
  • Updated the post. – Rtsne42 Dec 19 '16 at 15:43
  • Possibly related: [Problems with keybindings when using terminal](http://emacs.stackexchange.com/questions/1020/problems-with-keybindings-when-using-terminal). – Dan Dec 19 '16 at 15:48
  • The "outside" screenshot is the so-called "graphical" environment (Emacs runs on top of something like Xorg). Most themes for Emacs have different colors for graphical and non-graphical environments (try running Emacs from a regular terminal emulator like this: `emacs -nw` to see that this will also happen outside tmux. – wvxvw Dec 19 '16 at 16:02
  • @wvxvw The second screenshot is inside gnome-terminal not the GUI version. I'll update it. – Rtsne42 Dec 19 '16 at 16:03
  • Ah, I got confused because the fringe looked "3D". – wvxvw Dec 19 '16 at 16:06
  • Are you sure your terminal or tmux don't "understand" some of the keybindings for themselves? – choroba Dec 19 '16 at 16:33

1 Answers1

6

The following additions to your .tmux.conf file ought to fix most or your problems:

set-option -g default-terminal "xterm-256color"
set-window-option -g xterm-keys on

The reason that your color themes aren't working as expected is most likely that emacs thinks that it is running in a terminal with only 8 colors. Setting the terminal to be xterm-256color tells emacs that your terminal can support 256 colors.

The reason that your keyboard shortcuts aren't working as expected is that the tmux doesn't know what you expect it to do with modified keys. Turning xterm-keys on tells tmux to send the modified keys as escape sequences the same way xterm does. Since emacs thinks that your terminal is xterm, it will interpret incoming escape sequences as if they were from xterm, and do the right thing.

nispio
  • 8,175
  • 2
  • 35
  • 73
  • Although this didn't fix the issue directly. For some reason after adding these settings not much changed other than the fact that the screen split lines had no background. Then after removing the changes. Suddenly everything works. Don't know what fixed it. If I find out I'll update the post. For now I might as well accept it as an answer. – Rtsne42 Dec 19 '16 at 17:24
  • This only worked for me after killing all current tmux sessions. – erjoalgo May 19 '19 at 22:33