From d78000728351986b0083013728dc3ef366112c0b Mon Sep 17 00:00:00 2001 From: Basil L. Contovounesios Date: Wed, 18 Mar 2026 12:42:28 +0100 Subject: Add predicate for initial_terminal This introduces the predicate frame-initial-p, which uses struct frame.output_method or struct terminal.type to detect initial_terminal without relying on its name (bug#80629). For some prior discussion, see: https://lists.gnu.org/r/emacs-devel/2019-12/msg00480.html https://lists.gnu.org/r/emacs-devel/2020-01/msg00120.html * doc/lispref/frames.texi (Frames): Document frame-initial-p. (Finding All Frames): Fix grammar. * etc/NEWS (Lisp Changes in Emacs 31.1): Announce frame-initial-p. * lisp/desktop.el (desktop--check-dont-save): * lisp/emacs-lisp/debug.el (debug): * lisp/frameset.el (frameset-restore): * lisp/menu-bar.el (menu-bar-update-buffers): * lisp/xt-mouse.el (turn-on-xterm-mouse-tracking-on-terminal): Use frame-initial-p instead of checking the "initial_terminal" name. * lisp/emacs-lisp/byte-opt.el: Mark frame-initial-p as error-free. * src/pgtkterm.c (pgtk_focus_changed): Use IS_DAEMON in place of Fdaemonp, thus also accepting a named daemon session. * src/terminal.c (decode_tty_terminal): Clarify commentary. (Fframe_initial_p): New function. (syms_of_terminal): Expose it. (init_initial_terminal): Update commentary now that menu-bar-update-buffers uses frame-initial-p (bug#53740). * test/lisp/xt-mouse-tests.el (with-xterm-mouse-mode): Simulate the lack of an initial terminal by overriding frame-initial-p now that turn-on-xterm-mouse-tracking-on-terminal uses it. * test/src/terminal-tests.el: New file. --- test/src/terminal-tests.el | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 test/src/terminal-tests.el (limited to 'test/src') diff --git a/test/src/terminal-tests.el b/test/src/terminal-tests.el new file mode 100644 index 00000000000..85c4fa04efc --- /dev/null +++ b/test/src/terminal-tests.el @@ -0,0 +1,55 @@ +;;; terminal-tests.el --- tests for terminal.c -*- lexical-binding: t -*- + +;; Copyright (C) 2026 Free Software Foundation, Inc. + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see . + +;;; Code: + +(require 'ert) + +(ert-deftest frame-initial-p () + "Test `frame-initial-p' behavior." + (should-not (frame-initial-p t)) + (should-not (frame-initial-p (current-buffer))) + (should-not (frame-initial-p (selected-window))) + ;; "Initial frame" implies "initial terminal", and + ;; no other terminal can have the initial frame. + (should-not (xor (equal (terminal-name) "initial_terminal") + (frame-initial-p))) + ;; Initial frame implies its terminal is a termcap-like + ;; text-mode terminal. + (should (or (not (frame-initial-p)) + (eq (terminal-live-p nil) t))) + ;; It similarly implies a termcap-like text-mode frame. + (should (or (not (frame-initial-p)) + (eq (frame-live-p (selected-frame)) t))) + (dolist (ft (append '(nil) (frame-list) (terminal-list))) + (ert-info ((prin1-to-string ft) :prefix "Argument: ") + (should-not (xor (equal (terminal-name ft) "initial_terminal") + (frame-initial-p ft))) + (should (or (not (frame-initial-p ft)) + (eq (terminal-live-p ft) t))))) + (cond (noninteractive + ;; Batch mode should have an initial frame. + (should (any #'frame-initial-p (frame-list))) + (should (any #'frame-initial-p (terminal-list)))) + ((not (daemonp)) + ;; Non-daemon interactive mode should have none. + (should-not (any #'frame-initial-p (frame-list))) + (should-not (any #'frame-initial-p (terminal-list)))))) + +;;; terminal-tests.el ends here -- cgit v1.2.1