-
-
Save amaurycatelan/1cdc92631817c572ec2777c0b81837f6 to your computer and use it in GitHub Desktop.
My personal Emacs config file
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
(setq custom-file (concat user-emacs-directory "auto-custom.el")) | |
(setq byte-compile-warnings '((not cl-functions))) | |
;(load custom-file 'noerror) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; set up and make sure packages are installed | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
(setq package-archives | |
'(("melpa" . "https://melpa.org/packages/") | |
("elpa" . "https://elpa.gnu.org/packages/") | |
("nongnu" . "https://elpa.nongnu.org/nongnu/"))) | |
(defvar grob/packages-refreshed nil) | |
(defmacro grob/ensure-package (package) | |
`(unless (package-installed-p ',package) | |
;; only refresh packages if we need to install one, and we haven't yet refreshed | |
(unless grob/packages-refreshed (package-refresh-contents) (setq grob/packages-refreshed t)) | |
(package-install ',package))) | |
;; make sure all the packages are installed | |
(package-initialize) | |
(grob/ensure-package evil) | |
(grob/ensure-package evil-collection) | |
(grob/ensure-package evil-org) | |
(grob/ensure-package magit) | |
(grob/ensure-package neotree) | |
(grob/ensure-package key-chord) | |
(grob/ensure-package company) | |
(grob/ensure-package undo-tree) | |
(grob/ensure-package origami) | |
(grob/ensure-package which-key) | |
(grob/ensure-package elgrep) | |
(grob/ensure-package good-scroll) | |
(grob/ensure-package paren-face) | |
(grob/ensure-package ligature) | |
(grob/ensure-package consult) | |
(grob/ensure-package eglot) | |
(grob/ensure-package monokai-theme) | |
;; language mode packages | |
(grob/ensure-package markdown-mode) | |
(grob/ensure-package julia-mode) | |
(grob/ensure-package lua-mode) | |
(grob/ensure-package glsl-mode) | |
(grob/ensure-package web-mode) | |
(grob/ensure-package powershell) | |
;; load the theme after all the settings have been set | |
(setq monokai-height-plus-1 0.999 | |
monokai-height-plus-2 0.999 | |
monokai-height-plus-3 0.999 | |
monokai-height-plus-4 0.999 | |
monokai-height-minus-1 0.999) | |
(load-theme 'monokai t) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; set font | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;;(set-frame-font "Unifont 12" nil t) | |
;;(set-frame-font "Hack Regular 9" nil t) | |
;;(set-frame-font "Cascadia Mono 9" nil t) | |
;;(set-frame-font "Consolas 9" nil t) | |
;;(set-frame-font "Source Code Pro 9" nil t) | |
;;(set-frame-font "Fira Code 9" nil t) | |
;;(set-frame-font "Jetbrains Mono-9" nil t) | |
(ignore-errors | |
(set-frame-font "Cascadia Code 9" nil t) | |
(set-frame-font "Berkeley Mono-9" nil t)) | |
(require 'ligature) | |
;; Enable the www ligature in every possible major mode | |
(ligature-set-ligatures 't '("www")) | |
;; Enable ligatures in programming modes, but not the star ones because i like my stars in a line | |
(ligature-set-ligatures 'prog-mode '("www" "*>" "\\\\" "\\\\\\" "{-" "::" "__" | |
":::" ":=" "!!" "-}" "----" "-->" "->" "->>" | |
"-<" "-<<" "-~" "#{" "#[" "#(" "#?" "#_" "#=" "=#" | |
"#_(" ".-" ".=" ".." "..<" "..." "?=" "??" | |
"/=" "/==" "/>" "//" "///" "&&" "||" "||=" "|=" "|>" "^=" "$>" | |
"++" "+++" "+>" "=:=" "==>" "=>" "=>>" "<=" ":>" "<:" | |
"=<<" "=/=" ">-" ">=" ">=>" ">>" ">>-" ">>=" ">>>" "<*" | |
"<*>" "<|" "<|>" "<$" "<$>" "<!--" "<-" "<--" "<->" "<+" | |
"<+>" "<=" "<==" "<=>" "<=<" "<>" "<<" "<<-" "<<=" "<<<" | |
"<~" "<~~" "</" "</>" "~@" "~-" "~>" "~~" "~~>" "%%")) | |
;; Eshell can have all the ligatures tho, it makes printouts more fun | |
(ligature-set-ligatures 'eshell-mode '("www" "**" "***" "**/" "*>" "*/" "\\\\" "\\\\\\" "{-" "::" | |
":::" ":=" "!!" "-}" "----" "-->" "->" "->>" "__" | |
"-<" "-<<" "-~" "#{" "#[" "#(" "#?" "#_" | |
"#_(" ".-" ".=" ".." "..<" "..." "?=" "??" | |
"/=" "/==" "/>" "//" "///" "&&" "||" "||=" "|=" "|>" "^=" "$>" | |
"++" "+++" "+>" "=:=" "==>" "=>" "=>>" "<=" | |
"=<<" "=/=" ">-" ">=" ">=>" ">>" ">>-" ">>=" ">>>" "<*" | |
"<*>" "<|" "<|>" "<$" "<$>" "<!--" "<-" "<--" "<->" "<+" | |
"<+>" "<=" "<==" "<=>" "<=<" "<>" "<<" "<<-" "<<=" "<<<" | |
"<~" "<~~" "</" "</>" "~@" "~-" "~>" "~~" "~~>" "%%")) | |
(global-ligature-mode t) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; my settings | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
(blink-cursor-mode -1) | |
(tool-bar-mode -1) | |
(menu-bar-mode -1) | |
(scroll-bar-mode -1) | |
(setq-default truncate-lines t | |
indent-tabs-mode nil | |
tab-width 4) | |
;; basic Emacs better defaults | |
(setq ring-bell-function 'ignore | |
make-backup-files nil | |
create-lockfiles nil | |
auto-save-default nil | |
initial-buffer-choice t | |
initial-scratch-message nil | |
frame-title-format '("" "%b - Emacs " emacs-version) | |
load-prefer-newer t ;; if a .el is newer than .elc, load it instead | |
read-buffer-completion-ignore-case t | |
recentf-auto-cleanup 'never) | |
;; org mode config | |
(org-babel-do-load-languages 'org-babel-load-languages '((lua . t))) | |
(setq org-agenda-include-diary t | |
org-cycle-separator-lines 1 | |
org-return-follows-link t | |
my-trusted-languages '("lua" "elisp") | |
org-adapt-indentation t | |
org-confirm-babel-evaluate #'(lambda (lang body) (not (member lang my-trusted-languages))) | |
completion-styles '(flex partial-completion) ;'(basic partial-completion emacs22) | |
sentence-end-double-space nil | |
org-link-frame-setup '((vm . vm-visit-folder-other-frame) | |
(vm-imap . vm-visit-imap-folder-other-frame) | |
(gnus . org-gnus-no-new-news) | |
(file . find-file) ;; so that following links happens in the same window | |
(wl . wl-other-frame))) | |
;; web mode config | |
(setq web-mode-enable-auto-quoting nil | |
web-mode-code-indent-offset 2 | |
web-mode-markup-indent-offset 2 | |
web-mode-css-indent-offset 2 | |
web-mode-content-types-alist '(("jsx" . "\\.js[x]?\\'"))) ;; render js as jsx | |
(add-to-list 'auto-mode-alist '("\\.js\\'" . web-mode)) | |
(add-to-list 'auto-mode-alist '("\\.json\\'" . web-mode)) | |
(add-to-list 'auto-mode-alist '("\\.jsx\\'" . web-mode)) | |
(add-to-list 'auto-mode-alist '("\\.ts\\'" . web-mode)) | |
(add-to-list 'auto-mode-alist '("\\.tsx\\'" . web-mode)) | |
(add-to-list 'auto-mode-alist '("\\.css\\'" . web-mode)) | |
(add-to-list 'auto-mode-alist '("\\.html\\'" . web-mode)) | |
(add-to-list 'auto-mode-alist '("\\.ejs\\'" . web-mode)) | |
(add-to-list 'auto-mode-alist '("\\.cjs\\'" . web-mode)) | |
(add-to-list 'auto-mode-alist '("\\.mjs\\'" . web-mode)) | |
(require 'dired) | |
(put 'dired-find-alternate-file 'disabled nil) ;; enable "a" in dired without the use of custom file | |
(setq dired-kill-when-opening-new-dired-buffer t) | |
;(define-key dired-mode-map (kbd "<mouse-1>") 'dired-find-alternate-file) | |
;(define-key dired-mode-map (kbd "<mouse-2>") 'dired-find-alternate-file) | |
;(define-key dired-mode-map (kbd "<normal-state> <mouse-2>") 'dired-find-alternate-file) | |
;(define-key dired-mode-map [mouse-2] 'dired-mouse-find-file) | |
;(define-key dired-mode-map [normal-state mouse-2] 'dired-mouse-find-file) | |
(setq tab-bar-close-button-show nil | |
tab-bar-new-button-show nil) | |
(put 'narrow-to-region 'disabled nil) | |
(require 'ediff) | |
(setq diff-command "c:/Program Files/Git/usr/bin/diff.exe") | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; enable global modes and hooks | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
(setq show-paren-when-point-inside-paren t | |
show-paren-delay 0) | |
(show-paren-mode 1) | |
(good-scroll-mode 1) | |
(icomplete-mode 1) ;; Move around with C-. and C-, select with C-j | |
(icomplete-vertical-mode 1) ;; Better way of viewing icomplete mode | |
(which-key-mode) | |
;(projectile-mode 1) | |
(global-so-long-mode 1) ;; so that long lines don't slow emacs down too much | |
(global-origami-mode 1) ;; to enable folding in all buffers | |
(global-company-mode 1) | |
(global-paren-face-mode 1) | |
(setq undo-tree-auto-save-history nil) | |
(global-undo-tree-mode 1) | |
;(marginalia-mode 1) | |
;(add-hook 'emacs-lisp-mode-hook 'rainbow-delimiters-mode) | |
;(add-hook 'lisp-interaction-mode 'rainbow-delimiters-mode) | |
(add-hook 'kill-buffer-query-functions #'(lambda () (not (equal (buffer-name (current-buffer)) "*scratch*")))) | |
(add-hook 'diary-list-entries-hook 'diary-include-other-diary-files) | |
(add-hook 'diary-mark-entries-hook 'diary-mark-included-diary-files) | |
(add-hook 'prog-mode-hook #'(lambda () (setq show-trailing-whitespace t))) | |
(add-hook 'org-mode-hook #'(lambda () (setq show-trailing-whitespace t))) | |
(add-hook 'org-mode-hook 'evil-org-mode) | |
(add-hook 'emacs-startup-hook (lambda () (message "Emacs loaded in %s" (emacs-init-time)))) | |
;(require 'projectile) | |
;(add-to-list 'projectile-globally-ignored-directories "node_modules") | |
(require 'eglot) | |
(add-to-list 'eglot-server-programs '(web-mode "typescript-language-server" "--stdio")) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; evil mode setup | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; turn on and enable evil mode | |
(setq evil-want-keybinding nil | |
evil-want-integration t | |
evil-collection-setup-minibuffer t) | |
(evil-mode 1) | |
(turn-on-evil-mode) | |
(require 'evil-collection) | |
(delete 'lua-mode evil-collection-mode-list) | |
(delete 'eglot evil-collection-mode-list) | |
(evil-collection-init) ;; make everything use basic vim movement | |
(evil-set-undo-system 'undo-tree) | |
(evil-set-leader 'normal (kbd "<SPC>")) | |
(key-chord-mode 1) | |
(defun grob/named-eshell (name) | |
"Make an eshell-mode buffer with a custom name in this directory." | |
(interactive "sName of new eshell buffer: ") | |
(get-buffer-create (concat "*" name "-eshell*")) | |
(set-buffer (concat "*" name "-eshell*")) | |
(eshell-mode) | |
(switch-to-buffer (concat "*" name "-eshell*"))) | |
(defun grob/named-powershell (name) | |
"Make an powershell buffer with a custom name in this directory." | |
(interactive "sName of new powershell buffer: ") | |
(make-comint (concat name "-powershell") "powershell") | |
(switch-to-buffer (concat "*" name "-powershell*"))) | |
(defun grob/copy-directory () | |
"Copies the path of the current buffer to system clipboard" | |
(interactive) | |
(gui-select-text default-directory) | |
(message (concat "Copied directory \"" default-directory "\" to system clipboard!"))) | |
(defun grob/copy-file-path () | |
"Copies the path of the current buffer to system clipboard" | |
(interactive) | |
(gui-select-text buffer-file-name) | |
(message (concat "Copied file path \"" buffer-file-name "\" to system clipboard!"))) | |
(defun grob/open-neotree-and-fit () | |
(interactive) | |
(setq neo-window-width (min 40 (round (/ (frame-width) 5)))) | |
(setq neo-theme 'ascii) | |
(setq grob/project-root default-directory) | |
(neotree-dir default-directory)) | |
(defun grob/create-tab (&optional name) | |
(interactive "sTab name? ") | |
(tab-bar-mode 1) | |
(tab-bar-new-tab) | |
(when name (tab-bar-rename-tab name))) | |
(defun grob/delete-tab () | |
(interactive) | |
(tab-bar-mode 1) | |
(tab-bar-close-tab) | |
(when (= (length (funcall tab-bar-tabs-function)) 1) | |
(tab-bar-mode -1))) | |
(defun grob/hide-dos-eol () | |
"Do not show ^M in files containing mixed UNIX and DOS line endings." | |
(interactive) | |
(setq buffer-display-table (make-display-table)) | |
(aset buffer-display-table ?\^M [])) | |
(defun grob/web-mode-eglot () | |
"Enable eglot for web mode." | |
(interactive) | |
(call-interactively 'eglot t (vector "npx typescript-language-server --stdio"))) | |
(defun grob/org-to-html () | |
(interactive) | |
(let ((output-file-name (concat (substring buffer-file-name 0 -4) ".html"))) | |
(eshell-command (concat "pandoc \"" buffer-file-name "\" -o \"" output-file-name "\"")) | |
(browse-url-of-file output-file-name))) | |
(defun grob/open-containing-folder () | |
(interactive) | |
(browse-url (expand-file-name default-directory))) | |
(defun grob/close-emacs-question () | |
(interactive) | |
(when (y-or-n-p "Close Emacs?") (save-buffers-kill-emacs))) | |
(defun grob/open-project-folder () | |
(interactive) | |
(browse-url (project-root (project-current t)))) | |
(defvar grob/highlighted-word nil) | |
(defun grob/highlight-word () | |
"Highlight the word under point" | |
(interactive) | |
(when grob/highlighted-word | |
(unhighlight-regexp grob/highlighted-word)) | |
(highlight-phrase (current-word) 'match) | |
(setq grob/highlighted-word (current-word))) | |
(defun grob/unhighlight-word () | |
"Unhighlight the word highlighted by grob/highlight-word" | |
(interactive) | |
(if grob/highlighted-word | |
(progn | |
(unhighlight-regexp grob/highlighted-word) | |
(setq grob/highlighted-word nil)) | |
(message "No word currently highlighted!"))) | |
(defun grob/open-init-file () | |
(interactive) | |
(find-file "~/.emacs.d/init.el")) | |
(defun grob/open-local-init-file () | |
(interactive) | |
(find-file "~/.emacs.d/local-config.el")) | |
(defun grob/conditional-build-haxe () | |
(interactive) | |
(when (and (eq major-mode 'haxe-mode) (get-buffer "*haxe-eshell*")) | |
(grob/build-haxe))) | |
(defun grob/build-haxe () | |
(interactive) | |
(set-buffer "*haxe-eshell*") | |
(goto-char (point-max)) | |
(insert "haxe build.hxml") | |
(eshell-send-input)) | |
(defun grob/reset-color-code () | |
(interactive) | |
(end-of-buffer) | |
(insert "echo -e \"\033[m\"") | |
(comint-send-input nil t)) | |
(defun grob/occur-word-at-point () | |
(interactive) | |
(let ((word (thing-at-point 'word t))) | |
(if (> (length word) 0) | |
(occur word) | |
(message "No word at point!")))) | |
;; for when i accidentally do :W instead of :w | |
(evil-ex-define-cmd "W[RITE]" 'evil-write) | |
(evil-ex-define-cmd "Fu[llscreen]" 'toggle-frame-maximized) | |
(add-hook 'after-save-hook 'grob/conditional-build-haxe) | |
(global-set-key (kbd "C-c t n") 'grob/create-tab) | |
(global-set-key (kbd "C-c t d") 'grob/delete-tab) | |
(global-set-key (kbd "C-c f o") 'grob/open-containing-folder) | |
(global-set-key (kbd "C-c f p") 'grob/open-project-folder) | |
(global-set-key (kbd "C-c n") 'grob/open-neotree-and-fit) | |
(global-set-key (kbd "C-c d") 'grob/copy-directory) | |
(global-set-key (kbd "C-c e") nil) | |
(global-set-key (kbd "C-c e s") 'grob/named-eshell) | |
(global-set-key (kbd "C-c p s") 'grob/named-powershell) | |
(global-set-key (kbd "C-c e e") 'grob/open-init-file) | |
(global-set-key (kbd "C-c e l") 'grob/open-local-init-file) | |
(global-set-key (kbd "C-c o h") 'grob/org-to-html) | |
(global-set-key (kbd "C-x C-k") 'kill-buffer) | |
(global-set-key (kbd "C-x C-c") 'grob/close-emacs-question) | |
(global-set-key (kbd "C-c g g") 'vc-git-grep) | |
(global-set-key (kbd "C-c i m") 'consult-imenu) | |
(global-set-key (kbd "C-S-u") 'universal-argument) | |
(global-set-key (kbd "C-<tab>") 'tab-bar-switch-to-next-tab) | |
(global-set-key (kbd "C-S-<tab>") 'tab-bar-switch-to-prev-tab) | |
(global-set-key (kbd "C-c h h") 'grob/highlight-word) | |
(global-set-key (kbd "C-c h n") 'grob/unhighlight-word) | |
(global-set-key [down-mouse-2] 'mouse-set-point) | |
(global-set-key [mouse-2] 'mouse-set-point) | |
(global-set-key [down-mouse-3] | |
`(menu-item ,(purecopy "Menu Bar") ignore | |
:filter (lambda (_) | |
(if (zerop (or (frame-parameter nil 'menu-bar-lines) 0)) | |
(mouse-menu-bar-map) | |
(mouse-menu-major-mode-map))))) | |
(define-key evil-normal-state-map (kbd "<leader> hh") 'grob/highlight-word) | |
(define-key evil-normal-state-map (kbd "<leader> hn") 'grob/unhighlight-word) ;; C-x w r to unhighlight word | |
;(define-key icomplete-minibuffer-map (kbd "C-n") 'icomplete-forward-completions) | |
;(define-key icomplete-minibuffer-map (kbd "C-p") 'icomplete-backward-completions) | |
(key-chord-define evil-insert-state-map "jk" 'evil-normal-state) | |
(key-chord-define evil-insert-state-map "JK" 'evil-normal-state) | |
(key-chord-define evil-insert-state-map "jK" 'evil-normal-state) | |
(key-chord-define evil-insert-state-map "Jk" 'evil-normal-state) | |
(define-key evil-normal-state-map (kbd "J") #'(lambda () (interactive) (evil-next-line 20))) | |
(define-key evil-normal-state-map (kbd "K") #'(lambda () (interactive) (evil-previous-line 20))) | |
(define-key evil-visual-state-map (kbd "J") #'(lambda () (interactive) (evil-next-line 20))) | |
(define-key evil-visual-state-map (kbd "K") #'(lambda () (interactive) (evil-previous-line 20))) | |
(define-key evil-normal-state-map (kbd "C-u") 'evil-scroll-up) | |
(define-key evil-normal-state-map (kbd "C-w C-h") 'evil-window-left) | |
(define-key evil-normal-state-map (kbd "C-w C-j") 'evil-window-down) | |
(define-key evil-normal-state-map (kbd "C-w C-k") 'evil-window-up) | |
(define-key evil-normal-state-map (kbd "C-w C-l") 'evil-window-right) | |
(define-key evil-normal-state-map (kbd "C-x C-b") 'ibuffer) | |
(define-key evil-normal-state-map (kbd "C-s") 'grob/occur-word-at-point) | |
(define-key evil-motion-state-map (kbd "RET") nil) ;; make RET actually work | |
(define-key evil-normal-state-map (kbd "C-j") 'evil-join) | |
(define-key evil-insert-state-map (kbd "C-n") 'company-complete) | |
(define-key evil-insert-state-map (kbd "C-p") | |
#'(lambda () | |
(interactive) | |
(company-complete) | |
(company-select-last))) | |
(define-key dired-mode-map (kbd "<normal-state> <mouse-2>") 'dired-mouse-find-file) | |
(define-key dired-mode-map (kbd "<mouse-2>") 'dired-find-alternate-file) | |
(define-key dired-mode-map [mouse-2] 'dired-find-alternate-file) | |
(define-key dired-mode-map [normal-state mouse-2] 'dired-find-alternate-file) | |
;; fix for clicking without dragging to sometimes go into visual mode | |
;(define-key evil-motion-state-map (kbd "<down-mouse-1>") 'mouse-set-point) | |
(load (concat user-emacs-directory "local-config.el") 'noerror) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment