318 lines
11 KiB
EmacsLisp
318 lines
11 KiB
EmacsLisp
;;; init.el --- Init -*- no-byte-compile: t; lexical-binding: t; -*-
|
||
|
||
;; Author: James Cherti
|
||
;; URL: https://github.com/jamescherti/minimal-emacs.d
|
||
;; Package-Requires: ((emacs "29.1"))
|
||
;; Keywords: maint
|
||
;; Version: 1.0.1
|
||
;; SPDX-License-Identifier: GPL-3.0-or-later
|
||
|
||
;;; Commentary:
|
||
;; This is the main initialization file for Emacs. It configures package
|
||
;; archives, ensures essential packages like `use-package` are installed, and
|
||
;; sets up further package management and customization settings.
|
||
|
||
;;; Code:
|
||
|
||
;;; Load pre-init.el
|
||
(minimal-emacs-load-user-init "pre-init.el")
|
||
|
||
;;; Variables
|
||
(defvar minimal-emacs-window-divider-mode-enabled t
|
||
"Non-nil to enable `window-divider-mode'.")
|
||
|
||
(defvar minimal-emacs-recentf-enabled t
|
||
"Non-nil to enable `recentf'.")
|
||
|
||
(defvar minimal-emacs-savehist-enabled t
|
||
"Non-nil to enable `savehist'.")
|
||
|
||
(defvar minimal-emacs-saveplace-enabled t
|
||
"Non-nil to enable `saveplace'.")
|
||
|
||
;;; package.el
|
||
|
||
(require 'package)
|
||
|
||
(when (version< emacs-version "28")
|
||
(add-to-list 'package-archives
|
||
'("nongnu" . "https://elpa.nongnu.org/nongnu/")))
|
||
(add-to-list 'package-archives
|
||
'("melpa-stable" . "https://stable.melpa.org/packages/"))
|
||
(add-to-list 'package-archives
|
||
'("melpa" . "https://melpa.org/packages/"))
|
||
|
||
(customize-set-variable 'package-archive-priorities
|
||
'(("gnu" . 99)
|
||
("nongnu" . 80)
|
||
("stable" . 70)
|
||
("melpa" . 0)))
|
||
|
||
(when package-enable-at-startup
|
||
(package-initialize)
|
||
(unless package-archive-contents
|
||
(package-refresh-contents t)))
|
||
|
||
;;; use-package
|
||
;; Load use-package for package configuration
|
||
|
||
;; Ensure the 'use-package' package is installed and loaded
|
||
(unless (package-installed-p 'use-package)
|
||
(package-refresh-contents t)
|
||
(package-install 'use-package)
|
||
(eval-when-compile
|
||
(require 'use-package)))
|
||
|
||
(eval-when-compile
|
||
(require 'use-package))
|
||
|
||
;;; Minibuffer
|
||
;; Allow nested minibuffers
|
||
(setq enable-recursive-minibuffers t)
|
||
|
||
;; Keep the cursor out of the read-only portions of the.minibuffer
|
||
(setq minibuffer-prompt-properties
|
||
'(read-only t intangible t cursor-intangible t face
|
||
minibuffer-prompt))
|
||
(add-hook 'minibuffer-setup-hook #'cursor-intangible-mode)
|
||
|
||
;;; Misc
|
||
|
||
;; switch-to-buffer runs pop-to-buffer-same-window instead
|
||
(setq switch-to-buffer-obey-display-actions t)
|
||
|
||
(setq show-paren-delay 0.1
|
||
show-paren-highlight-openparen t
|
||
show-paren-when-point-inside-paren t
|
||
show-paren-when-point-in-periphery t)
|
||
|
||
(setq whitespace-line-column nil) ; whitespace-mode
|
||
|
||
;; I reduced the default value of 9 to simplify the font-lock keyword,
|
||
;; aiming to improve performance. This package helps differentiate
|
||
;; nested delimiter pairs, particularly in languages with heavy use of
|
||
;; parentheses.
|
||
(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)
|
||
|
||
(setq comint-prompt-read-only t)
|
||
(setq comint-buffer-maximum-size 2048)
|
||
|
||
(setq compilation-always-kill t
|
||
compilation-ask-about-save nil
|
||
compilation-scroll-output 'first-error)
|
||
|
||
(setq truncate-string-ellipsis "…")
|
||
;;; Files
|
||
|
||
;; 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.
|
||
(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').
|
||
(setq find-file-visit-truename t
|
||
vc-follow-symlinks t)
|
||
|
||
;; Skip confirmation prompts when creating a new file or buffer
|
||
(setq confirm-nonexistent-file-or-buffer nil)
|
||
|
||
(setq uniquify-buffer-name-style 'forward)
|
||
|
||
(setq mouse-yank-at-point t)
|
||
|
||
(setq frame-title-format '("%b – Emacs")
|
||
icon-title-format frame-title-format)
|
||
|
||
;; Prefer vertical splits over horizontal ones
|
||
(setq split-width-threshold 170
|
||
split-height-threshold nil)
|
||
|
||
;; The native border "uses" a pixel of the fringe on the rightmost
|
||
;; splits, whereas `window-divider` does not.
|
||
(setq window-divider-default-bottom-width 1
|
||
window-divider-default-places t
|
||
window-divider-default-right-width 1)
|
||
|
||
(when minimal-emacs-window-divider-mode-enabled
|
||
(add-hook 'after-init-hook #'window-divider-mode))
|
||
|
||
;;; Backup files
|
||
|
||
;; Avoid generating backups or lockfiles to prevent creating world-readable
|
||
;; copies of files.
|
||
(setq create-lockfiles nil)
|
||
(setq make-backup-files nil)
|
||
|
||
(setq backup-directory-alist
|
||
`(("." . ,(expand-file-name "backup" user-emacs-directory))))
|
||
(setq tramp-backup-directory-alist backup-directory-alist)
|
||
(setq backup-by-copying-when-linked t)
|
||
(setq backup-by-copying t) ; Backup by copying rather renaming
|
||
(setq delete-old-versions t) ; Delete excess backup versions silently
|
||
(setq version-control t) ; Use version numbers for backup files
|
||
(setq kept-new-versions 5)
|
||
(setq kept-old-versions 5)
|
||
(setq vc-make-backup-files nil) ; Do not backup version controlled files
|
||
|
||
;;; Auto save
|
||
;; 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)
|
||
|
||
;; 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.
|
||
(setq auto-save-include-big-deletions t)
|
||
|
||
(setq auto-save-list-file-prefix
|
||
(expand-file-name "autosave/" user-emacs-directory))
|
||
(setq tramp-auto-save-directory
|
||
(expand-file-name "tramp-autosave/" user-emacs-directory))
|
||
|
||
;; Auto save options
|
||
(setq kill-buffer-delete-auto-save-files 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.
|
||
(setq revert-without-query (list ".") ; Do not prompt
|
||
auto-revert-stop-on-user-input nil
|
||
auto-revert-verbose t)
|
||
|
||
;;; 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.
|
||
(setq recentf-max-saved-items 300) ; default is 20
|
||
(setq recentf-auto-cleanup 'mode)
|
||
|
||
(when minimal-emacs-recentf-enabled
|
||
(add-hook 'after-init-hook #'recentf-mode))
|
||
|
||
;;; 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.
|
||
(setq save-place-file (expand-file-name "saveplace" user-emacs-directory))
|
||
(setq save-place-limit 600)
|
||
(when minimal-emacs-saveplace-enabled
|
||
(add-hook 'after-init-hook #'save-place-mode))
|
||
|
||
;;; savehist
|
||
(setq savehist-save-minibuffer-history t) ;; Default
|
||
|
||
(when minimal-emacs-savehist-enabled
|
||
(add-hook 'after-init-hook #'savehist-mode))
|
||
|
||
;;; Frames and windows
|
||
|
||
;; Resizing the Emacs frame can be costly when changing the font. Disable this
|
||
;; to improve startup times with fonts larger than the system default.
|
||
(setq frame-resize-pixelwise t)
|
||
|
||
;; However, do not resize windows pixelwise, as this can cause crashes in some
|
||
;; cases when resizing too many windows at once or rapidly.
|
||
(setq window-resize-pixelwise nil)
|
||
|
||
(setq resize-mini-windows 'grow-only)
|
||
|
||
;;; Smooth 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.
|
||
(setq fast-but-imprecise-scrolling t)
|
||
|
||
(setq hscroll-margin 2
|
||
hscroll-step 1
|
||
;; 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.
|
||
scroll-conservatively 10
|
||
scroll-margin 0
|
||
scroll-preserve-screen-position t
|
||
;; Minimize cursor lag slightly by preventing automatic adjustment of
|
||
;; `window-vscroll' for tall lines.
|
||
auto-window-vscroll nil
|
||
;; Mouse
|
||
mouse-wheel-scroll-amount '(2 ((shift) . hscroll))
|
||
mouse-wheel-scroll-amount-horizontal 2)
|
||
|
||
;;; Cursor
|
||
;; 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.
|
||
(setq blink-matching-paren nil)
|
||
|
||
;; Don't stretch the cursor to fit wide characters, it is disorienting,
|
||
;; especially for tabs.
|
||
(setq x-stretch-cursor nil)
|
||
|
||
;;; Annoyances
|
||
|
||
;; No beeping or blinking
|
||
(setq visible-bell nil)
|
||
(setq ring-bell-function #'ignore)
|
||
|
||
;;; Indent and formatting
|
||
(setq-default left-fringe-width 8)
|
||
(setq-default right-fringe-width 8)
|
||
|
||
;; Do not show an arrow at the top/bottomin the fringe and empty lines
|
||
(setq-default indicate-buffer-boundaries nil)
|
||
(setq-default indicate-empty-lines nil)
|
||
|
||
;; Continue wrapped lines at whitespace rather than breaking in the
|
||
;; middle of a word.
|
||
(setq-default word-wrap t)
|
||
|
||
;; Disable wrapping by default due to its performance cost.
|
||
(setq-default truncate-lines t)
|
||
|
||
;; If enabled and `truncate-lines' is disabled, soft wrapping will not occur
|
||
;; when the window is narrower than `truncate-partial-width-windows' characters.
|
||
(setq truncate-partial-width-windows nil)
|
||
|
||
;; Prefer spaces over tabs. Spaces offer a more consistent default compared to
|
||
;; 8-space tabs. This setting can be adjusted on a per-mode basis as needed.
|
||
(setq-default indent-tabs-mode nil
|
||
tab-width 4)
|
||
|
||
(setq-default tab-always-indent 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.
|
||
(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".
|
||
(setq require-final-newline t)
|
||
|
||
;; Remove duplicates from the kill ring to reduce clutter
|
||
(setq kill-do-not-save-duplicates t)
|
||
|
||
;;; Load post-init.el
|
||
(minimal-emacs-load-user-init "post-init.el")
|
||
|
||
(provide 'init)
|
||
|
||
;;; init.el ends here
|