Created
March 14, 2015 22:50
-
-
Save diiq/9594a8da596ac2e6b42b 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
(if (fboundp 'menu-bar-mode) (menu-bar-mode -1)) | |
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1)) | |
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1)) | |
(setq inhibit-startup-message t) | |
(setq site-lisp-dir | |
(expand-file-name "site-lisp" user-emacs-directory)) | |
;; Set up load path | |
;; (add-to-list 'load-path user-emacs-directory) | |
(add-to-list 'load-path site-lisp-dir) | |
;; Settings for currently logged in user | |
(setq user-settings-dir | |
(concat user-emacs-directory "users/" user-login-name)) | |
(add-to-list 'load-path user-settings-dir) | |
;; Add external projects to load path | |
(dolist (project (directory-files site-lisp-dir t "\\w+")) | |
(when (file-directory-p project) | |
(add-to-list 'load-path project))) | |
;; Write backup files to own directory | |
(setq backup-directory-alist | |
`(("." . ,(expand-file-name | |
(concat user-emacs-directory "backups"))))) | |
;; Make backups of files, even when they're in version control | |
(setq vc-make-backup-files t) | |
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/") | |
("marmalade" . "http://marmalade-repo.org/packages/") | |
("melpa" . "http://melpa.milkbox.net/packages/"))) | |
;; Are we on a mac? | |
(setq is-mac (equal system-type 'darwin)) | |
;; Setup packages | |
(require 'setup-package) | |
;; Install extensions if they're missing | |
(defun init--install-packages () | |
(packages-install | |
'(magit | |
paredit | |
move-text | |
gist | |
htmlize | |
visual-regexp | |
flycheck | |
css-eldoc | |
smartparens | |
ido-vertical-mode | |
ido-at-point | |
simple-httpd | |
guide-key | |
nodejs-repl | |
restclient | |
highlight-escape-sequences | |
whitespace-cleanup-mode | |
elisp-slime-nav | |
git-commit-mode | |
gitconfig-mode | |
gitignore-mode | |
clojure-mode | |
prodigy | |
jump-char | |
key-chord | |
expand-region | |
ace-jump-mode | |
multiple-cursors | |
workgroups2 | |
python-mode | |
projectile | |
flx | |
flx-ido | |
dash | |
dash-functional | |
evil | |
))) | |
(condition-case nil | |
(init--install-packages) | |
(error | |
(package-refresh-contents) | |
(init--install-packages))) | |
(require 'server) | |
(unless (server-running-p) | |
(server-start)) | |
(add-to-list 'default-frame-alist '(font . "-*-Anonymous Pro-normal-normal-normal-*-14-*-*-*-m-0-iso10646-1" )) | |
;(require 'smart-forward) | |
;(require 'change-inner) | |
;(require 'multifiles) | |
; Revert files with no diff on brnach change, etc. | |
(global-auto-revert-mode 1) | |
(defun ask-user-about-supersession-threat (filename)) | |
(defalias 'yes-or-no-p 'y-or-n-p) | |
;;;-------------------------- FORMATTING --------------------------------;;; | |
; Join battle on the side of spaces, 4 each^H^H^H^^H^H^H 2. | |
(setq-default indent-tabs-mode nil) | |
(setq indent-tabs-mode nil) | |
(setq tab-width 2) | |
(setq default-tab-width 2) | |
(setq-default tab-width 2) ; No really, I mean it. 2 | |
(add-hook 'before-save-hook 'delete-trailing-whitespace) | |
(setq c-site-default-style "k&r") | |
(setq c-basic-offset 2) ; Emacs k&r is 5-space? I really mean it, emacs. 2. | |
;;;------------------------ LANGUAGE MODES ------------------------------;;; | |
; Good js mode | |
(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode)) | |
;; My own replacement to two column mode | |
;; (load "~/.emacs.d/multi-column-mode/multi-column-mode.el") | |
;; (global-set-key (kbd "<f2>") 'multi-column-mode) | |
; Python mode | |
(setq py-shell-name "ipython") | |
(setq python-remove-cwd-from-path nil) | |
; For long-distance editing. | |
(require 'tramp) | |
(setq tramp-default-method "scp") | |
(setq js2-auto-indent-flag nil) | |
;;;------------------------ UTILITY FUNCTIONS ---------------------------;;; | |
(defun revert-buffer-keep-undo (&rest -) | |
"revert buffer but keep undo history." | |
(interactive) | |
(let ((inhibit-read-only t)) | |
(erase-buffer) | |
(insert-file-contents (buffer-file-name)) | |
(set-visited-file-modtime (visited-file-modtime)) | |
(set-buffer-modified-p nil))) | |
(setq revert-buffer-function 'revert-buffer-keep-undo) | |
; anti-m-q | |
(defun unfill-region () | |
(interactive) | |
(let ((fill-column (point-max))) | |
(fill-region (region-beginning) (region-end) nil))) | |
; c-a: move to beginning of line +- indentation | |
(defun smart-beginning-of-line () | |
"smart beginning of line goes first to char 0, then to end of indentation." | |
(interactive) | |
(let ((oldpos (point))) | |
(beginning-of-line) | |
(and (= oldpos (point)) | |
(back-to-indentation)))) | |
; emacs' default definition of word-boundaries is not ideal. | |
; these function make it better. | |
(defun move-forward-word () | |
(interactive) | |
(cond ((string-match "\s" (string (char-after))) | |
(if (re-search-forward "[^\s]" (point-max) t) | |
(goto-char (- (point) 1)) | |
(goto-char (point-max)))) | |
((string-match "[^a-z0-9]" (string (char-after))) | |
(goto-char (+ (point) 1))) | |
(t | |
(if (re-search-forward "[^a-z0-9]" (point-max) t) | |
(goto-char (- (point) 1)) | |
(goto-char (point-max)))))) | |
(defun move-backward-word () | |
(interactive) | |
(cond ((string-match "\s" (string (char-before))) | |
(if (re-search-backward "[^\s]" 0 t) | |
(goto-char (+ (point) 1)) | |
(goto-char (point-min)))) | |
((string-match "[^a-z0-9]" (string (char-before))) | |
(goto-char (- (point) 1))) | |
(t | |
(if (re-search-backward "[^a-z0-9]" 0 t) | |
(goto-char (+ (point) 1)) | |
(goto-char (point-min)))))) | |
(defun kill-forward-word () | |
(interactive) | |
(save-excursion | |
(let ((prev (point))) | |
(move-forward-word) | |
(kill-region prev (point))))) | |
(defun kill-backward-word () | |
(interactive) | |
(save-excursion | |
(let ((prev (point))) | |
(move-backward-word) | |
(kill-region prev (point))))) | |
; pydoc lookup | |
(defun hohe2-lookup-pydoc () | |
(interactive) | |
(let ((curpoint (point)) (prepoint) (postpoint) (cmd)) | |
(save-excursion | |
(beginning-of-line) | |
(setq prepoint (buffer-substring (point) curpoint))) | |
(save-excursion | |
(end-of-line) | |
(setq postpoint (buffer-substring (point) curpoint))) | |
(if (string-match "[_a-z][_\\.0-9a-z]*$" prepoint) | |
(setq cmd (substring prepoint (match-beginning 0) (match-end 0)))) | |
(if (string-match "^[_0-9a-z]*" postpoint) | |
(setq cmd (concat cmd (substring postpoint (match-beginning 0) (match-end 0))))) | |
(if (string= cmd "") nil | |
(let ((max-mini-window-height 0)) | |
(shell-command (concat "pydoc " cmd)))))) | |
(add-hook 'python-mode-hook | |
(lambda () (local-set-key (kbd "C-c p") 'hohe2-lookup-pydoc))) | |
(add-to-list 'load-path "~/.emacs.d/css-sort/") | |
(require 'css-sort) | |
(with-eval-after-load "scss-mode" | |
(define-key scss-mode-map (kbd "C-c C-s") 'css-sort-attributes)) | |
(defun insert-lambda () | |
(interactive) | |
(insert-char ?λ)) | |
(defun insert-left-arrow () | |
(interactive) | |
(insert-char ?⇒)) | |
;;;--------------------- inteRFACE, MOTION ------------------------;;; | |
(setq ring-bell-function 'ignore) | |
; de-chroming | |
(set-fill-column 80) | |
(setq inhibit-startup-message t) | |
(tool-bar-mode -1) | |
(menu-bar-mode -1) | |
(scroll-bar-mode -1) | |
; super cool buffer switching. | |
(iswitchb-mode t) | |
; workgroups saves a working setup. | |
(require 'workgroups2) | |
(setq wg-prefix-key (kbd "C-v")) | |
(setq wg-morph-on nil) | |
(require 'flx-ido) | |
(flx-ido-mode 1) | |
;; disable ido faces to see flx highlights. | |
(setq ido-use-faces nil) | |
(projectile-global-mode) | |
(setq mouse-wheel-scroll-amount '(2 ((shift) . 2))) | |
(setq mouse-wheel-progressive-speed nil) | |
;ace-jump-mode, only lower case keys | |
;(setq ace-jump-mode-move-keys (loop for i from ?a to ?z collect i)) | |
; jump char is like vim's f. | |
(require 'jump-char) | |
(define-key jump-char-isearch-map (kbd "<f18>") #'jump-char-switch-to-ace) | |
;;;-------------------------- COLOR THEMES ---------------------------;;; | |
(setq my-color-themes (list 'wheatgrass | |
'tango-dark | |
'dichromacy)) | |
(defun my-theme-cycle () | |
(interactive) | |
(disable-theme (car theme-current)) | |
(setq theme-current (cdr theme-current)) | |
(if (null theme-current) | |
(setq theme-current my-color-themes)) | |
(load-theme (car theme-current)) | |
(message "%S" (car theme-current))) | |
(setq theme-current my-color-themes) | |
(my-theme-cycle) | |
;;;-------------------------- KEYBINDINGS ----------------------------;;; | |
; Key chord allows for keybindings such as zx and ;;. | |
(require 'key-chord) | |
(key-chord-mode 1) | |
(defvar my-keys-minor-mode-map (make-keymap) "my-keys-minor-mode keymap.") | |
(key-chord-define my-keys-minor-mode-map "jk" 'global-fingers-mode) | |
(define-key my-keys-minor-mode-map (kbd "<f12>") 'my-theme-cycle) | |
(define-key my-keys-minor-mode-map (kbd "s-p") 'projectile-find-file) | |
(key-chord-define my-keys-minor-mode-map "zx" 'magit-status) | |
(define-key my-keys-minor-mode-map (kbd "s-8") 'comment-dwim) ; C-c c comments | |
(define-key my-keys-minor-mode-map (kbd "<s-return>") 'delete-backward-char) | |
(define-key my-keys-minor-mode-map (kbd "<S-M-return>") 'delete-forward-char) | |
(define-key my-keys-minor-mode-map (kbd "<s-M-return>") 'kill-backward-word) | |
(define-key my-keys-minor-mode-map (kbd "<S-s-M-return>") 'kill-forward-word) | |
(define-key my-keys-minor-mode-map (kbd "C-a") 'smart-beginning-of-line) | |
(define-key my-keys-minor-mode-map (kbd "s-;") 'undo) | |
(key-chord-define my-keys-minor-mode-map ":\"" 'ace-jump-mode) | |
(key-chord-define my-keys-minor-mode-map ";;" 'jump-char-backward) | |
(define-key my-keys-minor-mode-map (kbd "<f18>") 'jump-char-forward) | |
(define-key my-keys-minor-mode-map (kbd "C-=") 'er/expand-region) | |
(define-key my-keys-minor-mode-map (kbd "C-S-SPC") 'set-rectangular-region-anchor) | |
(define-key my-keys-minor-mode-map (kbd "C-+") 'mc/mark-next-like-this) | |
(keyboard-translate ?\C-i ?\H-i) ; tab is C-i; differentiate the two. | |
(define-key my-keys-minor-mode-map (kbd "C-;") 'next-line) | |
(define-key my-keys-minor-mode-map (kbd "C-p") 'previous-line) | |
(define-key my-keys-minor-mode-map (kbd "C-'") 'forward-char) | |
(define-key my-keys-minor-mode-map (kbd "C-l") 'backward-char) | |
(define-key my-keys-minor-mode-map (kbd "M-;") 'forward-paragraph) | |
(define-key my-keys-minor-mode-map (kbd "M-p") 'backward-paragraph) | |
(define-key my-keys-minor-mode-map (kbd "M-'") 'move-forward-word) | |
(define-key my-keys-minor-mode-map (kbd "M-l") 'move-backward-word) | |
(define-key my-keys-minor-mode-map (kbd "C-f") 'kill-line) | |
(define-key my-keys-minor-mode-map (kbd "s-x") 'ignore) | |
(define-key my-keys-minor-mode-map (kbd "C-S-<return>") 'kill-backward-word) | |
(define-key my-keys-minor-mode-map (kbd "M-S-<return>") 'kill-forward-word) | |
(define-key my-keys-minor-mode-map (kbd "C-M-<return>") 'kill-forward-word) | |
(define-key my-keys-minor-mode-map (kbd "s-l") 'insert-lambda) | |
(define-key my-keys-minor-mode-map (kbd "s-b") 'insert-left-arrow) | |
(define-minor-mode my-keys-minor-mode | |
"A minor mode so that my key settings override annoying major modes." | |
t " my-keys" 'my-keys-minor-mode-map) | |
(my-keys-minor-mode 1) | |
(defvar no-easy-keys-minor-mode-map (make-keymap) | |
"no-easy-keys-minor-mode keymap.") | |
(let ((f (lambda (m) | |
`(lambda () (interactive) | |
(message (concat "No! use " ,m " instead.")))))) | |
(dolist (l '(("<delete>" . "C-d") ("<C-delete>" . "M-d") | |
("<M-delete>" . "M-d") ("<next>" . "C-v") ("<C-next>" . "M-x <") | |
("<prior>" . "M-v") ("<C-prior>" . "M-x >"))) | |
(define-key no-easy-keys-minor-mode-map | |
(read-kbd-macro (car l)) (funcall f (cdr l))))) | |
(define-minor-mode no-easy-keys-minor-mode | |
"A minor mode that disables the arrow-keys, pg-up/down, delete | |
and backspace. | |
Use 'M-x no-easy-keys' to toggle this mode in all buffers except | |
the minibuffer. | |
Add (no-easy-keys-minor-mode 1) to your .emacs to enable no-easy-keys by | |
default." | |
nil nil 'no-easy-keys-minor-mode-map :global 't) | |
(no-easy-keys-minor-mode 1) | |
(electric-indent-mode -1) | |
;;;---------------------------- AUTO-CUSTOMIZE STUFF ---------------------------;;; | |
;Saves a keyboard macro by inserting it in this file | |
(defun save-macro (name) | |
"save a macro. Take a name as argument and save the last | |
defined macro under this name at the end of your .emacs" | |
(interactive "Name of the macro:") ; ask for the name of the macro | |
(kmacro-name-last-macro name) ; use this name for the macro | |
(find-file (user-init-file)) ; open ~/.emacs or other user init file | |
(goto-char (point-max)) ; go to the end of the .emacs | |
(newline) ; insert a newline | |
(insert-kbd-macro name) ; copy the macro | |
(newline) ; insert a newline | |
(switch-to-buffer nil)) ; return to the initial buffer | |
; AUTO BEYOND THIS POINT | |
; Narrow buffer with C-x n n; widen is C-x n w | |
(put 'narrow-to-region 'disabled nil) | |
(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-enabled-themes (quote (dichromacy))) | |
'(js2-basic-offset 2) | |
'(js2-bounce-indent-p t) | |
'(js2-cleanup-whitespace t) | |
'(js2-mirror-mode nil) | |
'(js2-mode-indent-ignore-first-tab t) | |
'(jump-char-backward-key ";") | |
'(jump-char-forward-key "nil") | |
'(magit-restore-window-configuration t) | |
'(menu-bar-mode nil) | |
'(py-beep-if-tab-change nil) | |
'(py-fontify-shell-buffer-p t) | |
'(py-match-paren-mode t) | |
'(py-sexp-function (quote py-end-of-expression)) | |
'(py-shell-name "ipython" t) | |
'(py-split-windows-on-execute-function (quote split-window-horizontally)) | |
'(py-split-windows-on-execute-p t) | |
'(python-python-command "python") | |
'(scss-compile-at-save nil) | |
'(scss-output-directory "../../static/css/") | |
'(sentence-end-double-space nil) | |
'(tool-bar-mode nil)) | |
(put 'upcase-region 'disabled 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. | |
) | |
(workgroups-mode 1) | |
(put 'downcase-region 'disabled nil) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment