Skip to content

Instantly share code, notes, and snippets.

@thiesen
Created May 11, 2021 10:21
Show Gist options
  • Save thiesen/08c0e36c3d58d707f5876e67329eee8e to your computer and use it in GitHub Desktop.
Save thiesen/08c0e36c3d58d707f5876e67329eee8e to your computer and use it in GitHub Desktop.
;;;; fixed instructions
;;; startup
(setenv "PATH" (concat (getenv "PATH") ":/usr/local/bin"))
(setq exec-path (append exec-path '("/usr/local/bin")))
;; full screen mode
(add-to-list 'default-frame-alist '(fullscreen . maximized))
;; remove menu bar
(if (fboundp 'menu-bar-mode) (menu-bar-mode -1))
;; remove tool bar
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
;; remove scroll ar
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
;; do not open startup page
(setq inhibit-startup-message t)
;;; mac stuff
(when (memq window-system '(mac ns))
(setq dired-use-ls-dired nil)
;; unset option key as meta
(setq mac-option-key-is-meta nil)
;; set command as meta
(setq mac-command-key-is-meta t)
;; set meta as command modifier
(setq mac-command-modifier 'meta)
;; unset option key
(setq mac-option-modifier nil)
(setq default-directory "~/")
(setq shell-file-name "zsh")
(setenv "ESHELL" "/bin/zsh")
(setq command-line-default-directory "~/"))
;; use y or n
(fset 'yes-or-no-p 'y-or-n-p)
;; set frame title format
(setq-default frame-title-format "%b %f")
;;cColumn beyond which automatic line-wrapping should happen
(setq-default fill-column 80)
;; highlight parens
(show-paren-mode t)
;; highlight current line
(global-hl-line-mode t)
;; require final newline
(setq-default require-final-newline t mode-require-final-newline t )
;; use subword mode
(global-subword-mode 1)
;; display column number in the mode line
(column-number-mode t)
;;(visual-line-mode t)
;; follow links to files under version control
(setq vc-follow-symlinks t)
; empty scratch
(setq initial-scratch-message nil)
;; do not set a ring bell function
(setq ring-bell-function 'ignore)
;; scroll compilation buffer as output appears
(setq compilation-scroll-output t)
;; in continuos mode, advance the page when reaching its edge
(setq doc-view-continuous t)
;; use utf-8 on system messages
(setq locale-coding-system 'utf-8)
(set-language-environment "UTF-8")
(set-default-coding-systems 'utf-8)
;; do not ask for confirmation when openning large files
(setq large-file-warning-threshold nil)
;; do not create lockfiles like xunda.#-emacsa08196
(setq create-lockfiles nil)
;; use clipboard for cutting and pasting
(setq select-enable-clipboard t)
;; save existing clipboard text into kill ring before replacing it
(setq save-interprogram-paste-before-kill t)
;; apropos commands search more extensively
(setq apropos-do-all t)
;; do not use tabs for indentation
(setq-default indent-tabs-mode nil)
;; tab width
(setq-default tab-width 2)
;;; keybindings
;; use shift-arrow to select windows
(windmove-default-keybindings)
;;;;;;;;;;;; TODO: ensure everything below this line runs only once
;;; package management
;; bootstrap straight
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 5))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
;; install use-package
(straight-use-package 'use-package)
(straight-use-package 'el-patch)
;; set default theme
(straight-use-package 'cyberpunk-theme)
(load-theme 'cyberpunk t)
;; set default font
(set-face-attribute 'default nil :font "Fira Code")
;; macos
(when (memq window-system '(mac ns))
(straight-use-package 'exec-path-from-shell)
(exec-path-from-shell-initialize))
;;; common lisp
;; roswell slime helper
(load (expand-file-name "~/.roswell/helper.el"))
;; ;; set roswell as our lisp
(setq inferior-lisp-program "ros -Q run")
;; edit files as sudo
(straight-use-package 'sudo-edit)
;; add docstring to eldoc
(with-eval-after-load 'elisp-mode
(defadvice elisp--get-fnsym-args-string (after add-docstring activate compile)
"Add a 1st line of docstring to ElDoc's function information."
(when ad-return-value
(let* ((doc (elisp--docstring-first-line (documentation (ad-get-arg 0) t)))
(w (frame-width))
(color-doc (propertize doc 'face 'font-lock-comment-face)))
(when (and doc (not (string= doc "")))
(setq ad-return-value (concat ad-return-value " " color-doc))
(when (> (length doc) w)
(setq ad-return-value (substring ad-return-value 0 (1- w))))))
ad-return-value)))
;;; git
;; magit!
(straight-use-package 'magit)
(global-set-key (kbd "C-x g") 'magit-status)
(global-set-key (kbd "C-x M-g") 'magit-dispatch)
;; git gutter
(straight-use-package 'git-gutter)
(global-git-gutter-mode +1)
;; backups
(setq backup-directory-alist `(("." . "~/.emacs.d/saves")))
(setq backup-by-copying t)
(setq delete-old-versions t
kept-new-versions 6
kept-old-versions 2
version-control t)
;; pinentry
(setq epa-pinentry-mode 'loopback)
(put 'erase-buffer 'disabled nil)
;; delete whitespace before saving
(add-hook 'before-save-hook 'delete-trailing-whitespace)
;; yml mode
(straight-use-package 'yaml-mode)
;; projectile
(straight-use-package 'projectile)
(projectile-mode +1)
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)
;; projectile rails
(straight-use-package 'projectile-rails)
(projectile-rails-global-mode)
(define-key projectile-rails-mode-map (kbd "C-c r") 'projectile-rails-command-map)
;; the silver searcher
(straight-use-package 'ag)
(setq ag-highlight-search t)
(setq ag-reuse-window nil)
;; ivy
(straight-use-package 'ivy)
(straight-use-package 'counsel)
(straight-use-package 'smex)
(straight-use-package 'flx)
(ivy-mode 1)
(setq ivy-use-virtual-buffers t)
(setq ivy-count-format "(%d/%d) ")
(setq ivy-format-function 'ivy-format-function-arrow)
(setq enable-recursive-minibuffers t)
(setq ivy-re-builders-alist
'((swiper . ivy--regex-plus)
(counsel-git-grep-function . ivy--regex-plus)
(t . ivy--regex-fuzzy)))
;; (setq ivy-re-builders-alist
;; '((t . ivy--regex-plus)))
(setq projectile-completion-system 'ivy)
(setq magit-completing-read-function 'ivy-completing-read)
;;; ivy-based interface to standard commands
(global-set-key (kbd "C-s") 'swiper-isearch)
(global-set-key (kbd "M-x") 'counsel-M-x)
(global-set-key (kbd "C-x C-f") 'counsel-find-file)
(global-set-key (kbd "M-y") 'counsel-yank-pop)
(global-set-key (kbd "<f1> f") 'counsel-describe-function)
(global-set-key (kbd "<f1> v") 'counsel-describe-variable)
(global-set-key (kbd "<f1> l") 'counsel-find-library)
(global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
(global-set-key (kbd "<f2> u") 'counsel-unicode-char)
(global-set-key (kbd "<f2> j") 'counsel-set-variable)
(global-set-key (kbd "C-x b") 'ivy-switch-buffer)
(global-set-key (kbd "C-c v") 'ivy-push-view)
(global-set-key (kbd "C-c V") 'ivy-pop-view)
;; use ibuffer to list buffers
(global-set-key (kbd "C-x C-b") 'ibuffer)
;; open directory in dired mode
(global-set-key (kbd "C-x C-d") 'dired)
;; search backward using regex
(global-set-key (kbd "C-r") 'isearch-backward-regexp)
;; default isearch functions
(global-set-key (kbd "C-M-s") 'isearch-forward)
(global-set-key (kbd "C-M-r") 'isearch-backward)
;; set <RET> as newline and indent
(global-set-key (kbd "<RET>") 'newline-and-indent)
;; flycheck
(straight-use-package 'flycheck)
(global-flycheck-mode)
(add-hook 'after-init-hook #'global-flycheck-mode)
;; lsp
(straight-use-package 'lsp-mode)
(straight-use-package 'lsp-ui)
(setq lsp-eldoc-render-all t)
(setq lsp-prefer-flymake t)
(add-hook 'lsp-after-open-hook 'lsp-enable-imenu)
(setq lsp-ui-doc-enable nil
lsp-enable-snippet nil
lsp-ui-peek-enable t
lsp-ui-sideline-enable t
lsp-ui-imenu-enable t
lsp-ui-flycheck-enable t)
;; Company mode is a standard completion package that works well with lsp-mode.
(straight-use-package 'company)
;; (straight-use-package 'company-lsp)
(setq company-idle-delay 0)
(setq company-minimum-prefix-length 1)
;; protocol buffers mode
(straight-use-package 'protobuf-mode)
;; go-mode
(straight-use-package 'go-mode)
(setq lsp-gopls-complete-unimported t)
(setq lsp-gopls-staticcheck t)
(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))
(defun custom-go-mode ()
(display-line-numbers-mode 1)
(if (not (string-match "go" compile-command))
(set (make-local-variable 'compile-command)
"go build -v && go test -v && go vet"))
(set (make-local-variable 'compilation-read-command) nil)
(local-set-key (kbd "M-.") 'godef-jump)
(local-set-key (kbd "M-*") 'pop-tag-mark)
(local-set-key (kbd "M-p") 'compile)
(local-set-key (kbd "M-p") 'recompile)
(local-set-key (kbd "M-]") 'next-error)
(local-set-key (kbd "M-[") 'previous-error))
(add-hook 'go-mode-hook 'custom-go-mode)
(add-hook 'go-mode-hook #'lsp-go-install-save-hooks)
(add-hook 'go-mode-hook #'lsp-deferred)
;; python
(straight-use-package 'lsp-python-ms)
(straight-use-package 'pyvenv)
(straight-use-package 'py-autopep8)
(straight-use-package 'pyenv-mode)
(setq py-autopep8-options '("--max-line-length=120"))
(setq lsp-pyls-plugins-flake8-enabled t)
(setq lsp-python-ms-auto-install-server t)
(add-hook 'python-mode-hook #'lsp) ;
(pyenv-mode)
;;; org mode
(setq org-replace-disputed-keys t)
(define-key global-map "\C-cl" 'org-store-link)
(define-key global-map "\C-ca" 'org-agenda)
(setq org-log-done t)
;; http client source block
(straight-use-package 'ob-http)
;; edit source blocks in other window
(setq org-src-window-setup 'other-window)
;; define babel languages
(org-babel-do-load-languages
'org-babel-load-languages
'((lisp . t)
(python . t)
(http . t)))
;; expands snippets to structures defined in org-structure-template-alist and org-tempo-keywords-alist
(require 'org-tempo)
;; recent files
(setq recentf-save-file (concat user-emacs-directory ".recentf"))
(setq recentf-max-menu-items 40)
(recentf-mode 1)
(run-at-time nil (* 5 60) 'recentf-save-list)
;; delete duplicates in history
(setq history-delete-duplicates t)
;; set how to createunique buffer bnames
(setq uniquify-buffer-name-style 'forward)
;; web mode
(straight-use-package 'web-mode)
(add-to-list 'auto-mode-alist '("\\.jsx?$" . web-mode)) ;; auto-enable for .js/.jsx files
(setq web-mode-content-types-alist '(("jsx" . "\\.js[x]?\\'")))
(defun web-mode-init-hook ()
"Hooks for Web mode. Adjust indent."
(setq web-mode-markup-indent-offset 4)
(setq web-mode-code-indent-offset 2))
(add-hook 'web-mode-hook 'web-mode-init-hook)
(setq-default flycheck-disabled-checkers
(append flycheck-disabled-checkers
'(javascript-jshint json-jsonlist)))
;; Enable eslint checker for web-mode
(flycheck-add-mode 'javascript-eslint 'web-mode)
;; Enable flycheck globally
(straight-use-package 'add-node-modules-path)
(add-hook 'flycheck-mode-hook 'add-node-modules-path)
(straight-use-package 'prettier-js)
(defun web-mode-init-prettier-hook ()
(add-node-modules-path)
(prettier-js-mode))
(add-hook 'web-mode-hook 'web-mode-init-prettier-hook)
;; docker
(straight-use-package 'docker)
(global-set-key (kbd "C-c d") 'docker)
;; kubernetes
(straight-use-package 'kubernetes)
(global-set-key (kbd "C-c k") 'kubernetes-overview)
;; persistent scratch
(straight-use-package 'persistent-scratch)
(persistent-scratch-setup-default)
;; http client
(straight-use-package 'request)
;; api blueprint
(straight-use-package 'apib-mode)
(add-to-list 'auto-mode-alist '("\\.apib\\'" . apib-mode))
(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
'("e9d47d6d41e42a8313c81995a60b2af6588e9f01a1cf19ca42669a7ffd5c2fde" "ce784eb8135893a19e5553ed94cc694320b05228ce712a64b2fb69c0c54161b9" default)))
(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.
)
;; add port option to postgres client
(setq sql-postgres-login-params
'((user :default "nathan.thiesen")
(database :default "user-service")
(server :default "localhost")
(port :default 5432)))
;; csv mode
(straight-use-package 'csv-mode)
(put 'upcase-region 'disabled nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment