From 5a8fae45221cfdf30e7f899dd2bb68a108f81b19 Mon Sep 17 00:00:00 2001 From: James Cherti <60946298+jamescherti@users.noreply.github.com> Date: Wed, 5 Mar 2025 12:39:33 -0500 Subject: [PATCH 1/4] Add: auto-save-no-message --- init.el | 1 + 1 file changed, 1 insertion(+) diff --git a/init.el b/init.el index 0081b32..4fec987 100644 --- a/init.el +++ b/init.el @@ -182,6 +182,7 @@ ;; `recover-file' or `recover-session' functions can be used to restore ;; auto-saved data. (setq auto-save-default t) +(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 From 944c74ef6a11ea1c7832922184e2112c83b888a2 Mon Sep 17 00:00:00 2001 From: James Cherti <60946298+jamescherti@users.noreply.github.com> Date: Thu, 6 Mar 2025 07:54:14 -0500 Subject: [PATCH 2/4] Disable auto-save and document it in README.md --- README.md | 13 +++++++++++++ init.el | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7680a01..9d548cf 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ The author uses *minimal-emacs.d* as his `early-init.el` and `init.el`, alongsid - [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) + - [Activating autosave](#activating-autosave) - [Code completion with corfu](#code-completion-with-corfu) - [Configuring Vertico, Consult, and Embark](#configuring-vertico-consult-and-embark) - [Code Folding](#code-folding) @@ -208,6 +209,18 @@ The recentf, savehist, saveplace, and auto-revert built-in packages are already (add-hook 'after-init-hook #'save-place-mode) ``` +### Activating autosave + +Auto-save helps prevent data loss in case of crashes. You can restore auto-saved data using the `recover-file` or `recover-session` functions. + +To enable autosave, add the following to `~/.emacs.d/post-init.el`: + +```emacs-lisp +;; Enable auto-save to prevent data loss. Use `recover-file` or +;; `recover-session` to restore unsaved changes. +(setq auto-save-default t) +``` + ### Code completion with corfu Corfu enhances in-buffer completion by displaying a compact popup with current candidates, positioned either below or above the point. Candidates can be selected by navigating up or down. diff --git a/init.el b/init.el index 4fec987..a6fc989 100644 --- a/init.el +++ b/init.el @@ -181,7 +181,7 @@ ;; 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 From 5e4be5b8b23ec20c9f468e71adcea127581c9edd Mon Sep 17 00:00:00 2001 From: James Cherti <60946298+jamescherti@users.noreply.github.com> Date: Thu, 6 Mar 2025 08:04:57 -0500 Subject: [PATCH 3/4] Update README.md: code folding --- README.md | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 9d548cf..38300da 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ The author uses *minimal-emacs.d* as his `early-init.el` and `init.el`, alongsid - [Activating autosave](#activating-autosave) - [Code completion with corfu](#code-completion-with-corfu) - [Configuring Vertico, Consult, and Embark](#configuring-vertico-consult-and-embark) - - [Code Folding](#code-folding) + - [Code folding](#code-folding) - [Configuring vterm](#configuring-vterm) - [Configuring Vim keybindings using Evil?](#configuring-vim-keybindings-using-evil) - [Configuring LSP Servers with Eglot (built-in)](#configuring-lsp-servers-with-eglot-built-in) @@ -412,26 +412,35 @@ Add the following to `~/.emacs.d/post-init.el` to set up Vertico, Consult, and E (setq consult-narrow-key "<")) ``` -### Code Folding +### Code folding -The **outline-indent** Emacs package provides a minor mode that enables code folding based on indentation levels: +The built-in `outline-minor-mode` provides structured code folding in modes such as Emacs Lisp and Python, allowing users to collapse and expand sections based on headings or indentation levels. This feature enhances navigation and improves the management of large files with hierarchical structures. + +Alternatively, `hs-minor-mode` offers basic code folding for blocks defined by curly braces, functions, or other language-specific delimiters. However, for more flexible folding that supports multiple nested levels, `outline-minor-mode` is generally the preferred choice, as it enables finer control over section visibility in deeply structured code. + +For example, to enable `outline-minor-mode` in Emacs Lisp: + +``` emacs-lisp +(add-hook 'emacs-lisp-mode-hook #'outline-minor-mode) +``` + +For folding based on indentation levels, the **[outline-indent @GitHub](https://github.com/jamescherti/outline-indent.el)** Emacs package provides a minor mode that enables folding according to the indentation structure: ```elisp (use-package outline-indent :ensure t :defer t :commands outline-indent-minor-mode + :custom + (outline-indent-ellipsis " ▼ ") + :init ;; The minor mode can also be automatically activated for a certain modes. - ;; For example for Python and YAML: (add-hook 'python-mode-hook #'outline-indent-minor-mode) (add-hook 'python-ts-mode-hook #'outline-indent-minor-mode) (add-hook 'yaml-mode-hook #'outline-indent-minor-mode) - (add-hook 'yaml-ts-mode-hook #'outline-indent-minor-mode) - - :custom - (outline-indent-ellipsis " ▼ ")) + (add-hook 'yaml-ts-mode-hook #'outline-indent-minor-mode)) ``` In addition to code folding, *outline-indent* also allows: moving indented blocks up and down, indenting/unindenting to adjust indentation levels, inserting a new line with the same indentation level as the current line, Move backward/forward to the indentation level of the current line, and more. From 42f4458695b3d9e04186a3cd84607aef04ee0e9a Mon Sep 17 00:00:00 2001 From: James Cherti <60946298+jamescherti@users.noreply.github.com> Date: Thu, 6 Mar 2025 08:19:27 -0500 Subject: [PATCH 4/4] Update README.md: auto save --- README.md | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 38300da..28defa1 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,8 @@ The author uses *minimal-emacs.d* as his `early-init.el` and `init.el`, alongsid - [Optimization: Native Compilation](#optimization-native-compilation) - [How to activate recentf, savehist, saveplace, and auto-revert?](#how-to-activate-recentf-savehist-saveplace-and-auto-revert) - [Activating autosave](#activating-autosave) + - [auto-save-mode (Prevent data loss in case of crashes)](#auto-save-mode-prevent-data-loss-in-case-of-crashes) + - [auto-save-visited-mode (Save file buffers after a few seconds of inactivity)](#auto-save-visited-mode-save-file-buffers-after-a-few-seconds-of-inactivity) - [Code completion with corfu](#code-completion-with-corfu) - [Configuring Vertico, Consult, and Embark](#configuring-vertico-consult-and-embark) - [Code folding](#code-folding) @@ -211,14 +213,30 @@ The recentf, savehist, saveplace, and auto-revert built-in packages are already ### Activating autosave -Auto-save helps prevent data loss in case of crashes. You can restore auto-saved data using the `recover-file` or `recover-session` functions. +#### auto-save-mode (Prevent data loss in case of crashes) + +Enabling `auto-save-mode` mitigates the risk of data loss in the event of a crash. Auto-saved data can be recovered using the `recover-file` or `recover-session` functions. To enable autosave, add the following to `~/.emacs.d/post-init.el`: ```emacs-lisp -;; Enable auto-save to prevent data loss. Use `recover-file` or -;; `recover-session` to restore unsaved changes. +;; Enable `auto-save-mode' to prevent data loss. Use `recover-file' or +;; `recover-session' to restore unsaved changes. (setq auto-save-default t) + +(setq auto-save-interval 300) +(setq auto-save-timeout 30) +``` + +#### auto-save-visited-mode (Save file buffers after a few seconds of inactivity) + +When `auto-save-visited-mode` is enabled, Emacs will auto-save file-visiting buffers after a certain amount of idle time if the user forgets to save it with `save-buffer` or `C-x s` for example. + +This is different from `auto-save-mode`: `auto-save-mode` periodically saves all modified buffers, creating backup files, including those not associated with a file, while `auto-save-visited-mode` only saves file-visiting buffers after a period of idle time, directly saving to the file itself without creating backup files. + +``` emacs-lisp +(setq auto-save-visited-interval 5) ; Save after 5 seconds if inactivity +(auto-save-visited-mode 1) ``` ### Code completion with corfu