Skip to content

Instantly share code, notes, and snippets.

@hacknightly
Last active November 14, 2024 17:03
Show Gist options
  • Save hacknightly/ba0d0fea0ebbfb07c42ea991ba62f200 to your computer and use it in GitHub Desktop.
Save hacknightly/ba0d0fea0ebbfb07c42ea991ba62f200 to your computer and use it in GitHub Desktop.
;; emacs housekeeping
(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
(global-auto-revert-mode 1)
(set-fringe-mode 0)
(setq warning-minimum-level :emergency)
;; pixel scroll
(setq pixel-scroll-precision-mode 1)
;; don't create lock files
(setq create-lockfiles nil)
; delete excess backup versions silently
(setq delete-old-versions -1)
; use version control
(setq version-control t)
; make backups file even when in version controlled dir
(setq vc-make-backup-files t)
; which directory to put backups file
(setq backup-directory-alist `(("." . "~/.emacs.d/backups")))
; don't ask for confirmation when opening symlinked file
(setq vc-follow-symlinks t)
; transform backups file name
(setq auto-save-file-name-transforms '((".*" "~/.emacs.d/auto-save-list/" t)))
; inhibit useless and old-school startup screen
(setq inhibit-startup-screen t)
; silent bell when you make a mistake
(setq ring-bell-function 'ignore)
; use utf-8 by default
(setq coding-system-for-read 'utf-8)
(setq coding-system-for-write 'utf-8)
; sentence SHOULD end with only a point.
(setq sentence-end-double-space nil)
; toggle wrapping text at the 80th character
(setq default-fill-column 80)
; Open to inbox file
(defun goto-inbox-file ()
"Open the inbox file."
(interactive)
(find-file "~/Sync/darrellbanks.com/org/inbox.org"))
(defun goto-projects-file ()
"Open the projects file."
(interactive)
(find-file "~/Sync/darrellbanks.com/org/projects.org"))
;; package management
(require 'package)
(setq package-enable-at-startup nil)
(package-initialize)
(setq package-archives '(("org" . "http://orgmode.org/elpa/")
("gnu" . "http://elpa.gnu.org/packages/")
("melpa" . "https://melpa.org/packages/")))
(use-package quelpa :ensure t)
(use-package quelpa-use-package :ensure t)
;; eglot
(add-hook 'web-mode-hook 'eglot-ensure)
(add-hook 'jtsx-typescript-mode-hook 'eglot-ensure)
(add-hook 'jtsx-tsx-mode-hook 'eglot-ensure)
(add-hook 'js-ts-mode-hook 'eglot-ensure)
(add-hook 'css-ts-mode-hook 'eglot-ensure)
;; completion
(use-package nerd-icons :ensure t)
(use-package nerd-icons-corfu
:ensure t
:after corfu
:config
(add-to-list 'corfu-margin-formatters #'nerd-icons-corfu-formatter))
(use-package corfu
:ensure t
:config
(setq
eglot-events-buffer-size 0
corfu-auto t
corfu-auto-delay 0.1
corfu-auto-prefix 1
corfu-cycle t
corfu-quit-at-boundary t
corfu-quit-no-match t
corfu-preview-current nil
corfu-max-width 100
completion-styles '(basic)
corfu-on-exact-match nil)
:init
(global-corfu-mode))
;; path management
(use-package exec-path-from-shell
:ensure t)
(when (memq window-system '(mac ns x))
(exec-path-from-shell-initialize))
;; dashboard
(use-package dashboard
:ensure t
:config
(dashboard-setup-startup-hook))
;; shell / vterm
(use-package vterm :ensure t
:init
(setq vterm-shell "zsh"))
(use-package multi-vterm :ensure t)
(defun goto-init-file ()
"Open the init file."
(interactive)
(find-file user-init-file))
;; magit
(use-package magit :ensure t)
;; org-mode
(use-package org-remark
:ensure t
:hook (after-init . org-remark-global-tracking-mode))
(use-package org-pomodoro
:ensure t
:config
(setq org-pomodoro-length 25
org-pomodoro-short-break-length 5
org-pomodoro-long-break-length 15)
:commands (org-pomodoro))
(use-package org-roam
:ensure t
:init
(setq org-roam-directory "~/Sync/darrellbanks.com/org/notes")
(setq org-link-file-path-type 'absolute)
:config
(org-roam-db-autosync-mode))
(use-package org-roam-ui
:ensure t
:config
(setq org-roam-ui-sync-theme t
org-roam-ui-follow t
org-roam-ui-update-on-save t
org-roam-ui-open-on-start t))
(define-skeleton babel-skeleton
"Header info for a emacs-org file."
"#+TITLE:" str " \n"
"#+AUTHOR: Darrell Banks\n"
"#+email: howdy@changeset.io\n"
"#+INFOJS_OPT: \n"
"#+BABEL: :session *js* :session *python* :cache yes :results output graphics :exports both :tangle yes \n"
"-----"
)
(org-babel-do-load-languages
'org-babel-load-languages
'((shell . t)
(js . t)
(python . t)))
(use-package org
:config
(setq
;; Basic Settings
org-startup-indented t
org-return-follows-link t
org-confirm-babel-evaluate nil
org-agenda-files '("~/Sync/darrellbanks.com/org")
org-outline-path-complete-in-steps nil
org-refile-use-outline-path nil
org-todo-keyword-faces '(("NOTE" . "#ffb951") ("ACHIEVEMENT" . "#32a852"))
org-todo-keywords
'((sequence "TODO(t)" "NEXT(n)" "IN-PROGRESS(i!)" "WAITING(w!)" "|" "DONE(d!)" "CANCELED(c!)" "DELEGATED(p!)"))
org-refile-targets '(("~/Sync/darrellbanks.com/org/projects.org" :maxlevel . 3)
("~/Sync/darrellbanks.com/org/someday.org" :maxlevel . 1)
("~/Sync/darrellbanks.com/org/nudge.org" :maxlevel . 1)
("~/Sync/darrellbanks.com/org/repeat.org" :maxlevel . 1)
)
org-refile-use-outline-path 'file
;; Edit settings
org-auto-align-tags nil
org-tags-column 0
org-catch-invisible-edits 'show-and-error
org-special-ctrl-a/e t
org-insert-heading-respect-content t
;; Org styling, hide markup etc.
org-hide-emphasis-markers t
org-pretty-entities t
org-ellipsis "…"
;; Pomodoro Settings
org-pomodoro-start-sound "~/Sync/chime.wav"
org-pomodoro-finished-sound "~/Sync/chime.wav"
org-pomodoro-short-break-sound "~/Sync/chime.wav"
org-pomodoro-long-break-sound "~/Sync/chime.wav"
;; Templates
org-capture-bookmark nil
org-capture-templates
'(
("t" "Inbox" entry (file "~/Sync/darrellbanks.com/org/inbox.org")
"* TODO %?\nAdded: %U")
("p" "Project" entry (file "~/Sync/darrellbanks.com/org/projects.org")
"* %? [%] :project: \n:PROPERTIES: \n:TRIGGER: next-sibling todo!(NEXT) scheduled!(copy)\n:ORDERED: t:END:\n** TODO Add entry\nAdded: %U")
(">" "Nudge" entry (file "~/Sync/darrellbanks.com/org/nudge.org")
"* TODO %? \nSCHEDULED: %^{Schedule}t\n:END:\nAdded: %U")
("n" "Note" entry (file "~/Sync/darrellbanks.com/org/inbox.org")
"* Note %?\nAdded: %U")
)
;; Agenda styling
org-agenda-tags-column 0
org-agenda-block-separator ?─
org-agenda-time-grid
'((daily today require-timed)
(800 1000 1200 1400 1600 1800 2000)
" ┄┄┄┄┄ " "┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄")
org-agenda-current-time-string
"◀── now ─────────────────────────────────────────────────"))
;; Hugo
(use-package ox-hugo :ensure t)
(setq org-hugo-base-dir "~/Sync/darrellbanks.com"
time-stamp-active t
time-stamp-start "#\\+lastmod:[ \t]*"
time-stamp-end "$"
time-stamp-format "%04Y-%02m-%02d")
(add-hook 'before-save-hook 'time-stamp nil)
;; Visual settings
;; - mode line
(use-package doom-modeline
:ensure t
:hook (after-init . doom-modeline-mode)
:init
(set-face-attribute 'mode-line-buffer-id nil :foreground "burlywood3")
(setq doom-modeline-height 50))
;; - org mode
(use-package org-modern :ensure t)
(with-eval-after-load 'org (global-org-modern-mode))
(with-eval-after-load 'org (auto-fill-mode))
(set-face-attribute 'org-modern-symbol nil :family "Iosevka")
(add-hook 'org-mode-hook 'auto-fill-mode)
(add-hook 'org-mode-hook 'display-fill-column-indicator-mode)
;; - font
(set-face-attribute 'default nil :font "MonoLisa" :height 180)
;; - emojis
(use-package emojify
:ensure t
:hook (after-init . global-emojify-mode)
:config
(setq emojify-emoji-styles '(unicode github)))
;; - icons
(use-package all-the-icons :ensure t)
(use-package all-the-icons-dired :ensure t)
;; - indents
(use-package indent-guide
:ensure t
:load-path "~/ThirdParty/indent-guide"
:hook (after-init . indent-guide-global-mode))
(setq-default indent-tabs-mode nil)
(setq-default tab-width 2)
(setq indent-line-function 'insert-space)
;; - themes
(setq custom-safe-themes t)
(use-package color-theme-modern
:ensure t
:config
(load-theme 'cobalt t))
;; use-package
(unless (package-installed-p 'use-package) ; unless it is already installed
(package-refresh-contents) ; update packages archive
(package-install 'use-package)) ; and install the most recent version of use-package
;; projectile
(use-package projectile :ensure t
:config
(projectile-global-mode)
(setq projectile-globally-ignored-directories '("dist"))
(setq projectile-indexing-method 'hybrid))
;; Editing
;; - brackets
(electric-pair-mode 1)
;; - folding
(use-package origami :ensure t
:config
(global-origami-mode))
;; - tag highlighting
;; Copilot
(use-package copilot
:ensure t
:quelpa (copilot :fetcher github
:repo "copilot-emacs/copilot.el"
:branch "main"
:files ("*.el"))
:init
(global-copilot-mode)
(define-key copilot-completion-map (kbd "<backtab>") 'copilot-accept-completion))
;; LLMS
(exec-path-from-shell-copy-env "OPENAI_API_KEY")
(use-package gptel :ensure t
:config
(setq gptel-api-key (getenv "OPENAI_API_KEY"))
(gptel-make-ollama "Ollama"
:host "localhost:11434"
:stream t
:models '("llama2:latest")))
;; Languages
;; tree sitter
(use-package treesit-auto
:ensure t
:custom
(treesit-auto-install t)
:config
(treesit-auto-add-to-auto-mode-alist 'all)
(global-treesit-auto-mode))
;; TS / TSX
(use-package jtsx
:ensure t
:mode (("\\.jsx?\\'" . jtsx-jsx-mode)
("\\.tsx\\'" . jtsx-tsx-mode)
("\\.js\\'" . js-ts-mode)
("\\.cjs\\'" . js-ts-mode)
("\\.ts\\'" . jtsx-typescript-mode))
:commands jtsx-install-treesit-language
:hook ((jtsx-jsx-mode . hs-minor-mode)
(jtsx-tsx-mode . hs-minor-mode)
(jtsx-typescript-mode . hs-minor-mode)))
;; PlantUML
(use-package plantuml-mode :ensure t
:mode (("\\.plantuml$" . plantuml-mode)))
(setq plantuml-executable-path "/opt/homebrew/bin/plantuml")
(setq plantuml-default-exec-mode 'executable)
;; Markdown
(use-package markdown-mode :ensure t)
;; Yasnippet
(use-package yasnippet :ensure t)
(require 'yasnippet)
(yas-global-mode 1)
;; - web
(use-package web-mode :ensure t
:mode (("\\.html$" . web-mode)
("\\.svelte$" . web-mode)))
(use-package emmet-mode :ensure t
:init
(add-hook 'tsx-ts-mode-hook 'emmet-mode))
;; rust
(use-package rust-mode :ensure t
:mode (("\\.rs$" . rust-mode)
))
;; cucumber
(use-package feature-mode :ensure t
:mode (("\\.feature$" . feature-mode)))
;; - prettier
(use-package prettier-js :ensure t
:init
(add-hook 'typescript-ts-mode-hook 'prettier-js-mode)
(add-hook 'tsx-ts-mode-hook 'prettier-js-mode)
(add-hook 'js-ts-mode 'prettier-js-mode)
(add-hook 'js-mode-hook 'prettier-js-mode)
(add-hook 'svelte-mode-hook 'prettier-js-mode)
(add-hook 'web-mode-hook 'prettier-js-mode)
(add-hook 'css-ts-mode-hook 'prettier-js-mode))
;; flycheck
(use-package flycheck :ensure t)
;; dired
(require 'ls-lisp)
(setq ls-lisp-dirs-first t)
(setq ls-lisp-use-insert-directory-program nil)
;; treemacs
(use-package treemacs :ensure t)
(use-package treemacs-evil :ensure t)
(use-package treemacs-projectile :ensure t)
(use-package treemacs-all-the-icons :ensure t)
;; evil-mc
(use-package evil-mc
:ensure t
:config
(global-evil-mc-mode 1))
;; ivy
(use-package ivy
:ensure t
:custom
(ivy-use-selectable-prompt t)
(ivy-count-format "(%d/%d) ")
(ivy-use-virtual-buffers t)
:config
(ivy-mode))
(use-package ivy-rich
:ensure t
:after ivy
:custom
(ivy-virtual-abbreviate 'full
ivy-rich-switch-buffer-align-virtual-buffer t
ivy-rich-path-style 'abbrev))
(use-package all-the-icons-ivy
:ensure t
:init (add-hook 'after-init-hook 'all-the-icons-ivy-setup))
(use-package counsel
:after ivy
:ensure t
:config
(counsel-mode))
(use-package counsel-projectile :ensure t)
;; movement
(use-package smex :ensure t)
(use-package avy :ensure t)
(use-package wgrep :ensure t)
(use-package swiper :ensure t)
(use-package imenu-list :ensure t
:init
(setq imenu-list-auto-resize t)
(setq imenu-list-focus-after-activation t))
;; Evil Mode
(use-package evil
:ensure t
:config
(evil-set-undo-system 'undo-redo)
(evil-mode))
;; Key Bindings
(use-package which-key :ensure t)
(which-key-mode)
(use-package general :ensure t
:config
(general-evil-setup t)
;; dired keys
(general-define-key
:states '(normal visual)
:keymaps 'dired-mode-map
"N" 'find-file)
;; web keys
(general-define-key
:states '(insert)
:keymaps 'web-mode-map
"TAB" 'emmet-expand-line)
;; xref keys
(general-define-key
:states '(normal)
:keymaps 'xref--xref-buffer-mode-map
"TAB" 'xref-goto-xref)
;; llm keys
(general-define-key
:states '(normal visual)
:prefix ","
:keymaps 'markdown-mode-map
"RET" 'gptel-send)
;; org keys
(general-define-key
:states '(normal visual)
:keymaps 'org-mode-map
"t" 'org-todo
"." 'org-time-stamp
"-" 'org-ctrl-c-minus
"+" 'org-ctrl-c-ctrl-c
"*" 'org-ctrl-c-star
"^" 'org-sort
"{" 'org-edit-src-code
"|" 'org-table-create-or-convert-from-region
"RET" 'org-open-at-point
"TAB" 'org-cycle)
(general-define-key
:states '(normal)
:prefix ","
:keymaps 'org-mode-map
"<backtab>" 'org-promote-subtree
"," "C-c C-c"
"/" 'org-sparse-tree
"b" '(:ignore t :which-key "Babel")
"bi" 'org-insert-structure-template
"bx" 'org-babel-execute-src-block
"bh" 'org-babel-insert-header-arg
"bn" 'org-babel-next-src-block
"bp" 'org-babel-previous-src-block
"bs" 'babel-skeleton
"c" '(:ignore t :which-key "Clocks")
"ci" 'org-clock-in
"co" 'org-clock-out
"cs" 'org-schedule
"cd" 'org-deadline
"cp" 'org-pomodoro
"t" 'org-set-tags-command
"o" 'org-occur
"r" 'org-refile
"A" 'org-archive-subtree
"il" 'org-insert-link
"RET" 'org-meta-return
"TAB" 'org-demote-subtree
)
;; eglot keys
(general-define-key
:states '(normal visual)
:prefix ","
"d" 'eglot-find-typeDefinition
"i" 'eglot-find-implementation
"R" 'eglot-reconnect)
;; llm keys
(general-define-key
:states '(normal visual)
:prefix ","
:keymaps 'markdown-mode-map
"RET" 'gptel-send)
;; application keys
(general-override-mode)
(general-define-key
:states '(normal visual insert emacs treemacs)
:prefix "SPC"
:keymaps 'override
:non-normal-prefix "C-SPC"
;; M-x
"SPC" '(smex :which-key "M-x")
"M" '(smex-major-mode-commands :which-key "M-x major")
;; Applications
"a" '(:ignore t :which-key "Applications")
"ad" '(dired :which-key "Dired")
"ae" '(:ignore t :which-key "Eldoc")
"aed" '(eldoc-doc-buffer :which-key "Doc Buffer")
"ai" '(:ignore t :which-key "AI")
"ai>" '(gptel-send :which-key "Send Line")
"aig" '(gptel :which-key "GPT Buffer")
"aim" '(gptel-menu :which-key "GPT Menu")
"ao" '(:ignore t :which-key "Org")
"aoa" '(org-agenda :which-key "Agenda")
"aoc" '(org-capture :which-key "Capture")
"ao>" '(org-goto-calendar :which-key "Go To Calendar")
"aot" '(org-tags-view :which-key "Tags View")
"aop" '(org-pomodoro :which-key "Pomodoro")
"aor" '(:ignore t :which-key "Org Roam")
"aori" '(org-roam-node-insert :which-key "Insert Node")
"aorf" '(org-roam-node-find :which-key "Find Node")
"aoru" '(org-roam-ui-open :which-key "Open UI")
"aos" '(org-edit-src-exit :which-key "Exit Src Edit")
"ag" '(:ignore t :which-key "Magit")
"agb" '(magit-blame :which-key "Magit Blame")
"agc" '(magit-branch-checkout :which-key "Magit Branch Checkout")
"ag," '(magit-commit :which-key "Magit Commit")
"agn" '(magit-branch-create :which-key "Magit Branch Create")
"ag>" '(magit-push :which-key "Magit Push")
"ag<" '(magit-pull :which-key "Magit Pull")
"ags" '(magit-status :which-key "Magit Status")
"at" '(:ignore t :which-key "Treemacs")
"atd" '(treemacs-select-directory :which-key "Treemacs Select Directory")
"av" '(:ignore t :which-key "VTerm")
"avn" '(multi-vterm :which-key "New Terminal")
"av>" '(multi-vterm-next :which-key "Next Terminal")
"av<" '(multi-vterm-previous :which-key "Previous Terminal")
;; Buffers
"b" '(:ignore t :which-key "Buffers")
"bl" '(list-buffers :which-key "List Buffers")
"bb" '(switch-to-buffer :which-key "Switch Buffer")
"bd" '(kill-this-buffer :which-key "Kill Buffer")
"bp" '(previous-buffer :which-key "Previous Buffer")
"bn" '(next-buffer :which-key "Next Buffer")
"bs" '(scratch-buffer :which-key "Scratch Buffer")
"br" '(rename-buffer :which-key "Rename Buffer")
;; Toggles
"t" '(:ignore t :which-key "Toggles")
"tl" '(display-line-numbers-mode :which-key "Line Numbers")
"ti" '(imenu-list-smart-toggle :which-key "IMenu List")
"t/" '(comment-or-uncomment-region :which-key "Comment Region")
;; Avy
"j" '(:ignore t :which-key "Jump To")
"jl" '(avy-goto-line :which-key "Jump To Line (avy)")
"jw" '(avy-goto-word-1 :which-key "Jump To Worg (avy)")
;; Counsel
"/" '(counsel-rg :which-key "Search in project")
"p" '(:ignore t :which-key "Projectile")
"pp" '(counsel-projectile-switch-project :which-key "Switch Project (projectile)")
"pf" '(counsel-projectile-find-file :which-key "Find Files In Project (projectile)")
;; Files
"f" '(:ignore t :which-key "Files")
"fed" '(goto-init-file :which-key "Go to init file")
"fei" '(goto-inbox-file :which-key "Go to inbox file")
"fep" '(goto-projects-file :which-key "Go to projects file")
"ft" '(treemacs :which-key "Treemacs")
;; Windows
"w" '(:ignore t :which-key "Windows")
"wd" '(delete-window :which-key "Delete Window")
"w/" '(split-window-right :which-key "Split Window Right")
"w-" '(split-window-below :which-key "Split Window Below")
"wh" '(windmove-left :which-key "Move to Window on Left")
"wl" '(windmove-right :which-key "Move to Window on Right")
"wj" '(windmove-down :which-key "Move to Window Below")
"wk" '(windmove-up :which-key "Move to Window Above")
;; Emacs
"q" '(:ignore t :which-key "Quit")
"qr" '(restart-emacs :which-key "Restart Emacs")
;; Images
"i" '(:ignore t :which-key "Images")
"ii" '(image-increase-size :which-key "Increase Size")
))
(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 nil)
'(package-selected-packages
'(general which-key imenu-list wgrep counsel-projectile all-the-icons-ivy ivy-rich evil-mc flycheck prettier-js rust-mode emmet-mode web-mode yasnippet markdown-mode plantuml-mode gptel editorconfig apropospriate-theme org-modern ox-hugo org-roam-ui org-pomodoro org-remark magit multi-vterm dashboard exec-path-from-shell)))
(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.
'(font-lock-comment-face ((t (:foreground "#5E656E"))))
'(font-lock-constant-face ((t (:foreground "#9752FF"))))
'(font-lock-function-name-face ((t (:foreground "bisque3"))))
'(font-lock-keyword-face ((t (:foreground "#0D9FA7"))))
'(font-lock-string-face ((t (:foreground "burlywood"))))
'(font-lock-type-face ((t (:foreground "thistle3")))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment