summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2022-09-30 23:47:07 -0700
committerSean Whitton <spwhitton@spwhitton.name>2022-10-01 16:19:41 -0700
commitb3796115d7c835c98fd1dcbb9509b784fac81542 (patch)
treec590845a30a6886c7f020d39d943772669463347
parent56f668ec94d02884062b6bcaa4c6a02a1dd16e69 (diff)
downloaddotfiles-b3796115d7c835c98fd1dcbb9509b784fac81542.tar.gz
rework & refactor spw/set-tmux-background-mode
-rw-r--r--.emacs.d/init.el27
1 files changed, 18 insertions, 9 deletions
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.