This commit is contained in:
2025-04-16 12:22:00 +09:00
7 changed files with 1819 additions and 353 deletions

1
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1 @@
github: jamescherti

42
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,42 @@
---
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This file is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
#
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
emacs-version:
- 29.1
- 29.4
- 30.1
python-version:
- 3.11
steps:
# Cask
- uses: actions/checkout@v2
- uses: purcell/setup-emacs@master
with:
version: ${{ matrix.emacs-version }}
- name: Compile
run: |
LISP_ERR_ON_WARN="(setq byte-compile-error-on-warn t) (setq byte-compile-warnings '(not obsolete free-vars))"
emacs -batch -L . --eval "(progn $LISP_ERR_ON_WARN )" -f batch-byte-compile early-init.el
emacs -batch -L . --eval "(progn $LISP_ERR_ON_WARN (load \"early-init.el\" nil t t) )" -f batch-byte-compile init.el

37
.gitignore vendored
View File

@@ -1,25 +1,12 @@
/auto-save-list/
/custom.el
/easysession
/eln-cache/
/elpa/
/elpaca/
/etc/
/history
/ielm-history.eld
/lisp/
/projectile-bookmarks.eld
/recentf
/saveplace
/tramp
/straight/
/themes/
/transient/
/tree-sitter/
/undo-fu-session/
/var/
/bookmarks
/bookmarks
/ido.last
/autosave/
/url/
*
!README.md
!early-init.el
!init.el
!.images/
!.github/
!.LICENSE
!custom.el
!pre-early-init.el
!post-init.el
!.config.d/

1362
README.md

File diff suppressed because it is too large Load Diff

12
custom.el Normal file
View File

@@ -0,0 +1,12 @@
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(auth-source-save-behavior nil))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)

View File

