Starting in Emacs 23, Emacs handles OS X and other windowing systems as different “terminals.” (An abstraction extended – perhaps too far – from old-school physical terminals like VT100s, and later virtual terminals like xterm.) More information is available in this section and this section of the Emacs manual.
This package simplifies the addition of terminal-specific configuration code via terminal-specific macros. Code wrapped in these macros will execute in the emacs-startup-hook
if and only if the window system is the one appropriate to the macro. In other words, wrap code in one of these macros and it will only execute in the relevant window system.
Since these macros add code to emacs-startup-hook
, the wrapped code will run after window-system initialization is run, so these macros can be used to “deconfigure” anything the terminal setup file configures. To make behavior a bit more intuitive and consistent, pg-terminal-any
does no window-system checks, but adds the contained code to emacs-startup-hook
so it will run after anything previously defined.
;;; pg-terminal.el --- Window system configuration
;; Copyright (C) 2017 Phil Groce
;; Author: Phil Groce <[email protected]>
;; Version: 0.2
;; Keywords: gui
This package has no dependencies.
(defmacro pg-terminal-t (&rest body)
"Arrange for BODY to be executed after terminal setup if the window-system is `t` (TTY terminal)"
`(when (eq (window-system) 't)
(add-hook 'emacs-startup-hook (lambda () ,@body))))
(defmacro pg-terminal-x (&rest body)
"Arrange for BODY to be executed after terminal setup if the window-system is `x` (X Windows GUI)"
`(when (eq (window-system) 'x)
(add-hook 'emacs-startup-hook (lambda () ,@body))))
(defmacro pg-terminal-w32 (&rest body)
"Arrange for BODY to be executed after terminal setup if the window-system is `w32` (MS Windows)"
`(when (eq (window-system) 'w32)
(add-hook 'emacs-startup-hook (lambda () ,@body))))
(defmacro pg-terminal-ns (&rest body)
"Arrange for BODY to be executed after terminal setup if the window-system is `ns` (NeXTStep/OS X)"
`(when (eq (window-system) 'ns)
(add-hook 'emacs-startup-hook (lambda () ,@body))))
(defmacro pg-terminal-pc (&rest body)
"Arrange for BODY to be executed after terminal setup if the window-system is `pc` (DOS console)"
`(when (eq (window-system) 'pc)
(add-hook 'emacs-startup-hook (lambda () ,@body))))
(defmacro pg-terminal-any (&rest body)
"Arrange for BODY to be executed after terminal setup if the window-system is `pc` (DOS console)"
`(add-hook 'emacs-startup-hook (lambda () ,@body)))
(provide 'pg-terminal)
;;; pg-terminal.el ends here