diff --git a/README.md b/README.md index a6ba2e4..cf8f928 100644 --- a/README.md +++ b/README.md @@ -23,10 +23,9 @@ The author uses *minimal-emacs.d* as his `early-init.el` and `init.el`, alongsid - [Install minimal-emacs.d into `~/.emacs.d`](#install-minimal-emacsd-into-emacsd) - [Alternative: Install minimal-emacs.d into `~/.minimal-emacs.d`](#alternative-install-minimal-emacsd-into-minimal-emacsd) - [Update minimal-emacs.d](#update-minimal-emacsd) - - [Customizations](#customizations) + - [Customizations: post-init.el](#customizations-post-initel) - [Never modify init.el and early-init.el. Modify these instead...](#never-modify-initel-and-early-initel-modify-these-instead) - [How to enable the menu-bar, the tool-bar, dialogs, the contextual menu, and tooltips?](#how-to-enable-the-menu-bar-the-tool-bar-dialogs-the-contextual-menu-and-tooltips) - - [Reducing clutter in `~/.emacs.d` by redirecting files to `~/emacs.d/var/`](#reducing-clutter-in-emacsd-by-redirecting-files-to-emacsdvar) - [How to prevent minimal-emacs.d from saving custom.el?](#how-to-prevent-minimal-emacsd-from-saving-customel) - [Optimization: Native Compilation](#optimization-native-compilation) - [How to activate recentf, savehist, saveplace, and auto-revert?](#how-to-activate-recentf-savehist-saveplace-and-auto-revert) @@ -45,9 +44,11 @@ The author uses *minimal-emacs.d* as his `early-init.el` and `init.el`, alongsid - [Inhibit the mouse](#inhibit-the-mouse) - [A better Emacs *help* buffer](#a-better-emacs-help-buffer) - [Enhancing the Elisp development experience](#enhancing-the-elisp-development-experience) + - [Which other customizations can be interesting to add?](#which-other-customizations-can-be-interesting-to-add) + - [Customizations: pre-early-init.el](#customizations-pre-early-initel) + - [Reducing clutter in `~/.emacs.d` by redirecting files to `~/emacs.d/var/`](#reducing-clutter-in-emacsd-by-redirecting-files-to-emacsdvar) - [Configuring straight.el?](#configuring-straightel) - [Configuring elpaca (package manager)](#configuring-elpaca-package-manager) - - [Which other customizations can be interesting to add?](#which-other-customizations-can-be-interesting-to-add) - [Frequently asked questions](#frequently-asked-questions) - [How to give more priority to MELPA over MELPA stable?](#how-to-give-more-priority-to-melpa-over-melpa-stable) - [How to load a local lisp file for machine-specific configurations?](#how-to-load-a-local-lisp-file-for-machine-specific-configurations) @@ -101,7 +102,7 @@ To keep your Emacs configuration up to date, you can pull the latest changes fro git -C ~/.emacs.d pull ``` -## Customizations +## Customizations: post-init.el ### Never modify init.el and early-init.el. Modify these instead... **The `init.el` and `early-init.el` files should never be modified directly** because they are intended to be managed by Git during an update. @@ -135,23 +136,6 @@ To customize your Emacs setup to include various user interface elements, you ca These settings control the visibility of dialogs, context menus, toolbars, menu bars, and tooltips. -### Reducing clutter in `~/.emacs.d` by redirecting files to `~/emacs.d/var/` - -Emacs, by default, stores various configuration files, caches, backups, and other data in the `~/.emacs.d` directory. Over time, this directory can become cluttered with numerous files, making it difficult to manage and maintain. - -A common solution to this issue is installing the no-littering package; however, this package is not essential. - -An alternative lightweight approach is to simply change the default `~/.emacs.d` directory to `~/.emacs.d/var/`, which will contain all the files that Emacs typically stores in the base directory. This can be accomplished by adding the following code to `~/.emacs.d/pre-early-init.el`: -``` emacs-lisp -;; Reducing clutter in ~/.emacs.d by redirecting files to ~/emacs.d/var/ -;; IMPORTANT: This part should be in the pre-early-init.el file -(setq minimal-emacs-var-dir (expand-file-name "var/" minimal-emacs-user-directory)) -(setq package-user-dir (expand-file-name "elpa" minimal-emacs-var-dir)) -(setq user-emacs-directory minimal-emacs-var-dir) -``` - -**IMPORTANT:** The code above should be added to `~/.emacs.d/pre-early-init.el`, not the other files, as it modifies the behavior of all subsequent init files. - ### How to prevent minimal-emacs.d from saving custom.el? To prevent Emacs from saving customization information to a custom file, set `custom-file` to `null-device` by adding to the following to `~/.emacs.d/post-init.el`: @@ -862,86 +846,6 @@ Other optional packages that may be useful include: elisp-refs-symbol)) ``` -### Configuring straight.el? - -[Add the straight.el bootstrap code](https://github.com/radian-software/straight.el?tab=readme-ov-file#getting-started) to `~/.emacs.d/pre-init.el`: -``` emacs-lisp -;; Straight bootstrap -(defvar bootstrap-version) -(let ((bootstrap-file - (expand-file-name - "straight/repos/straight.el/bootstrap.el" - (or (bound-and-true-p straight-base-dir) - user-emacs-directory))) - (bootstrap-version 7)) - (unless (file-exists-p bootstrap-file) - (with-current-buffer - (url-retrieve-synchronously - "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el" - 'silent 'inhibit-cookies) - (goto-char (point-max)) - (eval-print-last-sexp))) - (load bootstrap-file nil 'nomessage)) -``` - -### Configuring elpaca (package manager) - -Add to `~/.emacs.d/pre-early-init.el`: -```elisp -;; By default, minimal-emacs-package-initialize-and-refresh is set to t, which -;; makes minimal-emacs.d call the built-in package manager. Since Elpaca will -;; replace the package manager, there is no need to call it. -(setq minimal-emacs-package-initialize-and-refresh nil) -``` - -(According to arthsmn, a *minimal-emacs.d* user, the change above also improves startup time. [In this user's case](https://github.com/jamescherti/minimal-emacs.d/pull/22), the startup time decreased from 1.06 seconds to 0.56 seconds.) - -And [add the elpaca bootstrap code](https://github.com/progfolio/elpaca?tab=readme-ov-file#installer) to `~/.emacs.d/pre-init.el`: -```elisp -(defvar elpaca-installer-version 0.9) -(defvar elpaca-directory (expand-file-name "elpaca/" user-emacs-directory)) -(defvar elpaca-builds-directory (expand-file-name "builds/" elpaca-directory)) -(defvar elpaca-repos-directory (expand-file-name "repos/" elpaca-directory)) -(defvar elpaca-order '(elpaca :repo "https://github.com/progfolio/elpaca.git" - :ref nil :depth 1 :inherit ignore - :files (:defaults "elpaca-test.el" (:exclude "extensions")) - :build (:not elpaca--activate-package))) -(let* ((repo (expand-file-name "elpaca/" elpaca-repos-directory)) - (build (expand-file-name "elpaca/" elpaca-builds-directory)) - (order (cdr elpaca-order)) - (default-directory repo)) - (add-to-list 'load-path (if (file-exists-p build) build repo)) - (unless (file-exists-p repo) - (make-directory repo t) - (when (< emacs-major-version 28) (require 'subr-x)) - (condition-case-unless-debug err - (if-let* ((buffer (pop-to-buffer-same-window "*elpaca-bootstrap*")) - ((zerop (apply #'call-process `("git" nil ,buffer t "clone" - ,@(when-let* ((depth (plist-get order :depth))) - (list (format "--depth=%d" depth) "--no-single-branch")) - ,(plist-get order :repo) ,repo)))) - ((zerop (call-process "git" nil buffer t "checkout" - (or (plist-get order :ref) "--")))) - (emacs (concat invocation-directory invocation-name)) - ((zerop (call-process emacs nil buffer nil "-Q" "-L" "." "--batch" - "--eval" "(byte-recompile-directory \".\" 0 'force)"))) - ((require 'elpaca)) - ((elpaca-generate-autoloads "elpaca" repo))) - (progn (message "%s" (buffer-string)) (kill-buffer buffer)) - (error "%s" (with-current-buffer buffer (buffer-string)))) - ((error) (warn "%s" err) (delete-directory repo 'recursive)))) - (unless (require 'elpaca-autoloads nil t) - (require 'elpaca) - (elpaca-generate-autoloads "elpaca" repo) - (load "./elpaca-autoloads"))) -(add-hook 'after-init-hook #'elpaca-process-queues) -(elpaca `(,@elpaca-order)) - -;; Optional: Install use-package support -(elpaca elpaca-use-package - (elpaca-use-package-mode)) -``` - ### Which other customizations can be interesting to add? 1. Read the following article from the same author: [Essential Emacs Packages for Efficient Software Development and Text Editing](https://www.jamescherti.com/essential-emacs-packages/) @@ -1030,6 +934,106 @@ It is also recommended to read the following articles: - [Automating Table of Contents Update for Markdown Documents (e.g., README.md)](https://www.jamescherti.com/emacs-markdown-table-of-contents-update-before-save/) - [Maintaining proper indentation in indentation-sensitive programming languages](https://www.jamescherti.com/elisp-code-and-emacs-packages-for-maintaining-proper-indentation-in-indentation-sensitive-languages-such-as-python-or-yaml/) + +## Customizations: pre-early-init.el + +### Reducing clutter in `~/.emacs.d` by redirecting files to `~/emacs.d/var/` + +Emacs, by default, stores various configuration files, caches, backups, and other data in the `~/.emacs.d` directory. Over time, this directory can become cluttered with numerous files, making it difficult to manage and maintain. + +A common solution to this issue is installing the no-littering package; however, this package is not essential. + +An alternative lightweight approach is to simply change the default `~/.emacs.d` directory to `~/.emacs.d/var/`, which will contain all the files that Emacs typically stores in the base directory. This can be accomplished by adding the following code to `~/.emacs.d/pre-early-init.el`: +``` emacs-lisp +;; Reducing clutter in ~/.emacs.d by redirecting files to ~/emacs.d/var/ +;; IMPORTANT: This part should be in the pre-early-init.el file +(setq minimal-emacs-var-dir (expand-file-name "var/" minimal-emacs-user-directory)) +(setq package-user-dir (expand-file-name "elpa" minimal-emacs-var-dir)) +(setq user-emacs-directory minimal-emacs-var-dir) +``` + +**IMPORTANT:** The code above should be added to `~/.emacs.d/pre-early-init.el`, not the other files, as it modifies the behavior of all subsequent init files. + +### Configuring straight.el? + +[Add the straight.el bootstrap code](https://github.com/radian-software/straight.el?tab=readme-ov-file#getting-started) to `~/.emacs.d/pre-init.el`: +``` emacs-lisp +;; Straight bootstrap +(defvar bootstrap-version) +(let ((bootstrap-file + (expand-file-name + "straight/repos/straight.el/bootstrap.el" + (or (bound-and-true-p straight-base-dir) + user-emacs-directory))) + (bootstrap-version 7)) + (unless (file-exists-p bootstrap-file) + (with-current-buffer + (url-retrieve-synchronously + "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el" + 'silent 'inhibit-cookies) + (goto-char (point-max)) + (eval-print-last-sexp))) + (load bootstrap-file nil 'nomessage)) +``` + +### Configuring elpaca (package manager) + +Add to `~/.emacs.d/pre-early-init.el`: +```elisp +;; By default, minimal-emacs-package-initialize-and-refresh is set to t, which +;; makes minimal-emacs.d call the built-in package manager. Since Elpaca will +;; replace the package manager, there is no need to call it. +(setq minimal-emacs-package-initialize-and-refresh nil) +``` + +(According to arthsmn, a *minimal-emacs.d* user, the change above also improves startup time. [In this user's case](https://github.com/jamescherti/minimal-emacs.d/pull/22), the startup time decreased from 1.06 seconds to 0.56 seconds.) + +And [add the elpaca bootstrap code](https://github.com/progfolio/elpaca?tab=readme-ov-file#installer) to `~/.emacs.d/pre-init.el`: +```elisp +(defvar elpaca-installer-version 0.9) +(defvar elpaca-directory (expand-file-name "elpaca/" user-emacs-directory)) +(defvar elpaca-builds-directory (expand-file-name "builds/" elpaca-directory)) +(defvar elpaca-repos-directory (expand-file-name "repos/" elpaca-directory)) +(defvar elpaca-order '(elpaca :repo "https://github.com/progfolio/elpaca.git" + :ref nil :depth 1 :inherit ignore + :files (:defaults "elpaca-test.el" (:exclude "extensions")) + :build (:not elpaca--activate-package))) +(let* ((repo (expand-file-name "elpaca/" elpaca-repos-directory)) + (build (expand-file-name "elpaca/" elpaca-builds-directory)) + (order (cdr elpaca-order)) + (default-directory repo)) + (add-to-list 'load-path (if (file-exists-p build) build repo)) + (unless (file-exists-p repo) + (make-directory repo t) + (when (< emacs-major-version 28) (require 'subr-x)) + (condition-case-unless-debug err + (if-let* ((buffer (pop-to-buffer-same-window "*elpaca-bootstrap*")) + ((zerop (apply #'call-process `("git" nil ,buffer t "clone" + ,@(when-let* ((depth (plist-get order :depth))) + (list (format "--depth=%d" depth) "--no-single-branch")) + ,(plist-get order :repo) ,repo)))) + ((zerop (call-process "git" nil buffer t "checkout" + (or (plist-get order :ref) "--")))) + (emacs (concat invocation-directory invocation-name)) + ((zerop (call-process emacs nil buffer nil "-Q" "-L" "." "--batch" + "--eval" "(byte-recompile-directory \".\" 0 'force)"))) + ((require 'elpaca)) + ((elpaca-generate-autoloads "elpaca" repo))) + (progn (message "%s" (buffer-string)) (kill-buffer buffer)) + (error "%s" (with-current-buffer buffer (buffer-string)))) + ((error) (warn "%s" err) (delete-directory repo 'recursive)))) + (unless (require 'elpaca-autoloads nil t) + (require 'elpaca) + (elpaca-generate-autoloads "elpaca" repo) + (load "./elpaca-autoloads"))) +(add-hook 'after-init-hook #'elpaca-process-queues) +(elpaca `(,@elpaca-order)) + +;; Optional: Install use-package support +(elpaca elpaca-use-package + (elpaca-use-package-mode)) +``` + ## Frequently asked questions ### How to give more priority to MELPA over MELPA stable?