90 lines
4.5 KiB
EmacsLisp
90 lines
4.5 KiB
EmacsLisp
;;; 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
|
|
|
|
;; transparency
|
|
(set-frame-parameter (selected-frame) 'alpha '(95 . 95)) ;; VALUE: '(<active> . <inactive>) / <both>
|
|
(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))))
|