Skip to content

Instantly share code, notes, and snippets.

@jasonrobot
Last active July 13, 2019 05:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonrobot/b573c2af7212329b977c3ae7325923c3 to your computer and use it in GitHub Desktop.
Save jasonrobot/b573c2af7212329b977c3ae7325923c3 to your computer and use it in GitHub Desktop.
emacs configs because I'm too lazy to use real git
;;; package --- Summary
;; its not a package, its just all my customs
;;; Commentary:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; custom-set-variables - Dont edit below here! ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Code:
(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.
'(column-number-mode t)
'(compilation-message-face (quote default))
'(confirm-kill-emacs (quote yes-or-no-p))
'(custom-enabled-themes (quote (solarized-light)))
'(custom-safe-themes
(quote
("a4df5d4a4c343b2712a8ed16bc1488807cd71b25e3108e648d4a26b02bc990b3" "62c81ae32320ceff5228edceeaa6895c029cc8f43c8c98a023f91b5b339d633f" "f27c3fcfb19bf38892bc6e72d0046af7a1ded81f54435f9d4d09b3bff9c52fc1" "c856158cc996d52e2f48190b02f6b6f26b7a9abd5fea0c6ffca6740a1003b333" "42b9d85321f5a152a6aef0cc8173e701f572175d6711361955ecfb4943fe93af" "b571f92c9bfaf4a28cb64ae4b4cdbda95241cd62cf07d942be44dc8f46c491f4" "bf798e9e8ff00d4bf2512597f36e5a135ce48e477ce88a0764cfb5d8104e8163" "c9ddf33b383e74dac7690255dd2c3dfa1961a8e8a1d20e401c6572febef61045" "5a0eee1070a4fc64268f008a4c7abfda32d912118e080e18c3c865ef864d1bea" "70f5a47eb08fe7a4ccb88e2550d377ce085fedce81cf30c56e3077f95a2909f2" "c3e6b52caa77cb09c049d3c973798bc64b5c43cc437d449eacf35b3e776bf85c" "bc4b650c41b16b98166b35da94b366c6a9e1e7883bbf4937c897fb7bd05aa619" "bea5fd3610ed135e6ecc35bf8a9c27277d50336455dbdd2969809f7d7c1f7d79" "e11569fd7e31321a33358ee4b232c2d3cf05caccd90f896e1df6cab228191109" "8aebf25556399b58091e533e455dd50a6a9cba958cc4ebb0aab175863c25b9a4" "d677ef584c6dfc0697901a44b885cc18e206f05114c8a3b7fde674fce6180879" default)))
'(delete-trailing-lines nil)
'(display-line-numbers t)
'(fill-column 120)
'(git-commit-summary-max-length 200)
'(global-anzu-mode t)
'(global-company-mode t)
'(global-subword-mode t)
'(grep-find-ignored-directories
(quote
("SCCS" "RCS" "CVS" "MCVS" ".src" ".svn" ".git" ".hg" ".bzr" "_MTN" "_darcs" "{arch}" "node_modules")))
'(grep-find-ignored-files
(quote
(".#*" "*.hi" "*.o" "*~" "*.bin" "*.lbin" "*.so" "*.a" "*.ln" "*.blg" "*.bbl" "*.elc" "*.lof" "*.glo" "*.idx" "*.lot" "*.fmt" "*.tfm" "*.class" "*.fas" "*.lib" "*.mem" "*.x86f" "*.sparcf" "*.dfsl" "*.pfsl" "*.d64fsl" "*.p64fsl" "*.lx64fsl" "*.lx32fsl" "*.dx64fsl" "*.dx32fsl" "*.fx64fsl" "*.fx32fsl" "*.sx64fsl" "*.sx32fsl" "*.wx64fsl" "*.wx32fsl" "*.fasl" "*.ufsl" "*.fsl" "*.dxl" "*.lo" "*.la" "*.gmo" "*.mo" "*.toc" "*.aux" "*.cp" "*.fn" "*.ky" "*.pg" "*.tp" "*.vr" "*.cps" "*.fns" "*.kys" "*.pgs" "*.tps" "*.vrs" "*.pyc" "*.pyo" "*.wp.js" "*.wp.css" "*.sql" "*.dat" "*.min.js" "*.csv")))
'(highlight-indent-guides-auto-enabled nil)
'(js-switch-indent-offset 4)
'(magit-diff-use-overlays nil)
'(mode-require-final-newline nil)
'(package-selected-packages
(quote
(s delight yasnippet helm-c-yasnippet yasnippet-snippets flymake elm-mode lsp-typescript fennel-mode crystal-playground emmet-mode php-mode helm-rg eglot helm-projectile lsp-mode magit racket-mode solarized-theme web-mode clojure-mode company company-lsp fish-completion flycheck gruvbox-theme haskell-mode helm helm-core helm-ls-git js2-mode lsp-python markdown-mode projectile pyvenv rust-mode slime tide typescript-mode use-package with-editor zenburn-theme flycheck-crystal crystal-mode anzu lsp-hack lsp-haskell toml-mode dracula-theme flycheck-rust rust-playground json-mode helm-company xkcd molokai-theme ample-theme anti-zenburn-theme labburn-theme fish-mode lsp-go web-beautify better-defaults centered-cursor-mode dockerfile-mode expand-region ggtags helm-ls-hg highlight-indentation lsp-rust yaml-mode slime-company lua-mode)))
'(projectile-mode t nil (projectile))
'(require-final-newline nil)
'(scroll-margin 2)
'(tab-width 4)
'(vc-annotate-background nil)
'(vc-annotate-background-mode nil)
'(vc-annotate-very-old-color nil))
(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.
)
# This file has been auto-generated by i3-config-wizard(1).
# It will not be overwritten, so edit it as you like.
#
# Should you change your keyboard layout some time, delete
# this file and re-run i3-config-wizard(1).
#
# i3 config file (v4)
#
# Please see http://i3wm.org/docs/userguide.html for a complete reference!
set $mod Mod4
# Font for window titles. Will also be used by the bar unless a different font
# is used in the bar {} block below.
# font pango:monospace 8
# This font is widely installed, provides lots of unicode glyphs, right-to-left
# text rendering and scalability on retina/hidpi displays (thanks to pango).
font pango:DejaVu Sans Mono 8
# Before i3 v4.8, we used to recommend this one as the default:
# font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
# The font above is very space-efficient, that is, it looks good, sharp and
# clear in small sizes. However, its unicode glyph coverage is limited, the old
# X core fonts rendering does not support right-to-left and this being a bitmap
# font, it doesn’t scale on retina/hidpi displays.
# Use Mouse+$mod to drag floating windows to their wanted position
floating_modifier $mod
# start a terminal
#bindsym $mod+Return exec i3-sensible-terminal
bindsym $mod+Return exec terminology
bindsym $mod+Mod1+Return exec cool-retro-term
# kill focused window
bindsym $mod+Shift+q kill
# start dmenu (a program launcher)
bindsym $mod+d exec dmenu_run
# There also is the (new) i3-dmenu-desktop which only displays applications
# shipping a .desktop file. It is a wrapper around dmenu, so you need that
# installed.
# bindsym $mod+d exec --no-startup-id i3-dmenu-desktop
# change focus
bindsym $mod+j focus left
bindsym $mod+k focus down
bindsym $mod+l focus up
bindsym $mod+semicolon focus right
# alternatively, you can use the cursor keys:
bindsym $mod+Left focus left
bindsym $mod+Down focus down
bindsym $mod+Up focus up
bindsym $mod+Right focus right
# move focused window
bindsym $mod+Shift+j move left
bindsym $mod+Shift+k move down
bindsym $mod+Shift+l move up
bindsym $mod+Shift+semicolon move right
# alternatively, you can use the cursor keys:
bindsym $mod+Shift+Left move left
bindsym $mod+Shift+Down move down
bindsym $mod+Shift+Up move up
bindsym $mod+Shift+Right move right
# split in horizontal orientation
bindsym $mod+h split h
# split in vertical orientation
bindsym $mod+v split v
# enter fullscreen mode for the focused container
bindsym $mod+f fullscreen toggle
# change container layout (stacked, tabbed, toggle split)
bindsym $mod+s layout stacking
bindsym $mod+w layout tabbed
bindsym $mod+e layout toggle split
# toggle tiling / floating
bindsym $mod+Shift+space floating toggle
# change focus between tiling / floating windows
bindsym $mod+space focus mode_toggle
# focus the parent container
bindsym $mod+a focus parent
# focus the child container
#bindsym $mod+d focus child
# switch to workspace
bindsym $mod+1 workspace 1
bindsym $mod+2 workspace 2
bindsym $mod+3 workspace 3
bindsym $mod+4 workspace 4
bindsym $mod+5 workspace 5
bindsym $mod+6 workspace 6
bindsym $mod+7 workspace 7
bindsym $mod+8 workspace 8
bindsym $mod+9 workspace 9
bindsym $mod+0 workspace 10
# move focused container to workspace
bindsym $mod+Shift+1 move container to workspace 1
bindsym $mod+Shift+2 move container to workspace 2
bindsym $mod+Shift+3 move container to workspace 3
bindsym $mod+Shift+4 move container to workspace 4
bindsym $mod+Shift+5 move container to workspace 5
bindsym $mod+Shift+6 move container to workspace 6
bindsym $mod+Shift+7 move container to workspace 7
bindsym $mod+Shift+8 move container to workspace 8
bindsym $mod+Shift+9 move container to workspace 9
bindsym $mod+Shift+0 move container to workspace 10
# reload the configuration file
bindsym $mod+Shift+c reload
# restart i3 inplace (preserves your layout/session, can be used to upgrade i3)
bindsym $mod+Shift+r restart
# exit i3 (logs you out of your X session)
bindsym $mod+Shift+e exec "i3-nagbar -t warning -m 'You pressed the exit shortcut. Do you really want to exit i3? This will end your X session.' -b 'Yes, exit i3' 'i3-msg exit'"
# resize window (you can also use the mouse for that)
mode "resize" {
# These bindings trigger as soon as you enter the resize mode
# Pressing left will shrink the window’s width.
# Pressing right will grow the window’s width.
# Pressing up will shrink the window’s height.
# Pressing down will grow the window’s height.
bindsym j resize shrink width 10 px or 10 ppt
bindsym k resize grow height 10 px or 10 ppt
bindsym l resize shrink height 10 px or 10 ppt
bindsym semicolon resize grow width 10 px or 10 ppt
# same bindings, but for the arrow keys
bindsym Left resize shrink width 10 px or 10 ppt
bindsym Down resize grow height 10 px or 10 ppt
bindsym Up resize shrink height 10 px or 10 ppt
bindsym Right resize grow width 10 px or 10 ppt
# back to normal: Enter or Escape
bindsym Return mode "default"
bindsym Escape mode "default"
}
bindsym $mod+r mode "resize"
# Start i3bar to display a workspace bar (plus the system information i3status
# finds out, if available)
bar {
status_command i3status
}
set $Locker i3lock -c 000000 && sleep 1
set $mode_system System (l) lock, (e) logout, (s) suspend, (h) hibernate, (r) reboot, (Shift+s) shutdown
mode "$mode_system" {
bindsym l exec --no-startup-id $Locker, mode "default"
bindsym e exec --no-startup-id i3-msg exit, mode "default"
bindsym s exec --no-startup-id $Locker && systemctl suspend, mode "default"
bindsym h exec --no-startup-id $Locker && systemctl hibernate, mode "default"
bindsym r exec --no-startup-id systemctl reboot, mode "default"
bindsym Shift+s exec --no-startup-id systemctl poweroff -i, mode "default"
# back to normal: Enter or Escape
bindsym Return mode "default"
bindsym Escape mode "default"
}
#bindsym Print exec "python /home/jason/shoot-up-python/upload.py"
bindsym $mod+z mode "$mode_system"
bindsym XF86MonBrightnessUp exec xbacklight -inc 5
bindsym XF86MonBrightnessDown exec xbacklight -dec 5
bindsym XF86AudioRaiseVolume exec pactl set-sink-volume 0 +4%
bindsym XF86AudioLowerVolume exec pactl set-sink-volume 0 -4%
# this one is a hack to disable ctrl-q in firefox
bindsym Ctrl+q exec ~/noctrlq.sh
#### Execs!
exec xsetroot -solid \#232323
exec caffeine
exec redshift -l 34.429528:-119.795303 -b 1:0.60 -t 5500:3200
exec emacs --daemon
exec setxkbmap -option ctrl:nocaps
exec udiskie --tray
exec nm-applet
;;; package --- init.el
;;; Commentary:
;;; Code:
;; do this, since I usually run fish
(setq shell-file-name "/bin/bash")
;;;;;;;;;;;;;;
;; Packages ;;
;;;;;;;;;;;;;;
(require 'package)
(add-to-list 'package-archives
'("mepla" . "http://melpa.milkbox.net/packages/") t)
(package-initialize)
(unless (package-installed-p 'use-package)
(package-install 'use-package))
(use-package better-defaults
:ensure t)
(use-package delight
:ensure t)
(use-package helm
:ensure t
:bind (("M-x" . helm-M-x)
("C-x C-f" . helm-find-files)
("C-x b" . helm-buffers-list)
("M-y" . helm-show-kill-ring)))
(defun -strip-newlines-from-json (args) ;(output checker buffer)
"Remove newlines from the first element of ARGS."
(setcar args (replace-regexp-in-string "\n" "" (car args)))
args)
(use-package flycheck
:ensure t
:init
(global-flycheck-mode)
:config
(setq-default flycheck-disabled-checkers
(append flycheck-disabled-checkers
'(javascript-jshint)))
(flycheck-add-mode 'javascript-eslint 'js2-mode)
(advice-add 'flycheck-parse-eslint
:filter-args
#'-strip-newlines-from-json))
(use-package anzu
:delight anzu-mode
:config (global-anzu-mode))
;; (use-package cider
;; :config
;; (setq clojure-indent-style :always-indent))
(use-package company
:ensure t
:delight company-mode
:config (setq company-idle-delay nil)
:bind (("M-SPC" . company-complete)))
(use-package crystal-mode
:bind (("C-c C-f" . crystal-tool-format)))
(use-package helm-company
:bind (("M-S-SPC" . helm-company)))
(defun my-fix-diff-range (range)
"Change the diff RANGE from using three dots (useless) to two (normal)."
(when (stringp range)
(s-replace "..." ".." range)))
(defun my-always-make-upstream-origin (branch start-point)
"None of your shenanigans, Magit! I _ALWAYS_ want BRANCH upstream to be origin!
This is used to override \"magit-branch-maybe-adjust-upstream\", and it just always
sets branch.NAME.remote to origin. START-POINT is ignored."
(magit-call-git "branch" "--set-upstream-to=origin" branch))
(use-package magit
:config
(advice-add 'magit-diff--dwim
:filter-return
#'my-fix-diff-range)
(advice-add 'magit-branch-maybe-adjust-upstream
:override
#'my-always-make-upstream-origin))
(use-package projectile
:delight
'(:eval (let ((mode-string " プロジ"))
(if (projectile-project-p)
(let ((name (projectile-project-name))
(type (symbol-name (projectile-project-type))))
(concat mode-string
(concat "《" name ":" type "》"))
mode-string))))
:config
;; These are some projectile functions I dont care about, and I want them for other uses.
(unbind-key "C-c p l" projectile-mode-map)
(unbind-key "C-c p f" projectile-mode-map))
(use-package helm-projectile
:bind (("C-c p s" . helm-projectile-rg)))
(use-package highlight-indentation
:delight highlight-indentation-mode)
(use-package js2-mode
:ensure t
:mode "\\.js\\'"
:delight "JS²"
:bind (("C-." . js2-next-error))
:config
(setq js2-global-externs
'("ontraport"
"setTimeout" "setInterval" "clearTimeout" "clearInterval"
"describe" "it" "beforeEach" "afterEach" "beforeAll" "afterAll" "expect" "jasmine"
"Globalize"
"test_runner" "steal" "$" "$l" "_" "go" "ObjectAnimate")))
;; elpy and tide are disabled, try to replace them with eglot or lsp-mode! Except for JS2. for now.
;; (use-package elpy
;; :ensure t
;; :config
;; (setq elpy-rpc-python-command "python3")
;; :init (elpy-enable))
(use-package php-mode
:mode "\\.php\\'"
:config
(add-hook 'php-mode-hook (lambda () (flycheck-mode -1))))
;; hyper-useful
(use-package s)
(use-package slime
:config
(setq inferior-lisp-program "sbcl"))
(use-package web-mode
:mode "\\.ejs\\'"
:config
(add-hook 'web-mode-hook 'emmet-mode))
(use-package yasnippet
:init (yas-global-mode 1)
:bind (("C-c tab" . yas-next-field-or-maybe-expand)))
;; (use-package typescript-mode
;; :mode "\\.tsx\\'")
;; (use-package tide
;; :config
;; (defun setup-tide-mode ()
;; "Set up tide mode in the current buffer. Have hooks call this."
;; (tide-setup)
;; (setq flycheck-check-syntax-automatically '(save mode-enabled))
;; (tide-hl-identifier-mode +1))
;; ;; (add-hook 'web-mode-hook
;; ;; (lambda ()
;; ;; (when (string-equal "tsx" (file-name-extension buffer-file-name))
;; ;; (setup-tide-mode))))
;; (flycheck-add-mode 'typescript-tslint 'web-mode)
;; (setq company-tooltip-align-annotations t)
;; (add-hook 'before-save-hook 'tide-format-before-save)
;; (add-hook 'typescript-mode-hook #'setup-tide-mode))
;; (use-package flymake
;; :bind (("M-n" . flymake-goto-next-error)
;; ("M-p" . flymake-goto-prev-error)))
;; keep this package after projectile, so these key bindings are last
(use-package helm-ls-git
:ensure t
:bind (("C-c p f" . helm-ls-git-ls)))
;;;;;;;;;;;;;;;
;; Functions ;;
;;;;;;;;;;;;;;;
(defun beginning-of-line-or-indentation ()
"Move to beginning of line, or indentation."
(interactive)
(let ((start (point)))
(back-to-indentation)
;; now if point is the same as when we started, we're already at indent start
(if (= start (point))
(beginning-of-line))))
(defun insert-line-before-and-indent ()
"Insert a new line before the current line, keeping both at the same level of indentation."
(interactive)
(beginning-of-line)
(newline)
(forward-line -1)
(indent-for-tab-command))
(defun copy-file-path ()
"Copy the current file's path to the clipboard."
(interactive)
(let ((filename (buffer-file-name)))
(if (not filename)
(message "No file name for current buffer")
(kill-new filename))))
(defun copy-file-name ()
"Copy the current file's name to the clipboard."
(interactive)
(let ((filename (buffer-file-name)))
(if (not filename)
(message "No file name for current buffer")
(kill-new (file-name-nondirectory filename)))))
(defun insert-branch-name ()
"When making a commit in magit, insert the branch's name as the first word of the commit."
(interactive)
(unless (string= (thing-at-point 'word) "Merge")
(save-excursion
(forward-line 4)
(let ((branch-line (thing-at-point 'line))
(branch-name-regexp "On branch \\(\\w*/\\)?\\(\\w+-?[0-9]*\\)"))
(string-match branch-name-regexp branch-line)
(let ((ticket-name (match-string 2 branch-line)))
(when ticket-name
(goto-char 0)
(insert ticket-name)))))
(end-of-line)
(insert " ")))
;; (defun position-cursor-in-commit-buffer ()
;; "Move the cursor to the end of any text in the first line of the commit buffer."
;; (interactive)
;; (move-end-of-line nil))
;; Add a newline as line 2, then move to end of line 1 (assuming starting at pos 0)
;; (fset 'fix-commit-editmsg
;; [?\C-e return ?\C-b ? ])
(defun fix-commit-editmsg ()
"Add an empty line as line 2, move cursor in to position for typing."
(interactive)
(move-end-of-line nil)
(newline)
(move-end-of-line 0))
(defun wrap-in-$l ()
"Wrap a string in $l()."
(interactive)
(save-excursion
(search-forward "'")
(backward-char)
(insert "$l( ")
(forward-sexp)
(insert " )")))
;; A macro/function to find the next function definition in a JS file.
(fset 'js-next-function
[?\C-s return ?: ? ?? ?f ?u ?n ?c ?t ?i ?o ?n ? ?? ?\( return])
;; would be better to use a regex for this
;; var let or const, space, word, colon or (equals with maybe spaces around), function or =>
;; '(var|let|const)\s\w+(:\s*|\s*=\s*)(function|.*=>)
(fset 'js-prev-function
[?\C-r return ?: ? ?? ?f ?u ?n ?c ?t ?i ?o ?n ? ?? ?\( return])
;;;;;;;;;;;
;; Modes ;;
;;;;;;;;;;;
;; Any external packages should be in the previous section.
;; This is just for built-in modes.
(global-hl-line-mode 1)
(tool-bar-mode -1)
(global-subword-mode 1)
(column-number-mode 1)
(add-hook 'prog-mode-hook 'highlight-indentation-mode)
;; (add-hook 'prog-mode-hook 'auto-save-mode)
(add-hook 'emacs-lisp-mode-hook 'flymake-mode)
(add-hook 'before-save-hook
'delete-trailing-whitespace)
(add-hook 'git-commit-setup-hook
'fix-commit-editmsg)
;; 'insert-branch-name)
(let ((disable-line-numbers
'(lambda ()
(display-line-numbers-mode -1))))
(add-hook 'git-commit-setup-hook disable-line-numbers)
(add-hook 'magit-mode-hook disable-line-numbers)
(add-hook 'term-mode-hook disable-line-numbers))
(delight '((subword-mode "" "subword")))
;;;;;;;;;;;;;;;;;
;; Keybindings ;;
;;;;;;;;;;;;;;;;;
(windmove-default-keybindings)
(global-set-key (kbd "C-a") 'beginning-of-line-or-indentation)
(global-set-key (kbd "C-o") 'insert-line-before-and-indent)
(global-set-key (kbd "M-;") 'comment-line)
(global-set-key (kbd "C-x g") 'magit-status)
(global-set-key (kbd "C-x C-g") 'keyboard-quit)
(global-set-key
(kbd "C-v")
'(lambda ()
(interactive)
(scroll-up-command 16)))
(global-set-key
(kbd "M-v")
'(lambda ()
(interactive)
(scroll-up-command -16)))
(eval-after-load 'js2-mode
'(progn
(define-key js-mode-map (kbd "C-c f n") 'js-next-function)
(define-key js-mode-map (kbd "C-c f p") 'js-prev-function)
(define-key js-mode-map (kbd "C-c l") 'wrap-in-$l)))
;;;;;;;;;;;;;;;;;;;
;; Misc settings ;;
;;;;;;;;;;;;;;;;;;;
(setq mouse-wheel-progressive-speed nil)
(setq inhibit-startup-screen t)
(add-to-list 'default-frame-alist '(font . "Roboto Mono 9"))
;; (add-to-list 'default-frame-alist '(font . "Noto Sans Mono 8"))
(setq custom-file "~/.emacs.d/custom.el")
(load custom-file)
(provide 'init)
;;; init.el ends here
#tabbrowser-tabs { visibility: collapse !important; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment