mirror of
https://github.com/foo-dogsquared/wiki.git
synced 2025-02-24 21:18:59 +00:00

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
165 lines
5.2 KiB
Org Mode
165 lines
5.2 KiB
Org Mode
:PROPERTIES:
|
|
:ID: 994be8e1-6bf2-4621-adf2-1c9a5ec46521
|
|
:END:
|
|
#+title: Anki: Emacs
|
|
#+date: "2021-05-02 19:18:32 +08:00"
|
|
#+date_modified: "2021-05-10 08:40:00 +08:00"
|
|
#+language: en
|
|
#+property: anki_deck Emacs
|
|
|
|
* The overview of buffers
|
|
:PROPERTIES:
|
|
:ANKI_NOTE_TYPE: Styled cards
|
|
:ANKI_NOTE_ID: 1620039512243
|
|
:END:
|
|
** 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
|
|
:PROPERTIES:
|
|
:ANKI_NOTE_TYPE: Styled cards
|
|
:ANKI_NOTE_ID: 1620039513634
|
|
:END:
|
|
** 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
|
|
:PROPERTIES:
|
|
:ANKI_DECK: Emacs
|
|
:ANKI_NOTE_TYPE: Styled cards
|
|
:ANKI_NOTE_ID: 1620039514055
|
|
:END:
|
|
** 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
|
|
:PROPERTIES:
|
|
:ANKI_NOTE_TYPE: Styled cards
|
|
:ANKI_NOTE_ID: 1620040989788
|
|
:END:
|
|
** 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
|
|
:PROPERTIES:
|
|
:ANKI_NOTE_TYPE: Styled cards
|
|
:ANKI_NOTE_ID: 1620387028893
|
|
:END:
|
|
** 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
|
|
#+begin_src elisp :exports code
|
|
(with-temp-buffer
|
|
(insert "* Hello world")
|
|
(rename-buffer "hello")
|
|
(org-mode))
|
|
#+end_src
|
|
|
|
* String comparison in Emacs Lisp
|
|
:PROPERTIES:
|
|
:ANKI_NOTE_TYPE: Styled cards
|
|
:ANKI_NOTE_ID: 1620387016294
|
|
:END:
|
|
** Front
|
|
How to compare two strings?
|
|
** Back
|
|
~(string= STR1 STR2)~
|
|
|
|
#+begin_src elisp :exports both
|
|
(print (string= "WHOA" "whoa"))
|
|
(print (string= "WHOA" (upcase "whoa")))
|
|
(print (string= "Hello world" "HeLL0 World"))
|
|
#+end_src
|
|
|
|
#+results:
|
|
:
|
|
: nil
|
|
:
|
|
: t
|
|
:
|
|
: nil
|
|
|
|
* Using the help system
|
|
:PROPERTIES:
|
|
:ANKI_NOTE_TYPE: Styled cards
|
|
:ANKI_NOTE_ID: 1620386877252
|
|
:END:
|
|
** 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~, and ~describe-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
|
|
:PROPERTIES:
|
|
:ANKI_NOTE_TYPE: Styled cards
|
|
:ANKI_NOTE_ID: 1620607164221
|
|
:END:
|
|
** 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
|
|
:PROPERTIES:
|
|
:ANKI_NOTE_TYPE: Styled cards
|
|
:ANKI_NOTE_ID: 1620607164494
|
|
:END:
|
|
** 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 with ~evil-fill~.
|
|
|
|
- ~sort-lines~ is pretty useful for the common task of sorting lines.
|
|
Though, not useful for items that consist of multiple lines.
|
|
|