knoebber / emacs

~/.emacs.d/init.el Commits Diff Raw
; init.el --- Summary: Emacs
;;; Commentary:
;;; First Emacs install date: 04/30/2019
;;; To install config
;;; M-x list-packages U-x

;;; Code:
(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
(setq package-enable-at-startup nil)
(package-initialize)

;; (set-face-attribute 'default nil :height 130) ;; sets global font size

;; Setup use-package
;; https://github.com/jwiegley/use-package
(eval-when-compile (require 'use-package))

;; Always download packages that are not found
(setq use-package-always-ensure t)

;; Sync emacs path and shell path
(use-package exec-path-from-shell
  :config
  (when (memq window-system '(mac ns x))
  (exec-path-from-shell-initialize)))
  
;; Setup helm
(use-package helm
  :config
  (helm-mode 1)
  (helm-autoresize-mode t)
  (setq helm-buffer-max-length nil))

;; Setup magit
(use-package magit)

(use-package general
  :ensure t
  :init
  (setq evil-want-keybinding nil)

  :config
  (general-create-definer my-evil-leader :prefix "SPC")
  (my-evil-leader
   :states 'normal
   :keymaps 'override
   "?" 'general-describe-keybindings
   "C-i" (lambda() (interactive) (switch-to-buffer nil)) ;; C-i is tab
   "RET" 'eshell
   "b" 'helm-mini ;; In helm mini, use C-SPC to select buffers, M-D to kill all marked
   "d" (lambda() (interactive) (load-theme 'spacemacs-dark))
   "e" (lambda() (interactive) (find-file "~/.emacs.d/init.el"))
   "f" 'helm-find-files
   "g" 'magit-status
   "j" 'other-window
   "k" (lambda() (interactive) (kill-buffer nil))
   "l" (lambda() (interactive) (load-theme 'spacemacs-light))
   "o" 'delete-other-windows
   "r" (lambda() (interactive) (load-file "~/.emacs.d/init.el"))
   "s" 'rg-project
   "x" 'helm-M-x
   )
  )


(use-package emacs
  :config
  ;; Treesitter config

  ;; Tell Emacs to prefer the treesitter mode
  ;; You'll want to run the command `M-x treesit-install-language-grammar' before editing.
  (setq major-mode-remap-alist
        '((yaml-mode . yaml-ts-mode)
          (bash-mode . bash-ts-mode)
          (js2-mode . js-ts-mode)
          (typescript-mode . typescript-ts-mode)
          (json-mode . json-ts-mode)
          (css-mode . css-ts-mode)
          (python-mode . python-ts-mode)
	  (go-mode . go-ts-mode)
	)
  )
)

;; Setup evil
(use-package evil
  :ensure t
  :config
  (evil-mode 1))

(use-package evil-collection
  :after evil
  :ensure t
  :config
  (evil-collection-init))

;; Setup theme and powerline
(use-package spacemacs-theme
  :defer t
  :init (load-theme 'spacemacs-light t))

(use-package spaceline
  :config
  (require `spaceline-config)
  (spaceline-emacs-theme))


(use-package markdown-mode
  :hook ((markdown-mode . visual-line-mode)))

(use-package yaml-mode
  :ensure t)

(use-package json-mode
  :ensure t)

(use-package dockerfile-mode)

(defun eglot-format-buffer-on-save ()
  (add-hook 'before-save-hook #'eglot-format-buffer -10 t))

;; https://github.com/casouri/tree-sitter-module
(add-to-list 'treesit-extra-load-path (concat (getenv "HOME") "/package/tree-sitter-module/dist"))


(use-package elixir-ts-mode
  :ensure t
  :config
  (add-hook 'elixir-ts-mode-hook #'eglot-format-buffer-on-save)
)


(use-package go-mode :ensure t)
(require 'project)

(defun project-find-go-module (dir)
  (when-let ((root (locate-dominating-file dir "go.mod")))
    (cons 'go-module root)))

(cl-defmethod project-root ((project (head go-module)))
  (cdr project))

(add-hook 'project-find-functions #'project-find-go-module)


(use-package inf-elixir)

(use-package eglot
  :custom
  (eglot-send-changes-idle-time 0.1)

  :config
  (fset #'jsonrpc--log-event #'ignore)  ; massive perf boost---don't log every event
)


(dolist (mode '(elixir-ts-mode heex-ts-mode))
    (add-to-list 'eglot-server-programs `(,mode . ("/Users/nicolasknoebber/lang/elixir/language_server.sh"))))
(add-hook 'elixir-ts-mode-hook 'eglot-ensure)
(add-hook 'heex-ts-mode-hook 'eglot-ensure)
(add-hook 'go-mode-hook 'eglot-ensure)

(defun eglot-format-buffer-on-save ()
  (add-hook 'before-save-hook #'eglot-format-buffer -10 t))
(add-hook 'go-mode-hook #'eglot-format-buffer-on-save)

(setq eldoc-echo-area-use-multiline-p 1)

(setq js-indent-level 2)

;; Popup completion-at-point
(use-package corfu
  :ensure t
  :custom
  (corfu-auto t)
  :init
  (global-corfu-mode)
  :bind
  (:map corfu-map
        ("SPC" . corfu-insert-separator)
        ("C-n" . corfu-next)
        ("C-p" . corfu-previous)))


;; Pretty icons for corfu
(use-package kind-icon
  :if (display-graphic-p)
  :ensure t
  :after corfu
  :config
  (add-to-list 'corfu-margin-formatters #'kind-icon-margin-formatter))


;; Setup linting with flycheck
;; Use 'C-c ! v' to check flycheck status in buffer.
(use-package flycheck)

(use-package rg)

(use-package htmlize)

(add-hook 'org-mode-hook 'my-org-mode-hook)
(defun my-org-mode-hook()
  (flyspell-mode 1)
  (auto-fill-mode 1))

;;; General config
(show-paren-mode 1)
(menu-bar-mode -1)
(tool-bar-mode -1)
(toggle-scroll-bar -1)
(setq ediff-split-window-function 'split-window-horizontally)

;; Flash the modeline instead of ringing.
(setq visible-bell nil
      ring-bell-function 'flash-mode-line)
(setq user-full-name "Nicolas Knoebber")

(defun flash-mode-line ()
  (invert-face 'mode-line)
  (run-with-timer 0.1 nil #'invert-face 'mode-line))


;;; Enable banned commands
(put 'narrow-to-defun  'disabled nil)
(put 'narrow-to-page   'disabled nil)
(put 'narrow-to-region 'disabled nil)

;;; Don't save backup~ files in the same directory.
(setq backup-directory-alist `(("." . "~/.emacs.d/backups")))

;;; Custom functions

(defun export-nicolasknoebber ()
  "Build nicolasknoebber.com."
  (interactive)
  (load-file "~/projects/nicolasknoebber.com/src/site.el")
  (org-publish-all))

(setq tramp-default-method "ssh")


;; (setq-default org-display-custom-times nil)

;; (setq org-time-stamp-custom-formats
;;       '("<%m/%d/%Y>" . "<%m/%d/%Y>"))
(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")
 '(package-selected-packages
   '(go-mode yaml-mode spacemacs-theme spaceline rg markdown-mode magit kind-icon json-mode inf-elixir htmlize helm general flycheck exec-path-from-shell evil-leader evil-collection elixir-ts-mode dockerfile-mode corfu-terminal)))
(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.
 )