Skip to content

Instantly share code, notes, and snippets.

@manfromth3m0oN
Last active June 1, 2024 15:24
Show Gist options
  • Save manfromth3m0oN/e1991650f9d233f351a7b655815a4428 to your computer and use it in GitHub Desktop.
Save manfromth3m0oN/e1991650f9d233f351a7b655815a4428 to your computer and use it in GitHub Desktop.
Emacs Config
;; turn off the extra ui
(tool-bar-mode -1)
(scroll-bar-mode -1)
(setq inhibit-splash-screen t)
(setq use-file-dialog nil)
(setq default-frame-alist '((undecorated . t)))
;; make sure things work at work
;;(setq url-http-proxy-basic-auth-storage
;; (list (list "PROXY HOST"
;; (cons "Input your LDAP UID !"
;; (base64-encode-string "USERNAME:PASSWORD")))))
;; recompile init files at whim
(defun my-recompile-init-eln ()
(interactive)
;;(byte-compile-file "~/.emacs.d/early-init.el")
;;(native-compile "~/.emacs.d/early-init.el")
(byte-compile-file "~/.emacs.d/init.el")
(native-compile "~/.emacs.d/init.el"))
;; boostrap straight.el
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name
"straight/repos/straight.el/bootstrap.el"
(or (bound-and-true-p straight-base-dir)
user-emacs-directory)))
(bootstrap-version 7))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
;; add use-package
(straight-use-package 'use-package)
;; always defer for lazy loading
(setq straight-use-package-by-default t)
(setq use-package-always-defer t)
;; config time :)
(use-package emacs
:init
(setq initial-scratch-message nil)
(defun display-startup-echo-area-message ()
(message ""))
(defalias 'yes-or-no-p 'y-or-n-p)
(set-charset-priority 'unicode)
(setq locale-coding-system 'utf-8
coding-system-for-read 'utf-8
coding-system-for-write 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
(setq default-process-coding-system '(utf-8-unix . utf-8-unix))
(setq-default indent-tabs-mode nil)
(setq-default tab-width 2)
(setq backup-directory-alist `(("." . "~/.saves")))
(setq delete-old-versions t
kept-new-versions 6
kept-old-versions 2
version-control t)
(set-face-attribute 'default nil
:font "BlexMono Nerd Font"
:height 90)
(defun ab/enable-line-numbers ()
"Enable relative line numbers"
(interactive)
(display-line-numbers-mode)
(setq display-line-numbers 'relative))
(add-hook 'prog-mode-hook #'ab/enable-line-numbers))
;; lay out all windows in an even fashion
(use-package zoom
:init
(setq zoom-size '(0.618 . 0.618))
(zoom-mode t))
;; dim non focused windows
(use-package dimmer
:init
(dimmer-configure-which-key)
(dimmer-configure-hydra)
(dimmer-configure-magit)
(dimmer-configure-org)
(dimmer-mode t))
(use-package magit
:ensure t)
(use-package org
:mode (("\\.org$" . org-mode))
:ensure org-plus-contrib
:config
(progn
;; config stuff
(setq org-directory "~/org/")
(setq org-default-notes-file (concat org-directory "/notes.org"))))
;; ivy
(use-package counsel
:after ivy
:config (counsel-mode))
(use-package ivy
:defer 0.1
:diminish
:bind (("C-c C-r" . ivy-resume)
("C-x B" . ivy-switch-buffer-other-window))
:custom
(ivy-count-format "(%d/%d) ")
(ivy-use-virtual-buffers t)
:config (ivy-mode))
(use-package ivy-rich
:after ivy
:custom
(ivy-virtual-abbreviate 'full
ivy-rich-switch-buffer-align-virtual-buffer t
ivy-rich-path-style 'abbrev)
:config
(ivy-set-display-transformer 'ivy-switch-buffer
'ivy-rich-switch-buffer-transformer))
(use-package swiper
:after ivy)
;; ace window
(use-package ace-window
:bind ("M-o" . ace-window)
:delight
:config (ace-window-display-mode 1))
(use-package projectile
:ensure t
:init
(projectile-mode +1)
:bind (:map projectile-mode-map
("C-c p" . projectile-command-map))
:config (setq projectile-project-search-path '("~/projects/")))
(use-package perspective
:custom
(persp-mode-prefix-key (kbd "C-c w")) ; pick your own prefix key here
:init
(persp-mode))
(use-package persp-projectile
:init
(persp-mode))
;; doom theme
(use-package doom-themes
:demand
:config
(load-theme 'doom-challenger-deep t))
;; doom modeline
(use-package doom-modeline
:ensure t
:init (doom-modeline-mode 1))
;; nerd icons, duhh
(use-package nerd-icons)
;; nyaaan
(use-package nyan-mode
:init
(nyan-mode))
;; company
(use-package company
:ensure t
:config (progn
;; don't add any dely before trying to complete thing being typed
;; the call/response to gopls is asynchronous so this should have little
;; to no affect on edit latency
(setq company-idle-delay 0)
;; start completing after a single character instead of 3
(setq company-minimum-prefix-length 1)
;; align fields in completions
(setq company-tooltip-align-annotations t)
)
)
;; make company look cool
(use-package company-box
:hook (company-mode . company-box-mode))
;; optional, provides snippets for method signature completion
(use-package yasnippet
:ensure t)
;; optional package to get the error squiggles as you edit
(use-package flycheck
:ensure t)
;; if you use company-mode for completion (otherwise, complete-at-point works out of the box):
(use-package company-lsp
:ensure t
:commands company-lsp)
(use-package go-mode
:ensure t
:bind (
;; If you want to switch existing go-mode bindings to use lsp-mode/gopls instead
;; uncomment the following lines
("C-c C-j" . lsp-find-definition)
("C-c C-d" . lsp-describe-thing-at-point)
)
:hook ((go-mode . lsp-deferred)
(before-save . lsp-format-buffer)
(before-save . lsp-organize-imports)))
(provide 'gopls-config)
(use-package rustic
:ensure
:bind (:map rustic-mode-map
("M-j" . lsp-ui-imenu)
("M-?" . lsp-find-references)
("C-c C-c l" . flycheck-list-errors)
("C-c C-c a" . lsp-execute-code-action)
("C-c C-c r" . lsp-rename)
("C-c C-c q" . lsp-workspace-restart)
("C-c C-c Q" . lsp-workspace-shutdown)
("C-c C-c s" . lsp-rust-analyzer-status))
:config
;; uncomment for less flashiness
;; (setq lsp-eldoc-hook nil)
;; (setq lsp-enable-symbol-highlighting nil)
;; (setq lsp-signature-auto-activate nil)
;; comment to disable rustfmt on save
(setq rustic-format-on-save t))
;; which-key
(use-package which-key
:ensure t
:config
(which-key-mode)
(which-key-setup-side-window-bottom))
(use-package mistty
:ensure t
:bind (("C-c t" . mistty) ;; or mistty-in-project
;; bind here the shortcuts you'd like the
;; shell to handle instead of Emacs.
:map mistty-prompt-map))
(use-package hydra)
;; kakoune.el
(use-package kakoune
;; Having a non-chord way to escape is important, since key-chords don't work in macros
:bind ("<escape>" . ryo-modal-mode)
:hook (after-init . my/kakoune-setup)
:config
(defun ryo-enter () "Enter normal mode" (interactive) (ryo-modal-mode 1))
(defun my/kakoune-setup ()
"Call kakoune-setup-keybinds and then add some personal config."
(kakoune-setup-keybinds)
(setq ryo-modal-cursor-type 'box)
(add-hook 'prog-mode-hook #'ryo-enter)
(define-key ryo-modal-mode-map (kbd "SPC h") 'help-command)
;; Access all C-x bindings easily
(define-key ryo-modal-mode-map (kbd "SPC x") ctl-x-map)
(ryo-modal-key
"SPC n" :hydra
'(hydra-org ()
"org"
("l" org-store-link "Org Link")
("a" org-agenda "Org Agenda")
("c" org-capture "Org Capture")))
(ryo-modal-key
"SPC w" :hydra
'(hydra-org ()
"perspective"
("p" projectile-persp-switch-project "Switch Projects")
("s" persp-switch "Switch open perspectives")))
(ryo-modal-keys
("," save-buffer)
("P" counsel-yank-pop)
("m" mc/mark-next-like-this)
("M" mc/skip-to-next-like-this)
("n" mc/mark-previous-like-this)
("N" mc/skip-to-previous-like-this)
("M-m" mc/edit-lines)
("*" mc/mark-all-like-this)
("v" er/expand-region)
("C-v" set-rectangular-region-anchor)
("M-s" mc/split-region)
(";" (("q" delete-window)
("v" split-window-horizontally)
("s" split-window-vertically)))
("C-h" windmove-left)
("C-j" windmove-down)
("C-k" windmove-up)
("C-l" windmove-right)
("C-u" scroll-down-command :first '(deactivate-mark))
("C-d" scroll-up-command :first '(deactivate-mark))
("SPC" (("g" magit-status)
("b" persp-counsel-switch-buffer)
("o" ace-window)
("f" counsel-fzf)
("j" dired-jump)
("r" swiper)
("R" swiper-all)
("t" mistty-in-project))))))
;; This overrides the default mark-in-region with a prettier-looking one,
;; and provides a couple extra commands
(use-package visual-regexp
:ryo
("s" vr/mc-mark)
("?" vr/replace)
("M-/" vr/query-replace))
;; Emacs incremental search doesn't work with multiple cursors, but this fixes that
(use-package phi-search
:bind (("C-s" . phi-search)
("C-r" . phi-search-backward)))
;; Probably the first thing you'd miss is undo and redo, which requires an extra package
;; to work like it does in kakoune (and almost every other editor).
(use-package undo-tree
:config
(global-undo-tree-mode)
:custom
(undo-tree-history-directory-alist '(("." . "/home/m0on/.emacshistory/")))
:ryo
("u" undo-tree-undo)
("U" undo-tree-redo)
("SPC u" undo-tree-visualize "Undo Visualize")
:bind (:map undo-tree-visualizer-mode-map
("h" . undo-tree-visualize-switch-branch-left)
("j" . undo-tree-visualize-redo)
("k" . undo-tree-visualize-undo)
("l" . undo-tree-visualize-switch-branch-right)))
;; lsp-mode
(use-package lsp-mode
;;:init
;;(setq lsp-keymap-prefix "C-c l")
;:bind ("C-c l" . lsp-mode-map)
:ensure
:commands lsp
:bind-keymap ("s-l" . lsp-command-map)
:ryo ("SPC a" "s-l" "LSP")
:custom
;; what to use when checking on-save. "check" is default, I prefer clippy
(lsp-rust-analyzer-cargo-watch-command "clippy")
(lsp-eldoc-render-all t)
(lsp-idle-delay 0.6)
;; enable / disable the hints as you prefer:
(lsp-inlay-hint-enable t)
;; These are optional configurations. See https://emacs-lsp.github.io/lsp-mode/page/lsp-rust-analyzer/#lsp-rust-analyzer-display-chaining-hints for a full list
(lsp-rust-analyzer-display-lifetime-elision-hints-enable "skip_trivial")
(lsp-rust-analyzer-display-chaining-hints t)
(lsp-rust-analyzer-display-lifetime-elision-hints-use-parameter-names nil)
(lsp-rust-analyzer-display-closure-return-type-hints t)
(lsp-rust-analyzer-display-parameter-hints nil)
(lsp-rust-analyzer-display-reborrow-hints nil)
:config
(add-hook 'lsp-mode-hook 'lsp-ui-mode)
(add-hook 'lsp-mode-hook #'lsp-enable-which-key-integration))
(use-package lsp-ivy)
(use-package lsp-ui
:ensure
:commands lsp-ui-mode
:custom
(lsp-ui-peek-always-show t)
(lsp-ui-sideline-show-hover t)
(lsp-ui-doc-delay 1)
(lsp-ui-doc-enable nil))
(use-package yasnippet ; Snippets
:ensure t
:config
(validate-setq
yas-verbosity 1 ; No need to be so verbose
yas-wrap-around-region t)
(with-eval-after-load 'yasnippet
(validate-setq yas-snippet-dirs '(yasnippet-snippets-dir)))
(yas-reload-all)
(yas-global-mode))
(use-package yasnippet-snippets ; Collection of snippets
:ensure t)
(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.
'(org-agenda-files '("~/org/notes.org")))
(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.
)
(setq-default cursor-type 'bar)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment