From 306a7fc2a40c97a73c3149e6c465e3c1df7c455f Mon Sep 17 00:00:00 2001 From: Daniel Weschke Date: Sun, 16 Jan 2022 15:27:42 +0100 Subject: [PATCH] move more settings to the early init file --- README.md | 5 ++- README.org | 6 ++- early-init.el | 81 ++++++++++++++++++++++++++++++++++++++++ init | 10 ++++- settings/gui-settings.el | 37 ------------------ settings/pre-settings.el | 7 ---- 6 files changed, 97 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index 1d7f398f..20e98e3d 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,10 @@ a bunch of online resources. # Installation -Run one of the following install script commands (using curl, wget or fetch). +Download repo and point the emacs `init` (and `early-init.el`) file to +this configuration. + +Or run one of the following install script commands (using curl, wget or fetch). sh -c "$(curl -fsSL http://gitea.weseng.de/daniel/emacs/raw/master/scripts/install.sh)" sh -c "$(wget -O- http://gitea.weseng.de/daniel/emacs/raw/master/scripts/install.sh)" diff --git a/README.org b/README.org index 2e73f462..0087acc6 100644 --- a/README.org +++ b/README.org @@ -9,13 +9,15 @@ a bunch of online resources. :PROPERTIES: :CUSTOM_ID: installation :END: -Run one of the following install script commands (using curl, wget or fetch). +Download repo and point the emacs =init= (and =early-init.el=) file to +this configuration. + +Or run one of the following install script commands (using curl, wget or fetch). #+begin_src sh sh -c "$(curl -fsSL http://gitea.weseng.de/daniel/emacs/raw/master/scripts/install.sh)" sh -c "$(wget -O- http://gitea.weseng.de/daniel/emacs/raw/master/scripts/install.sh)" sh -c "$(fetch -o - http://gitea.weseng.de/daniel/emacs/raw/master/scripts/install.sh)" #+end_src - Installation path is =~/.config/emacs=. See details and other installed linux packages as requirements inside =sripts/install.sh=. diff --git a/early-init.el b/early-init.el index ac45ef06..96ff752a 100644 --- a/early-init.el +++ b/early-init.el @@ -1,4 +1,44 @@ +;;; early-init.el --- Early initialization file for Emacs -*- lexical-binding: t; -*- +;;; Commentary: +;; Emacs 27.1 introduced early-init.el, which is run before init.el, before +;; package and UI initialization happens, and before site files are loaded. + +;;; Code: +;; A big contributor to startup times is garbage collection. We up the gc +;; threshold to temporarily prevent it from running, then reset it later by +;; enabling `gcmh-mode'. Not resetting it will cause stuttering/freezes. +(setq gc-cons-threshold (* 50 1000 1000)) ;; Make startup faster by reducing the frequency of garbage collection. The default is 800 kilobytes. Measured in bytes. Will be decreased again at the end. + +;; make UTF-8 the default coding system: +(set-language-environment "UTF-8") +;; `set-language-enviornment' sets `default-input-method', which is unwanted +(setq default-input-method nil) + +(setq config-dir (file-name-directory (file-truename user-init-file))) ;; user-init-file: ~/.config/emacs/init, file-truename: /opt/emacs-conf/init +(setq user-emacs-directory "~/.config/emacs/") ;; for cache etc. +(defconst user-cache-directory + (file-name-as-directory (concat user-emacs-directory ".cache")) + "My Emacs storage area for persistent files.") +;; create the `user-cache-directory' if not exists +(make-directory user-cache-directory t) + +(mapc (lambda (item) (add-to-list 'load-path item)) + (list + (concat config-dir "settings") ;; path where settings files are kept + (concat config-dir "lisp") ;; personal elisp lib dir, for manually installed packages + (concat config-dir "lisp/adaptive-wrap") ;; https://elpa.gnu.org/packages/adaptive-wrap.html + (concat config-dir "lisp/dash") + (concat config-dir "lisp/with-editor") + (concat config-dir "lisp/hydra") ;; required by treemacs org-ref + (concat config-dir "lisp/async") ;; https://melpa.org/#/async required by ob-async + (concat config-dir "lisp/persist") ;; https://elpa.gnu.org/packages/persist.html required by org-drill + (concat config-dir "lisp/use-package") ;; https://melpa.org/#/use-package + )) + +;; +;; FRAME +;; ;; (add-to-list 'default-frame-alist '(fullscreen . maximized)) ;; restore saved geometry, see gui-settings.el my-frame-geometry- (add-to-list 'default-frame-alist '(tool-bar-position . left)) ;; (add-to-list 'default-frame-alist '(horizontal-scroll-bars . t)) ;; see gui-settings @@ -6,3 +46,44 @@ ;; transparency (set-frame-parameter (selected-frame) 'alpha '(95 . 95)) ;; VALUE: '( . ) / (add-to-list 'default-frame-alist '(alpha . (95 . 95))) + +;; Custom functions/hooks for persisting/loading frame geometry upon save/load +(setq my-frame-geometry-file (concat user-cache-directory "frame-geometry.el")) +(defun my-frame-geometry-save () + "Gets the current frame's geometry and save it to `my-frame-geometry-file'." + (let ((frameg-font (frame-parameter (selected-frame) 'font)) + (frameg-left (frame-parameter (selected-frame) 'left)) + (frameg-top (frame-parameter (selected-frame) 'top)) + (frameg-width (frame-parameter (selected-frame) 'width)) + (frameg-height (frame-parameter (selected-frame) 'height)) + (frameg-file my-frame-geometry-file)) + (with-temp-buffer + ;; Turn off backup for this file + (make-local-variable 'make-backup-files) + (setq make-backup-files nil) + (insert + ";;; This file stores the previous emacs frame's geometry.\n" + ";;; Last generated " (current-time-string) ".\n" + "(setq initial-frame-alist\n" + ;; " '((font . \"" frameg-font "\")\n" + " '(" + (format " (top . %d)\n" (max frameg-top 0)) + (format " (left . %d)\n" (max frameg-left 0)) + (format " (width . %d)\n" (max frameg-width 0)) + (format " (height . %d)))\n" (max frameg-height 0))) + (when (file-writable-p frameg-file) + (write-file frameg-file))))) +(defun my-frame-geometry-load () + "Load `my-frame-geometry-file' which should load the previous frame's geometry." + (let ((frameg-file my-frame-geometry-file)) + (when (file-readable-p frameg-file) + (load-file frameg-file)))) +;; Special work to do ONLY when there is a window system being used +;; (if (display-graphic-p) +;; (progn +;; (add-hook 'kill-emacs-hook 'my-frame-geometry-save))) +(my-frame-geometry-load) +(add-hook 'window-setup-hook + (lambda () + (if (display-graphic-p) + (add-hook 'kill-emacs-hook 'my-frame-geometry-save)))) diff --git a/init b/init index 6a795a91..23d2ebd3 100644 --- a/init +++ b/init @@ -7,8 +7,14 @@ ;; Requirements: git gnuplot ledger ;;; Code: -(setq config-dir (file-name-directory (file-truename user-init-file))) ;; user-init-file: ~/.config/emacs/init, file-truename: /opt/emacs-conf/init -(require 'pre-settings (concat config-dir "settings/pre-settings.el")) ;; use-package delight functions variables +;; Emacs 27.1 introduced early-init.el, which is run before init.el, before +;; package and UI initialization happens, and before site files are loaded. +;; In the case that early-init.el wasn't loaded (e.g. using old emacs? Or this +;; file directly loaded?), we do it explicitly: +(unless (version<= "27.1" emacs-version) + (load (concat (file-name-directory (file-truename user-init-file)) "early-init.el") + nil t)) +(require 'pre-settings) ;; use-package delight functions variables (require 'which-key-settings) ;; https://melpa.org/#/which-key (require 'general-settings) ;; requires which-key (require 'my-settings) diff --git a/settings/gui-settings.el b/settings/gui-settings.el index 6259860c..6144dedc 100644 --- a/settings/gui-settings.el +++ b/settings/gui-settings.el @@ -425,42 +425,5 @@ See also `dashboard-insert-section' for the sequence of elements." ;;:hook (help-mode . virtual-auto-fill-mode) ) -;; Custom functions/hooks for persisting/loading frame geometry upon save/load -(setq my-frame-geometry-file (concat user-cache-directory "frame-geometry.el")) -(defun my-frame-geometry-save () - "Gets the current frame's geometry and save it to `my-frame-geometry-file'." - (let ((frameg-font (frame-parameter (selected-frame) 'font)) - (frameg-left (frame-parameter (selected-frame) 'left)) - (frameg-top (frame-parameter (selected-frame) 'top)) - (frameg-width (frame-parameter (selected-frame) 'width)) - (frameg-height (frame-parameter (selected-frame) 'height)) - (frameg-file my-frame-geometry-file)) - (with-temp-buffer - ;; Turn off backup for this file - (make-local-variable 'make-backup-files) - (setq make-backup-files nil) - (insert - ";;; This file stores the previous emacs frame's geometry.\n" - ";;; Last generated " (current-time-string) ".\n" - "(setq initial-frame-alist\n" - ;; " '((font . \"" frameg-font "\")\n" - " '(" - (format " (top . %d)\n" (max frameg-top 0)) - (format " (left . %d)\n" (max frameg-left 0)) - (format " (width . %d)\n" (max frameg-width 0)) - (format " (height . %d)))\n" (max frameg-height 0))) - (when (file-writable-p frameg-file) - (write-file frameg-file))))) -(defun my-frame-geometry-load () - "Load `my-frame-geometry-file' which should load the previous frame's geometry." - (let ((frameg-file my-frame-geometry-file)) - (when (file-readable-p frameg-file) - (load-file frameg-file)))) -;; Special work to do ONLY when there is a window system being used -(if (display-graphic-p) - (progn - (add-hook 'after-init-hook 'my-frame-geometry-load) - (add-hook 'kill-emacs-hook 'my-frame-geometry-save))) - (provide 'gui-settings) ;;; gui-settings.el ends here diff --git a/settings/pre-settings.el b/settings/pre-settings.el index 07a79cb1..3e4ef157 100644 --- a/settings/pre-settings.el +++ b/settings/pre-settings.el @@ -14,7 +14,6 @@ (concat config-dir "lisp/use-package") ;; https://melpa.org/#/use-package )) -(setq gc-cons-threshold (* 50 1000 1000)) ;; Make startup faster by reducing the frequency of garbage collection. The default is 800 kilobytes. Measured in bytes. Will be decreased again at the end. ;; count startup time (add-hook 'emacs-startup-hook ;; Use a hook so the message doesn't get clobbered by other messages. (lambda () @@ -50,12 +49,6 @@ Both Win32 and Cygwin count.") (shell-command-to-string "uname -a | sed -n 's/.*\\( *Microsoft *\\).*/\\1/ip'")) "Microsoft")) -(setq user-emacs-directory "~/.config/emacs/") ;; for cache etc. -(defconst user-cache-directory - (file-name-as-directory (concat user-emacs-directory ".cache")) - "My Emacs storage area for persistent files.") -;; create the `user-cache-directory' if not exists -(make-directory user-cache-directory t) (defvar my-dbusp (and (boundp 'dbus-compiled-version) ;; t on WSL Debian machine (if (require 'dbus) (dbus-ping :session "org.freedesktop.Notifications"))) ;; is not enough