Skip to content

Latest commit

 

History

History
547 lines (462 loc) · 14.5 KB

alex.org

File metadata and controls

547 lines (462 loc) · 14.5 KB

Alex’s init.el — ☮ ☯ ☮

Emacs

initialization stuffs

;; keep customizations in a separate file
(setq custom-file "~/.emacs.d/custom.el")
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(load custom-file)
(set-cursor-color "#FF0000")

(setq dotfiles-dir (file-name-directory
                         (or (buffer-file-name) load-file-name)))

;; get packages from from melpa
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)

;; use package --- https://github.com/jwiegley/use-package
(defun package-require (pkg)
       "Install a package only if it's not already installed."
       (when (not (package-installed-p pkg))
         (package-install pkg)))

;; Setup use-package function
(package-require 'use-package)

(eval-when-compile
  (require 'use-package))
(require 'bind-key)
(require 'fringe)
(setq use-package-always-ensure t)

; Disable gui features
(dolist (mode '(menu-bar-mode tool-bar-mode scroll-bar-mode))
  (when (fboundp mode) (funcall mode -1)))

;; fix pasteboard error
(setq save-interprogram-paste-before-kill nil)

;; fix the PATH variable in shell
(defun set-exec-path-from-shell-PATH ()
  (let ((path-from-shell (shell-command-to-string "TERM=vt100 $SHELL -i -c 'echo $PATH'")))
    (setenv "PATH" path-from-shell)
    (setq exec-path (split-string path-from-shell path-separator))))

(when window-system (set-exec-path-from-shell-PATH))

;; set backup directory
(setq backup-directory-alist `(("." . "~/.saves")))

keybindings

;; toggle whitespace
(global-set-key (kbd "C-x w") 'whitespace-mode)

;; hippie expand completion
(global-set-key (kbd "M-/") 'hippie-expand)

;; open eshell
(global-set-key (kbd "C-x t") 'eshell)

;; rgrep
(global-set-key (kbd "C-x e") 'rgrep)

;; open org directory
(global-set-key (kbd "C-c o")
    (lambda ()
      (interactive)
      (find-file "~/org/")))

;; shift + arrow key to move between windows
(windmove-default-keybindings)

;; disable default downcasing keybinding
(put 'downcase-word 'disabled t)

preferences

;; set default font
(set-default-font "Iosevka 18")
(add-to-list 'default-frame-alist '(font . "Iosevka 18"))

;; prevent pop-ups on osx
(setq ns-pop-up-frames nil)

;; use tabs instead of spaces
(setq-default indent-tabs-mode nil)

;; set default tab-width to 2
(setq-default tab-width 2)

;; Always ask for y/n keypress instead of typing out 'yes' or 'no'
(defalias 'yes-or-no-p 'y-or-n-p)

;; get rid of left and right side-space
(set-fringe-mode 0)

;; auto-close parens
(electric-pair-mode 1)

;; show matching paren pair
(show-paren-mode 1)

;; fix eshell node repl weirdness
(setenv "NODE_NO_READLINE" "1")

;; navigate window history with C-c arrow
(when (fboundp 'winner-mode)
  (winner-mode 1))

dired

;; auto refresh buffers
(global-auto-revert-mode 1)

;; also auto refresh dired, but be quiet about it
(setq global-auto-revert-non-file-buffers t)
(setq auto-revert-verbose nil)

;; fix ls --dired startup error
(setq dired-use-ls-dired nil)

;; ignore dired metadata in ace jumps
(add-hook 'dired-mode-hook
          (lambda ()
            (setq-local ace-jump-search-filter
                        (lambda ()
                          (get-text-property (point) 'dired-filename)))))

magit

(use-package magit
  :ensure t
  :bind (("C-x g" . magit-status))
  :config

  ;; revert buffers in magit without notification
  (setq magit-revert-buffers 'silent)

  ;; fix a weird magit issue with the wombat color scheme
  ;; highlighting the selected hunk in diffs
  (defun disable-magit-highlight-in-buffer ()
    (face-remap-add-relative 'magit-item-highlight '()))
  (add-hook 'magit-status-mode-hook 'disable-magit-highlight-in-buffer))

ivy

(use-package ivy
  :ensure t
  :config
  (setq ivy-use-virtual-buffers t)
  (setq ivy-count-format "(%d/%d) ")
  (ivy-mode 1))

ace jump

(use-package ace-jump-mode
  :ensure t
  :bind ("C-c SPC" . ace-jump-mode))

(use-package ace-window
  :ensure t
  :bind ("M-p" . ace-window)
  :config
  (setq aw-keys '(?q ?w ?e ?r ?t ?y ?u ?i ?o)))

lsp

(use-package lsp-mode
  :ensure t
  :commands (lsp lsp-deferred)
  :hook (go-mode . lsp-deferred))

;; Set up before-save hooks to format buffer and add/delete imports.
;; Make sure you don't have other gofmt/goimports hooks enabled.
(defun lsp-go-install-save-hooks ()
  (add-hook 'before-save-hook #'lsp-format-buffer t t)
  (add-hook 'before-save-hook #'lsp-organize-imports t t))
(add-hook 'go-mode-hook #'lsp-go-install-save-hooks)

;; Optional - provides fancier overlays.
(use-package lsp-ui
  :ensure t
  :commands lsp-ui-mode)

elisp

(add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)

clojure

(use-package clojure-mode)
(use-package cider)

javascript

(use-package js2-mode
  :mode ("\\.js$" . js2-mode)
  :config
  (setq-default js2-mode-indent-ignore-first-tab t)
  (setq-default js2-show-parse-errors nil)
  (setq-default js2-strict-inconsistent-return-warning nil)
  (setq-default js2-strict-var-hides-function-arg-warning nil)
  (setq-default js2-strict-missing-semi-warning nil)
  (setq-default js2-strict-trailing-comma-warning nil)
  (setq-default js2-strict-cond-assign-warning nil)
  (setq-default js2-strict-var-redeclaration-warning nil)

  (add-hook 'js-mode-hook (lambda ()
                            (setq-default js2-basic-offset 2))))

coffeescript

(use-package coffee-mode
  :mode (("\\.coffee$" . coffee-mode)
         (".*\\.cjsx\\'" . coffee-mode))
  :config
  (setq coffee-js-mode 'js2-mode)
  (defun coffee-compile-region (start end)
    "Compiles a region and displays the JS in another buffer."
    (interactive "r")
    (let ((buffer (get-buffer coffee-compiled-buffer-name)))
      (when buffer (kill-buffer buffer)))
    (call-process-region start end coffee-command nil
                         (get-buffer-create coffee-compiled-buffer-name) nil "-s" "-p" "--bare")
    (let ((buffer (get-buffer coffee-compiled-buffer-name)))
      (with-current-buffer buffer
        (funcall coffee-js-mode)
        (goto-char (point-min)))
      (display-buffer buffer))))

stylus

(use-package sws-mode)
(use-package stylus-mode
  :mode ("\\.styl\\'" . stylus-mode))

sass

(use-package sass-mode)

go

(use-package go-mode)

elm

(use-package elm-mode)

geiser

(use-package geiser
  :config (setq geiser-active-implementations '(guile)))

haskell

(use-package haskell-mode
  :config
  (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation))

find file in project

(use-package find-file-in-project
  :bind ("C-x f" . find-file-in-project))

paredit

(use-package paredit
  :config
  (setq paredit-hooks
        '(emacs-lisp-mode-hook
          clojure-mode-hook
          geiser-mode-hook))

  (dolist (hook paredit-hooks)
    (add-hook hook #'enable-paredit-mode)))

skewer mode

;; https://github.com/skeeto/skewer-mode

(use-package simple-httpd)
(use-package skewer-mode
  :config
  (skewer-setup))

web mode

;; web-mode http://web-mode.org/

(use-package web-mode
  :mode (("\\.html?\\'" . web-mode)
         ("\\.eco\\'" . web-mode)
         ("\\.erb\\'" . web-mode))
  :config
  (setq web-mode-indent-style 2)
  (setq web-mode-markup-indent-offset 2)
  (setq web-mode-css-indent-offset 2)
  (setq web-mode-code-indent-offset 2))

nyan mode

(use-package nyan-mode
  :config
  (nyan-mode 1)
  (setq nyan-bar-length 16))

rainbow mode

(use-package rainbow-mode
  :config
  (defun activate-rainbow-mode ()
    (rainbow-mode 1))

  (defun stylus-rainbow-mode ()
    (when (and (stringp buffer-file-name)
               (string-match "\\.styl\\'" buffer-file-name))
      (activate-rainbow-mode)))

  (add-hook 'css-mode-hook 'activate-rainbow-mode)
  (add-hook 'find-file-hook 'stylus-rainbow-mode))

exec path from shell

(use-package exec-path-from-shell
  :init
  (when (memq window-system '(mac ns))
       (exec-path-from-shell-initialize)))

ag

;; the silver searcher --- https://github.com/Wilfred/ag.el
(use-package ag
  :config
  (global-set-key (kbd "C-x a") 'ag-project))

yasnippet

(use-package yasnippet
  :config
  (yas-global-mode 1)
  ;; prevent yasnippet from indenting
  (setq yas-indent-line nil)
  (setq yas-root-directory
           (concat dotfiles-dir "snippets")))

multiple cursors

(use-package multiple-cursors
  :config
  (global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines)

  (global-set-key (kbd "C->") 'mc/mark-next-like-this)
  (global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
  (global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this))

expand region

(use-package expand-region
  :bind ("C-=" . er/expand-region))

markdown mode

(use-package markdown-mode
  :mode (("\\.markdown\\'" . markdown-mode)
         ("\\.mdown\\'" . markdown-mode)
         ("\\.md\\'" . markdown-mode)))

org mode

(use-package org
  :pin manual
  :config
 (eval-after-load "org"
   '(progn
      (add-hook 'org-mode-hook
            (lambda () (local-unset-key (kbd "C-c SPC"))))
      (setq org-startup-indented t))))

org-present

(use-package org-present
  :config
  (add-hook 'org-present-mode-hook
            (lambda ()
              (visual-line-mode t)
              (org-present-big)
              (org-display-inline-images)
              (org-present-hide-cursor)
              (org-present-read-only)))
  (add-hook 'org-present-mode-quit-hook
            (lambda ()
              (visual-line-mode -1)
              (org-present-small)
              (org-remove-inline-images)
              (org-present-show-cursor)
              (org-present-read-write))))

beacon-mode

;; highlight cursor when scrolling
(use-package beacon
  :config
  (beacon-mode 1)
  (setq beacon-size 20))

company-mode

(use-package company
  :ensure t
  :config
  (global-set-key (kbd "M-n") 'company-complete))

;; company-lsp integrates company mode completion with lsp-mode.
(use-package company-lsp
  :ensure t
  :commands company-lsp)

restclient

(use-package restclient)

helpers

(defun reload-init-file ()
  (interactive)
  (load user-init-file)
  (message "reloaded init.el ✓ ☮ ☯ ☮"))

init.el

<<package-init>>
<<keybindings>>
<<preferences>>
<<dired>>
<<ace-jump-mode>>
<<lsp>>
<<coffeescript>>
<<stylus>>
<<sass>>
<<clojure>>
<<elisp>>
<<geiser>>
<<haskell>>
<<golang>>
<<elm>>
<<javascript>>
<<magit>>
<<ivy>>
<<find-file-in-project>>
<<paredit>>
<<skewer-mode>>
<<web-mode>>
<<rainbow-mode>>
<<nyan-mode>>
<<ag.el>>
<<yasnippet>>
<<multiple-cursors>>
<<markdown-mode>>
<<org-present>>
<<exec-path>>
<<beacon-mode>>
<<auto-complete>>
<<restclient>>
<<helpers>>
<<org-mode>>