Skip to content

Latest commit

 

History

History
1348 lines (1100 loc) · 40.8 KB

core.org

File metadata and controls

1348 lines (1100 loc) · 40.8 KB

MEGUMACS @dotfiles @emacs

1 Introduction

./etc/banners/megumacs2.png

[M E G U M A C S]

(めぐマックス)

*Github* | *Source*

An infinite number of monkeys typing into GNU Emacs would never make a good program.

– Linus Torvalds

2 Installation

  1. Clone into .emacs.d: $ git clone https://github.com/b-coimbra/.emacs.d.git ~/.emacs.d
  2. Install nerd-icons fonts: M-x nerd-icons-install-fonts
  3. Install ligatures font (Fira Code Symbol): M-x fira-code-mode-install-fonts
  4. Install emoji font (Noto Emoji) for Linux
  5. Install language servers manually or with M-x lsp-install-server

3 Bootstrap

3.1 Globals

Global variables to easily customize portions of Megumacs.

(setq
 globals--banner-path  "etc/banners/megumacs.png" ; Banner image path shown in the dashboard
 globals--font         "Fantasque Sans Mono 11"   ; Font family and font size
 globals--theme        'mirwood                   ; Theme used by Emacs.
 globals--email        "b-coimbra@hotmail.com"    ; Email for GPG encryption
 globals--leader-key   "<SPC>"                    ; Leader prefix key used for most bindings
 )

3.2 Better defaults

Disable mouse and tooltips:

(when window-system
  (blink-cursor-mode 0) ; Disable the cursor blinking
  (scroll-bar-mode 0)   ; Disable the scroll bar
  (tool-bar-mode 0)     ; Disable the tool bar
  (tooltip-mode 0))     ; Disable the tooltips

General better defaults:

(setq-default
 ad-redefinition-action 'accept                   ; Silence warnings for redefinition
 auto-window-vscroll nil                          ; Lighten vertical scroll
 confirm-kill-emacs 'yes-or-no-p                  ; Confirm before exiting Emacs
 cursor-in-non-selected-windows nil               ; Hide the cursor in inactive windows
 delete-by-moving-to-trash t                      ; Delete files to trash
 display-time-default-load-average nil            ; Don't display load average
 display-time-format "%H:%M"                      ; Format the time string
 fill-column 80                                   ; Set width for automatic line breaks
 help-window-select t                             ; Focus new help windows when opened
 indent-tabs-mode nil                             ; Use tabs to indent
 inhibit-startup-screen t                         ; Disable start-up screen
 initial-scratch-message ""                       ; Empty the initial *scratch* buffer
 mouse-yank-at-point t                            ; Yank at point rather than pointer
 ns-use-srgb-colorspace nil                       ; Don't use sRGB colors
 select-enable-clipboard t                        ; Merge system's and Emacs' clipboard
 sentence-end-double-space nil                    ; End a sentence after a dot and a space
 show-help-function nil                           ; Disable help messages
 show-trailing-whitespace t                       ; Display trailing whitespaces
 split-height-threshold nil                       ; Disable vertical window splitting
 split-width-threshold nil                        ; Disable horizontal window splitting
 tab-width 4                                      ; Set width for tabs
 uniquify-buffer-name-style 'forward              ; Uniquify buffer names
 window-combination-resize t                      ; Resize windows proportionally
 x-stretch-cursor t                               ; Stretch cursor to the glyph width
 delete-old-versions -1                           ; Delete excess backup versions silently
 version-control t                                ; Use version control
 ring-bell-function 'ignore                       ; Silent bell when you make a mistake
 inhibit-compacting-font-caches t                 ; Faster navigation point (costs more memory)
 recentf-mode t                                   ; Keep recent files
 make-backup-files nil                            ; Stop creating backup files
 display-line-numbers-type 'relative              ; Use relative line numbers
 vc-follow-symlinks t                             ; When the symlink points to a version-controlled file
 use-default-font-for-symbols nil                 ; Do not use the frame font when rendering emojis
 frame-inhibit-implied-resize nil)                ; Don't ask for confirmation when opening symlinked file
