I want to enforce only one GUI instance for Emacs, so I want to check if at least one GUI frame is open or not (i.e. the frame that is open with emacsclient -c), and ignore the ones opened in Terminal. How do I do that? I already tried visible-frame-list function but this seems to count all frames.

  • frame-list returns a list of all live frames and frame-visible-p returns if a frame is visible – eflanigan00 Mar 8 '17 at 4:39

You can use the framep function to determine the type of each frame. It returns a symbol describing the type of the frame: t for terminal, x for X window, w32 for MS windows, ns for Mac/GNUstep, and pc for a direct-write MS-DOS frame.

Once you have this you could count the number of (say) X Window frames with something like (length (seq-filter (lambda (f) (eq (framep f) 'x)) (frame-list))), or for a function that returns t if there is an X Window frame otherwise nil, use (seq-some (lambda (f) (eq (framep f) 'x)) (frame-list)). There are many other variations as well :-)

| improve this answer | |

Use the display-graphic-p function:

display-graphic-p is a compiled Lisp function in `frame.el'.

(display-graphic-p &optional DISPLAY)

Return non-nil if DISPLAY is a graphic display. Graphical displays are those which are capable of displaying several frames and several different fonts at once. This is true for displays that use a window system such as X, and false for text-only terminals. DISPLAY can be a display name, a frame, or nil (meaning the selected frame's display).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.