anchor
Blog /  
Another Emacs setup (with GIFs) to enjoy Clojure

Another Emacs setup (with GIFs) to enjoy Clojure

December 8, 2023
->
25 min read

If you're here, you've likely heard of Emacs. Or just started learning it. Or you have nothing better to do than waste your time on one of the least user-friendly programs ever...

But wait!

If you're here, I want to tell you why Emacs іs more than just a text editor and how to enjoy this masterpiece (without wasting your days and nights).

<medium>Disclaimer:<medium> This brief tutorial describes the settings of the .emacs configuration file. It may help you enjoy Emacs and have a great time with Clojure (or another Lisp-family language). 

<medium>Disclaimer #2:<medium> The opinions and tips expressed do not necessarily reflect the view of other Emacsers. It’s not a guide on "how to craft text editor of my dreams" but rather my vision of why Emacs is worth trying and how to approach it in the best way. Feel free to discuss it and text me on Linkedin.

Is Emacs the answer?

Emacs was created based on the fundamental principle of freedom and made people appreciate the concept of software freedom.

Emacs Bee

People are free to choose what they want to buy, support financially, or fund the inventions they like. This freedom enables the implementation of ideas and solutions to enhance the human experience. People act as they choose. Sounds good, right?

However, the right to build doesn't exempt us from the need to purchase materials. Freedom is an idea, but practically acting as we choose, buying what we want, and realizing promising ideas requires some investments. Building a dream car will be expensive, and doing it yourself rarely surpasses the quality offered by the market's established technology. Building your dream house on your own is a more realistic option, though it can still be costly.

Car

Many things in this world limit us, but those few that don't are really exceptional. They empower us to bring to life all we imagine or desire and ultimately share it with like-minded individuals.

One of them is GNU Emacs, the extremely extensible editor.

But first things first. I welcome you to this less-than-perfect tutorial to:

  1. go back to the 90s
  2. get to know more about how to organize routine tasks
  3. throw your computer mouse out of the window

What does this tutorial require from you? Just patience, desire to learn new things, <s>salamander's tail, crystal ball, fairy dust, and tambourine</s>.

FAQ and tips before we start 

#1 Why Emacs shortcuts involve Ctrl?

Emacs is a rather old piece of Unix software. The keyboards used by Emacs developers at MIT AI Lab in the late 1970s differed from the ANSI and ISO layouts. The position of the Ctrl on the keyboard was another.

This is one of the main reasons why I often receive the same while sharing this delightful practice with developers: “Why is it so painful?” But things are never (almost never) as bad as they seem.

#2 How to remap CapsLock to Ctrl and enjoy Emacs?

Before we start learning the Emacs keyboard, let's remap CapsLock to Ctrl. This key swapping prevents you from accidentally breaking your finger(s) and undermining your motivation.

If you are a Windows user, use the SharpKeys free tool to remap your keyboard.

If you are a GNU/Linux user:

  • If you are a GNOME 3+ user, then run Gnome Tweeks. Find a keyboard Settings, and remap the CapsLock button with the Left Ctrl.
  • If you have ANY other environment, put this command: <mono>setxkbmap -option "ctrl:nocaps"<mono> into one of your startup scripts. For example, <mono>.bashrc<mono>, or <mono>.xprofile<mono>...

#3 How to set keyboard latency?

Another tip for smoother typing: open the terminal and change the keyboard delay/repeat rate. Put the next command to the terminal

$ xset r rate 200 130

200 — the delay between pressing a key on the keyboard and a symbol appearing on the screen

130 — the keyboard repeat rate

Both values should be adapted to your hardware.

#4 How to get rid of nausea at the sight of default Emacs?

Put a Fiat Multipla, Nissan Juke, or any car made by the USSR on your desktop wallpaper. After that, when you see Emacs, you should feel better.

Emacs shortcuts

Emacs Shortcuts

Once you have remapped Ctrl, open Emacs, and let’s start with shortcuts and aliases.

{{t-c1="/custom-block-to-blog/three-page"}}

Movement is probably the hardest part and can be scary and daunting. Anyway, give your brain at least 15 minutes to deal with the text in the open buffer. The key is to become accustomed to using it regularly. With practice, it can become second nature and even an exciting activity <s>for those who enjoy accidentally hitting their toe on the corner of the bed.</s>

I recommend you to familiarize yourself with the Emacs Reference Card. Check the list of all default Emacs shortcuts to enhance your Emacs experience.

The amazing community and powerful knowledge base can help you find many tips on how to deal with simple editing routines, and, what is even more important, how to customize Emacs. 

Hint: You will be amazed at how many out-of-the-box things Emacs already has; you just need to bind them to hotkeys.

Good habits make a good man

Movements

{{t-c2="/custom-block-to-blog/three-page"}}

Movements gif

Deleting / Coping and other editing hints 

{{t-c3="/custom-block-to-blog/three-page"}}

Deleting/Coping gif

In most editors, when we want to remove a symbol, we typically start at the end of the text we are going to delete and press the Backspace key or Ctrl+Backspace. This also applies to Emacs, but as an alternative (which I strongly recommend), you can delete text in the forward direction using <mono>C-k<mono>, <mono>C-d<mono> or <mono>M-d<mono>. Keep in mind that in Emacs, deleting text is a crop operation, which can be annoying: it saves the deleted text in the system clipboard, clearing previously copied text from the buffer.

Searching

{{t-c4="/custom-block-to-blog/three-page"}}

Searching

In Emacs, editing is closely linked to the search process. If you need to edit the word "escape", which is four lines above your current cursor position, you have two options:

1. press <mono>C-p<mono> to move up, and then <mono>C-b<mono>

2. the quickest method is to use <mono>C-r<mono> (searching backward); hold <mono>Ctrl<mono> and press <mono>r<mono> repeatedly until you find the "escape" word you want to edit. Try this for faster navigation in Emacs.

Window management

A quick note about Emacs terminology:

<medium>Buffer<medium> in Emacs contains the content you edit/view/modify. It is similar to what other systems refer to as a file, document, workspace, or editor. 

