Last active
November 13, 2024 21:59
-
-
Save gzmask/0de8c5eab64781cbc3ab372efd89652e to your computer and use it in GitHub Desktop.
emacs config
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
;;; This is only needed once, near the top of the file | |
(defvar bootstrap-version) | |
(let ((bootstrap-file | |
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory)) | |
(bootstrap-version 5)) | |
(unless (file-exists-p bootstrap-file) | |
(with-current-buffer | |
(url-retrieve-synchronously | |
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el" | |
'silent 'inhibit-cookies) | |
(goto-char (point-max)) | |
(eval-print-last-sexp))) | |
(load bootstrap-file nil 'nomessage)) | |
(straight-use-package 'use-package) | |
;; looks | |
(menu-bar-mode -1) | |
(toggle-scroll-bar -1) | |
(tool-bar-mode -1) | |
(load-theme 'manoj-dark t) | |
(set-face-attribute 'default nil :height 150) | |
(setq inhibit-splash-screen t) | |
(set-frame-parameter (selected-frame) 'alpha '(75 80)) | |
'(global-display-line-numbers-mode) | |
(fset 'yes-or-no-p 'y-or-n-p) | |
(when (fboundp 'winner-mode) | |
(winner-mode t)) | |
;;(setq pop-up-windows nil) | |
;; generic packs | |
(setq gc-cons-threshold 60000000) | |
;(desktop-save-mode 1) | |
(use-package helm :ensure t :straight t | |
:config (helm-mode 1)) | |
(use-package helm-ag :ensure t :straight t | |
:init (setq helm-ag-insert-at-point 'symbol | |
helm-ag-command-option "--path-to-ignore ~/.agignore")) | |
(use-package helm-descbinds :ensure t :straight t | |
:config (helm-descbinds-mode)) | |
(use-package projectile :ensure t :straight t | |
:config | |
(projectile-mode) | |
(setq projectile-enable-caching t)) | |
(use-package helm-projectile :ensure t :straight t | |
:config (helm-projectile-on)) | |
(use-package company :ensure t :straight t | |
:init (global-company-mode) | |
:config | |
(progn | |
;; Use Company for completion | |
(bind-key [remap completion-at-point] #'company-complete company-mode-map) | |
(setq company-tooltip-align-annotations t | |
;; Easy navigation to candidates with M-<n> | |
company-show-numbers t) | |
(setq company-dabbrev-downcase nil)) | |
:diminish company-mode) | |
(use-package which-key :ensure t :straight t | |
:config | |
(which-key-mode +1)) | |
(use-package helm-swoop :ensure t :straight t) | |
(use-package expand-region :ensure t :straight t) | |
(use-package flycheck :ensure t :straight t | |
:init (global-flycheck-mode)) | |
(use-package dumb-jump :ensure t :straight t) | |
(use-package lsp-mode :ensure t :straight t) | |
(use-package yasnippet :ensure t :straight t) | |
(use-package hydra :ensure t :straight t) | |
(use-package company-lsp :ensure t :straight t) | |
(use-package lsp-ui :ensure t :straight t) | |
(use-package treemacs :ensure t :straight t) | |
(use-package lsp-treemacs :ensure t :straight t) | |
(use-package editorconfig :ensure t :straight t | |
:config (editorconfig-mode 1)) | |
(use-package exec-path-from-shell :ensure t :straight t | |
:init | |
(when (memq window-system '(mac ns x)) | |
(exec-path-from-shell-initialize))) | |
(use-package magit :ensure t :straight t) | |
(use-package magit-remote-link | |
:straight (magit-remote-link :host github :repo "pkulev/magit-remote-link.el") | |
:ensure t) | |
;;brew install libvterm | |
(use-package vterm :ensure t :straight t | |
:custom | |
(vterm-max-scrollback 100000) | |
:config | |
(vterm--set-directory "/Users/i502158")) | |
(use-package avy :ensure t :straight t) | |
;;github copilot | |
(use-package copilot | |
:straight (:host github :repo "zerolfx/copilot.el" :files ("dist" "*.el")) | |
:ensure t) | |
;; evil packs | |
(use-package evil :ensure t :straight t | |
:custom | |
(evil-search-module 'evil-search) | |
(evil-ex-complete-emacs-commands nil) | |
(evil-vsplit-window-right t) | |
(evil-split-window-below t) | |
(evil-shift-round nil) | |
(evil-want-C-u-scroll t) | |
(evil-move-beyond-eol t) | |
(evil-want-keybinding nil) | |
:config (evil-mode 1)) | |
(use-package evil-collection :ensure t :straight t | |
:after evil | |
:config | |
(evil-collection-init)) | |
(use-package evil-org :ensure t :straight t | |
:after org | |
:custom | |
(org-startup-with-inline-images t) | |
:config | |
(add-hook 'org-mode-hook 'evil-org-mode) | |
(add-hook 'org-mode-hook | |
(lambda () | |
(when truncate-lines | |
(toggle-truncate-lines)))) | |
(add-hook 'evil-org-mode-hook | |
(lambda () | |
(evil-org-set-key-theme))) | |
(require 'evil-org-agenda) | |
(evil-org-agenda-set-keys) | |
(org-babel-do-load-languages | |
'org-babel-load-languages '((shell . t) | |
(clojure . t) | |
(emacs-lisp . t)))) | |
(use-package ox-gfm :ensure t :straight t) | |
(use-package vimish-fold :straight t | |
:ensure t | |
:after evil) | |
(use-package evil-vimish-fold :straight t | |
:ensure t | |
:after vimish-fold | |
:hook ((prog-mode conf-mode text-mode) . evil-vimish-fold-mode)) | |
(defun previous-code-buffer () | |
(interactive) | |
(let (( bread-crumb (buffer-name) )) | |
(previous-buffer) | |
(while | |
(and | |
(equal "*Messages*" (buffer-name)) | |
(not ( equal bread-crumb (buffer-name) )) ) | |
(previous-buffer)))) | |
(defun next-code-buffer () | |
(interactive) | |
(let (( bread-crumb (buffer-name) )) | |
(switch-to-next-buffer) | |
(while | |
(and | |
(equal "*Messages*" (buffer-name)) | |
(not ( equal bread-crumb (buffer-name) )) ) | |
(switch-to-next-buffer)))) | |
(defun kill-other-buffers () | |
"Kill all other buffers." | |
(interactive) | |
(mapc 'kill-buffer (delq (current-buffer) (buffer-list)))) | |
(defun general-root-key-map () | |
"key mapping for SPC" | |
(general-evil-define-key '(normal visual) 'general-override-mode-map ;;force override, or 'global to avoid overriding | |
:prefix "SPC" | |
"" nil | |
"RET" 'gptel-send | |
"SPC" 'helm-M-x | |
"TAB" 'previous-code-buffer | |
":" 'eval-expression | |
";" 'comment-line | |
"p" 'projectile-command-map | |
"v" 'er/expand-region | |
"V" 'vterm-other-window | |
"w" 'evil-window-map | |
"w f" 'toggle-frame-fullscreen | |
"w u" 'winner-undo | |
"w U" 'winner-redo | |
"b" '(:ignore t :which-key "buffer cmd") | |
"b b" 'helm-buffers-list | |
"b c" 'comint-clear-buffer | |
"b d" 'kill-current-buffer | |
"b D" 'kill-other-buffers | |
"b n" 'next-code-buffer | |
"d" '(:ignore t :which-key "describe cmd") | |
"d b" 'helm-descbinds | |
"d d" 'helm-apropos | |
"d f" 'describe-function | |
"e" '(:ignore t :which-key "flycheck cmd") | |
"e c" 'flycheck-clear | |
"e e" 'flycheck-explain-error-at-point | |
"e l" 'flycheck-list-errors | |
"e n" 'flycheck-next-error | |
"e N" 'flycheck-previous-error | |
"f" '(:ignore t :which-key "file cmd") | |
"f f" 'helm-find-files | |
"f d" 'delete-file | |
"g" '(:ignore t :which-key "magit cmd") | |
"g s" 'magit-status | |
"g b" 'magit-blame | |
"g l" 'magit-remote-link-copy-at-point | |
"g L" 'magit-remote-link-browse-at-point | |
"i" '(:ignore t :which-key "skeleton cmd") | |
"i c" 'snippet-nyan-cat | |
"j" '(:ignore t :which-key "jump cmd") | |
"j j" 'avy-goto-char-2 | |
"j l" 'avy-goto-line | |
"j b" 'avy-resume | |
"m"' (:ignore t :which-key "bookmark/menu cmd") | |
"m b" 'bookmark-set | |
"m d" 'bookmark-delete | |
"m i" 'helm-imenu | |
"m m" 'helm-filtered-bookmarks | |
"s" '(:ignore t :which-key "search cmd") | |
"s b" 'helm-ag-buffers | |
"s d" 'helm-ag | |
"s p" 'helm-ag-project-root | |
"s s" 'helm-swoop | |
"t" 'treemacs | |
"k" '(:ignore t :which-key "paredit cmd") | |
"k b" 'paredit-forward-barf-sexp | |
"k k" 'paredit-splice-sexp-killing-backward | |
"k K" 'paredit-splice-sexp-killing-forward | |
"k s" 'paredit-forward-slurp-sexp)) | |
(defun general-dired-key-map () | |
"Dired keymap" | |
(general-define-key | |
:states 'normal | |
:keymaps 'dired-mode-map | |
"RET" 'dired-find-alternate-file | |
"^" (lambda () (interactive) (find-alternate-file "..")))) | |
(defun general-org-key-map () | |
"Org mode keymap." | |
(general-evil-define-key '(normal visual) 'org-mode-map | |
:prefix "," | |
"RET" 'gptel-send | |
"d" 'org-redisplay-inline-images | |
"h" 'org-up-element | |
"i" '(:ignore t :which-key "insert/skeleton cmd") | |
"i i" 'org-insert-heading-after-current | |
"i s" 'snippet-babel-src-block | |
"I" 'org-insert-subheading | |
"j" 'org-forward-element | |
"k" 'org-backward-element | |
"l" 'org-down-element | |
"o" 'org-meta-return | |
"e e" 'org-ctrl-c-ctrl-c | |
"t n" 'org-table-create | |
"t a" 'org-table-align | |
"t i r" 'org-table-insert-row | |
"t i c" 'org-table-insert-column)) | |
(defun general-vterm-key-map () | |
"Vterm keymap." | |
(general-evil-define-key '(normal visual) 'vterm-mode-map | |
"p" 'vterm-yank | |
:prefix "," | |
"s" '(:ignore t :which-key "screen cmd") | |
"s e" 'vterm-extra-read-and-send | |
"s c" 'vterm-clear | |
"s C" 'vterm-clear-scrollback)) | |
;; lang packs | |
;; Javascript | |
(add-hook 'js-mode-hook (lambda () | |
(setq indent-tabs-mode nil) | |
(setq js-indent-level 4))) | |
;; Java | |
(setq lsp-java-server-install-dir "/Users/i502158/jdtls") | |
(require 'cc-mode) | |
(use-package lsp-java :ensure t | |
:straight t | |
:defer t | |
:after lsp | |
:config (add-hook 'java-mode-hook 'lsp)) | |
(use-package dap-mode :ensure t | |
:straight t | |
:defer t | |
:after lsp-mode | |
:config | |
(dap-mode t) | |
(dap-ui-mode t)) | |
(use-package dap-java | |
:straight (dap-java :type git :host github :repo "emacs-lsp/lsp-java") | |
:defer t | |
:after (lsp-java)) | |
(defun general-java-key-map () | |
"java key map" | |
(general-evil-define-key '(normal visual) 'java-mode-map | |
:prefix "," | |
";" 'comment-or-uncomment-region | |
"d a" 'dap-breakpoint-add | |
"d d" 'dap-java-debug | |
"d c" 'dap-continue | |
"d v" 'dap-ui-locals | |
"d x" 'dap-breakpoint-delete | |
"d X" 'dap-breakpoint-delete-all)) | |
;;; Lisp | |
(use-package paredit :ensure t | |
:straight t | |
:init | |
(dolist (hook '(emacs-lisp-mode-hook lisp-mode-hook clojure-mode-hook)) | |
(add-hook hook 'paredit-mode)) | |
:diminish paredit-mode) | |
(defun general-elisp-key-map () | |
"Emacs lisp keymap." | |
(general-evil-define-key '(normal visual) 'emacs-lisp-mode-map | |
:prefix "," | |
";" 'comment-or-uncomment-region | |
"e b" 'eval-buffer | |
"e e" 'eval-last-sexp | |
"e f" 'eval-defun | |
"e u" 'ulisp-eval-last-expression-in-term | |
"g g" 'xref-find-definitions | |
"g b" 'xref-pop-marker-stack)) | |
;;; LLM | |
(use-package gptel | |
:ensure t | |
:straight t | |
:defer t | |
:custom | |
(gptel-default-mode 'org-mode)) | |
;;; Clojure | |
(use-package flycheck-clj-kondo :ensure t :straight t) | |
(use-package clojure-mode :ensure t | |
:straight t | |
:config (require 'flycheck-clj-kondo)) | |
(use-package cider | |
:ensure t | |
:straight t | |
:defer t | |
:custom | |
(nrepl-hide-special-buffers t) | |
(cider-repl-wrap-history t) | |
(cider-boot-parameters "cider repl -s wait") | |
(cider-auto-jump-to-error nil) | |
:config | |
(add-hook 'cider-mode-hook #'eldoc-mode) | |
(add-hook 'cider-repl-mode-hook #'paredit-mode) | |
;; Function definitions | |
(defun clj-style-region (startPos endPos) | |
"Use cljstyle to format selected region." | |
(interactive "r") | |
(let ((cmdStr "cljstyle pipe")) | |
(shell-command-on-region startPos endPos cmdStr nil t nil t))) | |
(defun clj-find-var (sym-name &optional arg) | |
"Attempts to jump-to-definition of the SYM-NAME. If CIDER fails, falls back to dumb-jump." | |
(interactive (list (cider-symbol-at-point))) | |
(if (and (cider-connected-p) (cider-var-info sym-name)) | |
(unless (eq 'symbol (type-of (cider-find-var nil sym-name))) | |
(dumb-jump-go)) | |
(dumb-jump-go))) | |
(defun clj-rm-ns (&optional prompt) | |
(interactive "P") | |
(if (cider-connected-p) | |
(let ((ns (if prompt | |
(string-remove-prefix "'" (read-from-minibuffer "Namespace: " (clojure-find-ns))) | |
(clojure-find-ns)))) | |
(cider-interactive-eval (format "(remove-ns '%s)" ns)))))) | |
(use-package clj-refactor :ensure t | |
:straight t | |
:defer t | |
:custom | |
(cljr-ignore-analyzer-errors t)) | |
(use-package inf-clojure :ensure t | |
:defer t | |
:straight (inf-clojure :type git :host github :repo "clojure-emacs/inf-clojure")) | |
(defun general-clojure-key-map () | |
"Clojure keymap." | |
(general-evil-define-key '(normal visual) 'clojure-mode-map | |
:prefix "," | |
"," 'cider-eval-last-sexp | |
";" 'comment-or-uncomment-region | |
"'" 'cider-jack-in-clj | |
"?" 'cider-cheatsheet | |
"d v" 'cider-inspect | |
"e" '(:ignore t :which-key "eval cmd") | |
"e b" 'cider-eval-buffer | |
"e c" 'cider-interrupt | |
"e e" 'cider-eval-last-sexp | |
"e f" 'cider-eval-defun-at-point | |
"e w" 'cider-eval-last-sexp-and-replace | |
"e ;" 'cider-pprint-eval-last-sexp-to-comment | |
"f" '(:ignore t :which-key "format cmd") | |
"f f" 'cider-format-defun | |
"f l" 'clojure-align | |
"f r" 'clj-style-region | |
"f R" 'cider-format-region | |
"i" '(:ignore t :which-key "inf-clojure cmd") | |
"i c" 'inf-clojure-connect | |
"i C" 'inf-clojure-clear-repl-buffer | |
"i e" 'inf-clojure-eval-last-sexp | |
"i f" 'inf-clojure-eval-defun | |
"i q" 'inf-clojure-quit | |
"i r" 'inf-clojure-eval-region | |
"n" '(:ignore t :which-key "NS cmd") | |
"n r" 'cider-ns-refresh | |
"n x" 'clj-rm-ns | |
"s" '(:ignore t :which-key "REPL cmd") | |
"s b" 'cider-load-buffer | |
"s c" 'cider-connect | |
"s e" (lambda () (interactive) (cider-insert-last-sexp-in-repl t)) | |
"s f" (lambda () (interactive) (cider-insert-defun-in-repl t)) | |
"s n" 'cider-repl-set-ns | |
"s q" 'cider-quit | |
"s r" 'cider-insert-region-in-repl | |
"s s" 'cider-switch-to-repl-buffer | |
"g" '(:ignore t :which-key "goto cmd") | |
"g g" 'clj-find-var | |
"g b" 'xref-pop-marker-stack | |
"r" '(:ignore t :which-key "cljr cmd") | |
"r c" 'cljr-clean-ns | |
"r d" 'cljr-destructure-keys | |
"r e" 'cljr-extract-function | |
"r f" 'cljr-find-usages | |
"r i" 'cljr-inline-symbol | |
"r m" 'cljr-move-form | |
"r n" 'cljr-add-missing-libspec | |
"r p" 'cljr-promote-function | |
"r r" 'cljr-rename-symbol | |
"r R" 'cljr-rename-file | |
"r t" 'cljr-thread-first-all | |
"r T" 'cljr-thread-last-all)) | |
(defun general-cider-key-map () | |
"cider keymap." | |
(general-evil-define-key '(normal visual) 'cider-repl-mode-map | |
:prefix "," | |
"s c" 'cider-repl-clear-buffer | |
"s q" 'cider-quit)) | |
;;; Python | |
;; if encounter error, run M-x elpy-rpc-reinstall-virtualenv | |
(use-package elpy :ensure t | |
:straight t | |
:defer t | |
:custom | |
(elpy-rpc-python-command "python3") | |
(python-indent-guess-indent-offset t) | |
(python-indent-guess-indent-offset-verbose nil) | |
(python-shell-interpreter "ipython3") | |
(python-shell-interpreter-args "--simple-prompt -c exec('__import__(\\'readline\\')') -i") | |
(python-shell-prompt-detect-failure-warning nil) | |
:init | |
(advice-add 'python-mode :before 'elpy-enable)) | |
(defun general-python-key-map () | |
"Python keymap." | |
(general-evil-define-key '(normal visual) 'python-mode-map | |
:prefix "," | |
"c" 'elpy-config | |
"v" 'pyvenv-activate | |
"e b" 'elpy-shell-send-region-or-buffer | |
"e e" 'elpy-shell-send-statement | |
"e E" 'elpy-shell-send-statement-and-step | |
"e f" 'elpy-shell-send-group | |
"e F" 'elpy-shell-send-group-and-step | |
"g b" 'xref-pop-marker-stack | |
"g g" 'elpy-goto-definition | |
"g G" 'elpy-goto-definition-other-window | |
"h h" 'elpy-doc | |
"s s" 'elpy-shell-switch-to-shell | |
"s c" 'elpy-shell-kill | |
"s C" 'elpy-shell-kill-all)) | |
;; uLisp | |
(defvar port "/dev/cu.usbmodem14501" "Arduino-mega-2560") | |
(defvar bauds 9600 "Bps") | |
(defvar ulisp-term-buffer) | |
(defun setup-ulisp () | |
(interactive) | |
(split-window-right) | |
(other-window 1) | |
(setq ulisp-term-buffer (serial-term port bauds)) | |
(other-window 1)) | |
(defun ulisp-eval-last-expression-in-term () | |
(interactive) | |
(let ((expr (buffer-substring-no-properties | |
(save-excursion (backward-sexp) (point)) | |
(point)))) | |
(with-current-buffer ulisp-term-buffer | |
(term-line-mode) | |
(insert expr) | |
(term-send-input)))) | |
(defun general-ulisp-key-map () | |
"Ulisp keymap." | |
(general-evil-define-key '(normal visual) 'lisp-mode-map | |
:prefix "," | |
";" 'comment-or-uncomment-region | |
"e e" 'ulisp-eval-last-expression-in-term | |
"g g" 'xref-find-definitions | |
"g b" 'xref-pop-marker-stack | |
"s c" 'setup-ulisp)) | |
;;; yaml | |
(use-package yaml-mode :ensure t :straight t :defer t) | |
;;; Metadata | |
(use-package dockerfile-mode :ensure t | |
:straight t | |
:defer t | |
:config | |
(add-to-list 'auto-mode-alist '("Dockerfile\\'" . dockerfile-mode))) | |
(use-package markdown-mode :ensure t :straight t) | |
;;; url encode | |
(defun ray-url-encode-string (str) | |
"URL-encode special characters in STR." | |
(let ((url-hexify-alist | |
'((?\s . "%20") (?! . "%21") (?# . "%23") (?$ . "%24") (?% . "%25") | |
(?& . "%26") (?' . "%27") (?( . "%28") (?) . "%29") (?* . "%2A") | |
(?+ . "%2B") (?,?,?,?,??. "%2C") (?- . "%2D") (?. . "%2E") (?/ . "%2F") | |
(?: . "%3A") (?? . "%3B") (?? . "%3C") (?= . "%3D") (?? . "%3E") | |
(?? . "%3F") (?? . "%40") (?[ . "%5B") (?\ . "%5C") (?] . "%5D") | |
(?^ . "%5E") (?_ . "%5F") (?` . "%60") (?{ . "%7B") (?| . "%7C") | |
(?} . "%7D") (?~ . "%7E")))) | |
(apply 'concat | |
(mapcar (lambda (c) | |
(if (or (and (>= c ?0) (<= c ?9)) ; digits | |
(and (>= c ?A) (<= c ?Z)) ; uppercase letters | |
(and (>= c ?a) (<= c ?z))) ; lowercase letters | |
(char-to-string c) | |
(or (cdr (assoc c url-hexify-alist)) | |
(format "%%%02X" c)))) | |
(string-to-list str))))) | |
(defun ray-url-encode-region (start end) | |
"URL-encode the region from START to END." | |
(interactive "r") | |
(let ((encoded (ray-url-encode-string (buffer-substring-no-properties start end)))) | |
(delete-region start end) | |
(insert encoded))) | |
;; Key bindings | |
(use-package general :ensure t | |
:straight t | |
:init | |
(setq general-override-states '(insert | |
emacs | |
hybrid | |
normal | |
visual | |
motion | |
operator | |
replace)) | |
:config | |
(progn | |
(general-root-key-map) | |
(general-java-key-map) | |
(general-clojure-key-map) | |
(general-cider-key-map) | |
(general-elisp-key-map) | |
(general-ulisp-key-map) | |
(general-org-key-map) | |
(general-vterm-key-map) | |
(general-python-key-map) | |
(general-dired-key-map))) | |
;; snippets | |
(defun snippet-babel-src-block () | |
"Write a babel src block." | |
(interactive) | |
(let* ((cmd (read-from-minibuffer "Enter your command: ")) | |
(cmd (if (string= "" cmd) | |
nil | |
cmd))) | |
(insert (concat "#+begin_src bash :results output\n" (or cmd "ls") "\n#+end_src")))) | |
(defun snippet-nyan-cat () | |
"nyan cat." | |
(interactive) | |
(insert | |
";; ~~,__/V\\ | |
;;`*.,*'^`*.,*'^`*.,*'^`*.,*'^`*.,*'^`*.,*'^`*.,*'^`*. |__(o.o) | |
;;^`*.,*'^`*.,*'^`*.,*'^`*.,*'^`*.,*'^`*.,*'^`*.,*'^`*.,*' UU UU\n")) | |
(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. | |
'(helm-minibuffer-history-key "M-p") | |
'(warning-suppress-log-types '(emacs emacs emacs emacs))) | |
(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. | |
) | |
(put 'dired-find-alternate-file 'disabled nil) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment