当我在终端中打开一个框架时,我想让emacs没有背景颜色。我正在使用具有半透明背景的终端,而具有背景颜色的字符不是“透视”。 TERM设置为“xterm-256color”。
当框架不是图形时,如何让emacs使用默认背景颜色(根本没有颜色)?
编辑:我有它,有点:
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes")
(load-theme 'my-awesome-theme t)
(defun on-frame-open (frame)
(if (not (display-graphic-p frame))
(set-face-background 'default "unspecified-bg" frame)))
(on-frame-open (selected-frame))
(add-hook 'after-make-frame-functions 'on-frame-open)
我将上面的代码放在我的init文件中,但只是在终端中打开emacsclient而不是emacs本身时(即仅在使用emacsclient -t
调用时,而不是在使用emacs
调用时)。添加额外的(unless window-system (set-face-background 'default "unspecified-bg" (selected-frame)))
不起作用,只会混淆图形框架。
有关为何会发生这种情况的任何想法
(defun on-after-init ()
(unless (display-graphic-p (selected-frame))
(set-face-background 'default "unspecified-bg" (selected-frame))))
(add-hook 'window-setup-hook 'on-after-init)
结合编辑中的代码,它对我来说非常适用于emacsterms和新启动的emacsen。至于为什么window-setup-hook
:http://www.gnu.org/software/emacs/manual/html_node/elisp/Startup-Summary.html
(除了这个之外,早期的钩子似乎都没有用。)
我尝试了在this answer中建议的方法,但我没有运气让它工作。这个片段对我有用
(defun on-frame-open (&optional frame)
"If the FRAME created in terminal don't load background color."
(unless (display-graphic-p frame)
(set-face-background 'default "unspecified-bg" frame)))
(add-hook 'after-make-frame-functions 'on-frame-open)
虽然它有一个挫折,但如果终端的背景设置与我使用的主题不同(黑暗与光线),则使用默认的主题面部,在浅色或深色背景下看起来可能不太好。但在我的情况下,终端和主题都是黑暗的,它工作正常。
这个问题已经有两个答案,one使用window-setup-hook
,在启动时调用,another使用after-make-frame-functions
,在制作新帧时调用,包括在调用emacsclient
之后。为了涵盖所有可能的情况,我发现我需要这样做:
(defun set-background-for-terminal (&optional frame)
(or frame (setq frame (selected-frame)))
"unsets the background color in terminal mode"
(unless (display-graphic-p frame)
(set-face-background 'default "unspecified-bg" frame)))
(add-hook 'after-make-frame-functions 'set-background-for-terminal)
(add-hook 'window-setup-hook 'set-background-for-terminal)
请注意,如果需要,我只使用selected-frame
;似乎在客户端模式下,在选择帧之前调用钩子,因此在这种情况下使用frame参数很重要。