From b3796115d7c835c98fd1dcbb9509b784fac81542 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Fri, 30 Sep 2022 23:47:07 -0700 Subject: rework & refactor spw/set-tmux-background-mode --- .emacs.d/init.el | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to '.emacs.d') diff --git a/.emacs.d/init.el b/.emacs.d/init.el index 0ba5c8c0..8c864913 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -116,15 +116,24 @@ windows side-by-side in the frame." :height (if scale-up-p 151 120))))))) (add-to-list 'window-size-change-functions #'spw/maybe-scale-basic-faces) -;; `frame--current-backround-mode' assumes that TERM=screen-256color means a -;; dark background. But if we're in tmux then I can always have dark-on-light -;; by typing C-\ W (see ~/.tmux.conf). -(defun spw/set-tmux-background-mode (frame) - (when (cl-find-if (apply-partially #'string-prefix-p "TMUX=") - (frame-parameter frame 'environment)) - (let ((frame-background-mode 'light)) - (frame-set-background-mode frame)))) -(add-to-list 'after-make-frame-functions #'spw/set-tmux-background-mode) +;;; `frame--current-backround-mode' assumes that TERM=screen-256color means a +;;; dark background. But if we're in tmux then I can always have a light +;;; background by typing C-\ W (see ~/.tmux.conf). + +;; Handle 'emacs -nw' initial frames. +(when (and (framep terminal-frame) + (cl-find-if + (apply-partially #'string-prefix-p "TMUX=") initial-environment)) + (set-terminal-parameter terminal-frame 'background-mode 'light)) + +;; Handle 'emacsclient -tc' frames. +;; Require that TMUX is set in the frame's own environment parameter. +;; The hook is run with the new tty frame selected. +(defun spw/set-tmux-background-mode () + (when (and (frame-parameter nil 'environment) ; check it has one + (getenv "TMUX" (selected-frame))) + (set-terminal-parameter nil 'background-mode 'light))) +(add-hook 'tty-setup-hook #'spw/set-tmux-background-mode) (custom-set-variables ;; custom-set-variables was added by Custom. -- cgit v1.2.3