When you open a file, Emacs buffer creates its clone and opens it for editing. Each buffer may be wrapped with Major/Minor mode. You can also open a system buffer (which doesn't display any File or Document) and use it, for example, for customizing or debugging.

For instance, <mono>customize-theme<mono> opens a system buffer, or <mono>*Messages*<mono> buffer that outputs Emacs commands. System buffer (in most cases) has asterisks <mono>*<mono> around its name, like <mono>*Custom Themes*<mono>. It’s just a name without any special effects on the user experience.

Window management

<medium>Window<medium> is a buffer container that can be shrunk, closed, or swapped. Windows can display parts of different buffers or different parts of a single buffer.

<medium>Frame<medium> is a screen object provided by X-Org or by Windows (referred to as a "window" in the Windows ecosystem). Emacs can split a frame into multiple windows.

{{t-c5="/custom-block-to-blog/three-page"}}

Window managmenent gif

Frame management

{{t-c6="/custom-block-to-blog/three-page"}}

Font size

and my favorite

{{t-c7="/custom-block-to-blog/three-page"}}

Font size giff

System keys

{{t-c8="/custom-block-to-blog/three-page"}}

System keys

Ok, that's all you need to know.
Now, let's configure your Emacs.

Getting help without leaving Emacs

Getting help without leaving Emacs

Emacs offers a wide range of help functions. To access them, press <mono>F1<mono> or <mono>C-h<mono> Emacs will then wait for your next key/shortcut to open a help-buffer, which will assist you with the problem you face. I recommend using <mono>C-h C-h<mono> to open the buffer that will redirect you to the page you are searching for. Alternatively, you can use more specific help views:

{{t-c9="/custom-block-to-blog/three-page"}}

Compiling inside Emacs

Scripts and the large internal mechanics (configuration, etc.) are implemented with the Emacs Lisp Compiler. Modifying Emacs behavior by editing its source code could be a challenging task. Fortunately, the creators of Emacs built a compiler within the program, allowing users to compile something directly within their files. This means you can enhance Emacs behavior and change its appearance on-the-fly. But how? 

To add a function to the global namespace or perform calculations, open an Emacs Lisp buffer. Create a file with the <mono>.el<mono> extension or use the existing scratch buffer. Then, write your code and evaluate it using <mono>C-x C-e<mono>.

Compiling inside Emacs

If you are not going to compile a specific part and want to streamline the process, use <mono>C-M-x<mono>.

compiling schema

Alternatively, you can evaluate the entire currently opened buffer by using <mono>M-x eval-buffer<mono>. 

Start with Emacs configuration

First, create a <mono>~/.emacs<mono> file in your home dir or open an existing one.

Place the following text at the top of the file. The package is necessary for loading packages from remote repositories and compiling those already downloaded from the ~/.emacs.d/elpa folder.

(require 'package)
(load "package")
(package-initialize)

Next, set a list of repositories. Let’s organize them in a variable. We will use it a few lines later to streamline config file management.

(setq repository-list
      '(("melpa" . "https://melpa.org/packages/")
	("gnu" . "https://elpa.gnu.org/packages/")
	("org" . "http://orgmode.org/elpa/")
	;; ("melpa-stable" . "https://stable.melpa.org/packages/")
	))

In the default configuration, Emacs doesn't save selected themes, resetting the user's choice with each startup. Therefore, set the <mono>custom-safe-themes<mono> on true. Make it the first step during program startup.

Note! In ELisp, only <medium>'nil<medium> is real <medium>false<medium> value. <medium>True<medium> value is <medium>t<medium> symbol.

After setting this variable, the program will no longer ask you about the previously chosen theme. Variables related to Emacs built-in functionality can be placed either before <mono>custom-set-variables<mono> macros (using <mono>setq<mono>) body

(setq custom-safe-themes t)

or inside it.

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they wont work right.
 '(custom-safe-themes t))

The next .emacs lines should be: <mono>custom-set-variables<mono>, <mono>custom-set-faces<mono>. These are macros where Emacs keeps and controls all settings. It offers a wide range of setting-variables, such as previously mentioned <mono>custom-safe-themes<mono> which allows you to tailor Emacs behavior to your preferences.

As an Emacs user, you can set variables directly within your <mono>.emacs<mono> file. However, Emacs has a kind of graphical interface that simplifies the process of setting variable values. For example, let’s set <mono>custom-safe-themes<mono> again:

  1. Press <mono>M-x<mono>
  2. Type <mono>customize-variable<mono>
  3. Type <mono>custom-safe-themes<mono> and press <mono>Enter<mono>

Now you see the customizing view. Open any parameter, make your edits, and press <mono>C-x C-s<mono> to save all changes to <mono>custom-set-variables<mono>.

Start with Emacs configuration

As a result, the corresponding variable is recorded in the <mono>custom-set-variables<mono> macros body in <mono>.emacs<mono> file. Open to confirm that Emacs has saved the changes.

Emacs settings are just simple variables. We should format our <mono>custom-set-variables<mono> as follows:

(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful. 
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work correctly. '(custom-safe-themes t)
 ‘(package-archives repository-list))

All lines from <mono>(custom-set-variables ...)<mono> to the very end allow you to style Emacs and configure packages according to your needs. 

Copy and paste the code into the appropriate sections of your .emacs file and evaluate it using the <mono>C-M-x<mono> (CTRL+ALT+x) shortcut.

So go on!

Emacs UI, or Let’s set default behavior

Stay a true keyboard warrior and don't touch your mouse! Let’s get rid of unnecessary UI components that require mouse interactions.

Hint: The scrollbar steals 0.3 mm of your screen space, steals 1 second to place your hand on the mouse, steals precious time you could spend with your children. What will it steal next, maybe your wife's heart? Stop it. This shouldn't happen, be wise and drop the scrollbar.

(scroll-bar-mode -1)
(tool-bar-mode   -1)
(menu-bar-mode   -1)
default behavior

Unlike most text editors, Emacs doesn't display line numbers by default. To display them, enable the corresponding mode

(global-display-line-numbers-mode 1)

either

(setq column-number-mode t)

to add the current cursor line and column position to the mode-bar.

mode-bar

Threshold settings force Emacs to open another buffer in a horizontally split window. If you are using a standard Full HD monitor (or smaller), just keep standard Emacs behavior and delete the following lines

(setq split-width-threshold 0)
(setq split-height-threshold nil)

Emacs creates backups the first time you create a file and when you save it. Autosaving, backuping, <s>seat belts</s> make our life so boring and predictable. So let's disable them (and use <mono>C-x C-s<mono> for saving)

(setq make-backup-files nil)

Integrate the Emacs clipboard with the system XOrg clipboard (only for Linux users)

(delete-selection-mode t)
(transient-mark-mode t)
(setq x-select-enable-clipboard t)

The <mono>C-z<mono> shortcut freezes the frame, enabling you to return to the shell where the program was invoked. But in practice, it can painfully disrupts the programming flow <s>and developers' mental health</s>. 

We will unpin and reuse it for further customizations.

(global-unset-key (kbd "C-z"))

Switching between split windows in Emacs can be frustrating for beginners. We can resolve it by remapping this highly needed functionality to other keys.

(defun other-window-back ()
  (interactive)
  (other-window -1))

<mono>C-x o<mono> replacement

(global-set-key (kbd "C-o") 'other-window) 
(global-set-key (kbd "C-i") 'other-window-back)

Emacs Packages

What is an Emacs package? In short, it’s Emacs Lisp code that integrates or overrides specific Emacs behaviors or provides public functions for further use. You can find it in the global namespace by pressing <mono>M-x<mono>.

After installing the <mono>dashboard<mono> package, press <mono>M-x<mono> and search for the <mono>dashboard-open<mono> function, which instantly opens the *dashboard* buffer (it's a public interactive function provided by the package after loading). 

Emacs Packages

<medium>How to install Emacs packages?<medium>

Before we start, let’s review the installation case for a specific package – the <mono>dashboard<mono> extension, which replaces our welcome buffer with a new, more organized view. An indispensable thing, believe me :)

{{t-list="/custom-block-to-blog/three-page"}}

Installation code

<medium>Few words about 'use-package'<medium>

As mentioned, <mono>use-package<mono> helps us organize configurations, reduce Emacs startup time, and control the loading process.

(use-package <package-name-symb>)

The previous declaration compiles code from local repositories and puts <package-related> functions in the common Emacs Lisp namespace, equivalent to the <mono>require<mono> emacs function <mono>(require <package-name-symb>)<mono>

Use-package provides even more control with the following keywords:

  • <mono>:ensure<mono> – if the package is not installed, it will be downloaded and installed into the local repository.
  • <mono>:init<mono> – the next code segment will be evaluated before the corresponding package is compiled.
  • <mono>:config<mono> – the next code segment will be evaluated after the package is loaded.
  • <mono>:defer<mono> | <mono>:demand<mono> (t|nil) – both rely on the <mono>autoload<mono> Emacs feature. Some installed packages can be quite complex, consisting of dozens of heavy files. For example, Major mode can contain hundreds of functions that are not required to be compiled and loaded immediately. You don't need a full list of java-mode interactive functions if you plan to work with Clojure files. Package authors mostly use the <mono>autoload<mono> feature for the mode-toggle function to make it visible (when loading an Emacs package, only functions marked as <mono>autoload<mono> are added to the common namespace and can be invoked using M-x; the other functions are not loaded until you manually invoke <mono>java-mode<mono>, as an example). :defer and :demand keys gіve us control over this process.
  • <mono>:defer<mono> – defers the evaluation of the entire library until you use it directly. In most cases, you don't need to use it manually.
  • <mono>:demand<mono> – opposite to the :defer, it compiles the entire package with all functions and makes them available in the public namespace. It's useful for packages you need to be ready during the startup process of Emacs.
  • <mono>:bind<mono> – a pleasant way to declare keybindings.
  • <mono>:after<mono> – provides control over the sequence of package loading.
  • <mono>:hook<mono> – a simplified hook declaration, replacing the traditional approach with add-hook macros.
use package

For full documentation with more examples, visit this GitHub page. 

About Modes & Hooks

A mode is code that modifies the default behavior. In Emacs, we have only two modes:

  • <mono>Major<mono> is a 'parser' for a specific language with its unique semantics. Major mode code describes how we work within the buffer. For example, the clojure-mode package is a Major mode.
  • <mono>Minor<mono> complements the Major mode and offers additional functionality beyond the currently edited mode. For example, yafolding brings code folding functionality to Emacs.

The problem with a Minor mode is that it requires manual activation from the command-menu (M-x) for the specific buffer you're using. It can’t be automatically activated for all buffers.

  • <mono>Hook<mono>. To avoid repeatedly activating a mode, we need to add Hooks for the Major mode in which we use specific Emacs packages. Hence, we need to decide where and when to enable it on a case-by-case basis for the particular buffer or Major mode.

For example, it comes in handy when you're editing a large file with 400 lines of Clojure code, which can be quite challenging to analyze. Here, we can use <mono>M-x yafolding-mode<mono> and our current Keymap will be enhanced with additional bindings (<mono>&lt;<span>DEL</span>&gt;<mono> is Enter). Once the Major mode is enabled, hooks are executed. For example, when you open a Clojure file, Emacs automatically runs the <mono>clojure-mode<mono> and then triggers a <mono>clojure-mode-hook<mono> containing a list of user-defined hooks.

<mono>C-&lt;<span>DEL</span>&gt;<mono> – yafolding-toggle-element shortens large code inside brackets (...)

<mono>C-S-&lt;<span>DEL</span>&gt;<mono> – yafolding-toggle-all performs almost the same as a previous one but applies to entire top level function or expression.

Anyway, if your editing habits include this experience, you might find it frustrating to enable this mode every time.

Emacs addresses this frustration by adding a <mono>Hook<mono> function in the Major mode, which is automatically invoked every time you open the buffer. Here is an example to illustrate this:

(defun my-clojure-hooks ()
  (yafolding-mode +1))

(add-hook 'clojure-mode-hook 'my-clojure-hooks)

Once you've opened the Clojure buffer, enable <mono>yafolding-mode<mono>. You can also do it using an inline lambda without defining a dedicated function.

(add-hook 'clojure-mode-hook (lambda ()
                                    (yafloding-mode +1)))

Note! Each Minor mode has a different approach for self-enabling or disabling (by using 't as True or a number greater than 0). To learn how to do it correctly, use <mono>C-h f<mono> (M-x describe-function) shortcut and enter the function name you are searching for.

Supplied arguments MUST be described. 

The enabled Minor/Major is indicated on the Modebar.

<medium>Read more:<medium> https://www.gnu.org/software/emacs/manual/html_node/elisp/Modes.html

Install and configure packages

Now, that’s enough text. Let's add packages to our EMACS! 

<medium>Dashboard<medium>

An extendable Emacs buffer that displays useful information during the Emacs startup. It lists "last used files", opened projects, bookmarks, and more.

<medium>Read more:<medium> https://github.com/emacs-dashboard/emacs-dashboard

(use-package dashboard
  :demand t ;; compile whole library!
  :ensure t ;; download if it doesn't already installed
  :init
   agenda
  (setq dashboard-week-agenda nil)
   other
  (setq dashboard-set-heading-icons nil)
  (setq dashboard-set-file-icons nil)
  (setq dashboard-page-separator "\n\n")
  (setq dashboard-set-init-info nil)
  (setq dashboard-center-content t)
  (setq dashboard-show-shortcuts t)
  (setq dashboard-set-footer nil)
  (setq dashboard-set-navigator t)
  (setq dashboard-items '((recents  . 15)
			  (projects . 20)
			  (bookmarks . 5) 
			  (agenda . 100)))
  :config
  (dashboard-setup-startup-hook))

<medium>Helm<medium>

mem

Helm is Emacs incremental completion and selection narrowing framework (sound like a dissertation topic, right). It comes in handy when you finally decide to replace the built-in <mono>M-x<mono> Emacs action, which can be hard to use because of non-intuitive standards.

Helm contains dozens of extensions that add extra functionality to Emacs.

<medium>Read more:<medium> https://github.com/emacs-helm/helm

(use-package helm
  :ensure t
  :demand t
  :bind (("M-x" . helm-M-x)
	 ("C-x C-f" . helm-find-files)
	 ("C-." . helm-imenu-in-all-buffers)
	 ("C-x b" . helm-buffers-list)
	 ("C-x r b" . helm-filtered-bookmarks))
  :config 
  (helm-mode 1))

<medium>Projectile<medium>

Emacs doesn't keep track of opened folders, and it’s too much even for me 😁

You have two methods to save a Folder as a project directory:

1. Use <mono>M-x<mono> <mono>projectile-add-known-project<mono> (select the project directory)

2. Add an empty file <mono>.projectile<mono> to the directory <mono>cd .... & touch .projectile<mono>

The dashboard extension should display the available projects you’ve added.

Bind Projectile to a shortcut, like <mono>C-c p<mono>. The following shortcuts will come in handy:

{{t-c12="/custom-block-to-blog/three-page"}}

<medium>Read more:<medium> https://github.com/bbatsov/projectile

(use-package projectile
  :ensure t
  :init (projectile-mode +1)
  :bind (:map projectile-mode-map
	      ("C-c p" . projectile-command-map)))

Let's look at some examples. I’ve created a "dummy-project" directory and filled it up with the following commands:

# create some dummy directory
mkdir “dummy-project”
# get inside folder 
cd dummy-project
# to create project from that directory, 
# just make empty projectile file. 
touch .projectile 
# dot from start make it file invisible 
# let create some README.md
touch README.md 
# and two different samples Clojure libraries
# using Leiningen 
lein new app dummy-lib-1
lein new app dummy-lib-2
# finally open any file through the unbeatable Emacs
# and use any of the shortcuts i mentioned.
projectile

<medium>helm-projectile<medium>

The Helm wrapper, together with Projectile, enhances Projectile’s UI and makes code search more user-friendly by grep, ag,...

(use-package helm-projectile
  :ensure t
  :after (helm projectile)
  :init (helm-projectile-on))

<medium>helm-ag + ag<medium>

For searching within a project or system, I recommend using <mono>SilverSearch<mono>, a faster alternative to <mono>grep<mono>. It requires the <mono>projectile<mono> package to get started.

<medium>Read more:<medium>
https://github.com/ggreer/the_silver_searcher
https://github.com/emacsorphanage/helm-ag

(use-package ag
  :ensure t)
(use-package helm-ag
  :ensure t
  :after (helm projectile ag)
  :custom
  (helm-ag-base-command "ag --hidden --nocolor --nogroup --ignore-case"))

<medium>Multiple-Cursors<medium>

Multiple cursors for Emacs, a beautiful and simple tool for multiline editing. 

<medium>Read more:<medium> https://github.com/magnars/multiple-cursors.el

(use-package multiple-cursors
  :ensure t
  :bind (("C->" . mc/mark-next-like-this)
	 ("C-<" . mc/mark-previous-like-this)
	 ("C-c C-<" . mc/mark-all-like-this)
	 ("C-S-<mouse-1>" . mc/add-cursor-on-click)))
Cursors

<medium>Visual-Regexp<medium>

Visual Regular Expression editing is one of my favorite tools (I like it even more than multiple-cursor)

This package doesn't use ANSI regexp, not so easy :) Emacs regexp is a bit more complex, but it offers greater flexibility and speed for replacing or modifying content.

Press <mono>C-Spc<mono> and mark the segment you're working with, then press <mono>C-c r<mono>.

You'll see the modeline ready for your pattern. Write the text you want to replace, press Enter, and then enter the replacement text.

Here is an example of Regexp Editing

(list "Steven12" "Bruse30")

To mark the entire list, use <mono>C-Spc<mono> from the open bracket to the end of the line, and press <mono>C-c r<mono>. In the opened minibuffer, write the following Emacs Regexp Pattern:

"\([[:alpha:]]+\)\([[:digit:]]+\)"

Press Enter, and write replacement pattern <mono>"\1('\2')"<mono>

Finally, apply the changes, and you will see 

(list "Steven('12')" "Bruse('30')")
Visual regex

If you made a mistake, press <mono>C-S-&lt;<span>minus</span>&gt;<mono> to undo the changes and reopen <mono>C-c r<mono>. Use <mono>M-(n/p)<mono> keys to navigate through the user history, accessible within the minibuffer.

<medium>Read more:<medium>
https://www.emacswiki.org/emacs/RegularExpression
https://github.com/benma/visual-regexp.el

(use-package visual-regexp
  :bind (("C-c r" . vr/replace)
         ("C-c q" . vr/query-replace)))

<medium>Auto-Complete<medium>

A simple context helper popup. Plug and Play; no extra configuration is needed.

<medium>Read more:<medium> https://github.com/auto-complete/auto-complete

(use-package auto-complete
  :init (ac-config-default))

<medium>Magit<medium>

One of the most powerful tools in the Emacs universe, Magit is a highly flexible version GUI control.

{{t-c11="/custom-block-to-blog/three-page"}}

<medium>Read more:<medium> https://magit.vc

(use-package magit
  :ensure t
  :defer 3
  :bind (("C-x g" . magit-status)))

<medium>Treemacs<medium>

Files and projects explorer.

{{t-c12="/custom-block-to-blog/three-page"}}

<medium>Read more:<medium> https://github.com/Alexander-Miller/treemacs

(use-package treemacs
  :ensure t
  :defer t
  :config
  (progn
    (setq treemacs-width 50)
    (treemacs-follow-mode t)
    (treemacs-filewatch-mode t)
    (treemacs-fringe-indicator-mode 'always))
  :bind
  (:map global-map
	("<f9>"   . treemacs)
	("<f10>"   . treemacs-bookmark)))

<medium>Recentf<medium>

Keeps a list of recently accessed files in a special file located in the .emacs.d/ directory. 

<medium>Read more:<medium> https://wikemacs.org/wiki/Recentf

(use-package recentf
  :bind (("C-c C-b" . recentf-open-files)
         ("C-c C-r" . ido-recentf-open))
  :config (setq recentf-max-menu-items 30
                recentf-max-saved-items 50)
  (recentf-mode 1))

<medium>Reverse-Im<medium>

For example, if you’re using a Ukrainian keyboard, <mono>С-M-ї<mono> may result in an unknown command message in the minibuffer. In such cases, you can use the <mono>Reverse-Im package<mono> to remap Ukrainian <mono>ї<mono> key to <mono>]<mono>.

<medium>Read more:<medium> https://github.com/emacsmirror/reverse-im

(use-package reverse-im
  :ensure t
  :custom
  (reverse-im-input-methods '("ukrainian-computer"))
  :config
  (reverse-im-mode t))

<medium>Which-Key<medium>

Even the basic Emacs keymap is hard to keep in mind. Just press <mono>C-c<mono> and wait a moment — Emacs will display a buffer with all keys and shortcuts.

Which-Key

Note! Enable <mono>Which-Key<mono> mode after <mono>Helm<mono> is loaded.

<medium>Read more:<medium> https://github.com/justbur/emacs-which-key

(use-package which-key
  :ensure t
  :after (helm)
  :config (which-key-mode))
Note! Enable Which-Key

<medium>Sudo-Edit<medium>

This package allows you to edit files as a root user. For example, quick modification <mono>/etc/resolv.conf<mono>

<medium>Read more:<medium> https://melpa.org/#/sudo-edit

(use-package sudo-edit
  :ensure t
  :bind (("C-x x f" . sudo-edit-find-file)
	 ("C-x x e" . sudo-edit)))

<medium>Lisp mode hook<medium>

Now, let's configure Emacs for a Lisp programming environment. First, you need to learn some keybindings to work with parentheses and quotes (in Emacs, it’s called "s-expression"): <mono>''<mono>, <mono>()<mono>, <mono>[]<mono>, <mono><><mono>, <mono>""<mono>.

{{t-c13="/custom-block-to-blog/three-page"}}

Lisp mode hook

<medium>Paredit<medium>

Meet Paredit, a framework that simplifies working with parentheses. Here's a list of all available shortcuts: https://github.com/joelittlejohn/paredit-cheatsheet

but for MOST cases, the following next three keybinds should be enough:

{{t-c14="/custom-block-to-blog/three-page"}}

Paredit

<medium>Read more:<medium>
https://paredit.org
https://github.com/joelittlejohn/paredit-cheatsheet

(use-package paredit
  :ensure t)

<medium>flycheck-clj-kondo<medium>

An embedded Emacs tool that integrates with the language linters you prefer. This explains how flycheck should work with the <mono>clj-kondo<mono> CLI tool (make sure it's installed on your system)

<medium>Read more:<medium> https://github.com/clj-kondo/clj-kondo

(use-package flycheck-clj-kondo
  :ensure t)
flycheck

<medium>Rainbow-delimiters<medium>

Highlight brackets according to their deps and the color themes you choose. This mode makes code easier to analyze.

(use-package Rainbow-delimiters
  :ensure t)

<medium>Lisp modes<medium>

Ok, let's configure the Lisp mode hook. This simple function enables additional minor modes every time the mode-hook mentioned in the <mono>defun<mono> name is triggered.

(defun lisp-mode-hook ()
  "enable some plugins after init mode"
  (paredit-mode)
  (prettify-symbols-mode)
  (rainbow-delimiters-mode))

<medium>elisp-mode<medium>

A built-in Emacs mode for working with Elisp code. This mode is also covered by the lisp-mode-hook.

(use-package elisp-mode
  :defer t
  :config (add-hook 'emacs-lisp-mode-hook 'lisp-mode-hook))

<medium>prettify-symbols-mode<medium>

This fantastic mode enables us to replace the standard text representation of identifiers/symbols with aesthetically pleasing ones (several ASCII characters can be replaced with a single Unicode character).

It helps keep the code more understandable and pretty. For example, when you write <mono>lambda<mono>, it gets replaced with the <mono>λ<mono> symbol, which saves space and looks attractive. :)

Not a bad idea! As well as replacing some functions with math symbols.

(defun clojure-lisp-pretty-symbols ()
  "Make some word or string show as pretty Unicode symbols"
  (setq prettify-symbols-alist
	'(;; ("lambda" . ?λ)
	  ("fn" . ?λ)
	  ;; Ƒ Ɣ ƒ Ƭ Ʃ Ƴ ƴ ɀ ℎ ℰ ℱ Ⅎ ℳ ℓ ⊂ ⊃ ⋂ ⋃ ∩ ∪ ∈ ∊ ∋ ∍ ∘ ⇩ ⇘ ⯆ ⯅ 🭶 ⯇ ⯈
	  ;; Greek alphabet 
	  ;; Α α, Β β, Γ γ, Δ δ, Ε ε, Ζ ζ, Η η, Θ θ, Ι ι, Κ κ, Λ λ, Μ μ, Ν ν, 
	  ;; Ξ ξ, Ο ο, Π π, Ρ ρ, Σ σ/ς, Τ τ, Υ υ, Φ φ, Χ χ, Ψ ψ, Ω ω
	  ;; ("->" . ?→)
	  ;; ("->>" . ?↠)
	  ;; ("=>" . ?⇒)
	  ("defmulti" . ?Ƒ)
	  ("defmethod" . ?ƒ)
	  ("/=" . ?≠)   ("!=" . ?≠)
	  ("==" . ?≡)   ("not" . ?!)
	  ("<=" . ?≤)   (">=" . ?≥)
	  ("comp" . ?υ) ("partial" . ?ρ))))

Using <mono>lisp-mode-hooks<mono> within <mono>clojure-mode-hook<mono> is a good idea because Clojure inherits the full usability of Emacs Lisp.

(defun clojure-mode-hook ()
  (clojure-lisp-pretty-symbols)
  ;; --
  ;;  These couple of lines are optional if you
  ;; want to use linter in EVERY Clojure buffer.
  ;;  You also can set (flycheck-mode nil) and
  ;; enable it only in buffer you need following
  ;; the next steps:
  ;;   M-x flycheck-mode
  (add-to-list 'flycheck-checkers 'clj-kondo-clj)
  (flycheck-mode t)
  ;; --
  (lisp-mode-hook))

<medium>Clojure-Mode<medium>

The most popular package for parsing and working with Clojure structures. It includes dozens of helper functions: <mono>clojure-sort-ns<mono>, <mono>clojure-thread<mono>, etc.

<medium>Read more:<medium> https://github.com/clojure-emacs/clojure-mode

(use-package clojure-mode
  :ensure t
  :defer t
  :config (add-hook 'clojure-mode-hook 'clojure-mode-hook))

<medium>Cider<medium>

Ok, now we are getting to the stellar package with the sparkling name :) Cider greatly enhances the Clojure experience. It can work with different backends, as well as babashka. You can run Cider with or without project setup.

Let quickly discover Cider shortcuts.

In Emacs, the term <medium>at point<medium> refers to the cursor position under a <medium>symbol<medium> you want to find documentation or definition for.

{{t-c15="/custom-block-to-blog/three-page"}}

cider-eval

What if you want to stop the evaluation you started before dropping the result? Just interrupt it; however, this will not save you from getting stuck if you try to kill the infinite loop.

{{t-c16="/custom-block-to-blog/three-page"}}

evalution


{{t-c17="/custom-block-to-blog/three-page"}}

The fusion of all the wonderful editing opportunities with Cider's on-the-fly evaluation is implemented in the <mono>eval-and-replace<mono> function. It's a Swiss knife in your <s>survival</s> editing kit. This functionality enables you to write Clojure code that can write another Clojure code for generating examples and trivial code segments in loops and sculpting Clojure data structures — almost as if you are forming clay vessels.

All this, together with pretty printing functionality, brings programmers closer to art, where they can find joy and peace during the creation process.

{{t-c18="/custom-block-to-blog/three-page"}}

editing kit gif

Documentation is another big advantage of Cider. You can get a dry doc with just a description, print all examples from ClojureDocs in minibuffer to quickly clone one of them, or find quirky examples to test something locally.

{{t-c19="/custom-block-to-blog/three-page"}}

clojure-doc gif

As programmers spend most of their time learning code, it should be done in the fastest and most effortless way possible.

{{t-c20="/custom-block-to-blog/three-page"}}

le`

One more great thing about Cider is its debugging facilities. You have the flexibility to use its debugger according to your needs and preferences in various cases.

{{t-c21="/custom-block-to-blog/three-page"}}

Flexible debugging, additional macros <mono>#dbg<mono>, <mono>#break<mono>, slight hints for variables in Enlighten mode, a built-in Trace mode, handy inspector — all this and more makes Cider an absolute gem!

<medium>Read more:<medium>
https://docs.cider.mx/cider/index.html
https://docs.cider.mx/cider/usage/code_evaluation.html#keybindings
https://docs.cider.mx/cider/usage/working_with_documentation.html#keybindings
https://docs.cider.mx/cider/debugging/debugger.html
https://docs.cider.mx/cider/debugging/inspector.html
https://docs.cider.mx/cider/debugging/enlighten.html
https://docs.cider.mx/cider/debugging/tracing.html

(use-package cider
  :ensure t
  :bind (("C-M-S-i" . cider-inspect-last-result))
  :init
  ;; if you want to connect to some
  ;; already known front/back repl
  ;; you can add it known-endpoints
  ;; (<alias> <host> <nrepl-port>)
  (setq cider-known-endpoints
	'(("my-nrepl-back" "0.0.0.0" "3012")
	  ("my-nrepl-front" "0.0.0.0" "8333")
	  ("my-local-babashka" "0.0.0.0" "1667")))
  :config
  (defun presonal-cider-mode-hook ()
    ;; manually disable auto-complete popup
    (auto-complete-mode -1)
    ;; and replace it by the company popup
    (company-mode 1))
  :hook (cider-mode . presonal-cider-mode-hook))

<medium>Optional Packages<medium>

These packages allow you to skip the configuration as they represent tools or minor modes needed mostly for the current buffer you're working on.

One of the key benefits of Emacs packages is their optionality. Not all of them are mandatory, not all require configuration, and not all are auto-loaded when Emacs starts up.

Emacs supports a limited number of programming languages by default. While it can display .txt, .el, .py and Makefile files, it's not so good with Dockerfile syntax, YAML, or TypeScript source files.

To address this, you can manually install support for these languages using <mono>package-install<mono> or <mono>(use-package yaml-mode :ensure t)<mono>. The <mono>:ensure<mono> keyword downloads the package if it doesn't already exist in your local storage.

Find more here https://github.com/emacs-tw/awesome-emacs

Note! There are thousands of user scripts hosted in (m)elpa repositories and GitHub that enable you to do even more interesting things.

<medium>Docker<medium>

A UI for managing Docker.
Read more: https://github.com/Silex/docker.el

(use-package docker
  :ensure t)

<medium>Dockerfile-Mode<medium>

A Dockerfile Major mode.
Read more: https://github.com/spotify/dockerfile-mode

(use-package dockerfile-mode
  :ensure t)

<medium>Daemons<medium>

A system.d UI for Linux users. It will come in handy, for example, when you need to restart the MySQL daemon without leaving Emacs.
Read more: https://github.com/cbowdon/daemons.el

(use-package daemons
  :ensure t)

<medium>Markdown-Mode<medium>

A feature-rich mode for editing .md files. 
Read more: https://jblevins.org/projects/markdown-mode/

(use-package markdown-mode
  :ensure t)

<medium>Rainbow-mode<medium>

This mode colorizes color names in buffers. After enabling it in any buffer, you can easily find hex color codes (like <mono>#8432ff<mono>) and see the associated colors.

You can enable this mode like many other M-x rainbow modes. It will immediately paint your buffer. You can also set up a hook for a specific Major mode.

However, there is another way to use colorization in Emacs. You can enable some modes using file variables pinned at the top of the file, in a comment block like this:

 -*- mode: clojure; mode: rainbow; mode: yafolding -*-

After opening the file, the buffer will enable all three mentioned modes.

Read more:
https://github.com/emacsmirror/rainbow-mode
https://www.gnu.org/software/emacs/manual/html_node/emacs/Specifying-File-Variables.html

(use-package rainbow-mode
  :ensure t)

<medium>Olivetti<medium>

A configurable minor mode that automatically centers the content and balances window margins, with adjustable workspace width.

It's particularly useful for writers, as it solves the problem of 'floating' text.

Read more: https://github.com/rnkn/olivetti

(use-package olivetti
  :ensure t)

<medium>Yafolding<medium>

Enables code-folding. 

After enabling it, go into some brackets and press <mono>C-Enter<mono>. You will see <mono>(...)<mono> rolled code block.

Read more: https://github.com/emacsorphanage/yafolding

(use-package yafolding
  :ensure t)

<medium>Focus<medium>

This mode enhances live coding presentations by highlighting the code under the cursor while dimming the rest of the code.

Read more: https://github.com/larstvei/Focus

(use-package focus
  :ensure t)

<medium>TLDR<medium>

Emacs UI for great Linux Python utils.

Read more: https://github.com/kuanyui/tldr.el

(use-package tldr
  :ensure t)

Emacs Themes

It's a matter of personal taste, but here I'll share my favorite themes. I don't recommend installing them with <mono>use-package<mono> as it will consume space in your configuration without being necessary for startup loading. You can install themes using <mono>M-x package-install<mono>.

<medium>chyla-theme<medium> - a white/green theme I prefer a lot
<medium>sublime-themes<medium> - a pack of light and dark themes
<medium>cyberpunk-theme<medium> - a black theme with high contrast
<medium>dracula-theme<medium> - well-known to all
<medium>spacemacs-theme<medium> - light and dark theme from Spacemacs
<medium>twilight-bright-theme<medium> - one of the most beautiful ways to use light themes

To select a theme, enter <mono>M-x customize-themes<mono>. A buffer will open with a long list of themes you can change without leaving Emacs.

But what if you used to change themes based on the time of day (dracula, exotica themes), your playful mood (nano theme), or those special moments of writing about how deep your love for GNU is (eink, poet, eziam... themes). Let's satisfy this little whim with a custom script that provides us with the best way to change the look of Emacs by simply pressing a button or shortcut.

(defun toggle-theme (theme)
  (progn
    (mapcar (lambda (thm) (disable-theme thm)) custom-enabled-themes)
    (load-theme theme)))

(global-set-key (kbd "<f5>") (lambda () (interactive) (toggle-theme 'dracula)))
(global-set-key (kbd "<f6>") (lambda () (interactive) (toggle-theme 'chyla)))

Use <mono>F5<mono> or <mono>F6<mono> to switch between your preferred themes (e.g., Dracula, my personal favorite). Unlike other code in this tutorial, this can be directly placed in your .emacs file.

<medium>Custom Font<medium>

The small function <mono>set-my-custom-font<mono> globally changes the main font. It is a good example of how to write functions and organize Emacs customization.


(defun set-my-custom-font (&rest args)
  "Set 'default face font.
   :family - String font name
   :height - (default 110) String font size
   :wieght - (default 'normal) Symbol can be 'bold | 'normal | 'italic
   :width  - (default 'normal) Symbol.

  Example
   (riser/set-my-custom-font
    :family \"Source Code Pro\"
    :height 130)

  See also
    https://www.gnu.org/software/emacs/manual/html_node/elisp/Low_002dLevel-Font.html"
  (let ((family (plist-get args :family))
	(height (plist-get args :height))
	(f-weight (plist-get args :weight))
	(f-width (plist-get args :width)))
    (unless family (error "SET-MY-CUSTOM-FONT. Argument `:family' hasn't been setted"))
    (unless height (setq height 110))
    (unless f-weight (setq f-weight 'normal))
    (unless f-width (setq f-width 'normal))
    (set-face-attribute 'default nil
			:family family
			:height height
			:weight f-weight
			:width f-width)))

(defun customize-font-SourceCodePro ()
  (interactive)
  (set-my-custom-font
   :family "Source Code Pro"))

(defun customize-font-JetBrains ()
  (interactive)
  (riser/set-my-custom-font
   :family "JetBrains Mono"))

;; After making function `interactive', and compile it you 
;; can boldy using it through the 'M-x' or declare some
;; keybinding for it

 (global-set-key (kbd "C-z f s") 'customize-font-SourceCodePro)
 (global-set-key (kbd "C-z f j") 'customize-font-JetBrains)

After making the function <mono>interactive<mono> and compiling it, you can use it safely with <mono>M-x<mono> or assign another keybinding.


 (global-set-key (kbd "C-z f s") 'customize-font-SourceCodePro)
 (global-set-key (kbd "C-z f j") 'customize-font-JetBrains)

Code above is just example, because font's like <mono>SourceCode Pro<mono> either <mono>JetBrains Mono<mono> probably have not installed in your system by default. However you can do it by yourself, try to download all the font you like and test all off them directly in emacs invoking <mono>(set-my-custom-font :family "&lt;<span>proper font name</span>&gt;")<mono> (mean pressing C-M-x under that s-expression).

Small tip. Using <mono>C-z ...<mono> shortcut entry point for switching themes , fonts another ui-variable help you to keep organize the "directory" of your handy tools what never make collision with other Major/Minor modes and gave you a way to quickly Jack you scripts(mean interactive functions) to edit process.

<medium>Mood-line<medium>

Enjoy a minimalistic look for the standard Emacs mode bar.

Read more: https://github.com/jessiehildebrandt/mood-line

(use-package mood-line
  :ensure t
  :init 
  (mood-line-mode))

Clojure IDE 

Every Clojurist using Emacs in production has an individual approach to streamline routine tasks. Someone prefers fully-featured hints to gather as much information about edited file/structure/function as possible (sounds like a Perfect Setup).

Others enjoy Clojure experience even without an integrated linter or noisy completion popup (and that’s also a Perfect Setup).

What's unique is how developers discover the latest packages from the universe of melpa/elpa repositories, existing scripts, or Stack Overflow examples, as well as ways to manage daily tasks. Prepare for the fact that shaping and developing your habits takes time.

Returning to the subject, the fastest way to replace your Clojure IDE with Emacs Clojure IDE is Clojure LSP.

<medium>Clojure LSP<medium>

First of all, <mono>clojure-lsp<mono> uses the <mono>lsp-mode<mono> package as a client for the Language Server Protocol. A well-configured LSP is no worse than any other modern IDE. LSP clients offer more GUI settings, popups and user-friendly tool management.

Read more and see how it works through various examples on the technology page: https://clojure-lsp.io

Install clojure-lsp and make sure that it's located in your PATH variable.

<medium>Lsp-UI<medium>

The set of Emacs UI addons includes more intuitive navigation and hinting solutions. For example, a modal doc'string reader, typically used for hinting and displaying docs in modals. Discover this package to customize the UI according to your needs. This package also includes replacements for two built-in Emacs functions:

xref-find-definitions -> lsp-ui-peek-find-definitions
xref-find-references -> lsp-ui-peek-find-references

If you plan to use LSP mode daily, I recommend you bind these functions to keybindings.

(use-package lsp-mode
      :bind (("M-." . lsp-ui-peek-find-defintions)
             ("M-?" . lsp-ui-peek-find-references))
      ... )

<medium>Read more:<medium> https://emacs-lsp.github.io/lsp-ui/

<medium>Lsp-Mode<medium>

The LSP client for invoking without any configuration: <mono>M-x lsp<mono>

Note! The following configuration applies specifically to Clojure. Find more LSP-mode configurations here.

(use-package lsp-mode
  :ensure t
  ;; use <tab> for completition 
  :bind (("<tab>" . company-indent-or-complete-common))
  :hook ((clojure-mode . lsp)
	 (clojurec-mode . lsp)
	 (clojurescript-mode . lsp)
	 ;; integration with which-key
	 (lsp-mode . (lambda ()
		       (let ((lsp-keymap-prefix "C-c l"))
			 (lsp-enable-which-key-integration)
			 ;; hide auto-complete modal if
			 ;; auto-complete package was installed
			 ;; like we do before
			 (auto-complete-mode -1)))))
  :config
  ;; Using custom keybind for lsp
  (define-key lsp-mode-map (kbd "C-c l") lsp-command-map)
  ;; hide breadcrumb line on top of the buffer
  (setq lsp-headerline-breadcrumb-enable nil)
  (dolist (m '(clojure-mode
	       clojurec-mode
	       clojurescript-mode
	       clojurex-mode))
    (add-to-list 'lsp-language-id-configuration `(,m . "clojure"))))

Emacs Macros

One of the great Emacs (LISP) features is macros. It can be a lifesaver when dealing with repetitive, maddening, and time-consuming tasks.

Instead of using the <mono>query-replace<mono> feature or a package like <mono>multicursor<mono> for manual searching and editing all occurrences, you can benefit from Emacs macros. To use it, press <mono>F3<mono> to start recording your actions. Emacs will capture each keypress, similar to recording audio. Press <mono>F4<mono> to stop and save the recording, and press <mono>F4<mono> again to replay the sequence of actions.

In the GIF below, I show you a small example of how macros can efficiently eliminate sentence breaks, a useful feature when dealing with a large amount of text.

Emacs macros

Recorded keyboard macros can be saved for future sessions (and pinned to shortcuts if you want) in a simple Emacs function body. You can edit it or remove any misclick actions. Use the following functions to organize macros so that you won't lose them:

<medium>kmacro-name-last-macro<medium> - add a name to this macros to invoke it with the M-x as a global function
<medium>kmacro-edit-macro<medium> - edit the structure of macros to modify sequence of inserted keys or text
<medium>kmacro-bind-to-key<medium> - quickly bind macros to any key
<medium>insert-kbd-macro<medium> - add the macros sequence to the .init or .emacs file as an interactive function

emacs –no-window-system (or shorter -nw)

Emacs provides a particular advantage when working with external server machines or computers. If you need to connect to these remote systems for administrative tasks, Emacs offers a seamless and comfortable experience, just as if you were working on your desktop.

This functionality is known as Emacs Dired. While navigating through files with a mouse might feel more natural in a GUI environment, on a server, <mono>dired<mono> can be a good alternative to shell commands like <mono>cd ...<mono> or file managers such as <mono>ranger<mono> or <mono>fff<mono> that you might use for a better experience.

Emacs offers even more. You can copy your Emacs configuration and continue working within the familiar environment.

Additionally, you can use Emacs as a compiler for your automation scripts, which means you can write scripts for everything using Emacs Lisp. While this may be quite a challenging task, it will deepen your understanding of Emacs and simplify your coding life.

Another benefit is that Emacs provides a wide range of functions from dired and other packages that you are free to use. Upon installing Emacs, all your scripts will work seamlessy. In this context, Emacs becomes more than just an editor; it’s a powerful toolbox.

To run elisp script file, invoke the command below in shell

emacs –script my_script.el

...or use shebang in the first line of your script file.

#!/usr/local/emacs/emacs --script

Emacs in Server mode

When you reopen Emacs, the initial startup time may not be as quick as you'd like. However, achieving fast file access and using Emacs as a cross-system editor is possible.

Emacs can be launched in server mode using the <mono>--daemon<mono> key. Standalone instances will operate in the background with loaded packages, functioning as a service. When opening something, use the <mono>emacsclient -c<mono> (<mono>-c<mono> option to create frame) binary application, which is distributed alongside Emacs, instead of using <mono>emacs<mono>.

Let's set it up on your system. 

1. Add the command <mono>emacs --daemon &<mono> to one of your system startup files (it can be <mono>.xprofiles<mono> or <mono>.xinitrc<mono>). This ensures that every time your GUI environment initializes, the Emacs daemon will be loaded.

1.1. Alternatively, you can take a different approach. To declare the Emacs daemon as a fully controlled service over systemd, you need to first declare Emacs as a service in the <mono>emacs.service<mono> file:


[Unit]
Description=Emacs text editor
Documentation=info:emacs man:emacs(1) https://gnu.org/software/emacs/

[Service]
Type=forking
ExecStart=/usr/bin/emacs --daemon
ExecStop=/usr/bin/emacsclient --eval "(kill-emacs)"
Environment=SSH_AUTH_SOCK=%t/keyring/ssh
Restart=on-failure

[Install]
WantedBy=default.target

Put this file into the <mono>~/.config/systemd/user/<mono> directory or inside the <mono>/etc/systemd/system/<mono>. Afterwards, you should enable the <mono>systemd<mono> to run it each time the system starts. Invoke the following commands in the terminal:


# enable Emacs-as-a-service
systemctl enable --user emacs
# start it now if you want, or it will start automatically after the next system restart
systemctl start --user emacs

2. For better terminal access, create an alias within <mono>.bashrc<mono> (if you are using bash, of course) 


alias emdit="emacsclient -c -a emacs"
alias emdit-nw="emacsclient -nw -c -a emacs"
alias emcalc="emacs -f full-calc"

3. But you want to use it through the file manager (open and edit with a double-click), you should first create <mono>emacsclient.desktop<mono> with the following content:


[Desktop Entry]
Version=1.0
Name=EMACS Client
GenericName=Text Editor
Comment=View and edit files
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;
Exec=/usr/bin/emacsclient -c -a "emacs" %F
Icon=emacs
Type=Application
Terminal=false
Categories=Utility;Development;TextEditor;
StartupWMClass=Emacs
Name[en_US]=Emacsclient

Put it in <mono>/usr/share/applications/<mono> or <mono>~/.local/share/applications/<mono> directories for the file manager to see it. Then you can select the editor from the dropdown file menu by choosing "Open With" -> Emacsclient.

Final thoughts

Here is good and bad news at the same time: instead of reading this bunch of text, you could just download the .emacs file. Skeletor will return next week with more disturbing facts.

Well, anyway, I hope you find something useful in this guide. If not, I thank you for your time and attention 🤝 In any case, feel free to text me if you have any questions or topics to discuss.

Wish you happy coding! …And Emacs for all.

{{nn17-4="/custom-block-to-blog/three-page"}}

P.S.: After starting Emacs, please wait 2-5 minutes for all the packages to install.

P.S. #2: We didn't add 2mood-line to the .emacs file because of its compatibility issues with the latest version of Emacs. You can install it manually following the description in the  'How to install Emacs packages?" section.

{{about-loz-riz-red="/material/static-element"}}

Shall we discuss
your idea?
Uploading...
fileuploaded.jpg
Upload failed. Max size for files is 10 MB.
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
What happens after you fill this form?
We review your inquiry and respond within 24 hours
We hold a discovery call to discuss your needs
We map the delivery flow and manage the paperwork
You receive a tailored budget and timeline estimation