Created
February 13, 2021 20:36
-
-
Save jtrim/586ac19e7d73dcff37f4cae66b035556 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; Helper functions | |
(defun setup-go-mode () | |
(require 'go-guru) | |
(add-hook 'before-save-hook 'gofmt-before-save) | |
(setq fill-column 80) | |
(setq indent-tabs-mode 1) | |
(setq tab-width 2) | |
(setq gofmt-command "goimports") | |
(go-guru-hl-identifier-mode) | |
(local-set-key (kbd "M-.") 'godef-jump) | |
(local-set-key (kbd "M-*") 'pop-tag-mark) | |
(local-set-key (kbd "M-P") 'compile)) | |
(defun github-url-at-line () | |
(let ((repo (magithub-repo))) | |
(let ((base-url (let-alist repo .html_url)) | |
(current-file (magit-current-file)) | |
(current-commit (magit-rev-parse "HEAD")) | |
(current-line (number-to-string (line-number-at-pos)))) | |
(concat base-url "/tree/" current-commit "/" current-file "#L" current-line)))) | |
(defun save-github-url-at-line-to-kill-ring () | |
(interactive) | |
(let ((url (github-url-at-line))) | |
(kill-new url) | |
(message (concat "Saved " url " to kill ring")))) | |
(defun open-line-in-github () | |
(interactive) | |
(shell-command (concat "open " (github-url-at-line)))) | |
(defun copy-from-osx () | |
(shell-command-to-string "pbpaste")) | |
(defun paste-to-osx (text &optional push) | |
(let ((process-connection-type nil)) | |
(let ((proc (start-process "pbcopy" "*Messages*" "pbcopy"))) | |
(process-send-string proc text) | |
(process-send-eof proc)))) | |
(defun set-noop-indent-line-function () | |
(setq-local indent-line-function | |
(lambda () (interactive)))) | |
(defun open-init-files () | |
(interactive) | |
(split-window-right) | |
(windmove-right) | |
(find-file (concat user-emacs-directory "init.el")) | |
(split-window-right) | |
(windmove-right) | |
(find-file (concat user-emacs-directory "../.emacs.d.keep/src/config.el")) | |
(windmove-left)) | |
(defun setup-magit () | |
(interactive) | |
(setq-default magit-save-repository-buffers nil) | |
(setq magit-refresh-status-buffer nil) | |
(add-hook 'git-commit-mode-hook #'(lambda () (setq fill-column 72))) | |
(remove-hook 'magit-status-sections-hook 'magit-insert-unpushed-to-upstream-or-recent) | |
(remove-hook 'magit-status-sections-hook 'magit-insert-stashes) | |
(add-hook 'magit-status-sections-hook 'magit-insert-unpushed-to-upstream t) | |
(transient-append-suffix 'magit-commit "c" | |
'("W" "WIP Commit" magit-wip-commit-create)) | |
(remove-hook 'server-switch-hook 'magit-commit-diff)) | |
(defun magit-wip-commit-create (&optional args) | |
(interactive) | |
(magit-run-git "add" ".") | |
(magit-run-git "commit" "-am" "WIP [ci skip]" "--no-verify" "--no-gpg-sign")) | |
;;; Configuration | |
(setq interprogram-cut-function 'paste-to-osx) | |
(setq interprogram-paste-function 'copy-from-osx) | |
(setq-default auto-save-file-name-transforms `((".*" ,temporary-file-directory t)) | |
backup-directory-alist `((".*" . ,temporary-file-directory)) | |
fill-column 80 | |
frame-resize-pixelwise t | |
indent-tabs-mode nil | |
inhibit-startup-screen t | |
line-spacing 2 | |
vc-follow-symlinks t | |
whitespace-style '(trailing tabs empty indentation) | |
split-height-threshold nil | |
split-width-threshold 0) | |
(menu-bar-mode -1) | |
(global-linum-mode 1) | |
(show-paren-mode 1) | |
(desktop-save-mode -1) | |
(windmove-default-keybindings) | |
(add-to-list 'load-path "~/.emacs.d/elisp") | |
(set-default 'truncate-lines t) | |
(defalias 'yes-or-no-p 'y-or-n-p) | |
(defadvice split-window-right (after rebalance-windows activate) | |
(balance-windows)) | |
(defadvice delete-window (after rebalance-windows activate) | |
(balance-windows)) | |
(defadvice split-window-below (after rebalance-windows activate) | |
(balance-windows)) | |
(defadvice delete-other-windows (before snapshot-window-config activate) | |
(window-configuration-to-register 1)) | |
;; Disable auto-indent for text-mode | |
(add-hook 'text-mode-hook 'set-noop-indent-line-function) | |
;; Fixes `ls does not support --dired` error | |
(when (string= system-type "darwin") | |
(setq dired-use-ls-dired nil)) | |
;; Scratch buffer configuration | |
(setq initial-major-mode 'markdown-mode) | |
(setq initial-scratch-message "# Scratch | |
") | |
(setq explicit-shell-file-name "/usr/local/bin/zsh") | |
;;; js mode | |
(setq js-indent-level 2) | |
;;; Turn off vc, prefer magit | |
(setq vc-handled-backends nil) | |
;;; electric indent | |
(setq auto-indent-newline-function 'newline-and-indent) | |
;;; Whitespace | |
(add-hook 'prog-mode-hook 'whitespace-mode) | |
(add-hook 'before-save-hook 'whitespace-cleanup) | |
;;; html mode | |
(add-hook 'html-mode-hook | |
(lambda () | |
(progn | |
(setq | |
indent-line-function 'sgml-indent-line | |
sgml-basic-offset 2)))) | |
;;; Theme | |
(load-theme 'spacemacs-dark t) | |
;;; Keymaps | |
(global-unset-key (kbd "C-\\")) | |
(global-set-key (kbd "M-g M-s") 'magit) | |
(global-set-key (kbd "C-\\ . f") 'open-init-files) | |
(global-set-key (kbd "C-\\ s") 'counsel-ag) | |
(global-set-key (kbd "C-o") 'save-github-url-at-line-to-kill-ring) | |
(global-set-key (kbd "C-c o") 'open-line-in-github) | |
(global-set-key (kbd "C-c c") 'comment-or-uncomment-region) | |
(global-set-key (kbd "C-c j") 'join-line) | |
(global-set-key (kbd "C-c q") 'fill-region) | |
(global-set-key (kbd "C-c <backspace>") (lambda () (interactive) (jump-to-register 1))) | |
(global-set-key (kbd "C-c SPC") (lambda () (interactive) (jump-to-register 2))) | |
(global-set-key (kbd "C-s") 'swiper) | |
(global-set-key (kbd "C-c C-r") 'ivy-resume) | |
(global-set-key (kbd "M-x") 'counsel-M-x) | |
(global-set-key (kbd "M-p") 'projectile-find-file) | |
;;; Package config | |
(require 'package) | |
(add-to-list 'package-archives | |
'("melpa" . "https://melpa.org/packages/") t) | |
;;; Magit | |
(add-hook 'magit-mode-hook 'setup-magit) | |
;;; Smartparens | |
(smartparens-global-strict-mode t) | |
(global-set-key (kbd "C-M-g") 'sp-forward-slurp-sexp) | |
;;; Ivy | |
(ivy-mode 1) | |
(setq ivy-use-virtual-buffers t) | |
(setq enable-recursive-minibuffers t) | |
;;; Counsel | |
(counsel-mode 1) | |
;;; Golang | |
(add-hook 'go-mode-hook 'setup-go-mode) | |
;;; Customize vars below | |
(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. | |
'(custom-safe-themes | |
'("bffa9739ce0752a37d9b1eee78fc00ba159748f50dc328af4be661484848e476" default)) | |
'(package-selected-packages | |
'(projectile counsel go-mode magithub ivy markdown-mode spacemacs-theme magit smartparens yaml-mode))) | |
(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. | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment