Configuring Emacs from scratch
The small wisdom is like water in a glass: clear, transparent & pure. The great wisdom is like the water in the sea: dark, mysterious, impenetrable. -Rabindranath Tagore
Hello everyone,
I am using Emacs since 2015. Overtime the configuration file had grown to be a large 1000 line file with keybindings I do not use anymore & macros that were replaced by modern packages with newer features.
So, this got me thinking “let me clean it up!”; issue was- inertia. I didn’t wanted to clean packages one by one & fix the startup. Eventually I decided to delete my .Emacs & make a new one.
I had an even better idea. Make it a video series & post it on relevant forums. Thus I started creating the video series on: “configuring Emacs from scratch”.
In the following section, I will update my journey with the video & description for the same. This will include:
- a small summery of the packages that I install
- a brief description of the settings I change
- reason for not including any specific package.
This is my effort to make the Emacs configured from scratch. Hope you like it.
Video 1: (setting up init file & org file for literate programming)
In the first video, I start by deleting my previous .emacs.d directory. Then I start by creating the init.el & settings.org file. The init.el file contained the org-babel for elisp code blocks used in settings.org file.
I liked the idea of literate programming. So org mode with the org-babel tangle feature got me really exited. Thus this became the first video on how to do so.
In the settings, I always enjoy the full screen Emacs editing with no GUI mouse click options. Thus following settings are made:
- disable menu bar, tool bar, scroll bar, init splash screen
- enable global linum mode
- no auto save file
Related links for this video
Video 2: (IDO)
In the next video, continuing with the trend, IDO (interactive Do) mode specific things are set. It is a mode that does things interactively. E.g. if I need to find a file, by default Emacs will not show the files in the directory, it only shows after 2 tabs are pressed. This is solved by IDO with a linear list of files or directory separated by ‘|’ character.
Related links for this video
Video 3: (melpa package repo, ido grid mode)
In this section, I set up the melpa package repository for Emacs to load the packages. Form the repository, I installed the package for displaying the IDO find files with a grid mode, rather than the default linear one.
Related links for this video
Video 4: (Themes & org bullets)
In this one, I set up the theme for the Emacs. I like to choose the theme, based on the readability of the code. I like dark contrasting colors for that job. Also I really like the org bullets package for making some cool bullets for org mode.
Related links for this video
Video 5: (key bindings & other setup)
Keybinding is one of the important aspect of the Emacs. In this video I remap some of the keybindings:
- hippie-expand
- backward-kill-word
- backward-delete-char
- replace-string
- replace-regex
- count-matches
Related links for this video
Video 6: (ivy + counsel + swiper)
The default isearch, M-x, switch-buffer of Emacs is nice, but to make it nicer, ivy + swiper (replacement of isearch) + counsel (replacement of find-file switch-buffer etc). I set the keybindings for the swiper but do not replace the find-file. I like the IDO feature for the find file.
Related links for this video
Video 7: (magit)
In this video, I install & set up magit. Magit or Emacs got git is a great package for using git inside Emacs.
Related links for this video
Video 8: (iedit & paredit)
For the 8Th video, I am setting up 2 very useful packages for coding.
- iedit:
iedit is for interactive editing. Say we need to edit the name of the variable in a defun/buffer. For that we can interactively search & replace. I find it better to use the iedit package. If I place the point below the symbol & start iedit, it replaces the symbol in the buffer. Same can be done with line, defun or in a region with narrow-region.
- paredit:
paredit is most useful when we use the elisp codes. It has many useful features like keeping braces & quotes balanced, burfage / slurpage of the braces, joining 2 sexp, splitting 2 sexp, making escape string etc to name a few.
Related links for this video
Video 9: (company anaconda company-quickhelp company-anaconda)
Next, we need to have some sort of autocomplete features in Emacs while coding. There are 2 primary packages for doing that job:
- auto-complete
- company
Both packages are great, but personally I like company mode better. This does come with a drawback. To get all the features in autocomplete in Python, we need some more packages, namely:
- company-quickhelp: for displaying the doc string
- anaconda: for running python based autocomplete
- company-anaconda: for running anaconda with company
But overall I find it useful.
Related links for this video
Video 10: (yasnippets with company)
In order to get some quick scripting in Emacs, we installed the package called yasnippets (yet another snippets).
The default package for yasnippets do not contain any snippets. For that, we need yasnippets snippets.
Now by default, it is expected to work seamlessly with [tabs] but that kind of conflicts with the company mode’s auto feature sometime. What I found was, we need to have an extra space to get it working. I did not lie that behaviour. So I bounded it to M-z which by default is zap-to-char, but I hardly needed that feature, so I remapped it.
Related links for this video
Video 11: (hilight-indent-guides)
In this video, after describing the org mode readme to Github; I am showing a minor package for highlighting the indentation in the Python code. This is useful as for languages that depend on the indentation, it is handy to see the different indentation levels.
Related links for this video
video 12: (orgmode contrib package)
In this video, I am showing the demo on how to install orgmode contrib packages from Emacs. I am showing the demo for taskjuggler install and org-export for the same. A quick demo for the taskjuggler is also shown.
Also, lately while coding in elisp, I found that some of the paredit bindins are not available. So I am setting them too in this video.
Related links for this video
video 12: (hide show mode)
In this video, I am setting up hide-show minor mode. This is really helpfull navigating large codes and helpfull for viewing only the intended function’s definations.