Skip to content

Latest commit

 

History

History
309 lines (182 loc) · 13.2 KB

30.improve-emacs-qol.md

File metadata and controls

309 lines (182 loc) · 13.2 KB

Improve quality of life with your font, theme, and minimal select packages.

You don't need many packages and spend hours configuring them to make Emacs "perfect fit" for you. Let me introduce a minimum survival kit to make your Emacs life a little better.

This section is completely optional for your Org-roam life, and no problem completely ignoring it, or selectively apply some parts of it. You decide. With just a minimum added to your kit, I hope, you might find your quality of life one notch better.

My aim of this section is you get a little more motivated to continue the path to Org-roam and Emacs.

At the end of this section, your Emacs will look something like this:

Here is the configuration file as at the end of this chaper.

My selection is purely subjective, and aimed at long-form writing as opposed to programming. Some of them are not even a package or configuration.

Here is my minimum survival kit:

  • Full screen
  • Menu bar
  • Customization with menu bar
  • Font
  • Undo/Cut & Paste with CUA Keys (CTRL-z, CTRL-c, CTRL-v, CTRL-x)
  • MELPA
  • Theme
  • Selectrum
  • Olivetti
  • Small aesthetic changes

Full screen

Press F11 on your keyboard to make Emacs display in full screen. It's a toggle, so pressing it again will shrink the screen to the original size. If you don't have function keys, you can call the command M-x toggle-frame-fullscreen.

Menu bar

I have mentioned in the previous section. I suggest you don't hide it until you are more comfortable with Emacs -- I keep it on almost always, and still find it useful.

If you have hidden it and can't get it back, call M-x menu-bar-mode to toggle it on again.

We will see how you can use it to customize your Emacs next.

Customization with menu bar

Let's use the menu bar for customization. I will show you two examples.

One example is to hide the tool bar, the bar with the icons as shown in the screen shot below. It's highlighted in green.

Navigate the "Option" menu tree like so, and click on Tool Bar.

You will see the tick box next to it is removed, and no longer see the tool bar. If you look at the minibuffer at the bottom, you will also see showhide-tool-bar command was used to toggle the tool bar.

Now... It's a temporary change; once you quick Emacs and launch it again, the tool bar will be shown. How can we make the change survive the quick and launch? The simple answer is that you can save this change by another selection in the menu bar.

Try pressing "Save Options". You will see your .emacs modified automatically by this action.

Quit Emacs. Next time you launch Emacs, this part of .emacs is read to automatically turn off the tool bar for you.

If you have seen other people's Emacs configuration, you may be asking: "What about setq?" It's a good question. What I have done is (almost) the same as writing (setq tool-bar-mode nil), but instead of doing it, the menu-bar takes advantages of customize features within Emacs. We can talk about this much longer and will be happy to do so someday in a separate section. For now, I hope that you find this way with customize easier than using setq. You can go very far with it; I use customize extensively for my own Emacs settings.

Font

Let's set a font of your choice. It's easy by the menu, again.

You can select a font, style, and size in a dialog box that should look familiar to Windows users:

You can choose any font. If you would like the same one shown in the screen, it's Overpass Mono by Delve Fonts and RedHut (it's free).

Select a font and do "Save Options" like above. You should see custom-set-faces updated with a default font with your font set like this:

Undo/Cut & Paste with CUA Keys (CTRL-z, CTRL-c, CTRL-v, CTRL-x)

Emacs undo and cut & paste are not intuitive for most of Windows users. I have learned the Emacs way, so I can do both. But it's still useful to enable the "normal" shortcuts like CTRL-z for undo, CTRL-c for copy, and so on. It's easy; turn on CUA keys on.

If you like the way it is, you can save the option; you will see cua-mode on.

It is not clearly shown in the menu bar option, but CTRL-z for undo is also enabled by this.

MELPA

MELPA (Milkypostman’s Emacs Lisp Package Archive) is a collection of Emacs packages that are publicly shared. There are more than 5,000 packages in it. I guess most of Emacs users use it to get "third-party" packages -- packages that are not built-in to Emacs.

You need to put some configuration/customization to connect to it. MELPA's "Getting started" page shows how to do it; you can copy and paste the code in the "Installing" instruction section:

(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
;; Comment/uncomment this line to enable MELPA Stable if desired.  See `package-archive-priorities`
;; and `package-pinned-packages`. Most users will not need or want to do this.
;;(add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t)
(package-initialize)

I will paste it before the automatic customizing part. In addition, add this one line after the pasted part:

(setq package-check-signature nil)

Your .emacs buffer should look like this:

Then call M-x eval-buffer to get Emacs to run the code -- one of the differences with customize is that you need to manually run the program to get the code to be effective.

When you have done eval-buffer, you won't see anything. Let's look at the list of packages to see if it worked or not. You can open the list via the menu like so:

You will likely get this screen asking if it is OK to connect to MELPA. I'll press a to always accept it.

If everything is successful, then you should see a list like this. Emacs will also automatically "refresh" the list -- sync to the latest in the remote server via the internet. You see "Package refresh done" message at the bottom in the minibuffer. It should take about 10-20 seconds or so (it depends on your internet connection speed).

If you didn't add (setq package-check-signature nil), you will likely get this error saying the process failed to verify signature.

If so, you can use your mouse and put your cursor ("point" in Emacs' language) in the error message, and press q (quit) twice to go back to your .emacs and add it in.

Now you can add packages from MELPA. Let's add a theme of your choice.

Theme

Let's use a filter function to narrow the selection. Again via the menu-bar.

I will choose "Filter by keyword" and enter "theme" when prompted in the minibuffer at the bottom. It may take some seconds for the prompt to appear, so just be patient.

I use Modus-themes. You can choose any but for now let me stick to Modus.

Click on the name of the package, a separate window (it would be another "pane" in Window's terminology; Emacs calls it "window") will appear. Click on the "Install" button (highlighted in green).

You will see a confirmation dialog and click on "Yes".

You can press q twice to get back to .emacs. You will see modus-themes added to the package-selected-packages customizing variable.

This is how Emacs (and you) can keep track of packages installed by default.

Now you can choose a Modus theme (there are two included in the package, one is Modus-operandi, the light theme; the other, Modus-videndi, the dark theme).

Again, you can use the menu bar...

In the selection menu, click on the check box next to the theme (e.g. modus-operandi) and click on the "Yes" button in the dialog that appears:

Click "Yes" to another pop-up dialog.

You can see that the them has taken effect already:

Click on the "Save Theme Settings" in the selection screen; you will see "Custom themes saved for future sessions." in the minibuffer.

Press q to get back to .emacs. You will see "modus-operandi" is added. Now you can quit and relaunch Emacs; your theme should be set correctly.

Selectrum

Selectrum is a package that enhances the experience of "search and select" in the minibuffer.

An alternative way to install a package is to call M-x package-install and then type the name of package you want, for example, selectrum then RET (that is, to press Enter).

Follow the "Usage" instruction of its README on GitHub:

  • Install selectrum-prescient
  • Add the following code
  • Calleval-buffer to get the code effective.
;; Selectrum -- Completion in minibuffer
(selectrum-mode +1)
;; to make sorting and filtering more intelligent
(selectrum-prescient-mode +1)

;; to save your command history on disk, so the sorting gets more
;; intelligent over time
(prescient-persist-mode +1)

To see what this change does, do M-x.

Or do C-x C-f to call find-file

Selectrum, together with Selectrum-prescient will remember your last selection. So overtime, it will be more clever. You do not change your keyboard shortcuts ("keybindings" in Emacs terminology); I find it more beginner friendly compared to other similar packages such as Ivy or Helm 1.

Olivetti

Selectrum is functional improvements for "search and select" in the minibuffer. Olivetti is for UX improvement for writing and reading in Emacs. Install it in the same way: package-install RET olivetti RET – notice that Selectrum is also enabled here for searching packages.

Add the following in, and do M-x eval-buffer.

;; Olivetti
;; Look & Feel for long-form writing

;; Enable Olivetti for text-related mode such as Org Mode
(add-hook 'text-mode-hook 'olivetti-mode)

Open/create a long-form Org note, like this one.

Notice that you have very generous margins on both sides in the main body. The texts are also wrapped on the right. They are "visually" wrapped. You can see the difference Olivetti makes by turning it off with M-x olivetti-mode.

Notice that each paragraph now continues onto the invisible end to the right.

You can manually turn on the visual line wrapping with Option > Word Wrap (Visual Line mode). Olivetti turns Visual Line mode for you and add the margins to make writing and reading long texts more comfortable. To me, it's a simple and beautiful solution for readability.

Small aesthetic changes

[WIP: this subsection is copy and paste from V1 -- I will revisit it. I would liek to see if adding more with customize is useful here. I like customize but it takes more time to write about it...]

Lastly, throw in some aesthetic changes. For example, one of the things we can do is to remove the vertical scroll bar between the main body and the Org-roam side pane. To me, it is a little too prominent and gets in the way.

I like the way Elegant Emacs by Nicolas Rougier (rougier on GitHub) deals with these changes in a compact package. Below, I have liberally copied from his code.

Add the following in your .emacs, and do M-x eval-buffer.

;; Optional additional aesthetic changes
;; Adapted from `sanity.el' in Elegant Emacs by Nicolas P. Rougier (rougier)
;; https://github.com/rougier/elegant-emacs

(setq inhibit-startup-screen t)
(setq inhibit-startup-echo-area-message t)
(setq inhibit-startup-message t)
(setq initial-scratch-message nil)
(setq initial-major-mode 'org-mode)
(setq-default indent-tabs-mode nil)
(setq pop-up-windows nil)
(tool-bar-mode 0) 
(tooltip-mode  0)
(scroll-bar-mode 0)
(menu-bar-mode 1) ;menu bar is explicitly turned on for beginners. Change the value to 0.

;; Optional aditional aesthetic changes
;; Adapted from `elegance.el' in Elegant Emacs by Nicolas P. Rougier (rougier)
;; https://github.com/rougier/elegant-emacs

;; Line cursor and no blink
(set-default 'cursor-type  '(bar . 1))
(blink-cursor-mode 0)

;; Line spacing, can be 0 for code and 1 or 2 for text
(setq-default line-spacing 0)

;; Underline line at descent position, not baseline position
(setq x-underline-at-descent-line t)

Footnotes

  1. They are both good packages used and loved by many Emacs users, so there is no problem choosing them over Selectrum. For the purpose of this Guide, I will stick to Selectrum as it does not require you to add more to your configuration.