Declare minimal-emacs.d global variables before loading pre-early-init.el

This commit is contained in:
James Cherti
2024-08-24 09:45:21 -04:00
parent 3544884c61
commit 08ab2a8d0f
3 changed files with 48 additions and 65 deletions

View File

@@ -2,7 +2,7 @@
![License](https://img.shields.io/github/license/jamescherti/be-quiet.el) ![License](https://img.shields.io/github/license/jamescherti/be-quiet.el)
![](https://raw.githubusercontent.com/jamescherti/minimal-emacs.d/main/.images/made-for-gnu-emacs.svg) ![](https://raw.githubusercontent.com/jamescherti/minimal-emacs.d/main/.images/made-for-gnu-emacs.svg)
The **minimal-emacs.d** repository offers a starter kit with improved Emacs defaults and optimized startup, designed to serve as a robust foundation for your vanilla Emacs configuration and enhance your overall Emacs experience. The **minimal-emacs.d** starter kit provides improved Emacs defaults and optimized startup, intended to serve as a solid foundation for your vanilla Emacs configuration and enhance your overall Emacs experience.
The author is using **[minimal-emacs.d](https://github.com/jamescherti/minimal-emacs.d)** as his `early-init.el` and `init.el`. He is using 146 packages and his Emacs configuration starts in 0.22 seconds: The author is using **[minimal-emacs.d](https://github.com/jamescherti/minimal-emacs.d)** as his `early-init.el` and `init.el`. He is using 146 packages and his Emacs configuration starts in 0.22 seconds:
![](https://www.jamescherti.com/wp-content/uploads/minimal-emacs-startup-time.png) ![](https://www.jamescherti.com/wp-content/uploads/minimal-emacs-startup-time.png)
@@ -145,20 +145,7 @@ To prevent Emacs from saving customization information to a custom file, set `cu
To customize your Emacs setup to include various user interface elements, you can use the following settings in your ``~/.emacs.d/pre-early-init.el``: To customize your Emacs setup to include various user interface elements, you can use the following settings in your ``~/.emacs.d/pre-early-init.el``:
``` emacs-lisp ``` emacs-lisp
;; Enable both file dialogs and dialog boxes (setq minimal-emacs-ui-features '(context-menu tool-bar menu-bar dialogs tooltips))
(setq minimal-emacs-disable-dialogs nil)
;; Enable context menu (right-click menu)
(setq minimal-emacs-disable-context-menu nil)
;; Enable the tool bar at the top
(setq minimal-emacs-disable-tool-bar nil)
;; Enable the menu bar at the top
(setq minimal-emacs-disable-menu-bar nil)
;; Enable tooltips (hover text)
(setq minimal-emacs-disable-tooltips nil)
``` ```
These settings control the visibility of dialogs, context menus, toolbars, menu bars, and tooltips. These settings control the visibility of dialogs, context menus, toolbars, menu bars, and tooltips.

View File

@@ -8,17 +8,46 @@
;; SPDX-License-Identifier: GPL-3.0-or-later ;; SPDX-License-Identifier: GPL-3.0-or-later
;;; Commentary: ;;; Commentary:
;; This file contains early initialization settings for Emacs. It is designed ;; The minimal-emacs.d starter kit provides improved Emacs defaults and
;; to optimize the startup process and configure essential settings before the ;; optimized startup, intended to serve as a solid foundation for your vanilla
;; main initialization. ;; Emacs configuration and enhance your overall Emacs experience.
;;; Code: ;;; Code:
;;; Load pre-early-init.el ;;; Variables
(defvar minimal-emacs-ui-features '(context-menu)
"List of user interface features to disable in minimal Emacs setup.
This variable holds a list Emacs UI features that can be enabled:
- `context-menu`: Enables the context menu in graphical environments.
- `tool-bar`: Enables the tool bar in graphical environments.
- `menu-bar`: Enables the menu bar in graphical environments.
- `dialogs`: Enables both file dialogs and dialog boxes.
- `tooltips`: Enables tooltips.
Each feature in the list corresponds to a specific UI component that can be
turned on.")
(defvar minimal-emacs-frame-title-format "%b Emacs"
"Template for displaying the title bar of visible and iconified frame.")
(defvar minimal-emacs-debug nil
"Non-nil to enable debug.")
(defvar minimal-emacs-gc-cons-threshold (* 16 1024 1024)
"The value of `gc-cons-threshold' after Emacs startup.")
(defvar minimal-emacs-package-initialize-and-refresh t
"Whether to automatically initialize and refresh packages.
When set to non-nil, Emacs will automatically call `package-initialize' and
`package-refresh-contents' to set up and update the package system.")
(defvar minimal-emacs-user-directory user-emacs-directory (defvar minimal-emacs-user-directory user-emacs-directory
"The default value of the `user-emacs-directory' variable.") "The default value of the `user-emacs-directory' variable.")
;;; Load pre-early-init.el
(defun minimal-emacs-load-user-init (filename) (defun minimal-emacs-load-user-init (filename)
"Execute a file of Lisp code named FILENAME." "Execute a file of Lisp code named FILENAME."
(let ((user-init-file (let ((user-init-file
@@ -33,42 +62,6 @@
(expand-file-name "themes/" minimal-emacs-user-directory)) (expand-file-name "themes/" minimal-emacs-user-directory))
(setq custom-file (expand-file-name "custom.el" minimal-emacs-user-directory)) (setq custom-file (expand-file-name "custom.el" minimal-emacs-user-directory))
;;; Variables
(defvar minimal-emacs-debug nil
"Non-nil to enable debug.")
(defvar minimal-emacs-gc-cons-threshold (* 16 1024 1024)
"The value of `gc-cons-threshold' after Emacs startup.")
(defvar minimal-emacs-frame-title-format "%b Emacs"
"Template for displaying the title bar of visible and iconified frame.")
(defvar minimal-emacs-default-gc-cons-threshold gc-cons-threshold
"The default value of `gc-cons-threshold'.")
(defvar minimal-emacs--default-mode-line-format mode-line-format
"Default value of `mode-line-format'.")
(defvar minimal-emacs-disable-context-menu t
"Non-nil enables the context menu in graphical environments.")
(defvar minimal-emacs-disable-tool-bar t
"Non-nil enables the tool bar in graphical environments.")
(defvar minimal-emacs-disable-menu-bar t
"Non-nil enables the tool bar in graphical environments.")
(defvar minimal-emacs-disable-dialogs t
"If non-nil, enable both file dialogs and dialog boxes.")
(defvar minimal-emacs-disable-tooltips t
"When non-nil, tooltips are enabled. If nil, tooltips are disabled.")
(defvar minimal-emacs-package-initialize-and-refresh t
"Whether to automatically initialize and refresh packages.
When set to non-nil, Emacs will automatically call `package-initialize' and
`package-refresh-contents' to set up and update the package system.")
;;; Misc ;;; Misc
(set-language-environment "UTF-8") (set-language-environment "UTF-8")
@@ -157,10 +150,12 @@ When set to non-nil, Emacs will automatically call `package-initialize' and
inhibit-message nil) inhibit-message nil)
(redraw-frame)) (redraw-frame))
(defvar minimal-emacs--default-mode-line-format mode-line-format
"Default value of `mode-line-format'.")
(setq-default mode-line-format nil) (setq-default mode-line-format nil)
(defun minimal-emacs--startup-load-user-init-file (fn &rest args) (defun minimal-emacs--startup-load-user-init-file (fn &rest args)
"Around advice for startup--load-user-init-file to reset mode-line-format." "Advice for startup--load-user-init-file to reset mode-line-format."
(let (init) (let (init)
(unwind-protect (unwind-protect
(progn (progn
@@ -255,7 +250,7 @@ When set to non-nil, Emacs will automatically call `package-initialize' and
;; a superfluous and potentially expensive frame redraw at startup, depending ;; a superfluous and potentially expensive frame redraw at startup, depending
;; on the window system. The variables must also be set to `nil' so users don't ;; on the window system. The variables must also be set to `nil' so users don't
;; have to call the functions twice to re-enable them. ;; have to call the functions twice to re-enable them.
(when minimal-emacs-disable-menu-bar (unless (memq 'menu-bar minimal-emacs-ui-features)
(push '(menu-bar-lines . 0) default-frame-alist) (push '(menu-bar-lines . 0) default-frame-alist)
(unless (memq window-system '(mac ns)) (unless (memq window-system '(mac ns))
(setq menu-bar-mode nil))) (setq menu-bar-mode nil)))
@@ -269,7 +264,7 @@ When set to non-nil, Emacs will automatically call `package-initialize' and
(:before (&rest _) minimal-emacs-setup-toolbar) (:before (&rest _) minimal-emacs-setup-toolbar)
(advice-remove #'tool-bar-setup #'ignore) (advice-remove #'tool-bar-setup #'ignore)
(tool-bar-setup)))) (tool-bar-setup))))
(when minimal-emacs-disable-tool-bar (unless (memq 'tool-bar minimal-emacs-ui-features)
(push '(tool-bar-lines . 0) default-frame-alist) (push '(tool-bar-lines . 0) default-frame-alist)
(setq tool-bar-mode nil)) (setq tool-bar-mode nil))
@@ -279,13 +274,13 @@ When set to non-nil, Emacs will automatically call `package-initialize' and
(when (fboundp 'horizontal-scroll-bar-mode) (when (fboundp 'horizontal-scroll-bar-mode)
(horizontal-scroll-bar-mode -1)) (horizontal-scroll-bar-mode -1))
(when minimal-emacs-disable-tooltips (unless (memq 'tooltips minimal-emacs-ui-features)
(when (bound-and-true-p tooltip-mode) (when (bound-and-true-p tooltip-mode)
(tooltip-mode -1))) (tooltip-mode -1)))
;; Disable GUIs because they are inconsistent across systems, desktop ;; Disable GUIs because they are inconsistent across systems, desktop
;; environments, and themes, and they don't match the look of Emacs. ;; environments, and themes, and they don't match the look of Emacs.
(when minimal-emacs-disable-dialogs (unless (memq 'dialogs minimal-emacs-ui-features)
(setq use-file-dialog nil) (setq use-file-dialog nil)
(setq use-dialog-box nil)) (setq use-dialog-box nil))

View File

@@ -8,9 +8,9 @@
;; SPDX-License-Identifier: GPL-3.0-or-later ;; SPDX-License-Identifier: GPL-3.0-or-later
;;; Commentary: ;;; Commentary:
;; This is the main initialization file for Emacs. It configures package ;; The minimal-emacs.d starter kit provides improved Emacs defaults and
;; archives, ensures essential packages like `use-package` are installed, and ;; optimized startup, intended to serve as a solid foundation for your vanilla
;; sets up further package management and customization settings. ;; Emacs configuration and enhance your overall Emacs experience.
;;; Code: ;;; Code:
@@ -211,8 +211,9 @@
;;; Mouse ;;; Mouse
;; Emacs 29 ;; Emacs 29
(when (memq 'context-menu minimal-emacs-ui-features)
(when (and (display-graphic-p) (fboundp 'context-menu-mode)) (when (and (display-graphic-p) (fboundp 'context-menu-mode))
(add-hook 'after-init-hook #'context-menu-mode)) (add-hook 'after-init-hook #'context-menu-mode)))
(setq hscroll-margin 2 (setq hscroll-margin 2
hscroll-step 1 hscroll-step 1