Skip to content

Instantly share code, notes, and snippets.

@slaykovsky slaykovsky/init.el
Created Apr 9, 2018

What would you like to do?
;;; package --- Summary
;;; Commentary:
;;; Use it on your own risk :)
;;; Code:
(setq gc-cons-threshold 64000000)
(add-hook 'after-init-hook #'(lambda () (setq gc-cons-threshold 800000)))
;;; global vars
inhibit-startup-screen t
create-lockfiles nil
make-backup-files nil
column-number-mode t
scroll-error-top-bottom t
use-package-always-ensure t
sentence-end-double-space nil
select-enable-clipboard t
select-enable-primary t
ring-bell-function 'ignore
max-lisp-eval-depth most-positive-fixnum
browse-url-browser-function 'browse-url-chromium
message-kill-buffer-on-exit t
ivy-use-virtual-buffers t
max-specpdl-size most-positive-fixnum)
;;; buffer local variables
indent-tabs-mode nil
show-parn-delay 0.5
tab-width 4
c-basic-offset 4)
;;; package management
(require 'package)
package-archives '(("gnu" . "")
("org" . "")
("melpa" . "")
("melpa-stable" . ""))
package-archive-priorities '(("melpa-stable" . 1)))
(when (not package-archive-contents)
(package-install 'use-package))
(require 'use-package))
(require 'bind-key)
(require 'diminish)
(use-package magit
:bind ("C-c s" . magit-status))
(use-package python-mode)
(use-package dockerfile-mode)
(use-package base16-theme)
(use-package bind-key)
(use-package dash)
(use-package dash-functional)
(use-package company)
(use-package smartparens)
(use-package org)
(use-package popwin)
(use-package s)
(use-package f)
(use-package expand-region)
(use-package markdown-mode+)
(use-package enh-ruby-mode)
(use-package org)
(use-package flycheck)
(use-package yaml-mode)
(use-package counsel)
(use-package ivy)
(use-package swiper)
(use-package rainbow-delimiters)
(use-package aggressive-indent)
(use-package intero)
(use-package anaconda-mode)
(use-package company-anaconda)
(use-package python-docstring)
(use-package py-isort)
(use-package diminish)
(use-package pip-requirements)
(use-package importmagic
:diminish importmagic-mode
(add-hook 'python-mode-hook 'importmagic-mode))
(use-package flycheck
:diminish flycheck-mode
:init (global-flycheck-mode))
(use-package base16-theme)
(use-package autorevert
:init (global-auto-revert-mode))
(require 'smartparens-config)
;;; modes
(remove-hook 'find-file-hooks 'vc-find-file-hook)
(electric-indent-mode 0)
(global-hl-line-mode -1)
(menu-bar-mode -1)
(scroll-bar-mode -1)
(tool-bar-mode -1)
(blink-cursor-mode -1)
(set-default 'truncate-lines t)
(show-paren-mode 't)
(global-visual-line-mode 't)
(global-flycheck-mode 't)
(ivy-mode t)
(desktop-save-mode 1)
(global-auto-revert-mode 1)
;;; global keybindings
(global-unset-key (kbd "C-z"))
(global-set-key (kbd "C-s") 'swiper)
(global-set-key (kbd "M-x") 'counsel-M-x)
(global-set-key (kbd "C-x C-f") 'counsel-find-file)
(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 "C-r") 'isearch-backward-regexp)
(global-set-key (kbd "C-M-s") 'isearch-forward)
(global-set-key (kbd "C-M-r") 'isearch-backward)
(global-set-key (kbd "C-;") 'toggle-comment-on-line)
(global-set-key (kbd "C-#") 'comment-or-uncomment-region)
;;; UI related stuff
(load-theme 'base16-gruvbox-dark-soft t)
(set-frame-font "Monospace 12")
;; Misc
(fset 'yes-or-no-p 'y-or-n-p)
(add-to-list 'auto-mode-alist '("Dockerfile\\'" . dockerfile-mode))
(add-to-list 'auto-mode-alist '("Vagrantfile\\'" . enh-ruby-mode))
;; Python
;; Python
(add-hook 'python-mode-hook 'anaconda-mode)
(add-hook 'python-mode-hook 'anaconda-eldoc-mode)
(add-hook 'python-mode-hook #'smartparens-mode)
(add-hook 'python-mode-hook 'python-docstring-mode)
(add-hook 'before-save-hook 'py-isort-before-save)
(eval-after-load "company"
'(add-to-list 'company-backends 'company-anaconda))
;; Lisps
(defvar lisp-modes "clojure emacs-lisp cider-repl")
(defun standard-lisp-environment ()
"A collection of modes to be enabled for a LISP."
(subword-mode 1)
(smartparens-mode 1)
(rainbow-delimiters-mode 1)
(aggressive-indent-mode 1)
(eldoc-mode 1))
(defun append-suffix (suffix phrases)
"Take SUFFIX and append it to each of the PHRASES."
(mapcar #'(lambda (phrase) (concat phrase suffix)) phrases))
(defun multiple-mode-add-hook (modes hook)
"Given a list of x-mode-hook symbols in MODES, add the HOOK to them."
(mapc (lambda (mode) (add-hook mode hook)) modes))
(defun symbols-from-strings (strings)
"Given a list of STRINGS, get their symbol values."
(mapcar #'intern strings))
(defun hook-up-modes (string hook)
"Using mode string STRING add a hook HOOK to it."
(let ((modes (symbols-from-strings
(append-suffix "-mode-hook" (split-string string)))))
(multiple-mode-add-hook modes hook)))
(hook-up-modes lisp-modes 'standard-lisp-environment)
;;; Custom VERY useful functions ^_^
(defun duplicate-current-line-or-region (arg)
"Duplicates the current line or region ARG times.
if there is no region, the current line will be duplicated.
However, if there's a region, all lines that region covers
will be duplicated"
(interactive "p")
(let (beg end (origin (point)))
(if (and mark-active (> (point) (mark)))
(setq beg (line-beginning-position))
(if mark-active
(setq end (line-end-position))
(if mark-active
(setq end (line-end-position))
(let ((region (buffer-substring-no-properties beg end)))
(dotimes (i arg)
(goto-char end)
(insert region)
(setq end (point)))
(goto-char (+ origin (* (length region) arg) arg)))))
(global-set-key (kbd "M-d") 'duplicate-current-line-or-region)
(defun toggle-comment-on-line ()
"Comments or uncomments current line."
(provide 'init)
;;; init.el ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.