GeekSocket Plug in and be Geekified

Using GNU Emacs in Linux Foundation exam

I cleared the Certified Kubernetes Security Specialist (CKS) exam recently. It is an exam where one has to perform tasks on the clusters to solve the scenario based questions. In this post, I will be talking on how I used GNU Emacs in the exam environment. Though I’m referring to CKS here, this post should be helpful for other exams by Linux Foundation like CKA, CKAD, etc.

The exam environment

Before we get to Emacs related details, let’s understand the CKS exam environment. The exam user interface has a web based terminal to a GNU/Linux server (Ubuntu in case of CKS). This server has access to all the clusters and their nodes. All the tasks are basically performed from this web terminal.

Linux Foundation Exam environment Image from Training and Certification - Exam User Interface

The exam must be given using Chromium or Chrome. In case of these browsers, the keybindings like C-n, C-p, C-w cannot be captured by any website.

Why Emacs?

I have been using Emacs for more than 3 years now, and all the keybindings have become a muscle memory. In addition to that, I have been using Dvorak keyboard layout. So, I don’t have muscle memory for Vim keybindings on Dvorak layout. Instead of going into rabbit hole of configuring Vim to have more familiar keybindings, I thought of using Emacs. I can modify the vanilla Emacs the way I want for exam, and I don’t have to invest much time in that.

It is recommended to use a terminal multiplexer for the exam. That way, the session is not lost due to connectivity issues. You can also have two shell sessions split across the screen. Emacs can certainly do both these things with shell or term.

In these exams, you might have to write YAML files. The Fundamental mode in Emacs handles the indentation for YAML files correctly. Other editors like Vim might need some extra configuration to get this working correctly. You might also create text files to save output of some tasks. That’s where the commands to manipulate rectangles, flush-lines, keep-lines, and others shine.

Apart from all the above points, I just wanted to try this once and see how it turns out.

The setup

Now, let’s see what all I had to do in order to get Emacs working for the exam. I was aiming to do the setup without making any changes to the .emacs file, as doing that might be time taking during the exam.

Installing Emacs

Previously, the emacs package was used to be available in the exam environment, but that was not the case this time. Attempts to install the emacs package with apt failed. That tingled my nerves a bit, though I was able to install Emacs with sudo apt install emacs-nox. Since everything is done via a web based terminal, this was enough.

Starting Emacs server

To ensure that the buffers persist in case of session getting disconnected, I used Emacs server. emacs-nox package didn’t have any systemd service file for the Emacs server. I didn’t want to mess around with the exam environment much. So I just started tmux, and ran Emacs inside it.

Then I started the server with M-x server-start, and detached from the tmux session using C-b d.

Editing files

Now that I had Emacs server running in the background, I was able to connect to it using emacsclient -nw.

In the exam, one might have to run commands like kubectl edit, which open up the EDITOR. So, I set it to emacsclient using export EDITOR=emacsclient.

The keybindigs

As mentioned earlier, the keybindigs like C-n, C-p are captured by the browser. To solve this, I decided to use M-n and M-p instead of C-n and C-p respectively. I also disabled these shortcuts system-wide in GNOME to avoid issues like opening new window (C-n), print dialog (C-p) etc.

Looking around a bit, I found that the function global-set-key can be called interactively with M-x. I used C-h k (describe-key) on C-n and C-p to find wihch command is run by them. Setting the global keybindig was as easy as, M-x global-set-key RET M-n RET next-line RET.

The C-/ (undo) and C-w (kill-region) keybindigs didn’t work either. I work around these by using C-x u for undo, and M-w followed by DEL to kill a region.

During the exam

The above setup completed in not more than 2 minutes, and I started solving the exam questions.

I used ansi-term as my terminal emulator as it supports Bash completion out of the box. I also used shell where I wanted to quickly go through the text output of the shell commands and manipulate it.

I even had to ssh into some machines from the exam environment, and edit some files there. This is where I used Vim because I didn’t have much time to fiddle with Tramp. I used Vim with arrow keys over ssh from ansi-term.

Conclusion

I was able to give the exam without any issues, and Emacs worked really well throughout. As always, Emacs showed how easy it is to adopt it to your needs. I was surprised to see that I was able to do all this without adding a single line to Emacs configuration. Having practiced the Vim modal editing, along with keys for kill, yank, undo etc. helped in some of the cases where I had to use Vim.

If you are planning to give CKS, checkout the article How to Prepare for CNCF’s CKAD, CKA, CKS Certification? written by me and my colleagues at InfraCloud.


Comments

Comments are not enabled on this site. The old comments might still be displayed. You can reply on one of the platforms listed in ‘Posted on’ list, or email me.