My personal Emacs Config (LEmacs - L(ionyx)Emacs)

Cover Image for My personal Emacs Config (LEmacs - L(ionyx)Emacs)
Rahul M. Juliato
Rahul M. Juliato
#emacs#config# lsp# treesitter

For me, one of the finest things of using Emacs is having the same user experience both when I am sessioning trough SSH, hacking with Tmux, reading my RSS news or working as a software engineer. Having no worries about changing between text editors is really nice. Also, starting a "one session to rule" then all as a deamon and opening several GUI/TUI frames in the same session, wow... Emacs is still very cool :)

It's been a while since I "launched" my public Emacs config. It is something I was relutant to do as it reflected some 15+ years of learnig, patching and well, not cleaning it up as I should.

This led me to many situations where I wasn't confortable sharing stuff, either if I needed help or if I wanted to help someone.

And just as this blog is kind of an effort project to expose my self more. I redid my Emacs config to be at least "readable", maybe "enjoyable" :)

As I said before having GUI and TUI behaving the same is very important to me. It is horrible to see flymake anottating things on the fringe, just to find out that TUI has no fringe. An option to enable marking on the margin? No thanks. And that's one of several reasons I preferred flycheck over the years.

Do you want the cool Eglot to show documentation? Maybe use eldoc-box? No support for TUI unfortunally. And that's another big win to lsp-mode.

Little things like these added up trough the years to make this config the way it is nowadays.

What I expected from sharing it? Just the joy of providing other people with some insights and maybe receiving some positive improvable feedbacks.

You can find it in here: LEmacs Config

Bellow I provide a copy of LEmacs README so you can take a look at it.

LEmacs - L(ionyx)Emacs Config

    ██╗     ███████╗███╗   ███╗ █████╗  ██████╗███████╗
    ██║     ██╔════╝████╗ ████║██╔══██╗██╔════╝██╔════╝
    ██║     █████╗  ██╔████╔██║███████║██║     ███████╗
    ██║     ██╔══╝  ██║╚██╔╝██║██╔══██║██║     ╚════██║
    ███████╗███████╗██║ ╚═╝ ██║██║  ██║╚██████╗███████║
    ╚══════╝╚══════╝╚═╝     ╚═╝╚═╝  ╚═╝ ╚═════╝╚══════╝

Emacs for the modern developer focused on seamlessly TUI/GUI experience, either standalone or in a server/client mode.

Left (Terminal User Interface) / Right (Graphical User Interface)

Demo 01: img

Demo 02: img

Demo 03: img

Demo 04 (highlight guideline): img

Demo 05 (git gutter): img

Demo 06 (line blame): img

And all the power of Vertico, Orderless, Marginalia, Embark, Consult, LSP, TreeSitter, Vterm, and many more!

Fork it at will! :)

Motivation

Greetings to LEmacs, my customized configuration now shared with the community! This configuration is crafted to deliver a seamless and delightful Emacs experience, whether you're navigating through the Text User Interface (TUI) or the Graphical User Interface (GUI). It's designed to excel in both standalone mode and as a daemon/client setup.

This means (of course to my personal taste and opinions) that I will prefer packages that support both Terminal and Graphics, so you may never be worried about where to use Emacs or other editors.

You can use Emacs, everywhere, always ;)

Installation

Preparation

  1. Emacs Version

    Ensure you have Emacs version 29 or higher, compiled with native compilation, JSON, and tree-sitter support.

    emacs --version
    emacs -nw -q --batch --eval '(message system-configuration-options)'
    
  2. JS/TS LSP Servers

    To use LSP (and also node/typescript/eslint, prettier), you can install Node JS globally or use a version management tool, in the case you have several projects with several node versions it is common to use nvm or asdf. I recommend to install Node JS via asdf (https://asdf-vm.com/).

    Note: asdf must be loaded on .bashprofile for macos, and .bashrc for Linux, for testing (after Lemacs install), run eshell and look at asdf –version output.

    You need to Install globally (and for every every asdf plugin shim if you're using asdf):

    npm i -g vscode-langservers-extracted prettier@2.8.8
    npm i -g typescript-language-server typescript
    
  3. Backup your config

    Make a backup of your ~/.emacs.d/, ~/.emacs files and delete them, recommended:

    cp -r ~/.emacs.d/ ~/.emacs.d_backup
    cp ~/.emacs ~/.emacs_backup
    
    rm -rf ~/.emacs.d ~/.emacs
    

Clone and install LEmacs

Now, let's get you set up:

git clone https://github.com/LionyxML/LEmacs ~/.emacs.d
emacs -nw --eval="(my-first-install)"

During installation, you'll be prompted to:

  • Choose whether to compile vterm now or later (recommended: yes)
  • Specify the Tree Sitter library bundle version (hit RET for default)
  • Opt to display installed grammars (recommended: yes)
  • Decide on downloading and installing fonts for use with NerdFonts (recommended: yes)

If anything goes awry, exit and restart the installation script. If all goes smoothly, you'll be back at your shell prompt.

Launch Emacs, whether from the GUI or TUI (emacs -nw or emacs), and you're good to roll!

Troubleshooting

LSP-mode

It's always a good idea to run M-x lsp-doctor to check that everything is working.

This might be necessary when dealing with nodeJS, watches, etc:

echo fs.inotify.max_user_watches=393210 \
| sudo tee -a /etc/sysctl.conf \
&& sudo sysctl -p

Emacs is hanging…

If you're experiencing UI freezes in Emacs, here's a handy way to pinpoint the culprit:

M-x profiler-start
;; choose CPU
;; do stuff and make the UI freeze
M-x profiler-stop
M-x profiler-report

This will help you identify what's causing the slowdown. Pay attention to the profiler report for insights into resource-intensive operations.

It's worth noting that this configuration makes native compilation asynchronous. Consequently, the first time you use a package, there might be a background process compiling it. Check for any Async-native-compile-log buffers using:

M-x ibuffer

Inspect these buffers to ensure that compilation processes are running as expected.

FAQ

Why not X Feature?

If you're wondering, "Why not X feature?"—great question!

Open an issue on our GitHub repository, and let's dive into the discussion. I am open to exploring new additions or substitutions.

Extra: Emacs install

Debian (or Debian Based distros)

For Debian or Debian based Distros, such as Ubuntu and it's derivatives.

sudo apt install emacs

Check the installed version with:

emacs --version

MacOS

On macOS compiling with a brew formulae is the recommendated way:

brew install \
  --ignore-dependencies \
  emacs-plus@30 \
  --with-native-comp \
  --with-xwidgets \
  --with-imagemagick \
  --with-mailutils \
  --with-poll \
  --with-no-frame-refocus

Compile Emacs from scratch (Debian)

Before everything, this is optional, but may help on reducing troubleshooting time:

sudo apt-get build-dep emacs

Take a look on the repo first to make sure Emacs on master branch matches the above version requirement.

git clone git://git.savannah.gnu.org/emacs.git

./configure --with-native-compilation=aot --with-tree-sitter --with-gif --with-png --with-jpeg --with-rsvg --with-tiff --with-imagemagick --with-x-toolkit=lucid --with-json --with-mailutils

make clean

make -j8

sudo make install