Last active
April 18, 2021 17:38
-
-
Save CodeSigils/9fa88d23fb7c41b34c9b2eeac5928cf0 to your computer and use it in GitHub Desktop.
emacs configuration sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; package --- init.el | |
;; Author: Tom Geo | |
;; Keywords: emacs configuration tutorial | |
;; URL: https://github.com/ | |
;; This file is not part of GNU Emacs. | |
;;; Commentary: | |
;; This is an evil/leader/ivy/counsel/LSP based collection of Emacs plugins | |
;; with main focus on convenience, easy keybindings and some additional UI | |
;; elements. | |
;;; Code: | |
(custom-set-variables | |
;; custom-set-variables was added by Custom. | |
;; If you edit it by hand, you could mess it up, so be careful. | |
;; Your init file should contain only one such instance. | |
;; If there is more than one, they won't work right. | |
'(comp-deferred-compilation t) | |
'(display-time-mode t) | |
'(evil-want-keybinding nil) | |
'(ido-everywhere t) | |
'(lsp-ui-peek-always-show t) | |
'(package-selected-packages | |
'(vterm-toggle vterm hydra lispy htmlize iedit simple-httpd zoutline elpher darkroom know-your-http-well rainbow-mode yaml-mode skewer-mode impatient-mode web-mode cargo rust-mode ccls lispyville scheme-mode perspective minions skeletor aggressive-indent async ob-deno ob-async browse-at-remote kaesar ht lsp-mode lsp-treemacs markdown-mode pfuture posframe spinner tsc web-completion-data frame-local dash-functional cfrs bui annalist lsp-ui js2-mode flow-minor-mode company-flow company-lua lua-mode typescript-mode tree-sitter treemacs-all-the-icons direnv dap-mode treemacs flycheck prettier-js sql-indent delight undo-tree company-web company-box company-prescient company evil-collection ace-window evil-leader dash elisp-refs epl f git-commit goto-chg ivy ivy-rich lv pkg-info s shrink-path transient with-editor rainbow-delimiters evil-smartparens smartparens yasnippet evil-nerd-commenter expand-region org-superstar counsel-projectile projectile fzf ag ripgrep counsel helpful ivy-hydra ivy-prescient swiper prescient ace-isearch avy magit which-key flx-ido flx doom-modeline all-the-icons-ivy all-the-icons-ibuffer all-the-icons-gnus all-the-icons-dired doom-themes all-the-icons-ivy-rich all-the-icons smooth-scrolling evil no-littering bind-key use-package)) | |
'(swiper-include-line-number-in-search t) | |
'(tls-checktrust t t)) | |
(custom-set-faces | |
;; custom-set-faces was added by Custom. | |
;; If you edit it by hand, you could mess it up, so be careful. | |
;; Your init file should contain only one such instance. | |
;; If there is more than one, they won't work right. | |
) | |
;; ======================================= | |
;; === Start-up | |
;; ======================================= | |
;; = Remember latest frame size | |
;; Custom functions/hooks for persisting/loading frame geometry upon save/load | |
(defun save-frameg () | |
"Get the current frame's geometry and save it to ~/.emacs.frameg." | |
(let ((frameg-font (frame-parameter (selected-frame) 'font)) | |
(frameg-left (frame-parameter (selected-frame) 'left)) | |
(frameg-top (frame-parameter (selected-frame) 'top)) | |
(frameg-width (frame-parameter (selected-frame) 'width)) | |
(frameg-height (frame-parameter (selected-frame) 'height)) | |
(frameg-file (expand-file-name "~/.emacs.d/tmp/.emacs.frameg"))) | |
(with-temp-buffer | |
;; Turn off backup for this file | |
(make-local-variable 'make-backup-files) | |
(setq make-backup-files nil) | |
(insert | |
";;; This file stores the previous emacs frame's geometry.\n" | |
";;; Last generated " (current-time-string) ".\n" | |
"(setq initial-frame-alist\n" | |
;; " '((font . \"" frameg-font "\")\n" | |
" '(" | |
(format " (top . %d)\n" (max frameg-top 0)) | |
(format " (left . %d)\n" (max frameg-left 0)) | |
(format " (width . %d)\n" (max frameg-width 0)) | |
(format " (height . %d)))\n" (max frameg-height 0))) | |
(when (file-writable-p frameg-file) | |
(write-file frameg-file))))) | |
(defun load-frameg () | |
"It will load ~/.emacs.frameg which should contain the previous frame's geometry." | |
(let ((frameg-file (expand-file-name "~/.emacs.d/tmp/.emacs.frameg"))) | |
(when (file-readable-p frameg-file) | |
(load-file frameg-file)))) | |
;; Special work to do ONLY when there is a window system being used | |
(if window-system | |
(progn | |
(add-hook 'after-init-hook 'load-frameg) | |
(add-hook 'kill-emacs-hook 'save-frameg))) | |
;; = Improve startup time by reducing the number of garbage collections | |
;; (setq gc-cons-threshold (* 50 1000 1000)) | |
(setq gc-cons-threshold (* 10 1000 1000)) | |
;; = Print load time - save customization in separate file | |
(defun efs/display-startup-time () | |
"Print load up time and gc number." | |
(message "Emacs loaded in %s with %d garbage collections." | |
(format "%.2f seconds" | |
(float-time | |
(time-subtract after-init-time before-init-time))) | |
gcs-done)) | |
(add-hook 'emacs-startup-hook #'efs/display-startup-time) | |
;; ======================================= | |
;; = Melpa - e-lisp Package Archive | |
;; https://melpa.org | |
;; ======================================= | |
(require 'package) | |
(setq package-archives '(("melpa" . "https://melpa.org/packages/") | |
("org" . "https://orgmode.org/elpa/") | |
("gnu" . "https://elpa.gnu.org/packages/"))) | |
;; Load Emacs Lisp packages, and activate them. | |
(package-initialize) | |
;; Optional argument ASYNC specifies whether to perform the downloads in the background. | |
(unless package-archive-contents | |
(package-refresh-contents)) | |
;; ======================================= | |
;; = Package management with use-package | |
;; https://github.com/jwiegley/use-package | |
;; ======================================= | |
;; Initialize use-package | |
(unless (package-installed-p 'use-package) | |
(package-refresh-contents) | |
(package-install 'use-package)) | |
(require 'use-package) | |
;; Avoid the :ensure keyword for each package | |
(setq use-package-always-ensure t) | |
;; ======================================= | |
;; = Paths - directories - shell | |
;; ======================================= | |
;; connect emacs with our .bashrc and aliases | |
(setq shell-file-name "bash") | |
(setq shell-command-switch "-ic") | |
;; - direnv - only for unix | |
;; Description: Utility to set directory specific environment variables | |
;; direnv is an environment variable manager for your shell. It knows | |
;; how to hook into bash, zsh and fish shell to load or unload | |
;; environment variables depending on your current directory. This | |
;; allows one to have project-specific environment variables and not | |
;; clutter the "~/.profile" file. | |
;; . | |
;; Before each prompt it checks for the existence of an ".envrc" file in | |
;; the current and parent directories. If the file exists, it is loaded | |
;; into a bash sub-shell and all exported variables are then captured by | |
;; direnv and then made available to your shell. | |
;; . | |
;; Because direnv is compiled into a single static executable it is fast | |
;; enough to be unnoticeable on each prompt. It is also language | |
;; agnostic and can be used to build solutions similar to rbenv, pyenv, | |
;; phpenv, ... | |
;; https://github.com/wbolster/emacs-direnv | |
;; Hook into shell: https://direnv.net/docs/hook.html | |
;; Example: https://github.com/voloyev/.emacs.d/blob/master/init.el | |
(use-package direnv :defer t :config (direnv-mode)) | |
;; - windows paths | |
;; (setenv "PATH" | |
;; (concat | |
;; ;; "C:/cygwin/usr/local/bin" ";" | |
;; "C:/ProgramData/chocolatey/bin" ";" | |
;; (getenv "PATH"))) | |
;; - unix paths | |
(setenv "PATH" | |
(concat | |
"/mnt/c/ProgramData/chocolatey/bin" | |
":/usr/local/bin" | |
(getenv "PATH"))) | |
;; - Move to the user directory | |
;; (cd "~/") | |
(setq default-directory "~/") | |
;; (setq browse-url-firefox-program "firefox") | |
;; (setq browse-url-chrome-program "chrome") | |
;; ======================================= | |
;; === Clean up files | |
;; ======================================= | |
;; - no littering - Helps keeping ~/.emacs.d clean | |
;; Homepage: https://github.com/emacscollective/no-littering | |
;; NOTE: If you want to move everything out of the ~/.emacs.d folder | |
;; reliably, set `user-emacs-directory` before loading no-littering! | |
;(setq user-emacs-directory "~/.cache/emacs") | |
(use-package no-littering) | |
;; no-littering doesn't set this by default so we must place | |
;; auto save files in the same path as it uses for sessions | |
(setq auto-save-file-name-transforms | |
`((".*" ,(no-littering-expand-var-file-name "auto-save/") t))) | |
;; Collect and move all backup and auto-save files to a pre-definned directory: | |
(setq backup-directory-alist `(("." . ,(expand-file-name "tmp/backups/" user-emacs-directory)))) | |
(make-directory (expand-file-name "tmp/auto-saves/" user-emacs-directory) t) | |
;; ======================================= | |
;; === Better defaults | |
;; ======================================= | |
;; - ibuffer for list-buffers (C-x C-b) - "q" to quit | |
;; (defalias 'list-buffers 'ibuffer) | |
(defalias 'list-buffers 'ibuffer-other-window) | |
;; indent | |
(setq-default | |
;; Prefer spaces over tabs | |
indent-tabs-mode nil | |
tab-width 2 | |
standart-indent 2 | |
lisp-body-indent 2 | |
css-indent-offset 2 | |
scss-indent-offset 2 | |
python-indent-offset 4) | |
(setq-default | |
;; Silence warnings for redefinition | |
;; ad-redefinition-action 'accept | |
;; Hide the cursor in inactive windows | |
cursor-in-non-selected-windows t | |
;; Don't display load average | |
;; display-time-default-load-average nil | |
visible-bell t | |
;; disable bell | |
ring-bell-function #'ignore | |
;; Set width for automatic line breaks | |
fill-column 80 | |
;; Focus new help windows when opened | |
help-window-select t | |
;; inhibit-startup-message t | |
inhibit-startup-screen t | |
;; initial-scratch-message "" | |
;; Maximum length of kill ring | |
kill-ring-max 128 | |
;; Prefers the newest version of a file | |
load-prefer-newer t | |
;; Maximum length of mark ring | |
mark-ring-max 128 | |
read-process-output-max (* 1024 1024) | |
;; Always scroll by one line | |
scroll-conservatively most-positive-fixnum | |
select-enable-clipboard t | |
tab-width 2 | |
;; user-full-name "" | |
;; user-mail-address "" | |
vc-follow-symlinks t | |
;; time | |
display-time-mode t | |
display-time-24hr-format t | |
;; History | |
history-delete-duplicates t | |
;;sentences end with a single space | |
sentence-end-double-space nil | |
;; Always open read-only buffers in view-mode | |
view-read-only t) | |
;; Show the column number | |
(column-number-mode 1) | |
;; Replace yes/no prompts with y/n | |
(fset 'yes-or-no-p 'y-or-n-p) | |
;; Hightlight current line | |
(global-hl-line-mode) | |
;; Default to utf-8 encoding | |
(set-default-coding-systems 'utf-8) | |
;; Show the parent | |
(show-paren-mode 1) | |
;; Better space | |
(set-fringe-mode 10) | |
;; - Disable/enable the bars | |
;;(menu-bar-mode -1) | |
;;(tab-bar-mode 1) | |
(blink-cursor-mode -1) | |
(tool-bar-mode -1) | |
(scroll-bar-mode -1) | |
(global-prettify-symbols-mode) | |
;; ======================================= | |
;; === Terminal | |
;; ======================================= | |
;; - vterm: a better terminal | |
;; Installation: | |
;; cd ~/.emacs.d/elpa/vterm-XXXXXX.XXXX/ | |
;; rm -rf build | |
;; git clone https://github.com/akermu/emacs-libvterm.git | |
;; cd emacs-libvterm | |
;; mkdir -p build | |
;; cd build | |
;; cmake .. | |
;; make | |
(use-package vterm | |
:pin melpa | |
:bind (:map vterm-mode-map ("C-y" . vterm-yank)) | |
:config (setq vterm-max-scrollback 100000)) | |
(use-package vterm-toggle) | |
;; ======================================= | |
;; === Line numbers - scrolling | |
;; ======================================= | |
;; show column on modeline | |
(column-number-mode) | |
;; enable/disable display-line-numbers-mode globally | |
(global-display-line-numbers-mode 0) | |
;; disable line numbers on some modes | |
;; (only if global-display-line-numbers-mode is set to true) | |
(dolist (mode '(org-mode-hook | |
term-mode-hook | |
eshell-mode-hook)) | |
(add-hook mode (lambda () (display-line-numbers-mode 0)))) | |
;; - smooth scrolling | |
;; https://github.com/aspiers/smooth-scrolling | |
(use-package smooth-scrolling | |
:custom | |
(cache-long-lines t) | |
:config | |
(smooth-scrolling-mode 1)) | |
;; ======================================= | |
;; = Fonts = Symbols = Themes = Modeline | |
;; ======================================= | |
;; Enables you to customize the mode names displayed in the mode line. | |
(use-package delight) | |
;; - Default Fonts | |
(set-face-attribute 'default nil :font "Iosevka" :height 130) | |
;; (set-face-attribute 'default nil :font "Fira Code Retina" :height 120) | |
;; (set-face-attribute 'default nil :font "Inconsolata" :height 120) | |
;; (set-face-attribute 'default nil :font "Hack NF" :height 120) | |
;; (set-face-attribute 'default nil :font "Source Code Pro Medium") | |
;; (set-fontset-font t 'latin "Noto Sans") | |
;; - doom themes | |
;; Install | |
;; | |
;; M-x package-install RET all-the-icons | |
;; M-x all-the-icons-install-fonts | |
;; M-x package-install RET doom-themes | |
;; | |
;;A comprehensive configuration example: | |
;; | |
;; (require 'doom-themes) | |
;; ;; Global settings (defaults) | |
;; (setq doom-themes-enable-bold t ; if nil, bold is universally disabled | |
;; doom-themes-enable-italic t) ; if nil, italics is universally disabled | |
;; | |
;; ;; Load the theme (doom-one, doom-molokai, etc); keep in mind that each | |
;; ;; theme may have their own settings. | |
;; (load-theme 'doom-one t) | |
;; | |
;; ;; Enable flashing mode-line on errors | |
;; (doom-themes-visual-bell-config) | |
;; ;; Enable custom neotree theme: all-the-icons fonts must be installed! | |
;; (doom-themes-neotree-config) | |
(use-package all-the-icons) | |
;; Avoid slow rendering | |
(setq inhibit-compacting-font-caches t) | |
;; Additional packages for dired, gnus, ibuffer and ivy | |
;; Icons on mini-buffer, dired and ibuffer | |
(use-package all-the-icons-dired | |
:hook | |
(dired-mode-hook . all-the-icons-dired-mode)) | |
(use-package all-the-icons-gnus) | |
(use-package all-the-icons-ibuffer) | |
(use-package all-the-icons-ivy | |
:init (all-the-icons-ivy-setup)) | |
(use-package all-the-icons-ivy-rich | |
:init (all-the-icons-ivy-rich-mode 1)) | |
;; = doom theme | |
(use-package doom-themes | |
:config | |
;; (load-theme 'doom-Iosvkem t)) | |
(load-theme 'doom-one-light t)) | |
;; = minions | |
;; You must run (all-the-icons-install-fonts) one time after | |
;; installing this package! | |
(use-package minions | |
:hook (doom-modeline-mode . minions-mode)) | |
;; - doom modeline with all-the-icons | |
;; Homepage: https://seagle0128.github.io/doom-modeline/ | |
(use-package doom-modeline | |
:config | |
(doom-modeline-mode 1) | |
(set-face-attribute 'mode-line nil :height 130) | |
(set-face-attribute 'mode-line-inactive nil :height 130) | |
;; :hook (after-init . doom-modeline-mode) | |
:custom (;; change defaults | |
(doom-modeline-height 12) | |
(doom-modeline-bar-width 6) | |
(doom-modeline-major-mode-color-icon nil) | |
(doom-modeline-env-version t) | |
(doom-modeline-env-load-string "...") | |
;; whether display the modal state icon - nil or t | |
;; Including `evil', `overwrite', `god', `ryo' and `xah-fly-keys', etc. | |
(doom-modeline-modal-icon t) | |
;; Whether display the `lsp' state. Non-nil to display in the mode-line. | |
(doom-modeline-lsp t) | |
(doom-modeline-minor-modes nil) | |
(doom-modeline-major-mode-icon t) | |
;; Whether display icons in the mode-line. | |
;; While using the server mode in GUI, should set the value explicitly. | |
(doom-modeline-icon (display-graphic-p)))) | |
;; ======================================= | |
;; = ido - flx - flx-ido | |
;; ======================================= | |
;; - ido-mode everywhere | |
(setq ido-everywhere t) | |
(ido-mode 1) | |
;; - Improves sorting for fuzzy-matched results | |
;; Homepage: https://github.com/lewang/flx | |
(use-package flx | |
:after ivy | |
:defer t | |
:init | |
(setq ivy-flx-limit 10000)) | |
;; A better flex matching for ido mode. | |
(use-package flx-ido | |
:config | |
(flx-ido-mode 1)) | |
;; disable ido faces to see flx highlights. | |
(setq ido-enable-flex-matching t) | |
(setq ido-use-faces nil) | |
;; If you don't want to use the flx's highlights you can turn them off: | |
;; (setq flx-ido-use-faces nil) | |
;; ======================================= | |
;; = Hercules - Hydra & wich-key | |
;; ======================================= | |
;; - which key | |
;; https://github.com/justbur/emacs-which-key | |
(use-package which-key | |
:init (which-key-mode) | |
:diminish which-key-mode | |
:config | |
;; Allow C-h to trigger which-key before it is done automatically | |
(setq which-key-show-early-on-C-h t) | |
(setq which-key-idle-delay 0.3)) | |
;; - hydra | |
(use-package hydra) | |
;; - hydra hercules | |
;; Homepage: https://gitlab.com/jjzmajic/hercules.el | |
;; (use-package hercules) | |
;; (hercules-def | |
;; ;; read further to see why this works | |
;; :toggle-funs #'org-babel-mode | |
;; :keymap 'org-babel-map | |
;; :transient t) | |
;; ;; tweak binding to taste | |
;; (define-key org-mode-map (kbd "C-c C-v") #'org-babel-mode) | |
;; ======================================= | |
;; = Magit - gists | |
;; ======================================= | |
(use-package magit | |
:defer t | |
:bind("C-c SPC g" . magit-status)) | |
;; - aes encryption. Needed for gists | |
(use-package kaesar) | |
;; - browse at remote | |
;; Homepage: https://github.com/rmuslimov/browse-at-remote | |
(use-package browse-at-remote) | |
(global-set-key (kbd "C-g") 'browse-at-remote) | |
;; ======================================= | |
;; = avy = ace = winner = workspaces | |
;; ======================================= | |
;; - perspective | |
(use-package perspective | |
:demand t | |
:bind (("S-M-j" . persp-counsel-switch-buffer) | |
("S-M-k" . persp-switch) | |
("S-M-n" . persp-next) | |
("S-x k" . persp-kill-buffer*)) | |
:custom | |
(persp-initial-frame-name "Main") | |
:config | |
;; Running `persp-mode' multiple times resets the perspective list... | |
(unless (equal persp-mode t) | |
(persp-mode))) | |
;; - winner mode | |
(winner-mode 1) | |
(global-set-key (kbd "<S-right>") 'winner-redo) | |
(global-set-key (kbd "<S-left>") 'winner-undo) | |
;; - avy motions | |
(use-package avy) | |
;; - A seamless bridge between isearch, ace-jump-mode, | |
;; avy, helm-swoop and swiper | |
;; (global-set-key (kbd "M-o") 'ace-window) | |
(use-package ace-isearch | |
:bind ("M-o" . ace-window) | |
:custom | |
(aw-scope 'frame) | |
(aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l)) | |
(aw-minibuffer-flag t) | |
:init | |
(setq global-ace-isearch-mode 1)) | |
;; ======================================= | |
;; = Ivy = prescient = hydra = rich | |
;; ======================================= | |
;; - ivy, ivy-prescient and swiper | |
;; Ivy is a GNU Emacs package for jumping to visible text using | |
;; a char-based decision tree. See also ace-jump-mode and vim-easymotion. | |
;; Homepage: https://github.com/raxod502/prescient.el | |
(use-package prescient | |
:after counsel) | |
;; Disable short candidates by length | |
(setq prescient-sort-length-enable nil) | |
;; Remember candidate frequencies across sessions | |
(setq prescient-persist-mode t) | |
;; = ivy | |
(use-package ivy | |
;; :diminish | |
:bind ( | |
;; targeted | |
("C-'" . avy-goto-char-2) | |
("C-s" . swiper) | |
("C-S" . swiper-isearch) | |
("<S-up>" . ivy-push-view) | |
("<S-down>" . ivy-switch-view) | |
;; generic maps within minibuffer | |
:map ivy-minibuffer-map | |
("TAB" . ivy-alt-done) | |
("C-l" . ivy-alt-done) | |
("C-j" . ivy-next-line) | |
("C-k" . ivy-previous-line) | |
:map ivy-switch-buffer-map | |
("C-k" . ivy-previous-line) | |
("C-l" . ivy-done) | |
("C-d" . ivy-switch-buffer-kill) | |
:map ivy-reverse-i-search-map | |
("C-k" . ivy-previous-line) | |
("C-d" . ivy-switch-buffer-kill)) | |
:init (ivy-mode 1) | |
:config | |
;; Basic setup | |
(setq ivy-use-virtual-buffers t) | |
(setq ivy-wrap t) | |
(setq ivy-count-format "(%d/%d) ") | |
(setq enable-recursive-minibuffers t) | |
(setq avy-all-windows 'all-frames) | |
(setq avy-timeout-seconds 1.0) | |
;; Use different regex strategies per completion command | |
(setq ivy-re-builders-alist | |
'((swiper . ivy--regex-ignore-order) | |
(counsel-M-x . ivy--regex-ignore-order))) | |
;; (push '(swiper . ivy--regex-ignore-order) ivy-re-builders-alist) | |
;; (push '(counsel-M-x . ivy--regex-ignore-order) ivy-re-builders-alist) | |
;; Set general minibuffer height | |
;; (setq ivy-height 20) | |
;; Set minibuffer height for different commands | |
(setf (alist-get 'counsel-projectile-ag ivy-height-alist) 17) | |
(setf (alist-get 'counsel-projectile-rg ivy-height-alist) 17) | |
(setf (alist-get 'swiper ivy-height-alist) 17) | |
(setf (alist-get 'counsel-switch-buffer ivy-height-alist) 7)) | |
;; = ivy-prescient intellijence | |
(use-package ivy-prescient | |
:after counsel | |
:config | |
(ivy-prescient-mode 1)) | |
;; = ivy-posframe | |
;; (use-package ivy-posframe | |
;; :custom | |
;; (ivy-posframe-display-at-window-center) | |
;; :config | |
;; ;; Different command can use different display function. | |
;; (setq ivy-posframe-height-alist '((swiper . 10) | |
;; (t . 20))) | |
;; (setq ivy-posframe-display-functions-alist | |
;; '((swiper . ivy-display-function-fallback) | |
;; (complete-symbol . ivy-posframe-display-at-point) | |
;; (counsel-M-x . ivy-posframe-display-at-frame-bottom-window-center) | |
;; (t . ivy-posframe-display))) | |
;; (setq ivy-posframe-parameters | |
;; '((left-fringe . 9) | |
;; (right-fringe . 9))) | |
;; (ivy-posframe-mode 1)) | |
;; = ivy-hydra | |
(use-package ivy-hydra | |
:defer t | |
:after hydra) | |
;; = ivy rich - detailed information and descriptions on minibuffer | |
;; Homepage: https://github.com/Yevgnen/ivy-rich | |
(use-package ivy-rich | |
:init | |
(ivy-rich-mode 1) | |
:after counsel | |
:custom | |
(setq ivy-format-function #'ivy-format-function-line) | |
:config | |
(setq ivy-rich-display-transformers-list | |
(plist-put ivy-rich-display-transformers-list | |
'ivy-switch-buffer | |
'(:columns | |
((ivy-rich-candidate (:width 40)) | |
;; return the buffer indicators | |
(ivy-rich-switch-buffer-indicators (:width 4 :face error :align right)) | |
;; return the major mode info | |
(ivy-rich-switch-buffer-major-mode (:width 12 :face warning)) | |
;; return project name using `projectile' | |
(ivy-rich-switch-buffer-project (:width 15 :face success)) | |
(ivy-rich-switch-buffer-path (:width (lambda (x) (ivy-rich-switch-buffer-shorten-path x (ivy-rich-minibuffer-width 0.3)))))) ; return file path relative to project root or `default-directory' if project is nil | |
)))) | |
;; = swiper | |
(use-package swiper | |
:after ivy | |
:config | |
(setq swiper-action-recenter t) | |
(setq swiper-goto-start-of-match t) | |
(setq swiper-include-line-number-in-search t)) | |
;; ======================================= | |
;; = Counsel = ripgrep = ag = fzf | |
;; ======================================= | |
;; - ripgrep - ag - fzf | |
;; Homepage: https://github.com/nlamirault/ripgrep.el | |
(use-package ripgrep) | |
(use-package ag) | |
(use-package fzf) | |
;; = counsel | |
;; Homepage: https://github.com/abo-abo/swiper#counsel | |
(use-package counsel | |
:after projectile | |
:demand t | |
:bind (;; ---------------------- | |
;; - Ivy-based interface | |
;; to standard commands | |
;; ---------------------- | |
("C-x C-f" . counsel-find-file) | |
("M-x" . counsel-M-x) | |
("C-c r" . counsel-recentf) | |
("M-y" . counsel-yank-pop) | |
("<f1> f" . counsel-describe-function) | |
("<f1> v" . counsel-describe-variable) | |
("<f1> l" . counsel-find-library) | |
("<f2> i" . counsel-info-lookup-symbol) | |
("<f2> u" . counsel-unicode-char) | |
("<f2> j" . counsel-set-variable) | |
;; ("C-x b" . ivy-switch-buffer) | |
("M-\]" . counsel-switch-buffer) | |
("C-c b" . counsel-ibuffer) | |
("C-c v" . ivy-push-view) | |
("C-c V" . ivy-pop-view) | |
;; ------------------------------ | |
;; - Ivy-based interface to shell | |
;; and system tools | |
;; ------------------------------ | |
("C-c c" . counsel-compile) | |
("C-c g" . counsel-git) | |
("C-c j" . counsel-git-grep) | |
("C-c L" . counsel-git-log) | |
;; ("C-c k" . counsel-rg) | |
;; ("C-c m" . 'counsel-linux-app) | |
("C-c n" . counsel-fzf) | |
("C-x l" . counsel-locate) | |
("C-x r" . counsel-minibuffer-history) | |
("C-c J" . counsel-file-jump) | |
;; ("C-S-o" . counsel-rhythmbox) | |
;; ("C-c w" . counsel-wmctrl) | |
;; ------------------------------ | |
;; - Ivy-resume and misc commands | |
;; ------------------------------ | |
("C-c C-r". ivy-resume) | |
;; ("C-c b" . counsel-bookmark) | |
;; ("C-c d" . counsel-descbinds) | |
("C-c g" . counsel-git) | |
("C-c o" . counsel-outline) | |
("C-c t" . counsel-load-theme) | |
("C-c F" . counsel-org-file)) | |
:config | |
;; Dont't start searches with ^ | |
(setq ivy-initial-inputs-alist nil)) | |
;; = helpful - better help and info buffers | |
(use-package helpful | |
:custom | |
(counsel-describe-function-function #'helpful-callable) | |
(counsel-describe-variable-function #'helpful-variable) | |
:bind | |
([remap describe-function] . counsel-describe-function) | |
([remap describe-command] . helpful-command) | |
([remap describe-variable] . counsel-describe-variable) | |
([remap describe-key] . helpful-key)) | |
;; ======================================= | |
;; = Projectile | |
;; ======================================= | |
;; - projectile | |
(use-package projectile | |
:custom | |
(projectile-completion-system 'ivy) | |
:bind-keymap | |
("C-c p" . projectile-command-map) | |
:config | |
(projectile-mode 1)) | |
;; - counsel-projectile | |
(use-package counsel-projectile | |
:config (counsel-projectile-mode)) | |
;; ======================================= | |
;; = automation = skeletor | |
;; ======================================= | |
;; Skeletor provides project templates for Emacs. It also automates the | |
;; mundane parts of setting up a new project like version control, licenses | |
;; and tooling. | |
;; To create a new project interactively, run 'M-x skeletor-create-project'. | |
;; Homepage: https://github.com/chrisbarrett/skeletor.el | |
(use-package skeletor) | |
;; ======================================= | |
;; = Org & org-babel | |
;; ======================================= | |
;; expand org babel structure types using TAB (i.e: <s + TAB) | |
;; https://orgmode.org/manual/Structure-Templates.html | |
(require 'org-tempo) | |
;; - org superstar | |
(use-package org-superstar | |
:hook (org-mode . org-superstar-mode)) | |
;;(use-package org-bullets | |
;; :config | |
;; (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))) | |
;; - org babel | |
;; Homepage: https://github.com/astahlman/ob-async | |
(use-package ob-async) | |
;; Homepage: https://github.com/taiju/ob-deno | |
(use-package ob-deno) | |
;; ======================================= | |
;; = Selection = Commenting = indent | |
;; ======================================= | |
;; - expand region | |
(use-package expand-region | |
:bind ("C-M-=" . er/expand-region) | |
("C-M--" . er/contract-region)) | |
;; - evil nerd commenter | |
;; Homepage: https://github.com/redguardtoo/evil-nerd-commenter | |
(use-package evil-nerd-commenter | |
:after evil-leader) | |
;; - autoindent as you type | |
(use-package aggressive-indent | |
:config | |
(global-aggressive-indent-mode 1)) | |
(add-to-list 'aggressive-indent-excluded-modes 'html-mode) | |
;; ============================================ | |
;; = snippets = spartparens = rainbow delimiters | |
;; ============================================ | |
;; = yas | |
(use-package yasnippet | |
:hook (prog-mode . yas-minor-mode) | |
:config | |
(yas-reload-all) | |
(yas-global-mode 1)) | |
;; = smartparens | |
;; Wiki: https://github.com/Fuco1/smartparens/wiki | |
;; Tips: | |
;; * M-x customize-group smartparens | |
;; * Mx sp-cheat-sheet | |
(use-package smartparens | |
:config | |
(smartparens-global-mode 1)) | |
(require 'smartparens-config) | |
;; = evil-smartparens | |
;; Homepage: https://www.github.com/expez/evil-smartparens | |
(use-package evil-smartparens | |
:after smartparens | |
:config | |
(evil-smartparens-mode 1)) | |
(add-hook 'smartparens-enabled-hook #'evil-smartparens-mode) | |
;; smartparens strict mode | |
;; https://github.com/Fuco1/.emacs.d/blob/master/files/smartparens.el | |
;; (add-hook 'minibuffer-setup-hook 'turn-on-smartparens-strict-mode) | |
;; = rainbow delimiters | |
(use-package rainbow-delimiters | |
:hook | |
(prog-mode . rainbow-delimiters-mode)) | |
;; ======================================= | |
;; = Undo | |
;; ======================================= | |
(use-package undo-tree | |
:init (global-undo-tree-mode) | |
:custom (undo-tree-visualizer-timestamps t)) | |
;; ======================================= | |
;; = evil and leader key | |
;; ======================================= | |
;; - evil mode with evil collection | |
(use-package evil | |
:init | |
(setq evil-want-keybinding nil | |
evil-respect-visual-line-mode t | |
evil-want-integration t | |
evil-ex-search-case 'smart | |
evil-ex-substitute-case t | |
;; more vim-like behavior | |
evil-symbol-word-search t | |
evil-insert-skip-empty-lines t | |
evil-indent-convert-tabs t) | |
:config | |
(evil-mode 1)) | |
;; - evil collection | |
;; https://github.com/emacs-evil/evil-collection | |
;; Note: This also is setting evil for vterm - https://github.com/emacs-evil/evil-collection/blob/master/modes/vterm/evil-collection-vterm.el | |
(use-package evil-collection | |
:after evil | |
:custom | |
;; Set up Vim style bindings in the minibuffer | |
(evil-collection-setup-minibuffer t) | |
;; Set up Org functions in calendar keymap. | |
(evil-collection-calendar-want-org-bindings t) | |
;; Synchronize insert/normal state with char/line-mode in term-mode | |
(evil-collection-outline-bind-tab-p t) | |
;; Set up unimpaired bindings globally | |
(evil-collection-want-unimpaired-p t) | |
;; Bind -find references-, etc to various modes | |
(evil-collection-want-find-usages-bindings t) | |
;; Synchronize insert/normal state with char/line-mode in term-mode | |
(evil-collection-term-sync-state-and-mode-p t) | |
;; Set up debugger keys for certain modes. | |
(evil-collection-setup-debugger-keys t) | |
:config | |
(evil-collection-init)) | |
;; Make esc key to quit prompt | |
;; (global-set-key (kbd "<escape>") 'keyboard-escape-quit) | |
;; - evil leader | |
;; Homepage: https://github.com/cofi/evil-leader | |
(use-package evil-leader | |
;; define leader key here | |
:config | |
(setq evil-leader/leader "<SPC>") | |
:init | |
(global-evil-leader-mode)) | |
;; this code will let you use the non-prefixed <leader> in magit’s and gnus’ modes: | |
(setq evil-leader/no-prefix-mode-rx '("magit-.*-mode" "gnus-.*-mode")) | |
;; ======================================= | |
;; = keys | |
;; ======================================= | |
(evil-leader/set-key | |
"x" 'counsel-M-x | |
"<SPC>" 'ivy-resume | |
"cg" 'counsel-git | |
"cP" 'counsel-package | |
"co" 'counsel-outline | |
;; "cmh" 'counsel-minibuffer-history | |
;; comments | |
"ci" 'evilnc-comment-or-uncomment-lines | |
"cl" 'evilnc-quick-comment-or-uncomment-to-the-line | |
"ll" 'evilnc-quick-comment-or-uncomment-to-the-line | |
"cc" 'evilnc-copy-and-comment-lines | |
"cp" 'evilnc-comment-or-uncomment-paragraphs | |
"cr" 'comment-or-uncomment-region | |
"cv" 'evilnc-toggle-invert-comment-line-by-line | |
"." 'evilnc-copy-and-comment-operator | |
;; "\\" 'evilnc-comment-operator ; if you prefer backslash key | |
;; Help - use it with helpful for better results | |
"hh" 'help-for-help | |
"hP" 'describe-package | |
"hb" 'counsel-descbinds | |
"hf" 'describe-function | |
"hv" 'describe-variable | |
"hk" 'describe-key | |
"hK" 'Info-goto-emacs-key-command-node | |
"hl" 'counsel-find-library | |
"hi" 'counsel-info-lookup-symbol | |
"hu" 'counsel-unicode-char | |
"hj" 'counsel-set-variable | |
"hr" 'describe-char | |
"hc" 'describe-command | |
"ha" 'counsel-apropos | |
;; dired | |
"dd" 'counsel-dired | |
"dj" 'counsel-dired-jump | |
;; files - file-search | |
"ff" 'counsel-find-file | |
"fs" 'ido-write-file | |
"fj" 'counsel-file-jump | |
"fd" 'move-file-to-trash | |
"fn" 'make-empty-file | |
"fw" 'rename-file | |
"fr" 'counsel-recentf | |
"fi" 'ido-insert-file | |
"fc" 'counsel-compile | |
"fl" 'counsel-rg | |
"fL" 'counsel-locate | |
"fz" 'counsel-fzf | |
;; navigation - bookmarks - macros - marks | |
";" 'counsel-evil-marks | |
"kk" 'counsel-kmacro | |
"kl" 'counsel-bookmark | |
"kd" 'bookmark-delete | |
"kj" 'bookmark-jump | |
"kg" 'counsel-grep | |
"q" 'swiper | |
"ss" 'swiper-isearch | |
"as" 'evil-avy-goto-symbol-1 | |
"al" 'evil-avy-goto-line | |
"aw" 'evil-avy-goto-word-0 | |
"aa" 'avy-goto-char | |
"ac" 'evil-avy-goto-char | |
"ao" 'avy-pop-mark | |
;; windows | |
"wd" 'evil-window-delete | |
"wo" 'delete-other-windows | |
"wv" 'evil-window-vsplit | |
"ws" 'evil-window-split | |
"wj" 'evil-window-down | |
"wk" 'evil-window-up | |
"wl" 'evil-window-right | |
"wh" 'evil-window-left | |
"w]" 'ivy-push-view | |
"w[" 'ivy-pop-view | |
;; eww | |
"ew" 'eww-search-words | |
"ee" 'eww-open-in-new-buffer | |
"eu" 'browse-url | |
;; Buffers | |
"]" 'counsel-switch-buffer | |
"[" 'counsel-switch-buffer-other-window | |
"bb" 'ivy-switch-buffer | |
"bk" 'kill-current-buffer | |
"bj" 'previous-buffer | |
"b]" 'next-buffer | |
"b[" 'previous-buffer | |
"be" 'eval-buffer | |
"bo" 'view-buffer-other-frame | |
"bd" 'delete-frame | |
"br" 'rename-buffer | |
;; save | |
"sa" 'save-buffer | |
"sd" 'evil-save-modified-and-close | |
"zz" 'save-buffers-kill-terminal | |
;; Projectile | |
"pff" 'projectile--find-file | |
"pfd" 'counsel-projectile-find-dir | |
"psa" 'projectile-save-project-buffers | |
;; undo - C-_ C-/ | |
"zu" 'undo-tree-undo | |
;; M-_ c-? | |
"zr" 'undo-tree-redo | |
"zx" 'undo-tree-visualize | |
;; `undo-tree-switch-branch' - Switch undo-tree branch. | |
;; (What does this mean? Better press the button and see!) | |
"zb" 'undo-tree-switch-branch | |
;; C-x r u - Save current buffer state to register. | |
"zs" 'undo-tree-save-state-to-register | |
;; C-x r U - Restore buffer state from register. | |
"zR" 'undo-tree-save-state-to-register | |
;; lsp | |
"ld" 'xref-find-definitions | |
"lr" 'xref-find-references | |
"ln" 'lsp-ui-find-next-reference | |
"lp" 'lsp-ui-find-prev-reference | |
"ls" 'counsel-imenu | |
"le" 'lsp-ui-flycheck-list | |
"lS" 'lsp-ui-sideline-mode | |
"lX" 'ls-execute-code-action | |
;; yasnippets | |
"yn" 'yas-new-snippet | |
"yi" 'yas-insert-snippet | |
"yv" 'yas-visit-snippet-file | |
;; vterm | |
"`" 'vterm-toggle | |
;; darkroom toggle | |
"tf" 'darkroom-mode | |
"te" 'dw/enter-focus-mode | |
"tl" 'dw/leave-focus-mode) | |
;; ====================== | |
;; = lsp = lsp-ui = dap | |
;; ====================== | |
;; - Flycheck: Load flycheck first - recommended for lsp-mode | |
(use-package flycheck | |
:init (global-flycheck-mode t)) | |
;; - lsp mode | |
(use-package lsp-mode | |
:commands (lsp lsp-deferred) | |
:hook ((typescript-mode js2-mode web-mode) . lsp) | |
:bind (:map lsp-mode-map | |
("TAB" . completion-at-point)) | |
:custom (lsp-headerline-breadcrumb-enable nil) | |
:config | |
(lsp-enable-which-key-integration t)) | |
(use-package lsp-ui | |
;; :hook (lsp-mode . lsp-ui-mode) | |
:hook (lsp-ui-mode . lsp) | |
:config | |
(setq lsp-ui-sideline-enable t) | |
(setq lsp-ui-peek-enable t) | |
(setq lsp-ui-sideline-show-code-actions t) | |
(setq lsp-ui-sideline-show-hover nil) | |
(setq lsp-ui-sideline-show-diagnostics t) | |
(setq lsp-ui-sideline-show-hover t) | |
;; (setq lsp-ui-doc-enable t) | |
;; (lsp-ui-doc-show) | |
(setq lsp-ui-doc-position 'bottom)) | |
;; = dap - debug adapter support | |
(use-package dap-mode | |
:custom | |
(lsp-enable-dap-auto-configure nil) | |
:config | |
(dap-ui-mode 1) | |
(dap-tooltip-mode 1) | |
(require 'dap-node) | |
(dap-node-setup)) | |
;; ======================================= | |
;; = treesitter | |
;; ======================================= | |
(use-package tree-sitter | |
:hook | |
(rust-mode-hook . tree-sitter-mode) | |
(js2-mode-hook . tree-sitter-mode)) | |
;; ======================================= | |
;; = treemacs | |
;; ======================================= | |
(use-package treemacs) | |
(use-package treemacs-all-the-icons) | |
;; lsp with treemacs | |
(use-package lsp-treemacs | |
:after lsp-mode | |
:commands lsp-treemacs-errors-list) | |
;; ======================================= | |
;; = company = autocompletion | |
;; ======================================= | |
;; - company and company-prescient | |
;; Note: LSP will autodetect company | |
;; Homepage: http://company-mode.github.io/ | |
(use-package company | |
;; :init | |
;; (global-company-mode t) | |
:after lsp-mode | |
:defer 2 | |
:custom | |
(company-begin-commands '(self-insert-command)) | |
(company-idle-delay 0.2) | |
(company-minimum-prefix-length 2) | |
(company-tooltip-align-annotations 't) | |
(company-show-numbers t) | |
:config | |
(global-company-mode 1)) | |
;; global-company-mode for all buffers on init | |
(add-hook 'after-init-hook 'global-company-mode) | |
;; - company-ui | |
;; Note: An example - https://github.com/rememberYou/.emacs.d/blob/master/config.org | |
(use-package company-box | |
:after company | |
:diminish | |
:hook (company-mode . company-box-mode)) | |
;; - company prescient intellisense | |
(use-package company-prescient | |
:after company | |
:config | |
(company-prescient-mode 1)) | |
;; - company tabnine AI Autocompletion framework | |
;; Homepage: https://github.com/TommyX12/company-tabnine/ | |
;; Notes: | |
;; * After installation run "company-tabnine-install-binary" | |
;; * Heavy on CPU - Probably includes telemetry | |
;; (use-package company-tabnine | |
;; :after company | |
;; :config (add-to-list 'company-backends 'company-tabnine)) | |
;; - company native-complete for shell and sqlite | |
;; Homepage: https://github.com/CeleritasCelery/emacs-native-shell-complete | |
;; (use-package company-native-complete | |
;; :after company | |
;; :config (add-to-list 'company-backends 'company-native-complete)) | |
(use-package company-web | |
:config (add-to-list 'company-backends 'company-web-html)) | |
;; ======================== | |
;; = Languages & Frameworks | |
;; ======================== | |
;; = C/C++ | |
(use-package ccls | |
:hook ((c-mode c++-mode objc-mode cuda-mode) . | |
(lambda () (require 'ccls) (lsp)))) | |
;; defvar lispy-mode-map-base | |
;; let ((map (make-sparse-keymap))) | |
;; ;; navigation | |
;; (define-key map (kbd "C-a") 'lispy-move-beginning-of-line) | |
;; (define-key map (kbd "C-e") 'lispy-move-end-of-line) | |
;; (define-key map (kbd "M-o") 'lispy-left-maybe) | |
;; = lispy | |
(use-package lispy | |
:hook ((emacs-lisp-mode . lispy-mode) | |
(scheme-mode . lispy-mode))) | |
;; = lispyville | |
;; Homepage: https://github.com/noctuid/lispyville | |
(use-package lispyville | |
:hook ((lispy-mode . lispyville-mode)) | |
:config | |
(lispyville-set-key-theme '(operators c-w additional | |
additional-movement slurp/barf-cp | |
prettify))) | |
;; = rust | |
;; Note: Install rustup with: | |
;; curl https://sh.rustup.rs -sSf | sh && source $HOME/.cargo/env && rustc --version | |
(use-package rust-mode | |
:mode "\\.rs\\'" | |
:init (setq rust-format-on-save t)) | |
(use-package cargo | |
:defer t) | |
;; = yaml | |
(use-package yaml-mode | |
:mode "\\.ya?ml\\'") | |
;; = SQL | |
(use-package sql-indent | |
:after (:any sql sql-interactive-mode) | |
:delight sql-mode "Σ ") | |
;; = html = gemini = web | |
(use-package web-mode | |
:mode "(\\.\\(html?\\|ejs\\|tsx\\|jsx\\)\\'" | |
:config | |
(setq-default web-mode-code-indent-offset 2) | |
(setq-default web-mode-markup-indent-offset 2) | |
(setq-default web-mode-attribute-indent-offset 2)) | |
;; = rainbow color identifier | |
(use-package rainbow-mode | |
:defer t | |
:hook (org-mode | |
emacs-lisp-mode | |
web-mode | |
typescript-mode | |
js2-mode)) | |
;; = http | |
(use-package know-your-http-well | |
:defer t) | |
;; 1. Start the server with `httpd-start' | |
;; 2. Use `impatient-mode' on any buffer | |
(use-package impatient-mode) | |
(use-package skewer-mode) | |
;; = gemini | |
;; Elpher aims to provide a practical and friendly gopher and gemini | |
;; client for GNU Emacs. | |
(use-package elpher) | |
;; = JS TS and JSON | |
;; - prettier-js | |
(use-package prettier-js | |
:custom (prettier-js-args '("--print-width" "100" | |
"--single-quote" "true" | |
"--trailing-comma" "all"))) | |
;; - flow - company flow | |
;; https://flow.org/en/docs/install/ | |
(use-package flow-minor-mode) | |
(use-package company-flow | |
:after company | |
:config (add-to-list 'company-backends 'company-flow)) | |
;; - js2 | |
(use-package js2-mode | |
:mode "\\.js\\'" | |
:hook | |
(js2-mode-hook . flow-minor-mode)) | |
;; - Typescript | |
(use-package typescript-mode | |
:mode "\\.ts\\'" | |
:hook (typescript-mode . lsp-deferred) | |
:config (setq typescript-indent-level 2)) | |
;; = Lua | |
(use-package lua-mode | |
:mode "\\.lua'" | |
:hook (lua-mode-hook . lsp-deferred) | |
:config | |
(setq lua-indent-level 2) | |
(setq lua-documentation-url "http://www.lua.org/manual/5.3/manual.html#pdf-")) | |
(use-package company-lua | |
:after company | |
:config (add-to-list 'company-backends 'company-lua)) | |
;; ======================== | |
;; = Writing | |
;; ======================== | |
(use-package darkroom | |
:commands darkroom-mode | |
:config | |
(setq darkroom-text-scale-increase 0)) | |
(defun dw/enter-focus-mode () | |
(interactive) | |
(darkroom-mode 1) | |
(display-line-numbers-mode 0)) | |
(defun dw/leave-focus-mode () | |
(interactive) | |
(darkroom-mode 0) | |
(display-line-numbers-mode 1)) | |
(defun dw/toggle-focus-mode () | |
(interactive) | |
(if (symbol-value darkroom-mode) | |
(dw/leave-focus-mode) | |
(dw/enter-focus-mode))) | |
;;; init.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment