Alex's Slip-box

These are my org-mode notes in sort of Zettelkasten style

Emacs cheatsheet

:ID: BB17CF51-DA23-46BB-A641-7B9D599715E0

This is just a dump or random things I’ve learned how to do in Emacs but will probably forget.

# Word Wrapping

  • auto-fill-mode is what you need. This will automatically wrap words after the line exceeds whatever value is set for fill-column

    For example, turn it on for org-mode

    (setq-default fill-column 80)
    (add-hook 'org-mode-hook (lambda () (auto-fill-mode 1)))
    
  • fill-region does what is says

# Advising Functions

# After callback example

;; Save Org buffers after refiling
(advice-add 'org-refile :after 'org-save-all-org-buffers)

# Deleting text

Using evil-mode (these work in Vim as well)

dtx where x is the thing you want to delete up to. dt space will delete up to first whitespace df space will delete up to and including the first whitespace d$ will delete from cursor to end of line

# Surrounding

Just use Evil-surround.

  • s( to surround region (with parenthesis in this example) Example:

    1. visually select a symbol
    2. surround visual selection with '
    vio
    s'
    
  • cs' to replace surround (example using single quote, but can be anything)

# Selecting text within surround

vi [Option]

# Repeating text

  1. Select the region
  2. SHIFT I (evil insert line count)
  3. Type characters
  4. ESC (the repeated chars are added)

# Font

M-x menu-set-font offers a GUI font picker and size setter with previews.

# helm-projectile-find-file

  • This does fuzzy matching by default
  • Start search query with a SPC to switch from fuzzy to exact match.

# Treesitter

Having this in emacs means syntax highlighting via a syntax tree rather than regex patters, better movement and hopefully faster.

# Mac

If using emacs plus, tree-sitter will be installed as a dependency of emacs v29+. See also https://github.com/d12frosted/homebrew-emacs-plus/pull/546

# Linux

Need to install tree sitter first, then build emacs v29 from source.

See also https://www.masteringemacs.org/article/how-to-get-started-tree-sitter

# Install Grammars

https://tree-sitter.github.io/tree-sitter/ Tree sitter needs grammars to work. Emacs needs to know where they are. The easiest way is to create a make telling emacs where the grammars are located (ie, git repo) then you can have emacs download and compile them.

(setq treesit-language-source-alist
    '((bash "https://github.com/tree-sitter/tree-sitter-bash")
      (css "https://github.com/tree-sitter/tree-sitter-css")
      (elisp "https://github.com/Wilfred/tree-sitter-elisp")
      (html "https://github.com/tree-sitter/tree-sitter-html")
      (javascript "https://github.com/tree-sitter/tree-sitter-javascript" "master" "src")
      (json "https://github.com/tree-sitter/tree-sitter-json")
      (markdown "https://github.com/ikatyang/tree-sitter-markdown")
      (org "https://github.com/tree-sitter/tree-sitter-org")
      (ruby "https://github.com/ikatyang/tree-sitter-ruby")
      (scss "https://github.com/ikatyang/tree-sitter-scss")
      (tsx "https://github.com/tree-sitter/tree-sitter-typescript" "master" "tsx/src")
      (typescript "https://github.com/tree-sitter/tree-sitter-typescript" "master" "typescript/src")
      (vue "https://github.com/ikatyang/tree-sitter-vue")
      (yaml "https://github.com/ikatyang/tree-sitter-yaml")))

Then use treesit-install-language-grammar

Check if its working. This returns t if the language is supported, otherwise nil

(treesit-language-available-p 'typescript)

# New modes

You can map the old modes to the new ones. but this comes potentially at a price.

(setq major-mode-remap-alist
      '((typescript-mode . typescript-ts-mode)))

# Troubleshooting

# Performance issues (profiling)

Use the built in profiler.

  1. M-x profiler-start and select what you want to profile.
  2. Do the thing that is slow
  3. M-x profiler-stop
  4. M-x profiler-report
  5. Drill down into the items with TAB

# Freezes

# C g will break a loop

# Send kill cmd to trigger debugger

ps aux | grep -ie emacs | grep -v grep | awk '{print $2}' | xargs kill -SIGUSR2

See also https://emacs.stackexchange.com/a/649

Search Results