Rework Emacs config into org-babel

This commit is contained in:
Magic_RB 2020-11-01 02:56:34 +01:00
parent b5d3b8536e
commit 5e78d10ca0
9 changed files with 660 additions and 531 deletions

535
dot_emacs
View file

@ -1,538 +1,11 @@
; package --- Summary
;;; package --- Summary
;;; Commentary:
;;; Code:
(require 'package)
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
(not (gnutls-available-p))))
(proto (if no-ssl "http" "https")))
(when no-ssl (warn "\
Your version of Emacs does not support SSL connections,
which is unsafe because it allows man-in-the-middle attacks.
There are two things you can do about this warning:
1. Install an Emacs version that does support SSL and be safe.
2. Remove this warning from your init file so you won't see it again."))
(add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t)
(add-to-list 'package-archives '("ublt" . "https://elpa.ubolonton.org/packages/"))
(add-to-list 'package-archives '("celpa" . "https://celpa.conao3.com/packages/"))
;; Comment/uncomment this line to enable MELPA Stable if desired. See `package-archive-priorities`
;; and `package-pinned-packages`. Most users will not need or want to do this.
;;(add-to-list 'package-archives (cons "melpa-stable" (concat proto "://stable.melpa.org/packages/")) t)
)
(package-initialize)
(package-refresh-contents)
(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.
'(auth-source-save-behavior nil)
'(custom-enabled-themes '(doom-one))
'(custom-safe-themes
'("2f1518e906a8b60fac943d02ad415f1d8b3933a5a7f75e307e6e9a26ef5bf570" default))
'(package-selected-packages
'(chess scad-preview dockerfile-mode heaven-and-hell yaml-mode rustic scad-mode lsp-treemacs flycheck-rust telephone-line yasnippet flycheck-pos-tip flycheck magit lsp-ui all-the-icons doom-themes lsp-mode use-package treemacs-evil)))
(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.
)
(require 'org)
(setq backup-directory-alist `(("." . "~/.emacs.d/saves")))
(add-to-list 'load-path "~/.emacs.d/lisp/")
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package)
(require 'use-package))
(use-package scad-mode
:ensure t)
(setq evil-want-keybinding nil)
(use-package evil
:ensure t
:config
(evil-mode 1))
(use-package evil-surround
:ensure t
:config
(global-evil-surround-mode 1))
(use-package yasnippet
:ensure t
:config
(yas-global-mode 1))
(use-package treemacs
:ensure t)
(use-package treemacs-evil
:ensure t)
(use-package flycheck
:ensure t
:init (global-flycheck-mode))
;; Deprecated
;(use-package company-lsp
; :ensure t
; :config
; (push 'company-lsp company-backends))
(use-package company-box
:ensure t
:config
(add-hook 'company-mode-hook 'company-box-mode))
(use-package yaml-mode
:ensure t
:config
(add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode))
(add-to-list 'auto-mode-alist '("\\.yaml\\'" . yaml-mode)))
(use-package dockerfile-mode
:ensure t
:config
(add-to-list 'auto-mode-alist '("Dockerfile\\'" . dockerfile-mode)))
(use-package rustic
:ensure t
:config
(add-to-list 'auto-mode-alist '("\\.rs\\'" . rustic-mode)))
(use-package elcord
:ensure t
:config
(when (not (string= (system-name) "fractal"))
(elcord-mode))
)
(use-package magit
:ensure t)
(use-package evil-magit
:ensure t
:config
(setq evil-magit-state 'motion)
(evil-define-key evil-magit-state magit-mode-map ";" 'magit-log)
(evil-define-key evil-magit-state magit-mode-map "k" 'evil-previous-line)
(evil-define-key evil-magit-state magit-status-mode-map "l" 'evil-next-line))
(use-package magit-todos
:ensure t
:config
(add-hook 'rustic-hook 'hl-todo-mode))
(use-package lsp-ui
:ensure t)
(when (not (string= (system-name) "localhost"))
(use-package tree-sitter
:ensure t)
(use-package tree-sitter-langs
:ensure t)
(global-tree-sitter-mode)
(add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode))
;; aligns annotation to the right hand side
(setq company-tooltip-align-annotations t)
(use-package web-mode
:ensure t
:config
(add-to-list 'auto-mode-alist '("\\.html\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.xhtml\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.css\\'" . css-mode))
(add-to-list 'auto-mode-alist '("\\.scss\\'" . css-mode))
(flycheck-add-mode 'javascript-eslint 'web-mode)
)
(use-package lsp-pyright
:ensure t
:hook (python-mode . (lambda ()
(require 'lsp-pyright)
(lsp)))) ; or lsp-deferred
(use-package scala-mode
:ensure t
:mode "\\.s\\(cala\\|bt\\)$")
(use-package sbt-mode
:ensure t
:commands sbt-start sbt-command
:config
;; WORKAROUND: https://github.com/ensime/emacs-sbt-mode/issues/31
;; allows using SPACE when in the minibuffer
(substitute-key-definition
'minibuffer-complete-word
'self-insert-command
minibuffer-local-completion-map)
;; sbt-supershell kills sbt-mode: https://github.com/hvesalai/emacs-sbt-mode/issues/152
(setq sbt:program-options '("-Dsbt.supershell=false"))
)
(use-package lsp-metals
:ensure t)
(use-package lsp-mode
:ensure t
:config
(setq rustic-lsp-server 'rust-analyzer)
(setq rustic-compile-command "cargo build")
(setq rustic-format-trigger nil);'on-save)
(setq lsp-prefer-flymake nil)
:hook
(rustic . lsp)
(php-mode . lsp)
(rjsx-mode . lsp)
(css-mode . lsp)
(web-mode . lsp)
(js2-mode . lsp)
(lsp-mode . lsp-lens-mode)
(typescript-mode . lsp)
(scala-mode . lsp)
(tex-mode . lsp)
(lsp-mode . display-fill-column-indicator-mode)
(python-mode . lsp)
(lsp-mode . origami-mode))
(use-package typescript-mode
:ensure t
:config
(add-to-list 'auto-mode-alist '("\\.ts\\'" . typescript-mode))
(add-to-list 'auto-mode-alist '("\\.tsx\\'" . typescript-mode))
)
(use-package rjsx-mode
:ensure t
:config
(add-to-list 'auto-mode-alist '("\\.js\\'" . rjsx-mode))
(add-to-list 'auto-mode-alist '("\\.jsx\\'" . rjsx-mode))
)
(setq display-line-numbers-type 'relative)
(use-package impatient-mode
:ensure t)
(defun markdown-html (buffer)
(princ (with-current-buffer buffer
(format "<!DOCTYPE html><html><title>Impatient Markdown</title><xmp theme=\"united\" style=\"display:none;\"> %s </xmp><script src=\"http://strapdownjs.com/v/0.2/strapdown.js\"></script></html>" (buffer-substring-no-properties (point-min) (point-max))))
(current-buffer)))
(httpd-start)
(use-package vterm
:ensure t)
(use-package w3m
:ensure t)
(defun evil-collection-vterm-escape-stay ()
"Go back to normal state but don't move cursor backwards.
Moving cursor backwards is the default vim behavior but
it is not appropriate in some cases like terminals."
(setq-local evil-move-cursor-back nil))
(add-hook 'vterm-mode-hook #'evil-collection-vterm-escape-stay)
(use-package evil-collection
:ensure t)
(evil-collection-init 'vterm)
(use-package lsp-treemacs
:ensure t
:config
(lsp-treemacs-sync-mode 1))
(use-package all-the-icons
:ensure t)
(use-package doom-modeline
:ensure t
:config
(doom-modeline-mode))
(make-variable-buffer-local 'doom-modeline-icon)
(add-hook 'after-make-frame-hook
(lambda ()
(setq doom-modeline-icon (display-graphic-p))))
;(use-package telephone-line
; :ensure t
; :config
; (telephone-line-mode 1))
(use-package chess
:ensure t)
(use-package origami
:ensure t)
(use-package doom-themes
:ensure t
:config
;; Global settings (defaults)
<<<<<<< HEAD
(setq doom-themes-enable-bold t ; if nil, bold is universally disabled
doom-themes-enable-italic t) ; if nil, italics is universally disabled
;; Enable flashing mode-line on errors
(doom-themes-visual-bell-config)
;; Enable custom neotree theme (all-the-icons must be installed!)
(doom-themes-neotree-config)
=======
; (setq doom-themes-enable-bold t ; if nil, bold is universally disabled
; doom-themes-enable-italic t) ; if nil, italics is universally disabled
(load-theme 'doom-one t)
;; Enable flashing mode-line on errors
; (doom-themes-visual-bell-config)
;; Enable custom neotree theme (all-the-icons must be installed!)
;(doom-themes-neotree-config)
>>>>>>> d0a396dae183d57fe0d9f91d8e36cb1a9d28ce11
;; or for treemacs users
(setq doom-themes-treemacs-theme "doom-colors") ; use the colorful treemacs theme
(doom-themes-treemacs-config)
<<<<<<< HEAD
;; Corrects (and improves) org-mode's native fontification.
(doom-themes-org-config))
=======
>>>>>>> d0a396dae183d57fe0d9f91d8e36cb1a9d28ce11
;; Corrects (and improves) org-mode's native fontification.
; (doom-themes-org-config))
;(use-package man-preview
; :ensure t)
(use-package heaven-and-hell
:ensure t
:init
(setq heaven-and-hell-theme-type 'dark) ;; Omit to use light by default
(setq heaven-and-hell-themes
<<<<<<< HEAD
'((light . doom-one-light)
(dark . doom-one))); Themes can be the list: (dark . (tsdh-dark wombat))
=======
'((light . doom-one-light)
(dark . doom-peacock))) ;; Themes can be the list: (dark . (tsdh-dark wombat))
>>>>>>> d0a396dae183d57fe0d9f91d8e36cb1a9d28ce11
;; Optionall, load themes without asking for confirmation.
(setq heaven-and-hell-load-theme-no-confirm t)
:hook (after-init . heaven-and-hell-init-hook)
:bind (("<f6>" . heaven-and-hell-toggle-theme)))
(global-set-key (kbd "M-RET T") 'treemacs)
(global-set-key (kbd "M-RET t") 'treemacs-select-window)
(global-set-key (kbd "M-RET s") 'treemacs-switch-workspace)
(global-set-key (kbd "M-RET S") 'treemacs-edit-workspaces)
(global-set-key (kbd "M-RET w") 'ace-window)
(global-set-key (kbd "M-RET r b") 'rustic-cargo-build)
(global-set-key (kbd "M-RET r t") 'rustic-cargo-test)
(global-set-key (kbd "M-RET r r") 'rustic-cargo-run)
(global-set-key (kbd "M-RET r c") 'rustic-cargo-clippy)
(global-set-key (kbd "M-RET r f") 'rustic-cargo-fmt)
(global-set-key (kbd "M-RET e") 'lsp-execute-code-action)
(global-set-key (kbd "M-RET R") 'lsp-rename)
(global-set-key (kbd "M-RET m") 'magit-status)
(global-set-key (kbd "<f11>") 'fullscreen)
(add-hook 'prog-mode-hook 'display-line-numbers-mode)
;; show matching parenthesis
(show-paren-mode 1)
(use-package hydra
:ensure t)
(defvar hydra-stack nil)
(defun hydra-push (expr)
(push `(lambda () ,expr) hydra-stack))
(defun hydra-pop ()
(interactive)
(let ((x (pop hydra-stack)))
(when x
(funcall x))))
(defun magic_rb/hydra-launcher ()
"A launcher for hydras based on current context."
(interactive)
(cl-case major-mode
('rustic-mode (magic_rb/hydra-rust/body))
(t (magic_rb/hydra-base/body)))
)
(global-set-key (kbd "C-'") 'magic_rb/hydra-launcher)
(defhydra magic_rb/hydra-base (:color red :body-pre (setq hydra-stack nil))
("w" (progn
(magic_rb/hydra-window-sub/body)
(hydra-push '(magic_rb/hydra-launcher)))
"visit magic_rb/hydra-window-sub" :color teal)
("s" treemacs-switch-workspace)
("S" treemacs-edit-workspaces)
("t" treemacs-select-window)
("T" treemacs)
("m" magit)
("x" delete-window)
("RET" (progn (setq hydra-stack nil)) "Cancel" :color blue)
("SPC" (progn (setq hydra-stack nil)) "Cancel" :color blue))
(defhydra magic_rb/hydra-window-sub (:color red)
("a" ace-window)
("j" windmove-left)
("k" windmove-up)
("l" windmove-down)
(";" windmove-right)
("RET" hydra-pop "exit" :color blue)
("SPC" hydra-pop "exit" :color blue)
("q" (progn (setq hydra-stack nil)) "Cancel" :color blue)
)
(defhydra magic_rb/hydra-rust (:color red :inherit (magic_rb/hydra-base/heads))
("r" (progn
(magic_rb/hydra-rust-sub/body)
(hydra-push '(magic_rb/hydra-launcher)))
"visit magic_rb/hydra-rust-sub" :color teal)
)
(defhydra magic_rb/hydra-rust-sub ()
("b" rustic-cargo-build)
("r" rustic-cargo-run)
("RET" hydra-pop "exit" :color blue)
("SPC" hydra-pop "exit" :color blue)
("q" (progn (setq hydra-stack nil)) "Cancel" :color blue)
)
(use-package key-chord
:ensure t
:init
(defun key-chord-define-nonsymmetric (keymap keys command)
(if (/= 2 (length keys))
(error "Key-chord keys must have two elements"))
(let ((key1 (logand 255 (aref keys 0)))
(key2 (logand 255 (aref keys 1))))
(if (eq key1 key2)
(define-key keymap (vector 'key-chord key1 key2) command)
(define-key keymap (vector 'key-chord key1 key2) command)
;; just remove this line:
;(define-key keymap (vector 'key-chord key2 key1) command)
)))
;;Exit insert mode by pressing j and then j quickly
(setq key-chord-two-keys-delay 0.15)
(key-chord-define evil-insert-state-map "jj" 'evil-normal-state)
(key-chord-mode 1))
;(use-package jetbrains-darcula-theme
; :config
; (load-theme 'jetbrains-darcula t))
;; move hjkl to jkl;
(define-key evil-motion-state-map "h" nil)
(define-key evil-motion-state-map "j" 'evil-backward-char)
(define-key evil-motion-state-map "k" 'evil-previous-line)
(define-key evil-motion-state-map "l" 'evil-next-line)
(define-key evil-motion-state-map ";" 'evil-forward-char)
(evil-define-key 'treemacs treemacs-mode-map (kbd "h") nil)
(evil-define-key 'treemacs treemacs-mode-map (kbd "j") 'treemacs-root-up)
(evil-define-key 'treemacs treemacs-mode-map (kbd "k") 'treemacs-previous-line)
(evil-define-key 'treemacs treemacs-mode-map (kbd "l") 'treemacs-next-line)
(evil-define-key 'treemacs treemacs-mode-map (kbd ";") 'treemacs-root-down)
;; optimizations for emacs-lsp
(setq gc-cons-threshold 100000000)
(setq read-process-output-max (* 1024 1024))
;; enable ido
(setq ido-enable-flex-matching t)
(setq ido-everywhere t)
(ido-mode 1)
;; disable gtk stuff
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1)) ;; no toolbar
(menu-bar-mode -1) ;;no menubar
(scroll-bar-mode -1) ;; no scroll bar
;; set font
(when (string= (system-name) "omen")
(add-to-list 'default-frame-alist '(font . "Fira Code 12")))
(when (string= (system-name) "heater")
(add-to-list 'default-frame-alist '(font . "Fira Code 12")))
(when (string= (system-name) "fractal")
(add-to-list 'default-frame-alist '(font . "Fira Code 12")))
(set-face-attribute 'default nil :font "Fira Code" )
(custom-set-faces
'(default ((t (:family "Fira Code"))))
;; I should be able to set this just in treemacs...
'(variable-pitch ((t (:family "Fira Code"))))
)
;; disable focus on mouse over
(push '(no-accept-focus . t) lsp-ui-doc-frame-parameters)
(push '(no-accept-focus . t) company-box-frame-parameters)
(add-to-list 'lsp-ui-doc-frame-parameters '(no-accept-focus . t))
(add-to-list 'company-box-frame-parameters '(no-accept-focus . t))
(setq mouse-autoselect-window nil)
;; enable parenthesis and quotes pairing thing
(electric-pair-mode)
(add-hook 'after-make-frame-functions
<<<<<<< HEAD
(lambda (frame)
(select-frame frame)
(load-theme 'doom-one t)))
=======
(lambda (frame)
(select-frame frame)
(load-theme 'doom-peacock)))
>>>>>>> d0a396dae183d57fe0d9f91d8e36cb1a9d28ce11
;; fullscreen
(defun fullscreen ()
(interactive)
(set-frame-parameter nil 'fullscreen
(if (frame-parameter nil 'fullscreen) nil 'fullboth)))
;; :q should kill the current buffer rather than quitting emacs entirely
(evil-ex-define-cmd "q" 'kill-this-buffer)
;; Need to type out :quit to close emacs
(evil-ex-define-cmd "quit" 'evil-quit)
;; save and close buffer
(defun liu233w/ex-save-kill-buffer-and-close ()
(interactive)
(save-buffer)
(kill-this-buffer)
)
(evil-ex-define-cmd "wq" 'liu233w/ex-save-kill-buffer-and-close)
;; positional window movement
(when (fboundp 'windmove-default-keybindings)
(windmove-default-keybindings))
;; compositor based transparency
(add-to-list 'default-frame-alist '(alpha 90 90))
;; set fill column indicator column number
(setq-default display-fill-column-indicator-column 100)
(server-start)
(setq org-file-dir "~/.emacs.d/org")
(mapc #'org-babel-load-file (directory-files org-file-dir t "\\.org$"))

View file

@ -0,0 +1,202 @@
#+NAME: base
#+BEGIN_SRC emacs-lisp
(use-package elcord
:ensure t
:config
(when (not (string= (system-name) "fractal"))
(elcord-mode))
)
(when (not (string= (system-name) "localhost"))
(use-package tree-sitter
:ensure t)
(use-package tree-sitter-langs
:ensure t)
(global-tree-sitter-mode)
(add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode))
;; aligns annotation to the right hand side
(setq company-tooltip-align-annotations t)
(use-package edit-server
:ensure t
:commands edit-server-start
:init (if after-init-time
(edit-server-start)
(add-hook 'after-init-hook
#'(lambda() (edit-server-start))))
:config (setq edit-server-new-frame-alist
'((name . "Edit with Emacs FRAME")
(top . 200)
(left . 200)
(width . 80)
(height . 25)
(minibuffer . t)
(menu-bar-lines . t)
(window-system . x))))
(setq display-line-numbers-type 'relative)
(use-package impatient-mode
:ensure t)
(defun markdown-html (buffer)
(princ (with-current-buffer buffer
(format "<!DOCTYPE html><html><title>Impatient Markdown</title><xmp theme=\"united\" style=\"display:none;\"> %s </xmp><script src=\"http://strapdownjs.com/v/0.2/strapdown.js\"></script></html>" (buffer-substring-no-properties (point-min) (point-max))))
(current-buffer)))
(httpd-start)
(use-package pdf-tools
:ensure t
:hook (('TeX-mode-hook . visual-line-mode))
:config
;; initialise
(pdf-tools-install)
(setq TeX-PDF-mode 1)
;; open pdfs scaled to fit page
(setq-default pdf-view-display-size 'fit-page)
;; automatically annotate highlights
(setq pdf-annot-activate-created-annotations t))
(use-package auxtex
:ensure t)
(use-package vterm
:ensure t)
(use-package w3m
:ensure t)
(use-package all-the-icons
:ensure t)
(use-package doom-modeline
:ensure t
:config
(doom-modeline-mode)
(make-variable-buffer-local 'doom-modeline-icon)
(add-hook 'after-make-frame-hook
(lambda ()
(setq doom-modeline-icon (display-graphic-p))))
)
(use-package chess
:ensure t)
(use-package origami
:ensure t)
(use-package doom-themes
:ensure t
:config
;; 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
;; Enable flashing mode-line on errors
(doom-themes-visual-bell-config)
;; Enable custom neotree theme (all-the-icons must be installed!)
(doom-themes-neotree-config)
;; or for treemacs users
(setq doom-themes-treemacs-theme "doom-colors") ; use the colorful treemacs theme
(doom-themes-treemacs-config)
;; Corrects (and improves) org-mode's native fontification.
(doom-themes-org-config)
:after (hydra)
:config
(defhydra magic_rb/theme-select (:color blue)
("od" (progn
(load-theme 'doom-one t)
(set-frame-font "Fira Code 12" nil t)
)
)
("ol" (progn
(load-theme 'doom-one-light t)
(set-frame-font "Fira Code 12" nil t)
)
)
)
:bind ("<f6>" . magic_rb/theme-select/body))
(global-set-key (kbd "<f11>") 'fullscreen)
(add-hook 'prog-mode-hook 'display-line-numbers-mode)
;; show matching parenthesis
(show-paren-mode 1)
(setq ispell-program-name "hunspell")
;; optimizations for emacs-lsp
(setq gc-cons-threshold 100000000)
(setq read-process-output-max (* 1024 1024))
;; enable ido
(setq ido-enable-flex-matching t)
(setq ido-everywhere t)
(ido-mode 1)
;; disable gtk stuff
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1)) ;; no toolbar
(menu-bar-mode -1) ;;no menubar
(scroll-bar-mode -1) ;; no scroll bar
;; set ont
(when (string= (system-name) "omen")
(set-frame-font "Fira Code 12" nil t))
(when (string= (system-name) "heater")
(set-frame-font "Fira Code 12" nil t))
(when (string= (system-name) "fractal")
(set-frame-font "Fira Code 12" nil t))
;; disable focus on mouse over
(push '(no-accept-focus . t) lsp-ui-doc-frame-parameters)
(push '(no-accept-focus . t) company-box-frame-parameters)
(add-to-list 'lsp-ui-doc-frame-parameters '(no-accept-focus . t))
(add-to-list 'company-box-frame-parameters '(no-accept-focus . t))
(setq mouse-autoselect-window nil)
;; enable parenthesis and quotes pairing thing
(electric-pair-mode)
(add-hook 'after-make-frame-functions
(lambda (frame)
(select-frame frame)
(load-theme 'doom-one t)))
;; fullscreen
(defun fullscreen ()
(interactive)
(set-frame-parameter nil 'fullscreen
(if (frame-parameter nil 'fullscreen) nil 'fullboth)))
;; :q should kill the current buffer rather than quitting emacs entirely
(evil-ex-define-cmd "q" 'kill-this-buffer)
;; Need to type out :quit to close emacs
(evil-ex-define-cmd "quit" 'evil-quit)
;; save and close buffer
(defun liu233w/ex-save-kill-buffer-and-close ()
(interactive)
(save-buffer)
(kill-this-buffer)
)
(evil-ex-define-cmd "wq" 'liu233w/ex-save-kill-buffer-and-close)
(setq backup-directory-alist
`(("." . ,(concat user-emacs-directory "backups"))))
;; compositor based transparency
(add-to-list 'default-frame-alist '(alpha 90 90))
;; set fill column indicator column number
(setq-default display-fill-column-indicator-column 100)
(unless (server-running-p)
(server-start))
#+END_SRC

View file

@ -0,0 +1,55 @@
#+NAME: evil
#+BEGIN_SRC emacs-lisp
(use-package evil
:ensure t
:init
(setq evil-want-keybinding nil)
:bind (:map evil-motion-state-map
("h" . nil)
("j" . evil-backward-char)
("k" . evil-previous-line)
("l" . evil-next-line)
(";" . evil-forward-char))
:config
(evil-mode 1)
(with-eval-after-load "treemacs"
(evil-define-key 'treemacs treemacs-mode-map (kbd "h") nil)
(evil-define-key 'treemacs treemacs-mode-map (kbd "j") 'treemacs-root-up)
(evil-define-key 'treemacs treemacs-mode-map (kbd "k") 'treemacs-previous-line)
(evil-define-key 'treemacs treemacs-mode-map (kbd "l") 'treemacs-next-line)
(evil-define-key 'treemacs treemacs-mode-map (kbd ";") 'treemacs-root-down)))
(use-package evil-collection
:ensure t
:config
(evil-collection-init 'vterm)
(defun evil-collection-vterm-escape-stay ()
"Go back to normal state but don't move cursor backwards.
Moving cursor backwards is the default vim behavior but
it is not appropriate in some cases like terminals."
(setq-local evil-move-cursor-back nil))
(add-hook 'vterm-mode-hook #'evil-collection-vterm-escape-stay))
(use-package evil-surround
:ensure t
:after evil
:config
(global-evil-surround-mode 1))
(use-package key-chord
:ensure t
:config
(defun magic_rb/key-chord-define-nonsymmetric (keymap keys command)
(if (/= 2 (length keys))
(error "Key-chord keys must have two elements"))
(let ((key1 (logand 255 (aref keys 0)))
(key2 (logand 255 (aref keys 1))))
(if (eq key1 key2)
(define-key keymap (vector 'key-chord key1 key2) command)
(define-key keymap (vector 'key-chord key1 key2) command)
)))
(setq key-chord-two-keys-delay 0.15)
(key-chord-define evil-insert-state-map "jj" 'evil-normal-state)
(key-chord-mode 1))
#+END_SRC

View file

@ -0,0 +1,72 @@
* EXVM
** Moving workspace
Theoretically it's possible to move workspace N to monitor M, by binding \s-C-[0-9], like many people do in i3. All that needs to be done is that a suitable plist needs to be build:
#+NAME: workspace-plist
#+BEGIN_SRC emacs-lisp :tangle no
(setq exwm-randr-workspace-output-plist `(1 "HDMI-0" 2 "HDMI-1" 3 "HDMI-1"))
#+END_SRC
And then this function must be called for EXWM to pick up any changes made
#+NAME:
#+BEGIN_SRC emacs-lisp :tangle no
(exwm-randr-refresh)
#+END_SRC
** Autostart
#+NAME: autostart
#+BEGIN_SRC emacs-lisp :tangle no
(call-process-shell-command "xmodmap ~/.xmodmap &" nil 0)
(call-process-shell-command "dunst &" nil 0)
(call-process-shell-command "picom &" nil 0)
(call-process-shell-command "/mnt/data3/Programs/bin/nextcloud &" nil 0)
(call-process-shell-command "setxkbmap -layout us,sk variant ,qwerty -option grp:lalt_lshift_toggle &" nil 0)
(when (string= (system-name) "heater")
(call-process-shell-command "feh --bg-max /mnt/data3/Nextcloud/Multimedia/Wallpapers/0126.jpg" nil 0)))
#+END_SRC
#+NAME: exwm
#+BEGIN_SRC emacs-lisp :noweb yes
(use-package exwm
:ensure t
:after hydra
:init
(require 'exwm-config)
(exwm-config-default)
(require 'exwm-randr)
(setq exwm-randr-workspace-output-plist '(1 "HDMI-0" 2 "HDMI-1"))
(add-hook 'exwm-randr-screen-change-hook
(lambda ()
(start-process-shell-command
"xrandr" nil "xrandr --output HDMI-1 --right-of HDMI-0 --auto")))
(setq exwm-input-global-keys
`(([?\s-r] . exwm-reset)
([?\s-w] . exwm-workspace-switch)
,@(mapcar (lambda (i)
`(,(kbd (format "s-%d" i)) .
(lambda ()
(interactive)
(exwm-workspace-switch-create ,i))))
(number-sequence 0 9))
([?\s-\)] . (lambda () (interactive) (exwm-workspace-move-window 0)))
([?\s-!] . (lambda () (interactive) (exwm-workspace-move-window 1)))
([?\s-@] . (lambda () (interactive) (exwm-workspace-move-window 2)))
([?\s-#] . (lambda () (interactive) (exwm-workspace-move-window 3)))
([?\s-$] . (lambda () (interactive) (exwm-workspace-move-window 4)))
([?\s-%] . (lambda () (interactive) (exwm-workspace-move-window 5)))
([?\s-^] . (lambda () (interactive) (exwm-workspace-move-window 6)))
([?\s-&] . (lambda () (interactive) (exwm-workspace-move-window 7)))
([?\s-8] . (lambda () (interactive) (exwm-workspace-move-window 8)))
([?\s-*] . (lambda () (interactive) (exwm-workspace-move-window 9)))
([<print>] . (call-process-shell-command "screenshot select &" nil 0))
([?\s-d] . (lambda (command)
(interactive (list (read-shell-command "$ ")))
(start-process-shell-command command nil command)))))
;; Make focus follow mouse
(setq mouse-autoselect-window t
focus-follows-mouse t)
<<autostart>>
(setq exwm-workspace-number 10)
(exwm-randr-enable))
#+END_SRC

View file

@ -0,0 +1,91 @@
* Hydra
** Base
#+NAME: hydra-base
#+BEGIN_SRC emacs-lisp :tangle no
(defhydra magic_rb/hydra-base (:color red :body-pre (setq hydra-stack nil))
("w" (progn
(magic_rb/hydra-window-sub/body)
(hydra-push '(magic_rb/hydra-launcher)))
"visit magic_rb/hydra-window-sub" :color teal)
("s" treemacs-switch-workspace)
("S" treemacs-edit-workspaces)
("t" treemacs-select-window)
("T" treemacs)
("v" vterm)
("m" magit)
("RET" (progn (setq hydra-stack nil)) "Cancel" :color blue)
("SPC" (progn (setq hydra-stack nil)) "Cancel" :color blue))
(defhydra magic_rb/hydra-rust (:color red :inherit (magic_rb/hydra-base/heads))
("r" (progn
(magic_rb/hydra-rust-sub/body)
(hydra-push '(magic_rb/hydra-launcher)))
"visit magic_rb/hydra-rust-sub" :color teal)
("e" lsp-execute-code-action))
(defhydra magic_rb/hydra-lsp (:color red :inherit (magic_rb/hydra-base/heads))
("e" lsp-execute-code-action))
#+END_SRC
** Subs
*** Window
#+NAME: hydra-window
#+BEGIN_SRC emacs-lisp :tangle no
(defhydra magic_rb/hydra-window-sub (:color red)
("a" ace-window)
("j" windmove-left)
("k" windmove-up)
("l" windmove-down)
(";" windmove-right)
("x" delete-window)
("RET" hydra-pop "exit" :color blue)
("SPC" hydra-pop "exit" :color blue)
("q" (progn (setq hydra-stack nil)) "Cancel" :color blue))
#+END_SRC
*** Rust
#+NAME: hydra-rust-sub
#+BEGIN_SRC emacs-lisp :tangle no
(defhydra magic_rb/hydra-rust-sub ()
("b" rustic-cargo-build)
("r" rustic-cargo-run)
("t" rustic-cargo-test)
("f" rustic-format-buffer)
("RET" hydra-pop "exit" :color blue)
("SPC" hydra-pop "exit" :color blue)
("q" (progn (setq hydra-stack nil)) "Cancel" :color blue))
#+END_SRC
*** LSP
#+NAME: hydra
#+BEGIN_SRC emacs-lisp :noweb yes
(use-package hydra
:ensure t
:after (vterm magit treemacs lsp-mode rustic)
:config
(defvar hydra-stack nil)
(defun hydra-push (expr)
(push `(lambda () ,expr) hydra-stack))
(defun hydra-pop ()
(interactive)
(let ((x (pop hydra-stack)))
(when x
(funcall x))))
(defun magic_rb/hydra-launcher ()
"A launcher for hydras based on current context."
(interactive)
(cl-case major-mode
('rustic-mode (magic_rb/hydra-rust/body))
('lsp-mode (magic_rb/hydra-rust/body))
(t (magic_rb/hydra-base/body)))
)
<<hydra-base>>
<<hydra-window>>
<<hydra-rust>>
:bind (("C-'" . magic_rb/hydra-launcher)))
#+END_SRC

View file

@ -0,0 +1,147 @@
* LSP and IDE setup
** Languages
*** YAML
#+NAME: yaml
#+BEGIN_SRC emacs-lisp
(use-package yaml-mode
:ensure t
:mode ("\\.yml\\'" . yaml-mode)
:mode ("\\.yaml\\'" . yaml-mode))
#+END_SRC
*** Dockerfile
#+NAME: dockefile
#+BEGIN_SRC emacs-lisp
(use-package dockerfile-mode
:ensure t
:mode ("Dockerfile\\'" . dockerfile-mode))
#+END_SRC
*** Rust
#+NAME: rust
#+BEGIN_SRC emacs-lisp
(use-package rustic
:ensure t
:mode ("\\.rs\\'" . rustic-mode))
#+END_SRC
*** SCAD
#+NAME: scad
#+BEGIN_SRC emacs-lisp
(use-package scad-mode
:ensure t)
#+END_SRC
*** Scala
#+NAME: scala
#+BEGIN_SRC emacs-lisp
(use-package scala-mode
:ensure t
:mode ("\\.s\\(cala\\|bt\\)$" . scala-mode))
(use-package sbt-mode
:ensure t
:commands sbt-start sbt-command
:config
;; WORKAROUND: https://github.com/ensime/emacs-sbt-mode/issues/31
;; allows using SPACE when in the minibuffer
(substitute-key-definition
'minibuffer-complete-word
'self-insert-command
minibuffer-local-completion-map)
;; sbt-supershell kills sbt-mode: https://github.com/hvesalai/emacs-sbt-mode/issues/152
(setq sbt:program-options '("-Dsbt.supershell=false")))
#+END_SRC
*** Web - HTML + CSS
#+NAME: web
#+BEGIN_SRC emacs-lisp
(use-package web-mode
:ensure t
:mode ("\\.html\\'" . web-mode)
:mode ("\\.xhtml\\'" . web-mode)
:mode ("\\.css\\'" . css-mode)
:mode ("\\.scss\\'" . css-mode)
:config
(with-eval-after-load "flycheck"
(flycheck-add-mode 'javascript-eslint 'web-mode)))
#+END_SRC
*** Javascript
#+NAME: javascript
#+BEGIN_SRC emacs-lisp
(use-package rjsx-mode
:ensure t
:config
:mode ("\\.js\\'" . rjsx-mode)
:mode ("\\.jsx\\'" . rjsx-mode))
#+END_SRC
*** Typescript
#+NAME: typescript
#+BEGIN_SRC emacs-lisp
(use-package typescript-mode
:ensure t
:config
:mode ("\\.ts\\'" . typescript-mode)
:mode ("\\.tsx\\'" . typescript-mode))
#+END_SRC
** LSP
*** lsp-mode
#+NAME: lsp-mode
#+BEGIN_SRC emacs-lisp
(use-package lsp-mode
:ensure t
:after (rustic
rjsx-mode
typescript-mode
web-mode
scala-mode)
:config
(setq rustic-lsp-server 'rust-analyzer)
(setq rustic-compile-command "cargo build")
(setq rustic-format-trigger nil);'on-save)
(setq lsp-prefer-flymake nil)
:hook
(rustic . lsp)
(php-mode . lsp)
(rjsx-mode . lsp)
(css-mode . lsp)
(web-mode . lsp)
(lsp-mode . lsp-lens-mode)
(typescript-mode . lsp)
(scala-mode . lsp)
(tex-mode . lsp)
(lsp-mode . display-fill-column-indicator-mode)
(python-mode . lsp)
(lsp-mode . origami-mode))
#+END_SRC
*** lsp-metals
#+NAME: lsp-metals
#+BEGIN_SRC emacs-lisp
(use-package lsp-metals
:ensure t)
#+END_SRC
*** lsp-ui
#+NAME: lsp-ui
#+BEGIN_SRC emacs-lisp
(use-package lsp-ui
:ensure t)
#+END_SRC
*** lsp-pyright
#+NAME: lsp-pyright
#+BEGIN_SRC emacs-lisp
(use-package lsp-pyright
:ensure t
:hook (python-mode . (lambda ()
(require 'lsp-pyright)
(lsp)))) ; or lsp-deferred
#+END_SRC
*** yassnippet
#+NAME: yasnippet
#+BEGIN_SRC emacs-lisp
(use-package yasnippet
:ensure t
:config
(yas-global-mode 1))
#+END_SRC
*** flycheck
#+NAME: flycheck
#+BEGIN_SRC emacs-lisp
(use-package flycheck
:ensure t
:init (global-flycheck-mode))
#+END_SRC

View file

@ -0,0 +1,26 @@
* Magit
#+NAME: magit
#+BEGIN_SRC emacs-lisp
(use-package magit
:ensure t)
#+END_SRC
** Evil Magit
*** TODO The keybindings for <hjkl> to <jkl;> are kind of broken..
#+NAME: evil-magit
#+BEGIN_SRC emacs-lisp
(use-package evil-magit
:ensure t
:config
(setq evil-magit-state 'motion)
(evil-define-key evil-magit-state magit-mode-map ";" 'magit-log)
(evil-define-key evil-magit-state magit-mode-map "k" 'evil-previous-line)
(evil-define-key evil-magit-state magit-status-mode-map "l" 'evil-next-line))
#+END_SRC
** Magit Todos
#+NAME: magit-todos
#+BEGIN_SRC emacs-lisp
(use-package magit-todos
:ensure t
:hook (rustic . hl-todo-mode))
#+END_SRC

View file

@ -0,0 +1,48 @@
#+NAME: package
#+BEGIN_SRC emacs-lisp
(require 'package)
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
(not (gnutls-available-p))))
(proto (if no-ssl "http" "https")))
(when no-ssl (warn "\
Your version of Emacs does not support SSL connections,
which is unsafe because it allows man-in-the-middle attacks.
There are two things you can do about this warning:
1. Install an Emacs version that does support SSL and be safe.
2. Remove this warning from your init file so you won't see it again."))
(add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t)
(add-to-list 'package-archives (cons "ublt" (concat proto "://elpa.ubolonton.org/packages/")) t)
(add-to-list 'package-archives (cons "celpa" (concat proto "://celpa.conao3.com/packages/")) t)
)
(package-initialize)
(package-refresh-contents)
(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.
'(auth-source-save-behavior nil)
'(custom-enabled-themes '(doom-one))
'(custom-safe-themes
'("2f1518e906a8b60fac943d02ad415f1d8b3933a5a7f75e307e6e9a26ef5bf570" default))
'(package-selected-packages
'(chess scad-preview dockerfile-mode heaven-and-hell yaml-mode rustic scad-mode lsp-treemacs flycheck-rust telephone-line yasnippet flycheck-pos-tip flycheck magit lsp-ui all-the-icons doom-themes lsp-mode use-package treemacs-evil)))
(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 backup-directory-alist `(("." . "~/.emacs.d/saves")))
(add-to-list 'load-path "~/.emacs.d/lisp/")
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package)
(require 'use-package))
#+END_SRC

View file

@ -0,0 +1,15 @@
* Treemacs
#+NAME: treemacs
#+BEGIN_SRC emacs-lisp
(use-package treemacs
:ensure t)
(use-package treemacs-evil
:after (treemacs evil)
:ensure t)
(use-package lsp-treemacs
:ensure t
:after (lsp-mode treemacs)
:config
(lsp-treemacs-sync-mode 1))
#+END_SRC