Emacs

How to Use Emacs Themes

The default theme that comes with Emacs is not the best option you can use. Luckily, Emacs supports using different themes to customize how you want the appearance to be when utilizing this text editor. Throughout this post, we will discuss how to use the Emacs themes. We start by focusing on the default Emacs themes. Then, we cover how to install other themes by editing the Emacs init file to utilize better themes that align with your preferred style.

Two Ways on How to Use the Emacs Themes

When we open Emacs, the default theme is like the one in the following:

The previous theme is not the best appearance that you can enjoy when using the Emacs text editor. Here are two methods to customize this appearance and get better themes.

Method 1: Using the Default Emacs Themes

Installing the Emacs themes can be a hassle for some users. However, Emacs offers a few default themes to eliminate the need to install the other themes. Adding these themes is easy, but you are limited to only a few options.

To access these themes, press “M-x” and type “customize-themes”.

Once you press the “Enter” key, you will see the following window that shows all the default themes that you can use and the other settings options to help you work with the themes:

Let’s assume that we want to use the tango-dark theme. In that case, scroll down until your cursor selects tango-dark. You will notice an “X” that appears on its left to indicate that it is the highlighted theme. Press the “Enter” key, and you will immediately notice that the theme for your Emacs will change.

Our tango-dark theme will appear similar to the following output:

Although we learned the first way to use the Emacs theme, this change doesn’t persist when we restart Emacs. It is a temporary solution for changing the theme. To make it permanent, we must save the theme changes.

Scroll up the window to get to the option for “Save_Theme_Settings”. Highlight this option and press the “Enter” key to select it.

You will see a message which shows that your theme has been saved. With that, even after you restart Emacs, the selected tango-dark theme will be used until you disable it or set a new theme for your case.

Go ahead and exit or restart Emacs. Once you reopen it, you will verify that the selected theme is what is being used from the first welcome window like in our case.

Method 2: Using Other Themes

Apart from using the default Emacs themes, you can install the other themes. You must add a few lines in the Emacs initialization file to tell Emacs where to source the theme and what to do after sourcing it.

Let’s start by accessing the Emacs initialization file using the “C-x C-f” command. Then, type “.emacs” and press the “Enter” key.

The initialization file will open and contains similar contents to the one in the following. Notice how the custom-enabled theme is the tango-dark that we selected earlier.

We must edit this initialization file. The first step is to add the archive source and where to source the theme. For this case, we use the Melpa archive and we provide the link to the theme. Emacs references the provided link to install the package for the theme.

Feel free to use any theme that you want. We select the “gruvbox” theme available with the Melpa archive for our case. Add the lines in the following image to your init file and replace the archive, the achieve link, and the theme to suit your preference.

Once you have your initialization file edited correctly, save it by pressing “C-x C-s”. Then, you will get a similar message to the one in the following:

That’s it! Restart your Emacs for the new theme to take effect. Notice how our Emacs text editor now has a new and better theme than we previously had.

How to Disable the Emacs Theme

The last thing to learn is disabling a theme when you no longer require it. To disable an Emacs theme, access the init file as we did with method 2.

Once the file opens, add the “(disable-theme ‘theme-name)” command. In the following example, we disabled the tango-dark and gruvbox themes that we used in this post. Save the file and restart Emacs.

Conclusion

With Emacs, you can customize the appearance by adding themes to spice up things and give you a better user experience. There are two ways on how to use the Emacs theme. You can use the default Emacs themes or source the other themes from an archive. Both options are covered in this post. Moreover, we learned how to disable a theme. That’s it!

About the author

Denis Kariuki

Denis is a Computer Scientist with a passion for Networking and Cyber Security. I love the terminal, and using Linux is a hobby. I am passionate about sharing tips and ideas about Linux and computing.