how to check if emacs in frame or in terminal?
Asked Answered
D

2

7

Based on this question : How to set emacsclient background as Emacs background?

I need background only for frames, not for terminal and not for console.

Here is how I'm trying to add fix for console

(when (display-graphic-p)
    (tool-bar-mode -1)
    (scroll-bar-mode t)
    (require 'nyan-mode)
    (nyan-mode)
    (nyan-start-animation)
    (mouse-wheel-mode t)
    (setq default-frame-alist
          '((background-color . "#101416")
            (foreground-color . "#f6f3e8"))
          ) 
)

But with that I don't get background on emacsclient (even for frames). Maybe the check doesn't even run in emacsclient?

Basically I want to not add background to emacsclient in terminal and console but in frames.

Dulcie answered 15/2, 2012 at 4:16 Comment(2)
Where is your code being evaluated? Remember that .emacs is only evaluated once when Emacs starts, not when emacsclient connects.Foreknow
Okay, so your .emacs file evaluates your (nCdy-mode) function directly, which means that the body of your (when (display-graphic-p) ...) clause is going to be evaluated once at most*, and then only if (display-graphic-p) is true at the time that Emacs starts. (*) Unless you are also calling (nCdy-mode) elsewhere, but you don't say that you are.Foreknow
F
5
(defun my-frame-config (frame)
  "Custom behaviours for new frames."
  (with-selected-frame frame
    (when (display-graphic-p)
      (set-background-color "#101416")
      (set-foreground-color "#f6f3e8"))))
;; run now
(my-frame-config (selected-frame))
;; and later
(add-hook 'after-make-frame-functions 'my-frame-config)
Foreknow answered 15/2, 2012 at 8:41 Comment(0)
G
2

Maybe the simpler solution is to not touch *-frame-alist, nor set-frame-*, but instead to M-x customize-face RET default RET and then middle click on the "State" button and select "For all kinds of displays" at which point you'll be able to set the face appearence differently for different displays. This part of the UI is not used very much, and it shows, but you'd do: middle click on INS to insert a second set of settings, then middle-click on "Display" and select "nil", then click on the toggle to the left of "Type" and then on the toggle on the left of "TTY": this makes the first set of settings only apply to tty frames while the other one (which presumably still says "Display: all") applies to the remaining cases (i.e. non-tty frames).

Gadfly answered 15/2, 2012 at 20:53 Comment(2)
Ah, nice! FWIW I find that left-click is the same as middle-click for those widgets (both bound to widget-button-click)? And for this particular question, you would then need to click "Supports attributes" and "Show All Attributes" to access the foreground and background colour options.Foreknow
Actually, I guess you do leave the new settings blank, and change those colours in the default settings instead. I tried the inverse (changing the foreground/background colours for the TTY settings) with Ubuntu's default terminal, and couldn't get it to take effect (although the 'inverse video' option did work). YMMV?Foreknow

© 2022 - 2024 — McMap. All rights reserved.