summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2022-09-12 15:02:31 -0700
committerSean Whitton <spwhitton@spwhitton.name>2022-09-12 15:32:49 -0700
commit233e1762ff409345432d6f273c54d3dded6840a3 (patch)
tree6c2c22a8c04cb482c44c9e5e984d99d49e93ca0c
parenta64452ed4f4427d0eca8e8a98877ecc7870ae620 (diff)
downloaddotfiles-233e1762ff409345432d6f273c54d3dded6840a3.tar.gz
set frame-title-format and fontset fonts (even) earlier, & tidying
This ensures that both daemon and non-daemon initial frames have the correct frame-title-format and fontset fonts right after they are created.
-rw-r--r--.emacs.d/early-init.el85
-rw-r--r--.emacs.d/init.el79
2 files changed, 85 insertions, 79 deletions
diff --git a/.emacs.d/early-init.el b/.emacs.d/early-init.el
new file mode 100644
index 00000000..f7e32fb2
--- /dev/null
+++ b/.emacs.d/early-init.el
@@ -0,0 +1,85 @@
+;;; early-init.el --- frames conf. -*- lexical-binding:t;no-byte-compile:t -*-
+
+;; Copyright (C) 2020-2022 Sean Whitton <spwhitton@spwhitton.name>
+
+;;; See docstring for `after-make-frame-functions' for why these are here.
+
+(defun spw/set-fontset-fonts (frame)
+ "Set some fonts for specific charsets.
+
+This has to happen after there's at least one graphical frame, or
+the fonts won't be found and so won't be set. We use
+`after-focus-change-function' for this. We could call this
+function unconditionally if (not (daemonp)), but it's simpler to
+always go via `after-focus-change-function'."
+ (when (display-graphic-p frame)
+ (setq after-make-frame-functions
+ (delq #'spw/set-fontset-fonts after-make-frame-functions))
+ (let ((spec (font-spec :name "Noto Serif CJK JP")))
+ (dolist (charset '(kana han symbol cjk-misc bopomofo))
+ (set-fontset-font t charset spec)))
+ (set-fontset-font t 'hangul (font-spec :name "Noto Serif CJK KR"))))
+(add-to-list 'after-make-frame-functions #'spw/set-fontset-fonts)
+
+(defvar spw/tiling-wm-p nil
+ "Have we had at least one frame managed by a tiling window manager?")
+
+(defun spw/disable-mouse-autoselect-window (orig-fun &rest args)
+ (let (mouse-autoselect-window)
+ (apply orig-fun args)))
+
+;; 'emacsclient --spw/update-environment' supplies us with I3SOCK, so if we
+;; see that variable we know there is at least one frame under i3 or swaywm,
+;; and so we want to set `mouse-autoselect-window' and `focus-follows-mouse'
+;; to t. As we can't do that frame-locally, once they're set they're set.
+;;
+;; On the other hand, ideally functions like `spw/save-buffer-for-later'
+;; decide whether to open a new frame or a new tab frame-locally, so we used
+;; to temporarily set DISPLAY to (frame-parameter (selected-frame) 'display)
+;; and then call wmctrl(1) to get the name of the window manager for that
+;; frame, and stored it in a frame parameter. But that only works for X11,
+;; not Wayland. So for now we just set a boolean `spw/tiling-wm-p' frame
+;; parameter to which functions like `spw/save-buffer-for-later' can respond.
+(defun spw/detect-tiling-wm (frame)
+ (unless (or spw/tiling-wm-p
+ (not (setq spw/tiling-wm-p
+ (or (getenv "I3SOCK") (getenv "SWAYSOCK")))))
+ (setq focus-follows-mouse t
+ mouse-autoselect-window t
+ desktop-restore-forces-onscreen nil)
+ ;; Disable `mouse-autoselect-window' during `display-buffer', to avoid
+ ;; surprise focus changes -- some code that calls `display-buffer' does
+ ;; not expect `mouse-autoselect-window' to be on. E.g. `magit-status'
+ ;; can leave focus in the wrong window without this.
+ (advice-add 'display-buffer :around #'spw/disable-mouse-autoselect-window))
+ ;; If X or Sway, we know we have a usable primary selection, so we used to
+ ;; turn off additionally copying to the clipboard. However, we do want to
+ ;; be able to yank from the clipboard. See also NEWS.24.
+ ;; (setq select-enable-clipboard
+ ;; (not (or spw/tiling-wm-p (eq (framep frame) 'x))))
+ )
+(add-to-list 'after-make-frame-functions #'spw/detect-tiling-wm)
+
+(defun spw/use-tabs-not-frames (&optional frame)
+ "Whether to pop up new tabs instead of new frames.
+Should be t when do not have a good way to handle having lots of
+open frames, as I do have under i3/swaywm with its tabbed
+layout (which I use by default)."
+ (not (and spw/tiling-wm-p
+ (memq (framep (or frame (selected-frame))) '(x pgtk)))))
+
+;; If we're going to be using multiple frames, make `frame-title-format' not
+;; depend on whether there are multiple frames right now.
+(defun spw/set-frame-title-format (frame)
+ (unless (spw/use-tabs-not-frames frame)
+ (setq after-make-frame-functions
+ (delq #'spw/set-frame-title-format after-make-frame-functions))
+ (setq frame-title-format
+ (concat "%b - "
+ (if (file-in-directory-p
+ invocation-directory (expand-file-name "~/"))
+ "in-tree" "installed")
+ " GNU Emacs at " system-name)
+ icon-title-format frame-title-format)))
+;; Must come after `spw/detect-tiling-wm'.
+(add-to-list 'after-make-frame-functions #'spw/set-frame-title-format t)
diff --git a/.emacs.d/init.el b/.emacs.d/init.el
index 2727127c..11036520 100644
--- a/.emacs.d/init.el
+++ b/.emacs.d/init.el
@@ -79,22 +79,6 @@
;; belonging to shortlived instances from those belonging to main instance.
`(,ws . ((background-color . ,(if (daemonp) "#FFFFF6" "alice blue"))))))
-(defun spw/set-fontset-fonts ()
- "Set some fonts for specific charsets.
-
-This has to happen after there's at least one graphical frame, or
-the fonts won't be found and so won't be set. We use
-`after-focus-change-function' for this. We could call this
-function unconditionally if (not (daemonp)), but it's simpler to
-always go via `after-focus-change-function'."
- (when (display-graphic-p)
- (remove-function after-focus-change-function #'spw/set-fontset-fonts)
- (let ((spec (font-spec :name "Noto Serif CJK JP")))
- (dolist (charset '(kana han symbol cjk-misc bopomofo))
- (set-fontset-font t charset spec)))
- (set-fontset-font t 'hangul (font-spec :name "Noto Serif CJK KR"))))
-(add-function :after after-focus-change-function #'spw/set-fontset-fonts)
-
(defun spw/maybe-scale-basic-faces (frame)
"Entry for `window-size-change-functions' to increase font sizes
from those set by `custom-set-faces' for frames on wide monitors,
@@ -680,53 +664,6 @@ Lisp Interaction C-j in `lisp-interaction-mode' and similar."
tramp-auto-save-directory auto-saves-dir
tramp-backup-directory-alist backup-directory-alist))
-(defvar spw/tiling-wm-p nil
- "Have we had at least one frame managed by a tiling window manager?")
-
-(defun spw/disable-mouse-autoselect-window (orig-fun &rest args)
- (let ((mouse-autoselect-window nil))
- (apply orig-fun args)))
-
-;; 'emacsclient --spw/update-environment' supplies us with I3SOCK, so if we
-;; see that variable we know there is at least one frame under i3 or swaywm,
-;; and so we want to set `mouse-autoselect-window' and `focus-follows-mouse'
-;; to t. As we can't do that frame-locally, once they're set they're set.
-;;
-;; On the other hand, ideally functions like `spw/save-buffer-for-later'
-;; decide whether to open a new frame or a new tab frame-locally, so we used
-;; to temporarily set DISPLAY to (frame-parameter (selected-frame) 'display)
-;; and then call wmctrl(1) to get the name of the window manager for that
-;; frame, and stored it in a frame parameter. But that only works for X11,
-;; not Wayland. So for now we just set a boolean `spw/tiling-wm-p' frame
-;; parameter to which functions like `spw/save-buffer-for-later' can respond.
-(defun spw/detect-tiling-wm (frame)
- (unless (or spw/tiling-wm-p
- (not (setq spw/tiling-wm-p
- (or (getenv "I3SOCK") (getenv "SWAYSOCK")))))
- (setq focus-follows-mouse t
- mouse-autoselect-window t
- desktop-restore-forces-onscreen nil)
- ;; Disable `mouse-autoselect-window' during `display-buffer', to avoid
- ;; surprise focus changes -- some code that calls `display-buffer' does
- ;; not expect `mouse-autoselect-window' to be on. E.g. `magit-status'
- ;; can leave focus in the wrong window without this.
- (advice-add 'display-buffer :around #'spw/disable-mouse-autoselect-window))
- ;; If X or Sway, we know we have a usable primary selection, so we used to
- ;; turn off additionally copying to the clipboard. However, we do want to
- ;; be able to yank from the clipboard. See also NEWS.24.
- ;; (setq select-enable-clipboard
- ;; (not (or spw/tiling-wm-p (eq (framep frame) 'x))))
- )
-(add-to-list 'after-make-frame-functions #'spw/detect-tiling-wm)
-
-(defun spw/use-tabs-not-frames (&optional frame)
- "Whether to pop up new tabs instead of new frames.
-Should be t when do not have a good way to handle having lots of
-open frames, as I do have under i3/swaywm with its tabbed
-layout (which I use by default)."
- (not (and spw/tiling-wm-p
- (memq (framep (or frame (selected-frame))) '(x pgtk)))))
-
;; On remote hosts in the UTC timezone, assume I'm in Arizona. This is
;; relevant for using Org-mode, dired timestamps, etc.. Note that hosts in
;; the UK will be in GMT or BST, not UTC, so this won't affect those.
@@ -2189,22 +2126,6 @@ Used in my `message-mode' yasnippets."
(message-goto-body)
(insert type ": " package "\n" "Version: " version "\n")))
-;; if we're going to be using multiple frames, make `frame-title-format' not
-;; depend on whether there are multiple frames right now
-(defun spw/set-frame-title-format (frame)
- (unless (spw/use-tabs-not-frames frame)
- (setq after-make-frame-functions
- (delq #'spw/set-frame-title-format after-make-frame-functions))
- (setq frame-title-format
- (concat "%b - "
- (if (file-in-directory-p
- invocation-directory (expand-file-name "~/"))
- "in-tree" "installed")
- " GNU Emacs at " system-name)
- icon-title-format frame-title-format)))
-;; Must come after `spw/detect-tiling-wm'.
-(add-to-list 'after-make-frame-functions #'spw/set-frame-title-format t)
-
(defun spw/save-buffer-for-later ()
(interactive)
(if (spw/use-tabs-not-frames)