Must-have Emacs Packages for Efficient Software Development and Text Editing

To build an efficient Emacs setup, I focused on improving defaults to maintain simplicity and efficiency. The initial step involved creating minimal-emacs.d, a project that has resonated with the Emacs community, providing a foundational template for many users' init.el and early-init.el vanilla Emacs configuration. Next, I experimented with hundreds of Emacs packages, carefully selecting the most valuable ones that, ideally, leverage built-in Emacs functions. (This is why I chose corfu over company, eglot over lsp-mode, and flymake over flycheck...) In this article, I will share the Emacs packages I recommend for software development and general text editing. Please share the … Continue reading

Running Large Language Models locally with Ollama (compatible with Linux, macOS, and Windows)

Running Large Language Models on your machine can enhance your projects, but the setup is often complex. Ollama simplifies this by packaging everything needed to run a Large Language Model. Here's a concise guide on using Ollama to run LLMs locally. Requirements Step 1: Install Ollama Download and install Ollama for Linux using: Step 2: Download a Large Language Model Download a specific large language model using the Ollama command: The command above downloads the Gemma2 model by Google DeepMind. You can find other models by visiting the Ollama Library. (At the time of writing, downloading gemma2:2b retrieves a quantized … Continue reading

Emacs: Automating Table of Contents Update for Markdown Documents (e.g., README.md)

