Skip to content

Instantly share code, notes, and snippets.

@roman2ing
Last active October 18, 2024 18:03
Show Gist options
  • Save roman2ing/c44552e1f3d2f464a62d7bd801c90d76 to your computer and use it in GitHub Desktop.
Save roman2ing/c44552e1f3d2f464a62d7bd801c90d76 to your computer and use it in GitHub Desktop.
;; Set package repositories
(require 'package)
(add-to-list 'package-archives '("gnu" . "https://elpa.gnu.org/packages/"))
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
(eval-when-compile
(require 'use-package)
(require 'use-package-ensure))
(setq use-package-always-ensure t)
;; Autoupdate packages
(use-package auto-package-update
:config
(setq auto-package-update-delete-old-versions t
auto-package-update-hide-results t)
(auto-package-update-maybe))
;; Better defaults
(use-package better-defaults)
;;;;;;;;;;;;;;;;
;; Appearance ;;
;;;;;;;;;;;;;;;;
;; Set font (Fira Code, 12pt)
(set-face-attribute 'default nil :family "Fira Code" :height 120)
;; (load-theme 'deeper-blue t) ;; Load theme
;; Font ligatures
;; (use-package fira-code-mode
;; :custom (fira-code-mode-disabled-ligatures '("[]" "x"))
;; :hook prog-mode)
(use-package ligature
:config
;; Enable the "www" ligature in every possible major mode
(ligature-set-ligatures 't '("www"))
;; Enable ligatures in programming modes
(ligature-set-ligatures 'prog-mode '("www" "**" "***" "**/" "*>" "*/" "\\\\" "\\\\\\" "{-" "::"
":::" ":=" "!!" "!=" "!==" "-}" "----" "-->" "->" "->>"
"-<" "-<<" "-~" "#{" "#[" "##" "###" "####" "#(" "#?" "#_"
"#_(" ".-" ".=" ".." "..<" "..." "?=" "??" ";;" "/*" "/**"
"/=" "/==" "/>" "//" "///" "&&" "||" "||=" "|=" "|>" "^=" "$>"
"++" "+++" "+>" "=:=" "==" "===" "==>" "=>" "=>>" "<="
"=<<" "=/=" ">-" ">=" ">=>" ">>" ">>-" ">>=" ">>>" "<*"
"<*>" "<|" "<|>" "<$" "<$>" "<!--" "<-" "<--" "<->" "<+"
"<+>" "<=" "<==" "<=>" "<=<" "<>" "<<" "<<-" "<<=" "<<<"
"<~" "<~~" "</" "</>" "~@" "~-" "~>" "~~" "~~>" "%%"))
(global-ligature-mode 't))
;;;;;;;;;;;;;;;;;
;; Convenience ;;
;;;;;;;;;;;;;;;;;
;; Sets up exec-path-from shell
;; https://github.com/purcell/exec-path-from-shell
(use-package exec-path-from-shell)
(when (memq window-system '(mac ns))
(exec-path-from-shell-initialize)
(exec-path-from-shell-copy-envs
'("PATH")))
;; Enable toggle-comment-on-line
(defun toggle-comment-on-line ()
"Comment or uncomment current line."
(interactive)
(comment-or-uncomment-region (line-beginning-position) (line-end-position)))
(global-set-key (kbd "C-;") 'toggle-comment-on-line)
;; Vim bindings
;; (use-package evil
;; :init
;; (evil-mode 1))
;; Changes all yes/no questions to y/n type
(fset 'yes-or-no-p 'y-or-n-p)
;; No need for lock files when editing
(setq create-lockfiles nil)
(setq inhibit-startup-message t) ;; Hide the startup message
;; Remember position in files
(save-place-mode 1)
;; Persist history over Emacs restarts. Vertico sorts by history position.
(use-package savehist
:config
(savehist-mode))
;; Remember last open files
(recentf-mode 1)
(setq recentf-max-menu-items 25
recentf-max-saved-items 25)
(global-set-key "\C-x\ \C-r" 'recentf-open-files)
;; Show line numbers in programs
;; (global-display-line-numbers-mode 1)
(add-hook 'prog-mode-hook #'display-line-numbers-mode)
;; Automatically pair parentheses
(electric-pair-mode t)
(use-package which-key
:config
(which-key-mode))
(use-package diminish)
;; Ivy, Swiper & Counsel
(use-package ivy
:diminish (ivy-mode . "")
:init (ivy-mode 1) ; globally at startup
:config
(setq ivy-use-virtual-buffers t)
(setq ivy-height 20)
(setq ivy-count-format "%d/%d "))
(use-package counsel :demand
:after ivy
:diminish (counsel-mode . "")
:config
(counsel-mode))
(use-package swiper
:after ivy
:bind (("C-s" . swiper)
("C-r" . swiper)))
;;;;;;;;;;;;;;;;;
;; Development ;;
;;;;;;;;;;;;;;;;;
(use-package markdown-mode
:mode ("README\\.md\\'" . gfm-mode)
:init (setq markdown-command "multimarkdown"))
;; popup completions
(use-package company
:diminish (company-mode . "")
:init (setq company-idle-delay 0)
:config (global-company-mode))
;; working with projects
(use-package projectile
:init
(projectile-mode +1)
:bind (:map projectile-mode-map
("s-p" . projectile-command-map))
:config
(setq projectile-project-root-files-bottom-up
(cons "go.mod"
projectile-project-root-files-bottom-up))
)
;; File tree browser
;; (use-package treemacs
;; :bind
;; (:map global-map
;; ("M-0" . treemacs-select-window)
;; ("C-x t 1" . treemacs-delete-other-windows)
;; ("C-x t t" . treemacs)
;; ("C-x t d" . treemacs-select-directory)
;; ("C-x t B" . treemacs-bookmark)
;; ("C-x t C-t" . treemacs-find-file)
;; ("C-x t M-t" . treemacs-find-tag)))
;; Automate Tree-sitter grammar installation and mode remapping
(use-package treesit-auto
:custom
(treesit-auto-install 'prompt)
:config
(treesit-auto-add-to-auto-mode-alist 'all)
(global-treesit-auto-mode))
;; LSP with eglot
(use-package eglot
;; :config (add-to-list 'eglot-server-programs
;; '(python-mode . ("pylance" "--stdio")))
:hook (prog-mode . eglot-ensure)
:bind (:map eglot-mode-map
("C-c r" . eglot-rename)
("C-c o" . eglot-code-action-organize-imports)
("C-c f" . eglot-format-buffer)
("C-c h" . eldoc)))
;; https://www.emacswiki.org/emacs/RainbowDelimiters
;; (use-package rainbow-delimeters
;; :hook (prog-mode . rainbow-delimeters-mode)
(use-package flycheck
:init (global-flycheck-mode))
(use-package flycheck-eglot
:after (flycheck eglot)
:config
(global-flycheck-eglot-mode 1))
;; (use-package flycheck-projectile)
;; Git
(use-package magit)
;; Git diff
(use-package diff-hl
:config
(global-diff-hl-mode)
;; :hook (prog-mode . diff-hl-mode)
)
;; Github et al.
(use-package forge)
;; Golang
(use-package go-mode
:mode ("\\.go\\'" . go-mode))
;; :hook (go-mode . lsp-deferred)
;; Zig
(use-package zig-mode
:mode ("\\.zig\\'" . zig-mode))
(use-package gotest)
;; Python
;; (use-package elpy
;; :defer t
;; :init
;; (advice-add 'python-mode :before 'elpy-enable))
;; (use-package lsp-pyright
;; :ensure t
;; :hook (python-mode . (lambda ()
;; (require 'lsp-pyright)
;; (lsp-deferred)))) ; or lsp-deferred
;;;;;;;;;;;;;
;; Clojure ;;
;;;;;;;;;;;;;
(use-package clojure-mode)
(use-package paredit)
;; Automatically load paredit when editing a lisp file
;; More at http://www.emacswiki.org/emacs/ParEdit
;; (autoload 'enable-paredit-mode "paredit" "Turn on pseudo-structural editing of Lisp code." t)
;; (add-hook 'emacs-lisp-mode-hook #'enable-paredit-mode)
;; (add-hook 'eval-expression-minibuffer-setup-hook #'enable-paredit-mode)
;; (add-hook 'ielm-mode-hook #'enable-paredit-mode)
;; (add-hook 'lisp-mode-hook #'enable-paredit-mode)
;; (add-hook 'lisp-interaction-mode-hook #'enable-paredit-mode)
;; (add-hook 'scheme-mode-hook #'enable-paredit-mode)
;; eldoc-mode shows documentation in the minibuffer when writing code
;; http://www.emacswiki.org/emacs/ElDoc
;; (add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
;; (add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode)
;; (add-hook 'ielm-mode-hook 'turn-on-eldoc-mode)
;; ;; Enable paredit for Clojure
;; (add-hook 'clojure-mode-hook 'enable-paredit-mode)
;; ;; This is useful for working with camel-case tokens, like names of
;; ;; Java classes (e.g. JavaClassName)
;; (add-hook 'clojure-mode-hook 'subword-mode)
;; ;; A little more syntax highlighting
;; (require 'clojure-mode-extra-font-locking)
;;;;;;;;;;;
;; Cider ;;
;;;;;;;;;;;
;; (use-package cider
;; :hook
;; ;; enable paredit in your REPL
;; ;; provides minibuffer documentation for the code you're typing into the repl
;; ((cider-repl-mode . paredit-mode)
;; (cider-mode . eldoc-mode))
;; :config
;; (setq
;; ;; go right to the REPL buffer when it's finished connecting
;; cider-repl-pop-to-buffer-on-connect t
;; ;; When there's a cider error, show its buffer and switch to it
;; cider-show-error-buffer t
;; cider-auto-select-error-buffer t
;; )
;; )
;; ;; Use clojure mode for other extensions
;; (add-to-list 'auto-mode-alist '("\\.edn$" . clojure-mode))
;; (add-to-list 'auto-mode-alist '("\\.boot$" . clojure-mode))
;; (add-to-list 'auto-mode-alist '("\\.cljs.*$" . clojure-mode))
;; (add-to-list 'auto-mode-alist '("lein-env" . enh-ruby-mode))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment