emacs

Table of Contents

1. Concept & theory

1.1. Keys

1.1.1. Modifier

Certain keys

  • Ctrl (C) : Control key
  • Left alt (M) : Meta key
  • Windows key (s) : Super key
  • Space key (SPC) : Leader key (evil mode)

1.1.2. Chord

Modifier keys pressed with a single non-modifier key

  • Eg. C-c, M-x, S-v, C-S-v

1.1.3. Sequence

series of chords, pressed and released in row

  • Eg. C-x C-c

1.2. Layout

buffer buffers are assigned to windows. text you are editing in emacs resides in an object called a window.
window window displays a mode
mode-line windows contain a mode-line at the bottom
mini-buffer located at the bottom of emacs. It is used for the evil ex command line among other things.
frame/tab holds multiple windows, other names: workspace
session TODO
major-mode each buffer usually has only one major mode, eg. filetype. modes have their own keymaps
minor-mode buffer can have multiple minor modes that can be toggled on and off, eg. flyspell-mode
vim modes vim modes are called states in evil mode

2. Native usage

2.1. Help/Documentation/Info

  • h-RET-i : Open emacs offline manual and open index
  • M-x describe-mode : Documentation for current major and minor modes
  • SPC-h-m : Show active modes in buffer
  • SHIFT-k : for any documentation/signature
  • SPC-h-d : Open doom specific help and other shit
  • M-x yas-describe-table : Snippets help
  • pkill -SIGUSR2 emacs if emacs hangs

2.2. Basics

2.2.1. Global

  • C-g : To get out of fuckups (MOST IMPORTANT)
  • SPC-m : local leader key (this gives different keys based on the mode you're on or something similar)
  • C-/ : company-complete
  • SPC-f-p : Open dooms private config directory

2.2.2. Emacs specific

  • M-: : evaluate an expression in the minibuffer, also can use eshell

2.2.3. Old basics (remove later)

  • SPC-o-p : toggle sidebar (treemacs in our case)
  • SPC-p-p : list projects
  • select codeblock + = : to auto-format codeblock
  • M-x <mode-name> : switch major mode

2.2.4. Processes

  • M-x list-processes then we can use d on that specific process to kill it

2.3. Editing

  • gc : comment/un-comment
  • g-s-SPC : Jump to character (uses avy)
  • Multi-cursor
    • select and press R to select all in the current buffer
    • select and press M-d(next) M-D(previous)
  • M-x ispell : interactive spellchecker
  • z= : correcting spelling
  • Multiline edit: C-x r t

2.3.1. Evil bindings

  • c-i-( : clear inner w parentheses

2.3.2. Regex

  • Using capture groups w \1
    • Eg. `something` to something : :%s/`\(.*?\)`/\1/g

2.4. Buffers

  • SPC-b-b or SPC-, : List buffers in workspace
  • SPC-b-i : ibuffer
  • d : mark for delete (ibuffer)
  • x : commit changes (ibuffer)

2.5. Code editing & version control

  • SPC-o-t : Terminal
  • SPC-c-d : Go to def
  • M-x imenu : symbol search
  • Markers
    • More on like code exploration usage
    • m(Aa..Zz) : Set marker
    • '(Aa..Zz) : Go to marker
    • Stored in evil-markers-alist
    • SPC-s-r or :mark : List/goto markers
  • Bookmarkers
    • More on like global and persistent usage
    • SPC-Enter : List bookmarks
    • SPC-b-m : Add bookmark
    • SPC-b-M : Remove bookmark
  • Narrowing
    • C-x n n : Narrows the buffer to selected region and then you can run buffer operations there
    • C-x n w : To come back to the original buffer

2.6. Workspace

  • SPC-TAB-TAB : List tabs
  • SPC-TAB-d : Delete current workspace (switches to other existing workspace)

2.6.1. treemacs

  • ? : keybindings
  • c-{f,d} : create file/dir
  • M-x treemacs-edit-workspaces: edit project workspaces in org-mode

2.7. Magit

  • g-L (magit-log-buffer-file) : git history for a single file

2.7.1. forge

  • forge-add-repository : Add repo to local db
  • forge-pull-topic: Fetch PR info about some topic
  • forge-branch-pullreq : This creates the remote branch and a local branch for the PR

2.8. org-mode

2.8.1. org-tangle

  1. Tangle from CLI

    I think this can be done w emacsclient too, which should be shorter.

    emacs --batch --eval "(require 'org)" --eval '(org-babel-tangle-file "<file_name>.org")'
    
  2. Additional details on tangle
    #+PROPERTY: header-args :tangle yes
    
    • C-c C-v t : tangle code blocks
    • Tells emacs to tangle all code blocks in the file, unless the code block explicitly includes :tangle no
    • code-blocks with :comments link , this way the tangled file is linked to the source and we can use org-bable-detangle to update the original file.
    • If you updated tangle config, you might want to do C-c on the tangle line in the header or do a buffer reload(b-r) if you notice stale tangle output.

2.8.2. org-roam

  • C-RET : Lock-out of ambiguous fuzzy match when trying to insert new node.

2.8.3. org-agenda & todos

  • Calendar buffer: shift+arrow keys will move you in the calendar
  • SPC-m-d : Setting dates
  • SPC-m-t : Change todo status
  • SPC-m-p-p : Change priority

2.8.4. org-babel

  • C-c C-c : Execute
  • C-c ' : Open code in a buffer

2.9. winner-mode (window)

  • C-w m m : Maximize
  • C-w u : Undo window (back to old window layout)

2.10. artist-mode

  • M-x artist-mode
  • Toggle evil-emacs-state with C-z, if facing issues
  • Note: If inside org-mode, use src: artist and then C-c '
  • Left Mouse: Draw
  • Middle Mouse: Show context menu
  • Right Mouse: Erase

3. Misc package usage

3.1. deft

  • C-c : Deft options in deft mode
  • C-c C-f: Search files in mini-buffer (prefer this more than searching inside deft itself)

4. Issues & Bugs

5. elisp

  • LISP: List Processing (fullform)
  • Building blocks
    • sexps : symbolic expressions(s-expression) consists of atoms and other sexps
    • atoms: numbers(2), strings("acc"), symbols(+,-,abc,xyz)
  • In lisp-interactive-mode
    • Cursor at the end of the expression
      • C-j will evaluate it on the next line
      • C-x C-e will evaluate it on mini-buffer
  • Quick refresher

    (setq my-name "Bastien") ;; set variable
    (defvar my-name "Poop" "set value of my-name, if my-name is not set") ;; idk this doesn't work as advertised and overrides
    (insert "Hello " "world! " "I am " my-name) ;; will insert hello world where the cursor is atm
    ;; defun
    (defun hello (name) (insert "Hello, I am " my-name name)) ;; func def, needs to be evaluated itself
    (hello "hrishi") ;; evaluate func
    ;; progn
    ;; - progn define seq. code without declaring a func.
    ;; - Essentially to bundle multiple forms into one. It evaluates sexps but returns the last
    ;; - Helpful when you have arguments which accept just one thing, but you
    ;;   want multiple things to be happening when you pass it.
    ;; - usually only used when you have side-effects to do, usually used w macros
    ;; - "defun" is an "implict progn"
    (progn (print "yo boi") 22) ;; prints yo boi(side effect) but then returns 22
    ;; let
    ;; - elisp is by global scoped
    ;; - for local scope, we can pass a varlist when using let
    (let ((city "guwahati") (country "india"))
      (switch-to-buffer-other-window "*test*")
      (erase-buffer)
      (insert country)
      (hello city)
      (other-window 1))
    ;; lambda
    (setq numbers '(1 2 3))
    (mapcar (lambda (x) (* 10 x)) numbers)
    ;; working w lists
    ;; car : content of the address part of the register, returns symbol
    ;; cdr : content of the decremented part of the register, returns list
    ;; cons: construct
    ;; helpers
    ;; - non-mutable: nth and nthcdr are helpers for car and cdr
    ;; - mutates: setcar and setcdr
    (car '(john ringo paul george)) ;; returns symbol
    (cdr '(john ringo paul george)) ;; returns list
    (car (cdr '(john ringo paul george))) ;; returns symbol
    (car (cdr '((john ringo paul) george))) ;; returns symbol
    (cons 'john '(ringo paul george)) ;; => (john ringo paul george)
    ;; literal list
    (setq list-of-names '("A" "B" "C")) ;; ' quotes the list
    (setq list-of-names ("A" "B" "C")) ;; ("A" "B" "C") will be evaluated, i.e A is func name, B, C are args. this will error
    ;; formatting
    (format "Hello %s!\n" "visitor")
    

Created: 2024-07-16 Tue 16:44

Validate