(cd "~/")                                         ; Move to the user directory
(global-display-line-numbers-mode t)              ; Enable line numbers globally
(delete-selection-mode 1)                         ; Replace region when inserting text
(display-time-mode 1)                             ; Enable time in the mode-line
(global-auto-revert-mode 1)                       ; Automatically revert a buffer when it changes on disk
(fringe-mode '(8 . 0))                            ; Enable fringe on the left for git-gutter-fringe+
(electric-pair-mode t)                            ; Enable Matching delimeters
(electric-indent-mode t)                          ; Auto indentation
(fset 'yes-or-no-p 'y-or-n-p)                     ; Replace yes/no prompts with y/n
(global-subword-mode 1)                           ; Iterate through CamelCase words
(menu-bar-mode 0)                                 ; Disable the menu bar
(mouse-avoidance-mode 'jump)                      ; Avoid collision of mouse with point
(put 'downcase-region 'disabled nil)              ; Enable downcase-region
(put 'upcase-region 'disabled nil)                ; Enable upcase-region
(show-paren-mode 1)                               ; Highlight matching parenthesis

Enable fullscreen.

(if (eq window-system 'ns)
    (toggle-frame-maximized)
  (toggle-frame-fullscreen))

Garbage collection on focus-out, Emacs should feel snappier.

(add-hook 'focus-out-hook #'garbage-collect)

Remove trailing whitespace on save:

(add-hook 'before-save-hook 'delete-trailing-whitespace)

Default to utf-8 encoding.

(set-default-coding-systems 'utf-8)
(set-language-environment "UTF-8")
(prefer-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)

3.3 Load .custom.el

One is able to use the customization interface that is bundled within Emacs. It is meant to help people who are not familiar with Emacs Lisp in the configuration of Emacs itself. By default, changes in the customization will be automatically detected and appended at the end of the configuration file, init.el.

Since that in my case, the actual configuration file is a new one, crafted by org-mode, adding code at the end of init.el might mess things up. The following tells Emacs to add extra code in another file that would be then loaded, if existing.

(setq-default custom-file (expand-file-name "etc/.custom.el" user-emacs-directory))
(when (file-exists-p custom-file)
  (load custom-file))

3.4 Load config.el

Whenever the base core.org file is updated, all the custom user settings are wiped out.

To prevent this, the user may define permanent settings in the config.org file.

(setq-default userconfig-file (expand-file-name "config.el" user-emacs-directory))
(when (file-exists-p userconfig-file)
  (load userconfig-file))

3.5 Load custom themes

Custom themes location.

(add-to-list 'custom-theme-load-path (expand-file-name "etc/themes/" user-emacs-directory))

3.6 No littering

Keep ~/.emacs.d clean.

(use-package no-littering
  :straight t
  :demand t)

3.7 Performance

(use-package gcmh
  :demand t
  :straight t
  :config
  (gcmh-mode 1))

3.8 Utilities

(defun open-config-file ()
  (interactive)
  (find-file (expand-file-name "core.org" user-emacs-directory)))

4 Font

Font family used by Emacs.

Nice looking fonts:

(set-face-attribute 'default nil :font globals--font)
(set-frame-font globals--font nil t)

4.1 Ligatures

Rip off only the ligatures from the Fira Code font using the fira-code-mode minor mode.

Requires installation of the Fira Code Regular Symbol font with M-x fira-code-mode-install-fonts

(use-package fira-code-mode
  :straight t
  :demand t
  :hook prog-mode
  :custom (fira-code-mode-disabled-ligatures '("[]" ":" "x"))
  :config (fira-code-mode-set-font))

4.2 Emoji

Set up emoji rendering, requires installation of the Noto Emoji font for Linux.

;; Default Windows emoji font
(when (member "Segoe UI Emoji" (font-family-list))
  (set-fontset-font t 'symbol (font-spec :family "Segoe UI Emoji") nil 'prepend)
  (set-fontset-font "fontset-default" '(#xFE00 . #xFE0F) "Segoe UI Emoji"))

;; Linux emoji font
(when (member "Noto Color Emoji" (font-family-list))
  (set-fontset-font t 'symbol (font-spec :family "Noto Color Emoji") nil 'prepend)
  (set-fontset-font "fontset-default" '(#xFE00 . #xFE0F) "Noto Color Emoji"))

5 Themes

Conveniently create Emacs themes.

(use-package autothemer
  :straight t)

A pleaseant theme with earthy colors.

(straight-use-package
 '(emacs-mirwood-theme :type git :host github
                       :repo "b-coimbra/emacs-mirwood-theme"))

Set of eye pleasing themes for GNU Emacs. Supports both GUI and terminal.

(use-package kaolin-themes
  :defer 5
  :straight t
  :custom
  (kaolin-themes-bold t)
  (kaolin-themes-italic t)
  (kaolin-themes-underline t)
  (kaolin-themes-distinct-company-scrollbar t))

An opinionated pack of modern color-themes

(use-package doom-themes
  :straight t
  :demand t
  :custom
  (doom-themes-enable-bold t)
  (doom-themes-enable-italic t)
  (doom-themes-treemacs-enable-variable-pitch nil)
  :config
  (load-theme globals--theme t)
  (doom-themes-treemacs-config))

5.5 Theme customization

Persistent theme customization.

(set-face-attribute 'font-lock-keyword-face nil :weight 'bold)

6 Appearance

Adds fancy icons to emacs.

Cheat sheet

(use-package nerd-icons
  :straight t)

Gives other windows slightly different background colors (brightness).

(use-package solaire-mode
  :straight t
  :hook (after-init . solaire-global-mode))

Colorize color names in buffers.

(use-package rainbow-mode
  :straight t
  :hook prog-mode
  :config
  (rainbow-mode))

“Rainbow parentheses”-like mode which highlights delimiters such as parentheses, brackets or braces according to their depth.

(use-package rainbow-delimiters
  :straight t
  :hook (prog-mode . rainbow-delimiters-mode))

A utility package to collect various Icon Fonts and propertize them within Emacs.

(use-package all-the-icons
  :straight t
  :if (display-graphic-p))

7 Modeline

A fancy and fast mode-line inpsired by minimalism design.

(use-package doom-modeline
  :straight t
  :init (doom-modeline-mode)
  :custom
  (doom-modeline-major-mode-icon nil)
  (doom-modeline-major-mode-color-icon nil)
  (doom-modeline-icon (display-graphic-p))
  (doom-modeline-modal-modern-icon nil)
  (doom-modeline-buffer-modification-icon nil)
  (doom-modeline-flycheck-icon nil)
  (doom-modeline-checker-simple-format t)
  (doom-modeline-buffer-encoding nil)
  (doom-modeline-height 35))

Powerline theme from Spacemacs.

(use-package spaceline
  :disabled t
  :straight t
  :init
  (progn
    (setq spaceline-highlight-face-func 'spaceline-highlight-face-evil-state)
    (setq-default powerline-default-separator 'slant)
    )
  :config
  (spaceline-emacs-theme)
  (setq spaceline-buffer-encoding-abbrev-p nil
        spaceline-workspace-number-p t
        spaceline-window-numbers-unicode nil
        spaceline-version-control-p nil
        spaceline-minor-modes-p nil
        spaceline-major-mode-p nil
        spaceline-buffer-size-p t
        spaceline-window-number-p t
        spaceline-buffer-id-p t
        spaceline-bufFer-size-p t)
  (powerline-reset))

8 Dashboard

An extensible emacs startup screen showing you what’s most important.

(use-package dashboard
  :straight t
  :demand t
  :init
  (add-hook 'dashboard-mode-hook (lambda () (setq show-trailing-whitespace nil)))
  :custom
  (dashboard-banner-logo-title "[M E G U M A C S]")
  (dashboard-startup-banner (expand-file-name globals--banner-path user-emacs-directory))
  (dashboard-footer-messages '("EXPLOOOOOOOOOOSIONNN!"))
  (dashboard-footer-icon (nerd-icons-wicon "nf-weather-meteor" :height 1.5 :v-adjust 0.0 :face 'font-lock-keyword-face))
  (dashboard-center-content t)
  (dashboard-set-heading-icons t)
  (dashboard-set-file-icons t)
  (dashboard-set-navigator t)
  (dashboard-navigator-buttons
   `(
     ;; Links
     ((,(nerd-icons-codicon "nf-cod-octoface" :height 1.3 :v-adjust 0.0)
       "Homepage"
       "Browse homepage"
       (lambda (&rest _) (browse-url "https://github.com/b-coimbra/.emacs.d")) nil "" " |")
      (,(nerd-icons-faicon "nf-fa-refresh" :height 1.3 :v-adjust 0.0)
       "Update"
       "Update Megumacs"
       (lambda (&rest _) (straight-pull-all)) warning "" " |")
      (,(nerd-icons-faicon "nf-fa-flag" :height 1.3 :v-adjust 0.0) nil
       "Report a BUG"
       (lambda (&rest _) (browse-url "https://github.com/b-coimbra/.emacs.d/issues/new")) error "" ""))

     ;; Empty line
     (("" "\n" "" nil nil "" ""))

     ;; Keybindings
     ((,(nerd-icons-faicon "nf-fa-search" :height 1.1 :v-adjust -0.1)
       " Find file" nil
       (lambda (&rest _) (counsel-find-file)) nil "" "            SPC f f"))
     ((,(nerd-icons-octicon "nf-oct-file_directory" :height 1.1 :v-adjust -0.1)
       " Open project" nil
       (lambda (&rest _) (counsel-projectile-switch-project)) nil "" "         SPC p p"))
     ((,(nerd-icons-codicon "nf-cod-three_bars" :height 1.1 :v-adjust -0.1)
       " File explorer" nil
       (lambda (&rest _) (counsel-projectile-switch-project)) nil "" "        SPC t t"))
     ((,(nerd-icons-codicon "nf-cod-settings" :height 1.1 :v-adjust -0.1)
       " Open settings" nil
       (lambda (&rest _) (open-config-file)) nil "" "        SPC f P"))
     ))
  :config
  (dashboard-setup-startup-hook))

9 Auto Completion

Modular in-buffer completion framework.

(use-package company
  :defer 0.5
  :straight t
  :delight
  :init (global-company-mode)
  :custom
  (company-begin-commands '(self-insert-command))
  (company-minimum-prefix-length 2)
  (company-idle-delay 0.1)
  (company-show-numbers t)
  (company-tooltip-align-annotations t)
  :config
  (add-to-list 'company-backends
               '(company-yasnippet
                 company-files
                 company-keywords
                 company-capf
                 company-dabbrev
                 company-dabbrev-code)))

Company backend for Python jedi.

(use-package company-jedi
  :straight t
  :after company
  :init
  (add-to-list 'company-backends 'company-jedi)
  :config
  (setq jedi:setup-keys t)
  (setq jedi:complete-on-dot t))

10 Evil

Evil is an extensible vi layer for Emacs. It emulates the main features of Vim, and provides facilities for writing custom extensions.

Base package for evil-mode

(use-package evil
  :straight t
  :demand t
  :init
  (setq evil-want-keybinding nil
        evil-want-integration t)
  :custom
  (evil-want-C-u-scroll t)
  (evil-want-C-i-jump t)
  :config
  (evil-mode 1)
  (evil-set-undo-system 'undo-redo))

Unfortunately we need a separate package to handle custom <ESC> key sequences.

(use-package evil-escape
  :straight t
  :defer 1
  :custom
  (evil-escape-key-sequence "jk")
  :config
  (evil-escape-mode))

Useful package for adding, editing or removing all types of surrounding characters (even HTML tags!).

(use-package evil-surround
  :straight t
  :defer 2
  :after evil
  :config
  (global-evil-surround-mode 1))

10.4 evil-mc

Multiple cursors implementation for evil-mode.

(use-package evil-mc
  :straight t
  :after evil
  :init
  (global-evil-mc-mode 1))

Evil bindings for commenting out chunks of code.

(use-package evil-commentary
  :straight t
  :defer 2
  :config
  (evil-commentary-mode))
(use-package evil-collection
  :straight t
  :demand t
  :after evil
  :custom
  (evil-collection-minibuffer-setup t)
  :config
  (evil-collection-init))
(use-package evil-fringe-mark
  :straight t
  :init (global-evil-fringe-mark-mode))

11 Calendar

11.1 calfw

This program displays a calendar view in the Emacs buffer.

(use-package calfw
  :straight t)

12 Org-mode

12.1 org

Org mode is for keeping notes, maintaining to-do lists, planning projects, authoring documents, computational notebooks, literate programming and more — in a fast and effective plain text system

(use-package org
  :init
  (setq org-startup-folded t
        org-element-use-cache nil)
  :straight t
  :config
  ;; prettify
  (setq org-hide-macro-markers t
        org-hide-emphasis-markers t
        org-adapt-indentation t
        org-hide-leading-stars t
        org-odd-levels-only t)
  ;; org archive
  (setq org-archive-location (concat "archive/"
                                     (format-time-string "%Y-%m" (current-time))
                                     "_%s_archive::"))
  ;; org persist
  (setq org-persist-directory (concat user-emacs-directory "var/org/persist/"))
  ;; org modules
  (setq org-modules '(ol-w3m
                      ol-bbdb
                      ol-bibtex
                      ol-docview
                      ol-gnus
                      ol-info
                      ol-irc
                      ol-mhe
                      ol-rmail
                      ol-eww))
  ;; org-todo
  (setq org-todo-keywords
        '((sequence
           "TODO(t)"
           "DOING(d!)"
           "MAYBE(m)"
           "BLOCKED(b@)"
           "DONE(D!)"
           "READ(r)"
           "ARCHIVED(a!)")))
  (setq org-todo-keyword-faces
        '(("TODO"     . (:foreground "HotPink3" :weight bold))
          ("DOING"    . (:foreground "salmon" :weight bold))
          ("BLOCKED"  . (:foreground "DeepPink" :weight bold))
          ("MAYBE"    . (:foreground "LightSteelBlue4" :weight bold))
          ("DONE"     . (:foreground "SeaGreen3" :weight bold))
          ("READ"     . (:foreground "SteelBlue2" :weight bold))
          ("ARCHIVED" . (:foreground "LightSlateGrey" :weight bold)))))

Reveal.js presentation back-end for org export engine.

(use-package ox-reveal
  :straight t
  :defer 3
  :after org
  :custom
  (setq org-reveal-root "https://cdn.jsdelivr.net/npm/reveal.js")
  (setq org-reveal-klipsify-src t) ; Evaluate code
  )

12.3 calfw-org

Display org schedules.

(use-package calfw-org
  :straight t
  :defer 2
  :config
  (setq cfw:org-agenda-schedule-args '(:timestamp :scheduled :deadline)))

12.4 htmlize

Used for exporting source code with syntax highlighting.

(use-package htmlize
  :straight t)

13 Keybindings

13.1 General

More convenient key definitions.

(use-package general
  :straight t
  :demand t
  :config
  (general-evil-setup t)
  (define-key evil-motion-state-map " " nil)
  (general-create-definer leader-def :prefix globals--leader-key)
  (leader-def
    :states 'normal
    ;; Misc
    "TAB" 'mode-line-other-buffer
    "." 'xref-find-definitions
    "," 'xref-pop-marker-stack
    "'" 'eshell
    "qq" 'evil-quit

    ;; Applications
    "a" '(:ignore t :which-key "applications")
    "au" 'undo-tree-visualize
    "aU" 'straight-pull-all
    "ac" 'cfw:open-org-calendar

    ;; Buffers
    "b" '(:ignore t :which-key "buffers")
    "bb" 'counsel-switch-buffer
    "bd" 'kill-this-buffer
    "bp" 'previous-buffer
    "bn" 'next-buffer
    "bN" 'evil-buffer-new
    "be" 'erase-buffer

    ;; Bookmarks
    "B" '(:ignore t :which-key "bookmarks")
    "BB" 'bookmark-jump
    "Bs" 'bookmark-set

    ;; Compiling
    "c" 'compile

    ;; Errors
    "e" '(:ignore t :which-key "errors")

    ;; Files
    "f" '(:ignore t :which-key "file")
    "ff" 'find-file
    "fs" 'save-buffer
    "fS" 'evil-write-all
    "fR" 'rename-file
    "fb" 'ranger-show-bookmarks
    "fP" 'open-config-file

    ;; Focus
    "F" '(:ignore t :which-key "focus")

    ;; LSP
    "l" '(:ignore t :which-key "language")

    ;; Projects
    "p" '(:ignore t :which-key "project")

    ;; Toggles
    "t" '(:ignore t :which-key "toggles")
    "tn" 'display-line-numbers-mode
    "tL" 'visual-line-mode
    "tu" 'lsp-ui-mode
    "ti" 'highlight-indent-guides-mode

    ;; Themes
    "T" '(:ignore t :which-key "themes")

    ;; Windows
    "w" '(:ignore t :which-key "window")
    "wm" 'delete-other-windows
    "wf" 'delete-other-windows
    "wj" 'evil-window-down
    "wk" 'evil-window-up
    "wl" 'evil-window-right
    "wh" 'evil-window-left
    "ws" 'split-and-follow-horizontally
    "wv" 'split-and-follow-vertically
    "wd" 'evil-window-delete
    "wc" 'evil-window-delete
    "wH" 'evil-window-move-far-left
    "wL" 'evil-window-move-far-right
    "wK" 'evil-window-move-very-top
    "wJ" 'evil-window-move-very-bottom
    "w=" 'balance-windows

    ;; Help
    "h" '(:ignore t :which-key "help")
    "hk" 'describe-key
    "hv" 'describe-variable
    "hf" 'describe-function
    "hK" 'general-describe-keybindings
    ))

Package that displays available keybindings in a popup.

(use-package which-key
  :defer 5
  :straight t
  :config
  (which-key-mode))

14 Source Control

14.1 Magit

General source control package. Has a nice interface for every git operation there is.

(use-package magit
  :straight t
  :defer 3
  :general
  (nmap
    :prefix globals--leader-key
    "g" '(nil :which-key "magit")
    "gs" 'magit-status
    "gb" 'magit-blame))

Commit diff and other repo informations. Has the capability to stage hunks and what-not.

(use-package git-gutter+
  :straight t
  :defer 3
  :config
  (global-git-gutter+-mode))
(use-package git-gutter-fringe+
  :straight t
  :after git-gutter+
  :defer 3
  :custom
  (git-gutter-fr+-side 'left-fringe)
  :config
  (git-gutter-fr+-minimal))

15 Encryption

Interface for GPG, setup for transparent encryption and decryption:

(use-package epa-file
  :ensure nil
  :config
  (setq epa-file-encrypt-to '(globals--email))
  :custom
  (epa-file-select-keys 'silent))

16 File Management

16.1 Ranger

Bringing the goodness of ranger to dired!

(use-package ranger
  :straight t
  :general
  (nmap
    :prefix globals--leader-key
    "ar" 'ranger
    "ad" 'deer)
  :config
  (ranger-override-dired-mode t))

17 Project Management

A tree layout file explorer.

(use-package treemacs
  :straight t
  :after evil
  :general
  (nmap
    :prefix globals--leader-key
    "tt" 'treemacs)
  :custom
  (treemacs-no-png-images nil)
  (treemacs-width 35))

treemacs-evil must be installed and loaded if you use evil. The keybindings and the cursor will not be setup properly otherwise. It’ll also enable navigation with j/k instead of n/p.

(use-package treemacs-evil
  :straight t
  :demand t
  :after treemacs evil)

treemacs-magit is a small utility package to fill the small gaps left by using filewatch-mode and git-mode in conjunction with magit: it will inform treemacs about (un)staging of files and commits happening in magit.

(use-package treemacs-magit
  :straight t)

Project interaction library.

(use-package projectile
  :straight t
  :custom
  (projectile-enable-caching t)
  :config
  (setq projectile-indexing-method 'alien)
  (projectile-mode))

ivy UI for Projectile.

(use-package counsel-projectile
  :straight t
  :general
  (nmap
    :prefix globals--leader-key
    "pp" 'counsel-projectile-switch-project
    "pf" 'counsel-projectile-find-file
    "pd" 'counsel-projectile-find-dir
    "pg" 'counsel-projectile-git-grep
    "pR" 'projectile-replace
    "ps" 'projectile-save-project-buffers))

18 Syntax Checking

Modern on-the-fly syntax checking extension.

(use-package flycheck
  :straight t
  :hook (prog-mode . flycheck-mode)
  :general
  (nmap
    :prefix globals--leader-key
    "en" 'flycheck-next-error
    "ep" 'flycheck-previous-error))

19 Language Modes

Base language packages.

19.1 Rust

(use-package rust-mode
  :straight t)

19.2 Ruby

(use-package ruby-mode
  :straight t)
(use-package js2-mode
  :straight t
  :custom
  (js-indent-level 2)
  (js2-basic-offset 2)
  :init
  (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode)))

19.4 RSJX

(use-package rjsx-mode
  :straight t)
(use-package typescript-mode
  :custom
  (typescript-indent-level 2)
  :straight t)

19.6 Web

(use-package web-mode
  :straight t
  :custom
  (web-mode-code-indent-offset 2)
  (web-mode-markup-indent-offset 2))

19.7 Python

(use-package python-mode
  :straight t
  :hook (python-mode-hook . jedi:setup))

20 Language Server Protocol

20.1 LSP

lsp-mode aims to provide IDE-like experience by providing optional integration with the most popular Emacs packages like company, flycheck and projectile.

(use-package lsp-mode
  :straight t
  :general
  (nmap
    :prefix globals--leader-key
    "la" 'lsp-execute-code-action
    "lF" 'lsp-format-buffer
    "lR" 'lsp-rename)
  :hook ((js2-mode        . lsp-deferred)
         (js-mode         . lsp-deferred)
         (rjsx-mode       . lsp-deferred)
         (typescript-mode . lsp-deferred)
         (rust-mode       . lsp-deferred)
         (python-mode     . lsp-deferred)
         (ruby-mode       . lsp-deferred))
  :commands (lsp lsp-deferred)
  :config
  (setq lsp-enable-completion-at-point t))

20.1.1 LSP-UI

Higher level UI modules of lsp-mode.

(use-package lsp-ui
  :straight t
  :after lsp-mode
  :commands lsp-ui-mode
  :hook (lsp-mode . lsp-ui-mode)
  :general
  (nmap
    :prefix globals--leader-key
    "li" 'lsp-ui-peek-find-implementation
    "lr" 'lsp-ui-peek-find-references
    "ld" 'lsp-ui-peek-find-definitions
    "lg" 'lsp-ui-doc-glance
    "ll" 'lsp-ui-flycheck-list)
  :custom
  (lsp-ui-doc-enable t)
  (lsp-ui-sideline-enable t)
  (lsp-ui-flycheck-enable t)
  (lsp-ui-flycheck-live-reporting t)
  (lsp-ui-sideline-toggle-symbols-info t)
  (lsp-ui-sideline-show-hover t)
  (lsp-ui-peek-enable t))

21 Buffers and Windows

21.1 Winum

Numbering for buffers, windows and eyebrowse workspaces.

(use-package winum
  :straight t
  :defer 0.5
  :custom
  (winum-auto-setup-mode-line nil)
  :config
  (winum-mode))

A simple-minded way of managing window configs in emacs.

(use-package eyebrowse
  :straight t
  :defer 2
  :general
  :config
  (eyebrowse-mode)
  (eyebrowse-setup-opinionated-keys))

Windmove is used for moving buffers to other windows.

(use-package windmove
  :straight t
  :general
  (nmap
    :prefix globals--leader-key
    "wH" 'windmove-swap-states-left
    "wL" 'windmove-swap-states-right
    "wK" 'windmove-swap-states-up
    "wJ" 'windmove-swap-states-down)
  :init
  (windmove-default-keybindings))

21.4 Focus on newly created windows

(defun split-and-follow-horizontally ()
  (interactive)
  (split-window-below)
  (balance-windows)
  (other-window 1))

(defun split-and-follow-vertically ()
  (interactive)
  (split-window-right)
  (balance-windows)
  (other-window 1))

22 Navigation

22.1 Ivy

avy is similar to Vim’s easymotion plugin, it provides commands for jumping to visible text using a char-based decision tree.

(use-package ivy
  :straight t
  :demand t
  :general
  (nmap
    :prefix globals--leader-key
    "s" 'swiper
    ";" 'avy-goto-word-1
    ":" 'avy-goto-char)
  :custom
  (ivy-count-format "(%d/%d) ")
  (avy-background t)
  :config
  (global-set-key "\C-s" 'swiper)
  (ivy-mode))

(use-package ivy-rich
  :straight t
  :after ivy
  :init
  (ivy-rich-mode 1)
  :config
  (setcdr (assq t ivy-format-functions-alist) #'ivy-format-function-line))

Completion frontend for things such as M-x find-file.

(use-package counsel
  :straight t
  :after ivy
  :general
  (nmap
    :prefix globals--leader-key
    "SPC" 'counsel-M-x
    "fr" 'counsel-recentf
    "Ts" 'counsel-load-theme))

Indentation highlights via font-lock

(use-package highlight-indent-guides
  :straight t
  :custom
  (highlight-indent-guides-method 'character)
  (highlight-indent-guides-character ?\|))

23 Editing

23.1 Focus

Dim the font color of text in surrounding paragraphs.

(use-package focus
  :straight t
  :general
  (nmap
    :prefix globals--leader-key
    "tf" 'focus-mode
    "Fp" 'focus-pin
    "Fu" 'focus-unpin
    "Fc" 'focus-change-thing))

Branching tree of changes made in a file.

(use-package undo-tree
  :straight t
  :init
  (global-undo-tree-mode)
  :config
  (setq undo-tree-auto-save-history nil))

23.3 Origami

A text folding minor mode for Emacs. With this minor mode enabled, you can collapse and expand regions of text.

(use-package origami
  :straight t
  :hook ((js2-mode        . origami-mode)
         (js-mode         . origami-mode)
         (typescript-mode . origami-mode)
         (rust-mode       . origami-mode)))

24 Templates

A snippet template system.

(use-package yasnippet
  :straight t
  :general
  (nmap
    :prefix globals--leader-key
    "yt" 'yas-describe-tables)
  :init
  (yas-global-mode 1)
  :custom
  (yas-prompt-functions 'yas-ido-prompt))

Solve conflicts between company-mode and yasnippet-mode.

(defun company-yasnippet-or-completion ()
  "Solve company yasnippet conflicts."
  (interactive)
  (let ((yas-fallback-behavior
         (apply 'company-complete-common nil)))
    (yas-expand)))

(add-hook 'company-mode-hook
          (lambda ()
            (substitute-key-definition
             'company-complete-common
             'company-yasnippet-or-completion
             company-active-map)))

A collection of yasnippet snippets for many languages

(use-package yasnippet-snippets
  :after yasnippet
  :straight t)

25 Discord Presence

25.1 elcord

Discord rich presence for emacs.

(use-package elcord
  :straight t
  :defer 5
  :config
  (setq elcord-client-id "903078200886853665")
  (setq elcord-editor-icon "megumacs-icon")
  (elcord-mode))