13 KiB
13 KiB
Crony's Emacs Config
- GARBAGE COLLECTION
- BACKUPS
- SANE DEFAULTS
- GUI TWEAKS
- FONTS
- ELECTRIC PAIR
- TRANSFORM INTO VIM
- WHICH_KEY
- GENERAL KEYBINDINGS
- DIMINISH
- THEME
- HELPFUL
- COMPLETION
- IN BUFFER COMPLETION
- DIRED
- ALL THE ICONS
- GIT
- HIGHLIGHT TODO
- PROJECTS LIST
GARBAGE COLLECTION
(defvar file-name-handler-alist-old file-name-handler-alist)
(setq file-name-handler-alist nil
gc-cons-threshold most-positive-fixnum)
(add-hook 'after-init-hook
`(lambda ()
(setq file-name-handler-alist file-name-handler-alist-old)
(setq gc-cons-threshold (* 2 1000 1000))
(setq gc-cons-percentage 0.1))
t)
BACKUPS
Move backup files to a diff directory.
(setq backup-directory-alist '(("." . "~/.cache/emacs/"))
backup-by-copying t ; Don't delink hardlinks
version-control t ; Use version numbers on backups
delete-old-versions t ; Automatically delete excess backups
kept-new-versions 20 ; how many of the newest versions to keep
kept-old-versions 5 ; and how many of the old
)
SANE DEFAULTS
(delete-selection-mode 1) ;; You can select text and delete it by typing.
(electric-indent-mode -1) ;; Turn off the weird indenting that Emacs does by default.
(global-auto-revert-mode t) ;; Automatically show changes if the file has changed
(setq initial-scratch-message nil) ;; disable the initial scratch message.
(setq-default delete-pair-blink-delay 0) ;; remove delay when deleting pairs
(prefer-coding-system 'utf-8) ;; utf-8
(global-set-key [escape] 'keyboard-escape-quit) ;; escape minibuffers with ESC
GUI TWEAKS
(global-visual-line-mode t) ;; Enable truncated lines
(menu-bar-mode -1) ;; Disable the menu bar
(scroll-bar-mode -1) ;; Disable the scroll bar
(tool-bar-mode -1) ;; Disable the tool bar
(set-fringe-mode 10) ;; Give me some breathing room
(fset 'yes-or-no-p 'y-or-n-p) ;; don't ask to spell out "yes"
(setq-default frame-resize-pixelwise t) ;; avoid leaving a gap beetween the frame and the screen
(column-number-mode) ;; Display line colums
;; disable line numbers for following modes
(dolist (mode '(org-mode-hook
term-mode-hook
shell-mode-hook
eshell-mode-hook))
(add-hook mode (lambda () (display-line-numbers-mode 0))))
(global-display-line-numbers-mode 1) ;; Display line numbers
(blink-cursor-mode -1) ;; disable blinking cursor
FONTS
(set-face-attribute 'default nil
:font "CommitMono Nerd Font"
:height 140
:weight 'medium)
(set-face-attribute 'variable-pitch nil
:font "DejaVu Sans"
:height 150
:weight 'medium)
(set-face-attribute 'fixed-pitch nil
:font "CommitMono Nerd Font"
:height 140
:weight 'medium)
(add-to-list 'default-frame-alist '(font . "CommitMono Nerd Font-14"))
ELECTRIC PAIR
(electric-pair-mode 1)
(add-hook 'org-mode-hook (lambda ()
(setq-local electric-pair-inhibit-predicate
`(lambda (c)
(if (char-equal c ?<) t (,electric-pair-inhibit-predicate c))))))
TRANSFORM INTO VIM
EVIL MODE
(use-package evil
:init
(setq evil-want-integration t
evil-want-keybinding nil
evil-want-C-u-scroll t
evil-want-C-i-jump nil
evil-vsplit-window-right t
evil-split-window-below t
evil-undo-system 'undo-redo)
:config
(evil-mode 1)
(define-key evil-insert-state-map (kbd "C-g") 'evil-normal-state)
(define-key evil-insert-state-map (kbd "C-h") 'evil-delete-backward-char-and-join)
(evil-set-initial-state 'messages-buffer-mode 'normal)
(evil-set-initial-state 'dashboard-mode 'normal))
(use-package evil-collection
:after evil
:config
(evil-collection-init))
MODELINE
(use-package doom-modeline
:ensure t
:init (doom-modeline-mode 1)
:config
(setq doom-modeline-height 25
doom-modeline-bar-width 5
doom-modeline-persp-name t
doom-modeline-persp-icon t))
VIM LIKE SCROLLING
;; Vim like scrolling
(setq scroll-margin 10
scroll-step 1
scroll-conservatively 10000
scroll-preserve-screen-position 1)
WHICH_KEY
(use-package which-key
:init
(which-key-mode 1)
:diminish
:config
(setq which-key-side-window-location 'bottom
which-key-sort-order #'which-key-key-order-alpha
which-key-sort-uppercase-first nil
which-key-add-column-padding 1
which-key-max-display-columns nil
which-key-min-display-lines 6
which-key-side-window-slot -10
which-key-side-window-max-height 0.25
which-key-idle-delay 0.3
which-key-max-description-length 25
which-key-allow-imprecise-window-fit nil
which-key-separator " → " ))
GENERAL KEYBINDINGS
(use-package general
:ensure t
:init
(with-eval-after-load 'evil
(general-evil-setup))
(general-auto-unbind-keys)
:config
(general-override-mode)
(general-create-definer +config/leader-key
:keymaps 'override
:states '(insert emacs normal hybrid motion visual operator)
:prefix "SPC"
:non-normal-prefix "s-SPC")
(general-create-definer +config/local-leader
:keymaps 'override
:states '(emacs normal hybrid motion visual operator)
:prefix "m"
:non-normal-prefix "s-m"
"" '(:ignore t :which-key (lambda (arg) `(,(cadr (split-string (car arg) " ")) . ,(replace-regexp-in-string "-mode$" "" (symbol-name major-mode)))))))
DIMINISH
(use-package diminish)
ORG MODE
Update and setup org mode
;; fixes a bug where evil mnode bounds return key, so it isn't accesible
(with-eval-after-load 'evil-maps
(define-key evil-motion-state-map (kbd "RET") nil))
(defun crony/org-mode-setup ()
(org-indent-mode)
(visual-line-mode 1))
;; Replace list hyphen with dot
(font-lock-add-keywords 'org-mode
'(("^ *\\([-]\\) "
(0 (prog1 () (compose-region (match-beginning 1) (match-end 1) "•"))))))
(use-package org
:defer t
:init (require 'org-tempo)
:hook (org-mode . crony/org-mode-setup)
:config
(setq org-ellipsis " ▾")
(setq org-edit-src-content-indentation 0)
;; org agenda settings
(setq org-agenda-start-with-log-mode t)
(setq org-log-done 'time)
(setq org-log-into-drawer t)
(setq org-agenda-files
'("~/docs/notes/tasks.org"
"~/docs/notes/birthdays.org"))
;; refiling
(setq org-refile-targets
'(("archive.org" :maxlevel . 1)
("tasks.org" :maxlevel . 1)))
;; save after refiling
(advice-add 'org-refile :after 'org-save-all-org-buffers)
(setq org-return-follows-link t))
Column width
(defun crony/org-mode-visual-fill ()
(setq visual-fill-column-width 110
visual-fill-column-center-text t)
(visual-fill-column-mode 1))
(use-package visual-fill-column
:defer t
:hook (org-mode . crony/org-mode-visual-fill))
Enabling Org Bullets
(use-package org-bullets
:after org
:hook (org-mode . org-bullets-mode))
Enabling Table of Contents
(use-package toc-org
:after org
:commands toc-org-enable
:init (add-hook 'org-mode-hook 'toc-org-enable))
THEME
(use-package gruvbox-theme
:config
(load-theme 'gruvbox-dark-medium :no-confirm))
HELPFUL
(use-package helpful
:bind
([remap describe-function] . helpful-function)
([remap describe-command] . helpful-command)
([remap describe-variable] . helpful-variable)
([remap describe-key] . helpful-key))
COMPLETION
VERTICO
(use-package vertico
:bind (:map vertico-map
("C-j" . vertico-next)
("C-k" . vertico-previous)
("C-l" . vertico-exit)
:map minibuffer-local-map
("C-h" . backward-kill-word))
:custom
(vertico-scroll-margin 0) ;; Different scroll margin
(vertico-count 15) ;; Show more candidates
(vertico-resize t) ;; Grow and shrink the Vertico minibuffer
(vertico-cycle t) ;; Enable cycling for `vertico-next/previous'
:init
(vertico-mode))
(use-package savehist
:ensure nil
:init
(savehist-mode))
(use-package emacs
:ensure nil
:custom
(context-menu-mode t)
(enable-recursive-minibuffers t)
(read-extended-command-predicate #'command-completion-default-include-p)
(minibuffer-prompt-properties
'(read-only t cursor-intangible t face minibuffer-prompt)))
MARGINALIA
(use-package marginalia
:bind (:map minibuffer-local-map
("M-A" . marginalia-cycle))
:init
(marginalia-mode))
CONSULT
(use-package consult
:after vertico
:custom
(completion-in-region-function #'consult-completion-in-region)
:config
(recentf-mode t))
ORDERLESS
(use-package orderless
:ensure t
:custom
(completion-styles '(orderless basic))
(completion-category-overrides '((file (styles partial-completion))))
(completion-pcm-leading-wildcard t)) ;; Emacs 31: partial-completion behaves like substring
IN BUFFER COMPLETION
CORFU
Adds in buffer completion for code/snippets
(use-package corfu
;; Optional customizations
:custom
(tab-always-indent 'complete)
(completion-cycle-threshold nil)
(corfu-cycle t)
(corfu-auto t)
(corfu-auto-prefix 2)
(corfu-auto-delay 0.1)
(corfu-min-width 60)
(corfu-popupinfo-delay '(0.5 . 0.2))
(corfu-preview-current 'insert)
(corfu-preselect 'prompt)
(corfu-on-exact-match nil)
:bind (:map corfu-map
("C-j" . corfu-next)
("C-k" . corfu-previous)
("C-l" . corfu-insert))
:init
(corfu-history-mode)
(corfu-popupinfo-mode)
(global-corfu-mode)
:config
(add-hook 'eshell-mode-hook
(lambda () (setq-local corfu-quit-at-boundary t
corfu-quit-no-match t
corfu-auto nil)
(corfu-mode))))
KIND ICON
Eyecandy for corfu
(use-package kind-icon
:ensure t
:after corfu
:custom
(kind-icon-default-face 'corfu-default)
:config
(plist-put kind-icon-default-style :height 0.8)
(add-to-list 'corfu-margin-formatters #'kind-icon-margin-formatter))
CAPE
extending corpu
(use-package cape
:defer 10
:bind ("C-c f" . cape-file)
:init
(defalias 'dabbrev-after-2 (cape-capf-prefix-length #'cape-dabbrev 2))
(add-to-list 'completion-at-point-functions 'dabbrev-after-2 t)
(cl-pushnew #'cape-file completion-at-point-functions)
:config
(advice-add 'pcomplete-completions-at-point :around #'cape-wrap-silent)
(advice-add 'pcomplete-completions-at-point :around #'cape-wrap-purify))
YASNIPPET
(use-package yasnippet
:ensure t
:init
(setq yas-nippet-dir "~/.config/emacs/snippets/")
(yas-global-mode))
(use-package yasnippet-snippets
:ensure t
:after yasnippet)
DIRED
(use-package dired-open
:config
(setq dired-open-extensions '(("mkv" . "mpv")
("mp4" . "mpv"))))
(use-package peep-dired
:after dired
:hook (evil-normalize-keymaps . peep-dired-hook)
:config
(evil-define-key 'normal dired-mode-map (kbd "h") 'dired-up-directory)
(evil-define-key 'normal dired-mode-map (kbd "l") 'dired-open-file)
(evil-define-key 'normal peep-dired-mode-map (kbd "j") 'peep-dired-next-file)
(evil-define-key 'normal peep-dired-mode-map (kbd "k") 'peep-dired-prev-file)
)
ALL THE ICONS
(use-package all-the-icons
:ensure t
:if (display-graphic-p))
;; dired icons
(use-package all-the-icons-dired
:after all-the-icons
:hook (dired-mode . (lambda () (all-the-icons-dired-mode t))))
;; completion with marginalia
(use-package all-the-icons-completion
:after (marginalia all-the-icons)
:hook (marginalia-mode . all-the-icons-completion-marginalia-setup)
:init
(all-the-icons-completion-mode))
GIT
TIME MACHINE
(use-package git-timemachine
:after git-timemachine
:hook (evil-normalize-keymaps . git-timemachine-hook)
:config
(evil-define-key 'normal git-timemachine-mode-map (kbd "C-j") 'git-timemachine-show-previous-revision)
(evil-define-key 'normal git-timemachine-mode-map (kbd "C-k") 'git-timemachine-show-next-revision)
)
DIFF HIGHLIGHT
(use-package diff-hl
:config
(global-diff-hl-mode t))
MAGIT
(use-package magit)
HIGHLIGHT TODO
(use-package hl-todo
:hook ((prog-mode . hl-todo-mode))
:config
(setq hl-todo-highlight-punctuation ":"
hl-todo-keyword-faces
`(("TODO" warning bold)
("FIXME" error bold)
("HACK" font-lock-constant-face bold)
("REVIEW" font-lock-keyword-face bold)
("NOTE" success bold)
("DEPRECATED" font-lock-doc-face bold))))
PROJECTS LIST
(use-package projectile
:diminish
:config
(projectile-mode 1))