When working with markdown files in Emacs (e.g., README.md), users may need to manually update the table of contents. Automating this process saves time and ensures that the table of contents remains consistent with the document structure. This article presents an Emacs Lisp code snippet that uses: The code snippet that updates the table of contents and ensures that the cursor and window start remain unchanged The following code snippet updates the table of contents while ensuring that the cursor and window start remain unchanged: (The table of contents will be updated only if it is already present, so it … Continue reading

Emacs: Maintaining proper indentation in indentation-sensitive programming languages

As codebases grow, maintaining proper indentation becomes increasingly difficult, especially in languages like Python or YAML, where indentation is not just a matter of style but an important part of the syntax. When working with large code blocks or deeply nested structures, it’s easy to lose track of the correct indentation level, leading to errors and decreased readability. In this post, we’ll explore Emacs packages and an Elisp code snippet that can help manage indentation in these indentation-sensitive languages. Code snippet: Indenting new lines based on previous non-blank line The following code snippet configures Emacs to indent based on the … Continue reading

dir-config.el - Automatically find and evaluate .dir-config.el Elisp files (Flexible dir-locals alternative)

The dir-config Emacs package automatically loads and evaluates Elisp code from a .dir-config.el file found in the buffer's current directory or its closest parent directory. This facilitates adjusting settings or executing functions specific to the directory structure of each buffer. For instance, you can use the dir-config package to: Configure project-specific settings: Automatically set up environment variables, keybindings, or modes unique to each project. Apply directory-specific customizations: Set specific behaviors or preferences for files in different directories, such as enabling or disabling certain minor modes based on security considerations. For example, you might disable linters that execute code in directories … Continue reading

minimal-emacs.d - A Customizable Emacs init.el and early-init.el for Better Defaults and Optimized Startup

Introduction The minimal-emacs.d project is a fast and lightweight minimal Emacs starter kit (init.el and early-init.el) that gives you full control over your configuration. It provides better defaults, an optimized startup, and a clean foundation for building your own vanilla Emacs setup. Each setting in minimal-emacs.d is carefully chosen to answer this question: does it provide a better default that modernizes Emacs while keeping it lightweight, fast and stable? In just a few minutes of applying what's in this README.md file, you will have a fully functional, high-performance Emacs configuration ready for work. You will bypass hours of configuration and … Continue reading

easysession.el: Easily persist and restore Emacs sessions (windows, tab-bar, file buffers, scratch, Dired, narrowing, indirect buffers/clones, Magit buffers...); a robust desktop.el replacement

The easysession Emacs package provides a comprehensive session management for Emacs. It is capable of persisting and restoring file-visiting buffers, indirect buffers (clones), buffer narrowing, Dired buffers, window configurations, the built-in tab-bar (including tabs, their buffers, and associated windows), as well as entire Emacs frames (frame name, size, position, etc.). With easysession, your Emacs setup is restored automatically when you restart. All files, Dired buffers, and window layouts come back as they were, so you can continue working right where you left off. While editing, you can also switch to another session, switch back, rename sessions, or delete them, giving … Continue reading

outline-indent.el - A modern indentation-based folding mode for Emacs

The outline-indent Emacs package provides a minor mode for indentation-based code folding. It is fast and built directly on top of native Emacs functions. Beyond basic folding, outline-indent includes commands to: * Move indented blocks up and down using (outline-indent-move-subtree-up) and (outline-indent-move-subtree-down). * Adjust block indentation levels with (outline-indent-shift-right) and (outline-indent-shift-left). * Insert a new line matching the current indentation level via (outline-indent-insert-heading). * Navigate backward and forward to the same indentation level with (outline-indent-backward-same-level) and (outline-indent-forward-same-level). * Customize the folding ellipsis (e.g., replacing the default "..." with "▼"). * Select an entire indented block using (outline-indent-select). * Toggle visibility … Continue reading

Making 'cron' notify the user about a failed command by redirecting its output to stderr only when it fails (non-zero exit code)

Monitoring the success or failure of cron jobs can be challenging, especially when multiple jobs cause cron to send emails even when they don't fail. A more effective approach to handling cron job errors is to use a Bash script that directs the output to stderr only if the job fails, causing cron to notify the user about the error only when the script fails. Script overview The script provided below ensures that any command passed to it will redirect its output to a temporary file. If the command fails (i.e., returns a non-zero exit code), the script sends the … Continue reading

Emacs: Enhancing up and down subtree movement in outline-mode and outline-minor-mode

When editing outlined files (e.g., using the built-in outline-minor-mode, or packages like outline-indent.el, outline-yaml.el, etc.), handling subtrees efficiently can significantly enhance productivity, especially when working with complex documents. If you're familiar with outline-mode or outline-minor-mode, you might have noticed that the built-in functions for moving subtrees up and down, outline-move-subtree-up and outline-move-subtree-down: Here’s how you can address these issues by using custom functions to enhance subtree movement: I also recommend using Ctrl-Up and Ctrl-Down key bindings for moving subtrees up and down. With this setup, you will ensure that every time you use outline-move-subtree-up or outline-move-subtree-down, the last blank line … Continue reading

elispcomp - Compile Emacs Lisp code from the command-line

(The author also recommends trying: compile-angel.el, an Emacs package that automatically byte-compiles and native-compiles .el Elisp libraries, transparently, without any user intervention.) Introduction The elispcomp command line tool allows compiling Emacs Lisp (Elisp) code directly from the terminal or from a shell script. It facilitates the generation of optimized .elc (byte-compiled) and .eln (native-compiled) files, which can significantly improve the performance of Emacs. The command line tool executes a headless instance of Emacs and Elisp that recursively scans the specified directories, byte compiling and native compiling all the .el files that haven't been compiled yet. It supports various configuration options, … Continue reading

Emacs Evil Mode: Disabling the automatic removal of spaces after leaving Insert mode

By default, Emacs evil-mode removes newly inserted spaces when exiting insert mode. However, some users may find this disruptive to their workflow. This is particularly true for those who edit file formats where trailing spaces are significant or who simply prefer to manage whitespace manually. To prevent the automatic removal of trailing spaces when leaving insert mode, add the following Elisp code to the Emacs init file: The function above sets the evil-maybe-remove-spaces variable to nil when entering insert mode, preventing the evil-maybe-remove-spaces function from deleting whitespace after leaving insert mode. The evil-insert-state function, which Evil uses to switch to … Continue reading

Emacs: Customizing the Ellipsis "…" in outline-mode and outline-minor-mode to Use a More Visually Appealing Indicator for Folded Sections, Such as " ▼"

The built-in Emacs outline-mode and outline-minor-mode allow structuring documents with collapsible sections. By default, these modes use an ellipsis (“…”) to indicate folded text. However, the default ellipsis and its face can make it hard to distinguish between folded text and regular text. This is why it can be beneficial to customize the ellipsis. The code snippets provided in this article allow for customizing the ellipsis locally within a buffer. Set the buffer local outline ellipsis To apply the ellipsis locally to a buffer, the following Elisp code snippet modifies the display settings within that buffer. The ellipsis string is … Continue reading

Emacs: YAML file code Folding and Outlining

Working with long and complex YAML files can be a daunting task. In such cases, code folding becomes an invaluable tool, allowing the collapse and expansion of sections of the file and enhancing readability and navigation. This makes it easier to focus on specific parts of the code without being overwhelmed by the entire document. To address this need, I would like to introduce you to outline-indent.el, a minor mode for Emacs that brings code folding and outlining capabilities to Emacs, making editing YAML and other languages more efficient and enjoyable. How to change the Ellipsis (...) to (▼)? The … Continue reading

Enabling Emacs Native Compilation and Dynamically Adjusting the Number of Elisp Files Compiled in Parallel

Recommendation: The compile-angel Emacs package automatically byte-compiles and native-compiles Emacs Lisp libraries. It speeds up Emacs by ensuring all libraries are byte-compiled and native-compiled. Emacs has experienced a significant performance boost with the introduction of native compilation, available from version 27 and above. This feature converts Emacs Lisp code into machine-level code, enabling faster execution and enhanced responsiveness. Speeding up compilation by using the maximum number of available CPU cores significantly reduces compilation time. However, it's also necessary to leave a few CPU cores free to ensure the operating system runs smoothly, including the graphical user interface, shells, and other … Continue reading