There are many small tricks that can make your Emacs experience better, and in this article I will show you some of my favorites. To make it short and easy for beginners to experiment with, I will keep them simple. Don't let that fool you, these can really improve you experience (even if you have been using Emacs for a while!). Maybe you will find something that you really enjoy here?
emacsclient and server
I usually have my Emacs session open for days (or weeks? months?), and rarely close it unless I have to. Therefore it does not come naturally to me to close my session and open a file in it from the command line. Sometimes we may just want to open a file in our current Emacs session directly from the command line. This is where emacsclient comes in! The word client is used, so there must be a server, right? Yes. In your .emacs config (or just a scratch buffer) you can start a server using:
(you can also run M-x server-start in your session)
Now that you have started the server, you can use
emacsclient -n myfile.c to open myfile.c from your command line (or another file, or multiple files!).
There are many more things emacsclient can be used for than this simple example, so feel free to check out the documentation if the concept intrigues you.
It can be quite tedious if your PATH variables aren't included into Emacs when running it. Using exec-path-from-shell fixes that, and can be activated like I do here with this use-package configuration:
(use-package exec-path-from-shell :init (when (memq window-system '(mac ns x)) (exec-path-from-shell-initialize)))
(you can also use the built in package-install to install it, and use the when-block afterwards)
un-clutter the UI and show battery percentage
By default when starting a GUI session in Emacs, there are menu bars, tool bars and scroll bars. In my opinion, these clutter the UI, and take the focus away from the contents of the buffer. When running a graphical session (i.e, not a terminal session using -nw or over SSH without an X-server), I prefer to remove those. Showing the battery status in the modeline can also be very useful. I do all of the above using the following small snippet:
(if (display-graphic-p) (progn ;; Removed annoying UI elements (menu-bar-mode -1) (tool-bar-mode -1) (scroll-bar-mode -1) ;; show battery status (display-battery-mode 1)))
show-paren-mode is one of my favorite little nuggets of built-in Emacs goodness! What it does is highlight parenthesis (including brackets/braces), namely the beginning and end tags associated with each other, based upon your text cursor position. This functionality is best illustrated with a series of screenshots, here using the previous code block (removing UI clutter):
Works with other modes as well, including the obvious C-like languages (C, Java, Kotlin etc.). Configuring it is easy as pie:
There might be other bigger changes you may want to do, including big changes to navigation. I covered some in an article on recommended Emacs packages earlier.
Do you have any small tricks to improve your experience? Feel free to share them in the comments below :)