【问题标题】:Emacs: disable theme background color in terminalEmacs:在终端中禁用主题背景颜色
【发布时间】:2013-09-27 15:12:37
【问题描述】:

当我在终端中打开一个框架时,我希望 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)

我将上面的代码放在我的初始化文件中,但仅在终端中打开 emacsclient 时抑制背景,而不是 emacs 本身(即仅在使用 emacsclient -t 调用时而不是在使用 emacs 调用时)。添加额外的(unless window-system (set-face-background 'default "unspecified-bg" (selected-frame))) 不起作用,只会混淆图形框架。

关于为什么会发生这种情况的任何想法?

【问题讨论】:

    标签: emacs colors elisp


    【解决方案1】:
    (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-hookhttp://www.gnu.org/software/emacs/manual/html_node/elisp/Startup-Summary.html

    (除了这个,早期的钩子似乎都不起作用。)

    【讨论】:

    • 太棒了!这对我来说非常适合 iTerm2 + Emacs 24 + Base 16 主题。
    • 很棒的小技巧。我用它来将wombat 主题应用到终端 Emacs,而不是它看起来不太好的窗口版本。
    • 请注意,(set-face-background 'default nil (selected-frame)) 也可以。
    • 好人!现在我可以使用透明背景了! (Ubuntu基础终端+Emacs25.2)
    • Gnome 终端上的 Emacs 27.2,Fedora 34。像魅力一样工作!
    【解决方案2】:

    我尝试了this answer 中建议的方法,但没有成功。不过这个 sn-p 对我有用

    (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)
    

    虽然它有一个挫折,但如果终端的背景设置与我使用的主题不同(深色与浅色),则会使用默认主题面,这在浅色或深色背景上可能看起来不太好。但在我的情况下,终端和主题都是黑暗的,它工作正常。

    【讨论】:

      【解决方案3】:

      这个问题已经有两个答案了,one使用window-setup-hook,在启动时调用,another使用after-make-frame-functions,在制作新框架时调用,包括在调用@987654325之后@。为了涵盖所有可能的情况,我发现我需要这样做:

      (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;似乎在客户端模式下,在选择框架之前调用了钩子,因此在这种情况下使用框架参数很重要。

      【讨论】:

      • 颜色过渡有一秒,正常吗?
      • 我认为您的配置中的任何内容在一段时间内不加载是正常的,直到 Emacs 处理它。
      猜你喜欢
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-18
      • 2016-12-18
      • 1970-01-01
      相关资源
      最近更新 更多