![Gabriel Arazas](/assets/img/avatar_default.png)
The notes are mainly extracted from the daily fleeting notes which clutter some of the more important thoughts. I figured it would be better to create Dendron-inspired hierarchical notes. Also, some of the notes are updated. I also started to create my visual aids for whatever reason. ;p
5.2 KiB
Anki: Emacs
- The overview of buffers
- The basics of modes
- Eagle's eye view of a window
- Point and marker
- Interacting with buffers in Elisp
- String comparison in Emacs Lisp
- Using the help system
- Word manipulation
- Line manipulation
The overview of buffers
Front
What is a buffer?
Back
A buffer is anything that Emacs displays.
It usually display file contents among other examples with butterfly
, doctor
, or the starting buffer when you first open Emacs.
While buffers usually have an associated file path, a buffer doesn't need one. This is one of the concepts that is applied to other text editors (Vim, Atom, Visual Studio Code).
The basics of modes
Front
What is a mode?
Back
A mode is set of behavior quite similar to Vim modes.
Emacs further divides modes into two.
Major modes are Emacs' way of supporting programming languages and file formats.
Programming language support usually comes in major mode — e.g., R-mode
for R files, python-mode
for Python scripts, org-mode
for Org mode documents.
Think of them as an equivalent to Vim's filetype.
Only one major mode can be activated in one buffer at a time and all buffers have a major mode.
Minor modes usually contain little behavioral changes that improve the editing experience. When enabled, some of them are global modes — affecting every buffer in your session. Others are only buffer-local — affecting only the buffer when you activated the mode. Unlike major modes, multiple minor modes can be enabled at any given time.
Eagle's eye view of a window
Front
What is a window?
Back
A window is where the buffers are being displayed. One window can display all buffers but only one at a time. To display two buffers at a single time, just add another window.
All windows display the same buffer; if the buffer is modified in one of the window, it will show the changes in all windows.
Point and marker
Front
What is a point and a marker?
Back
A point is the current location of the cursor in the buffer.
You can get the point with point
function.
Often helpful for interacting with buffers.
A marker is another point in the buffer. It is usually found when interacting with regions when asked for the two points (i.e., the beginning and the ending position). Furthermore, a marker can be used to save locations and jump back to that marker when asked.
Interacting with buffers in Elisp
Front
Give a rough example on how to do the following:
Create a temporary buffer named "hello" containing an Org mode document with a "Hello world" entry.
Back
(with-temp-buffer
(insert "* Hello world")
(rename-buffer "hello")
(org-mode))
String comparison in Emacs Lisp
Front
How to compare two strings?
Back
(string= STR1 STR2)
(print (string= "WHOA" "whoa"))
(print (string= "WHOA" (upcase "whoa")))
(print (string= "Hello world" "HeLL0 World"))
nil t nil
Using the help system
Front
Name different ways to use the help system inside Emacs.
Back
help-for-help
is the most comprehensive help section (in my opinion).describe-*
series of functions are the next. Among the list of describe functions, you have:describe-key
,describe-function
,describe-variable
, anddescribe-package
. You can just open up the minibuffer and see what else is there.apropos
is similar to Unix apropos command which searches for every symbol in Emacs.
Word manipulation
Front
Give some functions on word manipulations.
Back
The following functions have multiple variations each for a character ($F-char
), word ($F-word
), region ($F-region
), and region or point ($F-dwim
).
capitalize-*
for making the first of the word in uppercase.downcase-*
for making a region all lowercase.upcase-*
for making a region all uppercase.
evil-mode has a keybinding associated with uppercase and downcase a certain region with evil-upcase
and evil-downcase
, respectively.
Line manipulation
Front
Give some functions on manipulating lines.
Back
- evil-mode has
evil-join
which works the same way Vim's join complete with smart spacing and everything. fill-region
is useful for formatting requirements/preferences like in the Linux kernel where the maximum width of 80 characters. evil-mode has an associated keybinding function withevil-fill
.sort-lines
is pretty useful for the common task of sorting lines. Though, not useful for items that consist of multiple lines.