@@ -1,10 +1,10 @@
;;; early-init.el --- Early Init -*- no-byte-compile: t; lexical-binding: t; -*-
;;; early-init.el --- Early Init -*- lexical-binding: t; -*-
;; Author: James Cherti
;; URL: https://github.com/jamescherti/minimal-emacs.d
;; Package-Requires: ((emacs "29.1"))
;; Keywords: maint
;; Version: 1.1.2
;; Version: 1.2.0
;; SPDX-License-Identifier: GPL-3.0-or-later
;;; Commentary:
@@ -17,54 +17,60 @@
;;; Variables
(defvar minimal-emacs-ui-features '()
"List of user interface features to disable in minimal Emacs setup.
"List of user interface features to enable 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.")
- 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.)")
(defvar minimal-emacs-frame-title-format "%b Emacs"
"Template for displaying the title bar of visible and iconified frame.")
(defvar minimal-emacs-debug nil
(defvar minimal-emacs-debug (bound-and-true-p init-file-debug)
"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-gc-cons-threshold (* 32 1024 1024)
"Value to set `gc-cons-threshold' to after Emacs startup.
Ignored if `minimal-emacs-optimize-startup-gc' is nil.")
(defvar minimal-emacs-optimize-startup-gc t
"If non-nil, increase `gc-cons-threshold' during startup to reduce pauses.
After Emacs finishes loading, `gc-cons-threshold' is restored to the value
stored in `minimal-emacs--restore-gc-cons-threshold'.")
(defvar minimal-emacs-inhibit-redisplay-during-startup nil
"Suppress redisplay during startup to improve performance.
This prevents visual updates while Emacs initializes. The tradeoff is that you
won't see the progress or activities during the startup process.")
(defvar minimal-emacs-inhibit-message-during-startup nil
"Suppress startup messages for a cleaner experience.
This slightly enhances performance. The tradeoff is that you won't be informed
of the progress or any relevant activities during startup.")
(defvar minimal-emacs-optimize-file-name-handler-alist t
"Enable optimization of `file-name-handler-alist'.
When non-nil, this variable activates optimizations to reduce file name handler
lookups during Emacs startup.")
(defvar minimal-emacs-disable-mode-line-during-startup t
"Disable the mode line during startup.
This reduces visual clutter and slightly enhances startup performance. The
tradeoff is that the mode line is hidden during the startup phase.")
(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-inhibit-redisplay-during-startup nil
"Suppress redisplay during startup to improve performance.
This prevents visual updates while Emacs initializes, leading to a cleaner and
faster startup. The tradeoff is that you won't see the progress or activities
during the startup process.")
(defvar minimal-emacs-inhibit-message-during-startup nil
"Suppress startup messages for a cleaner experience.
By disabling startup messages, this slightly enhances performance and provides a
cleaner startup. The tradeoff is that you won't be informed of the progress or
any relevant activities during startup.")
(defvar minimal-emacs-disable-mode-line-during-startup nil
"Disable the mode line during startup to improve performance.
This reduces visual clutter and slightly enhances startup performance. The
tradeoff is that the mode line is hidden during the startup phase, giving a more
minimalistic appearance during startup.")
(defvar minimal-emacs-setup-native-compilation t
"If non-nil, enable and configure native compilation.
When enabled, this variable sets the following:
- `native-comp-deferred-compilation'
- `native-comp-jit-compilation'
- `package-native-compile'")
(defvar minimal-emacs-user-directory user-emacs-directory
"The default value of the `user-emacs-directory' variable.")
@@ -73,14 +79,48 @@ minimalistic appearance during startup.")
;; Prefer loading newer compiled files
(setq load-prefer-newer t)
(setq debug-on-error minimal-emacs-debug)
(defvar minimal-emacs--success nil)
(defun minimal-emacs--check-success ()
"Verify that the Emacs configuration has loaded successfully."
(unless minimal-emacs--success
(cond
((or (file-exists-p (expand-file-name "~/.emacs.el"))
(file-exists-p (expand-file-name "~/.emacs")))
(error "Emacs ignored loading 'init.el'. Please ensure that files such as ~/.emacs or ~/.emacs.el do not exist, as they may be preventing Emacs from loading the 'init.el' file"))
(t
(error "Configuration error. Debug by starting Emacs with: emacs --debug-init")))))
(add-hook 'emacs-startup-hook #'minimal-emacs--check-success 102)
(defvar minimal-emacs-load-compiled-init-files nil
"If non-nil, attempt to load byte-compiled .elc for init files.
This will enable minimal-emacs to load byte-compiled or possibly native-compiled
init files for the following initialization files: pre-init.el, post-init.el,
pre-early-init.el, and post-early-init.el.")
(defun minimal-emacs--remove-el-file-suffix (filename)
"Remove the Elisp file suffix from FILENAME and return it (.el, .el.gz...)."
(let ((suffixes (mapcar (lambda (ext) (concat ".el" ext))
load-file-rep-suffixes)))
(catch 'done
(dolist (suffix suffixes filename)
(when (string-suffix-p suffix filename)
(setq filename (substring filename 0 (- (length suffix))))
(throw 'done t))))
filename))
(defun minimal-emacs-load-user-init (filename)
"Execute a file of Lisp code named FILENAME."
(let ((user-init-file
(expand-file-name filename
(let ((init-file (expand-file-name filename
minimal-emacs-user-directory)))
(when (file-exists-p user-init-file)
(load user-init-file nil t t))))
(if (not minimal-emacs-load-compiled-init-files)
(load init-file :no-error :no-message :nosuffix)
;; Remove the file suffix (.el, .el.gz, etc.) to let the `load' function
;; select between .el and .elc files.
(setq init-file (minimal-emacs--remove-el-file-suffix init-file))
(load init-file :no-error :no-message))))
(minimal-emacs-load-user-init "pre-early-init.el")
@@ -92,108 +132,61 @@ minimalistic appearance during startup.")
;; Garbage collection significantly affects startup times. This setting delays
;; garbage collection during startup but will be reset later.
(when minimal-emacs-optimize-startup-gc
(setq gc-cons-threshold most-positive-fixnum)
(setq garbage-collection-messages minimal-emacs-debug)
(defun minimal-emacs--restore-gc-cons-threshold ()
"Restore `minimal-emacs-gc-cons-threshold'."
(setq gc-cons-threshold minimal-emacs-gc-cons-threshold))
(when minimal-emacs-optimize-startup-gc
(setq gc-cons-threshold most-positive-fixnum)
(add-hook 'emacs-startup-hook #'minimal-emacs--restore-gc-cons-threshold 105))
;;; Misc
;;; Native compilation and Byte compilation
(if (and (featurep 'native-compile)
(fboundp 'native-comp-available-p)
(native-comp-available-p))
;; Activate `native-compile'
(setq native-comp-deferred-compilation minimal-emacs-setup-native-compilation
native-comp-jit-compilation minimal-emacs-setup-native-compilation
package-native-compile minimal-emacs-setup-native-compilation)
;; Deactivate the `native-compile' feature if it is not available
(setq features (delq 'native-compile features)))
(setq native-comp-warning-on-missing-source minimal-emacs-debug
native-comp-async-report-warnings-errors (or minimal-emacs-debug 'silent)
native-comp-verbose (if minimal-emacs-debug 1 0))
(setq jka-compr-verbose minimal-emacs-debug)
(setq byte-compile-warnings minimal-emacs-debug
byte-compile-verbose minimal-emacs-debug)
;;; Miscellaneous
(set-language-environment "UTF-8")
;; Set-language-environment sets default-input-method, which is unwanted.
(setq default-input-method nil)
;;; Performance
;; Increase how much is read from processes in a single chunk
(setq read-process-output-max (* 2 1024 1024)) ; 1024kb
(setq process-adaptive-read-buffering nil)
;; Don't ping things that look like domain names.
(setq ffap-machine-p-known 'reject)
(setq warning-minimum-level (if minimal-emacs-debug :warning :error))
(setq warning-suppress-types '((lexical-binding)))
;;; Performance: Miscellaneous options
;; Font compacting can be very resource-intensive, especially when rendering
;; icon fonts on Windows. This will increase memory usage.
(setq inhibit-compacting-font-caches t)
(unless (daemonp)
(let ((old-value (default-toplevel-value 'file-name-handler-alist)))
;; Determine the state of bundled libraries using calc-loaddefs.el.
;; If compressed, retain the gzip handler in `file-name-handler-alist`.
;; If compiled or neither, omit the gzip handler during startup for
;; improved startup and package load time.
(set-default-toplevel-value 'file-name-handler-alist
(if (eval-when-compile
(locate-file-internal "calc-loaddefs.el"
load-path))
nil
(list (rassq 'jka-compr-handler old-value))))
;; Ensure the new value persists through any current let-binding.
(put 'file-name-handler-alist 'initial-value old-value)
;; Emacs processes command-line files very early in startup. These files may
;; include special paths like TRAMP paths, so restore
;; `file-name-handler-alist' for this stage of initialization.
(define-advice command-line-1 (:around (fn args-left) respect-file-handlers)
(let ((file-name-handler-alist
(if args-left old-value file-name-handler-alist)))
(funcall fn args-left)))
;; Restore the old value to reset it as needed.
(defun minimal-emacs--restore-file-name-handler-alist ()
"Restore `file-name-handler-alist'."
(set-default-toplevel-value
'file-name-handler-alist
;; Merge instead of overwrite to preserve any changes made since startup.
(delete-dups (append file-name-handler-alist old-value))))
(add-hook
'emacs-startup-hook #'minimal-emacs--restore-file-name-handler-alist 101))
(unless noninteractive
(unless minimal-emacs-debug
(when minimal-emacs-inhibit-redisplay-during-startup
;; Suppress redisplay and redraw during startup to avoid delays and
;; prevent flashing an unstyled Emacs frame.
(defun minimal-emacs--reset-inhibit-redisplay ()
(setq-default inhibit-redisplay nil)
(remove-hook 'post-command-hook #'minimal-emacs--reset-inhibit-redisplay))
(setq-default inhibit-redisplay t)
(add-hook 'post-command-hook #'minimal-emacs--reset-inhibit-redisplay -100))
(when minimal-emacs-inhibit-message-during-startup
(defun minimal-emacs--reset-inhibit-message ()
(setq-default inhibit-message nil)
(remove-hook 'post-command-hook #'minimal-emacs--reset-inhibit-message))
(setq-default inhibit-message t)
(add-hook 'post-command-hook #'minimal-emacs--reset-inhibit-message -100))
(put 'mode-line-format
'initial-value (default-toplevel-value 'mode-line-format))
(when minimal-emacs-disable-mode-line-during-startup
(setq-default mode-line-format nil)
(dolist (buf (buffer-list))
(with-current-buffer buf
(setq mode-line-format nil))))
(defun minimal-emacs--startup-load-user-init-file (fn &rest args)
"Advice for startup--load-user-init-file to reset mode-line-format."
(unwind-protect
;; Start up as normal
(apply fn args)
;; If we don't undo inhibit-{message, redisplay} and there's an
;; error, we'll see nothing but a blank Emacs frame.
(when minimal-emacs-inhibit-message-during-startup
(setq-default inhibit-message nil))
(when minimal-emacs-inhibit-redisplay-during-startup
(setq-default inhibit-redisplay nil))
;; Restore the mode-line
(when minimal-emacs-disable-mode-line-during-startup
(unless (default-toplevel-value 'mode-line-format)
(setq-default mode-line-format (get 'mode-line-format
'initial-value))))))
(advice-add 'startup--load-user-init-file :around
#'minimal-emacs--startup-load-user-init-file))
(when (and (not (daemonp)) (not noninteractive))
;; Without this, Emacs will try to resize itself to a specific column size
(setq frame-inhibit-implied-resize t)
@@ -217,11 +210,11 @@ minimalistic appearance during startup.")
(setq bidi-inhibit-bpa t)
;; Remove "For information about GNU Emacs..." message at startup
(advice-add #'display-startup-echo-area-message :override #'ignore)
(advice-add 'display-startup-echo-area-message :override #'ignore)
;; Suppress the vanilla startup screen completely. We've disabled it with
;; `inhibit-startup-screen', but it would still initialize anyway.
(advice-add #'display-startup-screen :override #'ignore)
(advice-add 'display-startup-screen :override #'ignore)
;; Shave seconds off startup time by starting the scratch buffer in
;; `fundamental-mode'
@@ -234,30 +227,121 @@ minimalistic appearance during startup.")
(unless (eq system-type 'darwin)
(setq command-line-ns-option-alist nil))
(unless (memq initial-window-system '(x pgtk))
(setq command-line-x-option-alist nil)))))
(setq command-line-x-option-alist nil))))
;;; Native compilation and Byte compilation
;;; Performance: File-name-handler-alist
(if (and (featurep 'native-compile)
(fboundp 'native-comp-available-p)
(native-comp-available-p))
;; Activate `native-compile'
(setq native-comp-jit-compilation t
native-comp-deferred-compilation t ; Obsolete since Emacs 29.1
package-native-compile t)
;; Deactivate the `native-compile' feature if it is not available
(setq features (delq 'native-compile features)))
(defvar minimal-emacs--old-file-name-handler-alist (default-toplevel-value
'file-name-handler-alist))
;; Suppress compiler warnings and don't inundate users with their popups.
(setq native-comp-async-report-warnings-errors
(or minimal-emacs-debug 'silent))
(setq native-comp-warning-on-missing-source minimal-emacs-debug)
(defun minimal-emacs--respect-file-handlers (fn args-left)
"Respect file handlers.
FN is the function and ARGS-LEFT is the same argument as `command-line-1'.
Emacs processes command-line files very early in startup. These files may
include special paths like TRAMP paths, so restore `file-name-handler-alist' for
this stage of initialization."
(let ((file-name-handler-alist (if args-left
minimal-emacs--old-file-name-handler-alist
file-name-handler-alist)))
(funcall fn args-left)))
(setq debug-on-error minimal-emacs-debug
jka-compr-verbose minimal-emacs-debug)
(defun minimal-emacs--restore-file-name-handler-alist ()
"Restore `file-name-handler-alist'."
(set-default-toplevel-value
'file-name-handler-alist
;; Merge instead of overwrite to preserve any changes made since startup.
(delete-dups (append file-name-handler-alist
minimal-emacs--old-file-name-handler-alist))))
(setq byte-compile-warnings minimal-emacs-debug)
(setq byte-compile-verbose minimal-emacs-debug)
(when (and minimal-emacs-optimize-file-name-handler-alist
(not (daemonp))
(not minimal-emacs-debug))
;; Determine the state of bundled libraries using calc-loaddefs.el. If
;; compressed, retain the gzip handler in `file-name-handler-alist`. If
;; compiled or neither, omit the gzip handler during startup for improved
;; startup and package load time.
(set-default-toplevel-value
'file-name-handler-alist
(if (locate-file-internal "calc-loaddefs.el" load-path)
nil
(list (rassq 'jka-compr-handler
minimal-emacs--old-file-name-handler-alist))))
;; Ensure the new value persists through any current let-binding.
(put 'file-name-handler-alist 'initial-value
minimal-emacs--old-file-name-handler-alist)
;; Emacs processes command-line files very early in startup. These files may
;; include special paths TRAMP. Restore `file-name-handler-alist'.
(advice-add 'command-line-1 :around #'minimal-emacs--respect-file-handlers)
(add-hook 'emacs-startup-hook #'minimal-emacs--restore-file-name-handler-alist
101))
;;; Performance: Inhibit redisplay
(defun minimal-emacs--reset-inhibit-redisplay ()
"Reset inhibit redisplay."
(setq-default inhibit-redisplay nil)
(remove-hook 'post-command-hook #'minimal-emacs--reset-inhibit-redisplay))
(when (and minimal-emacs-inhibit-redisplay-during-startup
(not (daemonp))
(not noninteractive)
(not minimal-emacs-debug))
;; Suppress redisplay and redraw during startup to avoid delays and
;; prevent flashing an unstyled Emacs frame.
(setq-default inhibit-redisplay t)
(add-hook 'post-command-hook #'minimal-emacs--reset-inhibit-redisplay -100))
;;; Performance: Inhibit message
(defun minimal-emacs--reset-inhibit-message ()
"Reset inhibit message."
(setq-default inhibit-message nil)
(remove-hook 'post-command-hook #'minimal-emacs--reset-inhibit-message))
(when (and minimal-emacs-inhibit-message-during-startup
(not (daemonp))
(not noninteractive)
(not minimal-emacs-debug))
(setq-default inhibit-message t)
(add-hook 'post-command-hook #'minimal-emacs--reset-inhibit-message -100))
;;; Performance: Disable mode-line during startup
(when (and minimal-emacs-disable-mode-line-during-startup
(not (daemonp))
(not noninteractive)
(not minimal-emacs-debug))
(put 'mode-line-format
'initial-value (default-toplevel-value 'mode-line-format))
(setq-default mode-line-format nil)
(dolist (buf (buffer-list))
(with-current-buffer buf
(setq mode-line-format nil))))
;;; Restore values
(defun minimal-emacs--startup-load-user-init-file (fn &rest args)
"Advice to reset `mode-line-format'. FN and ARGS are the function and args."
(unwind-protect
;; Start up as normal
(apply fn args)
;; If we don't undo inhibit-{message, redisplay} and there's an error, we'll
;; see nothing but a blank Emacs frame.
(when minimal-emacs-inhibit-message-during-startup
(setq-default inhibit-message nil))
(when minimal-emacs-inhibit-redisplay-during-startup
(setq-default inhibit-redisplay nil))
;; Restore the mode-line
(when minimal-emacs-disable-mode-line-during-startup
(unless (default-toplevel-value 'mode-line-format)
(setq-default mode-line-format (get 'mode-line-format
'initial-value))))))
(advice-add 'startup--load-user-init-file :around
#'minimal-emacs--startup-load-user-init-file)
;;; UI elements
@@ -277,17 +361,23 @@ minimalistic appearance during startup.")
(unless (memq window-system '(mac ns))
(setq menu-bar-mode nil)))
(unless (daemonp)
(unless noninteractive
(defun minimal-emacs--setup-toolbar (&rest _)
"Setup the toolbar."
(when (fboundp 'tool-bar-setup)
(advice-remove 'tool-bar-setup #'ignore)
(when (bound-and-true-p tool-bar-mode)
(funcall 'tool-bar-setup))))
(when (and (not (daemonp))
(not noninteractive))
(when (fboundp 'tool-bar-setup)
;; Temporarily override the tool-bar-setup function to prevent it from
;; running during the initial stages of startup
(advice-add #'tool-bar-setup :override #'ignore)
(define-advice startup--load-user-init-file
(:after (&rest _) minimal-emacs-setup-toolbar)
(advice-remove #'tool-bar-setup #'ignore)
(when tool-bar-mode
(tool-bar-setup))))))
(advice-add 'tool-bar-setup :override #'ignore)
(advice-add 'startup--load-user-init-file :after
#'minimal-emacs--setup-toolbar)))
(unless (memq 'tool-bar minimal-emacs-ui-features)
(push '(tool-bar-lines . 0) default-frame-alist)
(setq tool-bar-mode nil))
@@ -306,12 +396,17 @@ minimalistic appearance during startup.")
(setq use-file-dialog nil)
(setq use-dialog-box nil))
;;; Security
(setq gnutls-verify-error t) ; Prompts user if there are certificate issues
(setq tls-checktrust t) ; Ensure SSL/TLS connections undergo trust verification
(setq gnutls-min-prime-bits 3072) ; Stronger GnuTLS encryption
;;; package.el
(setq use-package-compute-statistics minimal-emacs-debug)
;; Setting use-package-expand-minimally to (t) results in a more compact output
;; that emphasizes performance over clarity.
(setq use-package-expand-minimally (not noninteractive))
(setq use-package-expand-minimally (not minimal-emacs-debug))
(setq use-package-minimum-reported-time (if minimal-emacs-debug 0 0.1))
(setq use-package-verbose minimal-emacs-debug)
@@ -319,17 +414,19 @@ minimalistic appearance during startup.")
(setq use-package-always-ensure t)
(setq use-package-enable-imenu-support t)
(setq package-archives '(("melpa" . "https://melpa.org/packages/")
("melpa-stable" . "https://stable.melpa.org/packages/")
("gnu" . "https://elpa.gnu.org/packages/")
("nongnu" . "https://elpa.nongnu.org/nongnu/")))
(customize-set-variable 'package-archive-priorities '(("gnu" . 99)
("nongnu" . 80)
("stable" . 70)
("melpa" . 0)))
("melpa" . 70)))
;;; Load post-early-init.el
(minimal-emacs-load-user-init "post-early-init.el")
(provide 'early-init)
;; Local variables:
;; byte-compile-warnings: (not obsolete free-vars)
;; End:
;;; early-init.el ends here

213
init.el
View File

@@ -1,10 +1,10 @@
;;; init.el --- Init -*- no-byte-compile: t; lexical-binding: t; -*-
;;; init.el --- Init -*- lexical-binding: t; -*-
;; Author: James Cherti
;; URL: https://github.com/jamescherti/minimal-emacs.d
;; Package-Requires: ((emacs "29.1"))
;; Keywords: maint
;; Version: 1.1.2
;; Version: 1.2.0
;; SPDX-License-Identifier: GPL-3.0-or-later
;;; Commentary:
@@ -15,41 +15,47 @@
;;; Code:
;;; Load pre-init.el
(if (fboundp 'minimal-emacs-load-user-init)
(minimal-emacs-load-user-init "pre-init.el")
(error "The early-init.el file failed to loaded"))
;;; Before package
;; Increase how much is read from processes in a single chunk
(setq read-process-output-max (* 1024 1024)) ; 1024kb
;; Ask the user whether to terminate asynchronous compilations on exit.
;; This prevents native compilation from leaving temporary files in /tmp.
(setq native-comp-async-query-on-exit t)
;; Don't ping things that look like domain names.
(setq ffap-machine-p-known 'reject)
;; Allow for shorter responses: "y" for yes and "n" for no.
(setq read-answer-short t)
(if (boundp 'use-short-answers)
(setq use-short-answers t)
(advice-add 'yes-or-no-p :override #'y-or-n-p))
;;; Undo/redo
(setq undo-limit (* 13 160000)
undo-strong-limit (* 13 240000)
undo-outer-limit (* 13 24000000))
;;; package.el
(when (bound-and-true-p minimal-emacs-package-initialize-and-refresh)
;; Initialize and refresh package contents again if needed
(package-initialize)
(unless package-archive-contents
(package-refresh-contents))
;; Install use-package if necessary
(unless (package-installed-p 'use-package)
(unless (seq-empty-p package-archive-contents)
(package-refresh-contents))
(package-install 'use-package))
;; Ensure use-package is available at compile time
(eval-when-compile
(require 'use-package)))
;; Ensure the 'use-package' package is installed and loaded
;; Ensure use-package is available
(require 'use-package))
;;; Features, warnings, and errors
;; Disable warnings from the legacy advice API. They aren't useful.
(setq ad-redefinition-action 'accept)
(setq warning-suppress-types '((lexical-binding)))
;;; Minibuffer
;; Allow nested minibuffers
@@ -65,11 +71,6 @@
;; By default, Emacs "updates" its ui more often than it needs to
(setq idle-update-delay 1.0)
;; Allow for shorter responses: "y" for yes and "n" for no.
(setq read-answer-short t)
(if (boundp 'use-short-answers)
(setq use-short-answers t)
(advice-add #'yes-or-no-p :override #'y-or-n-p))
(defalias #'view-hello-file #'ignore) ; Never show the hello file
;; No beeping or blinking
@@ -89,14 +90,14 @@
compilation-ask-about-save nil
compilation-scroll-output 'first-error)
;; Recenter to the middle of the window for `compile-goto-error', which is also
;; used by `wgrep' and `embark-export'.
(setq next-error-recenter '(4))
;;; Misc
(setq whitespace-line-column nil) ; whitespace-mode
;; I reduced the default value of 9 to simplify the font-lock keyword,
;; aiming to improve performance.
(setq rainbow-delimiters-max-face-count 5)
;; Can be activated with `display-line-numbers-mode'
(setq-default display-line-numbers-width 3)
(setq-default display-line-numbers-widen t)
@@ -104,13 +105,8 @@
(setq truncate-string-ellipsis "")
;; Improve Emacs' responsiveness by delaying syntax highlighting during input
;; but may reduce visual feedback.
(setq redisplay-skip-fontification-on-input t)
;; Collects and displays all available documentation immediately, even if
;; multiple sources provide it. It concatenates the results.
(setq eldoc-documentation-strategy 'eldoc-documentation-compose-eagerly)
;; Disable truncation of printed s-expressions in the message buffer
(setq eval-expression-print-length nil
eval-expression-print-level nil)
@@ -122,13 +118,12 @@
;; Delete by moving to trash in interactive mode
(setq delete-by-moving-to-trash (not noninteractive))
(setq remote-file-name-inhibit-delete-by-moving-to-trash t)
;; Disable the warning "X and Y are the same file". Ignoring this warning is
;; acceptable since it will redirect you to the existing buffer regardless.
;; Ignoring this is acceptable since it will redirect to the buffer regardless.
(setq find-file-suppress-same-file-warnings t)
;; Resolve symlinks when opening files, so that any operations are conducted
;; from the file's true directory (like `find-file').
;; Resolve symlinks so that operations are conducted from the file's directory
(setq find-file-visit-truename t
vc-follow-symlinks t)
@@ -148,8 +143,7 @@
;;; Backup files
;; Avoid generating backups or lockfiles to prevent creating world-readable
;; copies of files.
;; Avoid backups or lockfiles to prevent creating world-readable copies of files
(setq create-lockfiles nil)
(setq make-backup-files nil)
@@ -173,11 +167,11 @@
;; Enable auto-save to safeguard against crashes or data loss. The
;; `recover-file' or `recover-session' functions can be used to restore
;; auto-saved data.
(setq auto-save-default t)
(setq auto-save-default nil)
(setq auto-save-no-message t)
;; Do not auto-disable auto-save after deleting large chunks of
;; text. The purpose of auto-save is to provide a failsafe, and
;; disabling it contradicts this objective.
;; text.
(setq auto-save-include-big-deletions t)
(setq auto-save-list-file-prefix
@@ -188,22 +182,23 @@
;; Auto save options
(setq kill-buffer-delete-auto-save-files t)
;; Remove duplicates from the kill ring to reduce clutter
(setq kill-do-not-save-duplicates t)
;;; Auto revert
;; Auto-revert in Emacs is a feature that automatically updates the
;; contents of a buffer to reflect changes made to the underlying file
;; on disk.
;; Auto-revert in Emacs is a feature that automatically updates the contents of
;; a buffer to reflect changes made to the underlying file.
(setq revert-without-query (list ".") ; Do not prompt
auto-revert-stop-on-user-input nil
auto-revert-verbose t)
;; Revert other buffers (e.g, Dired)
(setq global-auto-revert-non-file-buffers t)
(setq global-auto-revert-ignore-modes '(Buffer-menu-mode)) ; Resolve issue #29
;;; recentf
;; `recentf' is an Emacs package that maintains a list of recently
;; accessed files, making it easier to reopen files you have worked on
;; recently.
;; `recentf' is an that maintains a list of recently accessed files.
(setq recentf-max-saved-items 300) ; default is 20
(setq recentf-max-menu-items 15)
(setq recentf-auto-cleanup (if (daemonp) 300 'never))
@@ -213,20 +208,21 @@
;;; saveplace
;; `save-place-mode' enables Emacs to remember the last location within a file
;; upon reopening. This feature is particularly beneficial for resuming work at
;; the precise point where you previously left off.
;; Enables Emacs to remember the last location within a file upon reopening.
(setq save-place-file (expand-file-name "saveplace" user-emacs-directory))
(setq save-place-limit 600)
;;; savehist
;; `savehist-mode' is an Emacs feature that preserves the minibuffer history
;; between sessions. It saves the history of inputs in the minibuffer, such as
;; commands, search strings, and other prompts, to a file. This allows users to
;; retain their minibuffer history across Emacs restarts.
;; between sessions.
(setq history-length 300)
(setq savehist-save-minibuffer-history t) ;; Default
(setq savehist-additional-variables
'(kill-ring ; clipboard
register-alist ; macros
mark-ring global-mark-ring ; marks
search-ring regexp-search-ring)) ; searches
;;; Frames and windows
@@ -248,39 +244,30 @@
;;; Scrolling
;; Enables faster scrolling through unfontified regions. This may result in
;; brief periods of inaccurate syntax highlighting immediately after scrolling,
;; which should quickly self-correct.
;; Enables faster scrolling. This may result in brief periods of inaccurate
;; syntax highlighting, which should quickly self-correct.
(setq fast-but-imprecise-scrolling t)
;; Move point to top/bottom of buffer before signaling a scrolling error.
(setq scroll-error-top-bottom t)
;; Keeps screen position if the scroll command moved it vertically out of the
;; window.
;; Keep screen position if scroll command moved it vertically out of the window.
(setq scroll-preserve-screen-position t)
;; Emacs spends excessive time recentering the screen when the cursor moves more
;; than N lines past the window edges (where N is the value of
;; `scroll-conservatively`). This can be particularly slow in larger files
;; during extensive scrolling. If `scroll-conservatively` is set above 100, the
;; window is never automatically recentered. The default value of 0 triggers
;; recentering too aggressively. Setting it to 10 reduces excessive recentering
;; and only recenters the window when scrolling significantly off-screen.
(setq scroll-conservatively 10)
;; If `scroll-conservatively' is set above 100, the window is never
;; automatically recentered, which decreases the time spend recentering.
(setq scroll-conservatively 101)
;; Enables smooth scrolling by making Emacs scroll the window by 1 line whenever
;; the cursor moves off the visible screen.
(setq scroll-step 1)
;; Reduce cursor lag by :
;; 1. Prevent automatic adjustments to `window-vscroll' for long lines.
;; 2. Resolve the issue of random half-screen jumps during scrolling.
;; 1. Preventing automatic adjustments to `window-vscroll' for long lines.
;; 2. Resolving the issue of random half-screen jumps during scrolling.
(setq auto-window-vscroll nil)
;; Number of lines of margin at the top and bottom of a window.
(setq scroll-margin 0)
;; Number of lines of continuity when scrolling by screenfuls.
(setq next-screen-context-lines 0)
;; Horizontal scrolling
(setq hscroll-margin 2
hscroll-step 1)
@@ -298,8 +285,6 @@
;; The blinking cursor is distracting and interferes with cursor settings in
;; some minor modes that try to change it buffer-locally (e.g., Treemacs).
;; Additionally, it can cause freezing, especially on macOS, for users with
;; customized and colored cursors.
(blink-cursor-mode -1)
;; Don't blink the paren matching the one at point, it's too distracting.
@@ -319,9 +304,8 @@
;; Avoid automatic frame resizing when adjusting settings.
(setq global-text-scale-adjust-resizes-frames nil)
;; This controls how long Emacs will blink to show the deleted pairs with
;; `delete-pair'. A longer delay can be annoying as it causes a noticeable pause
;; after each deletion, disrupting the flow of editing.
;; A longer delay can be annoying as it causes a noticeable pause after each
;; deletion, disrupting the flow of editing.
(setq delete-pair-blink-delay 0.03)
(setq-default left-fringe-width 8)
@@ -354,44 +338,32 @@
(setq read-extended-command-predicate #'command-completion-default-include-p)
;; Enable multi-line commenting which ensures that `comment-indent-new-line'
;; properly continues comments onto new lines, which is useful for writing
;; longer comments or docstrings that span multiple lines.
;; properly continues comments onto new lines.
(setq comment-multi-line t)
;; Ensures that empty lines within the commented region are also commented out.
;; This prevents unintended visual gaps and maintains a consistent appearance.
(setq comment-empty-lines t)
;; We often split terminals and editor windows or place them side-by-side,
;; making use of the additional horizontal space.
(setq-default fill-column 80)
;; Disable the obsolete practice of end-of-line spacing from the
;; typewriter era.
;; Disable the obsolete practice of end-of-line spacing from the typewriter era.
(setq sentence-end-double-space nil)
;; According to the POSIX, a line is defined as "a sequence of zero or
;; more non-newline characters followed by a terminating newline".
;; According to the POSIX, a line is defined as "a sequence of zero or more
;; non-newline characters followed by a terminating newline".
(setq require-final-newline t)
;; Remove duplicates from the kill ring to reduce clutter
(setq kill-do-not-save-duplicates t)
;; Ensures that empty lines within the commented region are also commented out.
;; This prevents unintended visual gaps and maintains a consistent appearance,
;; ensuring that comments apply uniformly to all lines, including those that are
;; otherwise empty.
(setq comment-empty-lines t)
;; Eliminate delay before highlighting search matches
(setq lazy-highlight-initial-delay 0)
;;; Modeline
;; Setting `display-time-default-load-average' to nil makes Emacs omit the load
;; average information from the mode line.
;; Makes Emacs omit the load average information from the mode line.
(setq display-time-default-load-average nil)
;; Display the current line and column numbers in the mode line
(setq line-number-mode t)
(setq column-number-mode t)
;;; Filetype
;; Do not notify the user each time Python tries to guess the indentation offset
@@ -408,8 +380,6 @@
dired-recursive-deletes 'top
dired-recursive-copies 'always
dired-create-destination-dirs 'ask
;; Revert the Dired buffer without prompting.
dired-auto-revert-buffer #'dired-buffer-stale-p
image-dired-thumb-size 150)
(setq dired-vc-rename-file t)
@@ -419,16 +389,7 @@
;; dired-omit-mode
(setq dired-omit-verbose nil)
(setq dired-omit-files (concat "\\`[.]\\'"
"\\|\\(?:\\.js\\)?\\.meta\\'"
"\\|\\.\\(?:elc|a\\|o\\|pyc\\|pyo\\|swp\\|class\\)\\'"
"\\|^\\.DS_Store\\'"
"\\|^\\.\\(?:svn\\|git\\)\\'"
"\\|^\\.ccls-cache\\'"
"\\|^__pycache__\\'"
"\\|^\\.project\\(?:ile\\)?\\'"
"\\|^flycheck_.*"
"\\|^flymake_.*"))
(setq dired-omit-files (concat "\\`[.]\\'"))
;; ls-lisp
(setq ls-lisp-verbosity nil)
@@ -437,8 +398,8 @@
;;; Ediff
;; Configure Ediff to use a single frame and split windows horizontally
(setq ediff-window-setup-function #'ediff-setup-windows-plain
ediff-split-window-function #'split-window-horizontally)
(setq ediff-window-setup-function 'ediff-setup-windows-plain
ediff-split-window-function 'split-window-horizontally)
;;; Help
@@ -446,13 +407,12 @@
(setq apropos-do-all t)
;; Fixes #11: Prevents help command completion from triggering autoload.
;; (e.g., apropos-command, apropos-variable, apropos...)
;; Loading additional files for completion can slow down help commands
;; and may unintentionally execute initialization code from some libraries.
;; Loading additional files for completion can slow down help commands and may
;; unintentionally execute initialization code from some libraries.
(setq help-enable-completion-autoload nil)
(setq help-enable-autoload nil)
(setq help-enable-symbol-autoload nil)
(setq help-window-select t)
(setq help-window-select t) ;; Focus new help windows when opened
;;; Eglot
@@ -468,9 +428,7 @@
(setq eglot-report-progress nil) ; Prevent Eglot minibuffer spam
;; Eglot optimization: Disable `eglot-events-buffer' to maintain consistent
;; performance in long-running Emacs sessions. By default, it retains 2,000,000
;; lines, and each new event triggers pretty-printing of the entire buffer,
;; leading to a gradual performance decline.
;; performance in long-running Emacs sessions.
(setq eglot-events-buffer-config '(:size 0 :format full))
;;; Flymake
@@ -525,8 +483,8 @@
;;; xref
;; Enable completion in the minibuffer instead of the definitions buffer
(setq xref-show-definitions-function #'xref-show-definitions-completing-read
xref-show-xrefs-function #'xref-show-definitions-completing-read)
(setq xref-show-definitions-function 'xref-show-definitions-completing-read
xref-show-xrefs-function 'xref-show-definitions-completing-read)
;;; abbrev
@@ -543,8 +501,21 @@
(setq dabbrev-ignored-buffer-modes
'(archive-mode image-mode docview-mode tags-table-mode pdf-view-mode))
;;; Remove warnings from narrow-to-region, upcase-region...
(dolist (cmd '(list-timers narrow-to-region upcase-region downcase-region
erase-buffer scroll-left dired-find-alternate-file))
(put cmd 'disabled nil))
;;; Load post init
(minimal-emacs-load-user-init "post-init.el")
(when (fboundp 'minimal-emacs-load-user-init)
(minimal-emacs-load-user-init "post-init.el"))
(setq minimal-emacs--success t)
(provide 'init)
;; Local variables:
;; byte-compile-warnings: (not obsolete free-vars)
;; End:
;;; init.el ends here