diff options
Diffstat (limited to 'init')
-rw-r--r-- | init/bindings.el | 75 | ||||
-rw-r--r-- | init/custom.el | 29 | ||||
-rw-r--r-- | init/eshell-setup.el | 92 | ||||
-rw-r--r-- | init/functions.el | 102 | ||||
-rw-r--r-- | init/misc.el | 9 | ||||
-rw-r--r-- | init/modes.el | 80 | ||||
-rw-r--r-- | init/settings.el | 243 |
7 files changed, 630 insertions, 0 deletions
diff --git a/init/bindings.el b/init/bindings.el new file mode 100644 index 000000000000..d29081d1720b --- /dev/null +++ b/init/bindings.el @@ -0,0 +1,75 @@ +;; Various keybindings, most of them taken from starter-kit-bindings + +;; Font size +(define-key global-map (kbd "C-+") 'text-scale-increase) +(define-key global-map (kbd "C--") 'text-scale-decrease) + +;; Use regex searches by default. +(global-set-key (kbd "C-s") 'isearch-forward-regexp) +(global-set-key (kbd "\C-r") 'isearch-backward-regexp) +(global-set-key (kbd "M-%") 'query-replace-regexp) +(global-set-key (kbd "C-M-s") 'isearch-forward) +(global-set-key (kbd "C-M-r") 'isearch-backward) +(global-set-key (kbd "C-M-%") 'query-replace) + +;; Jump to a definition in the current file. (Protip: this is awesome.) +(global-set-key (kbd "C-x C-i") 'imenu) + +;; Ace-jump-mode +(global-set-key (kbd "M-j") 'ace-jump-word-mode) + +;; Jump to next occurence of char +(global-set-key (kbd "C-c f") 'iy-go-to-char) + +;; Window switching. (C-x o goes to the next window) +(windmove-default-keybindings) ;; Shift+direction + +;; Start eshell or switch to it if it's active. +(global-set-key (kbd "C-x m") 'eshell) + +;; Start a new eshell even if one is active. +(global-set-key (kbd "C-x M") (lambda () (interactive) (eshell t))) + +;; Eval sexp and replace it with result +(global-set-key (kbd "C-c e") 'esk-eval-and-replace) + +;; Start a regular shell if you prefer that. +(global-set-key (kbd "C-x C-m") 'shell) + +;; So good! +(global-set-key (kbd "C-c g") 'magit-status) + +;; Open project drawer +(global-set-key (kbd "M-p") 'project-explorer-open) + +;; Add a fullscreen toggle - TODO: reenable in next Emacs release +; (global-set-key (kbd "M-RET") 'toggle-frame-fullscreen) + +;; Replace standard goto-line with goto-line-with-feedback +(global-set-key (kbd "M-g g") 'goto-line-with-feedback) + +;; Goodness from @magnars +;; I don't need to kill emacs that easily +;; the mnemonic is C-x REALLY QUIT +(global-set-key (kbd "C-x r q") 'save-buffers-kill-terminal) +(global-set-key (kbd "C-x C-c") 'delete-frame) + +;; Create new frame +(define-key global-map (kbd "C-x C-n") 'make-frame-command) + +;; Cider/nrepl stuff +;; I want history up/down without modifiers +(define-key cider-repl-mode-map (kbd "<up>") 'cider-repl-backward-input) +(define-key cider-repl-mode-map (kbd "<down>") 'cider-repl-forward-input) +(define-key cider-repl-mode-map (kbd "C-<up>") 'previous-line) +(define-key cider-repl-mode-map (kbd "C-<down>") 'next-line) + +;; ... and ac-cider with C-c C-d +(define-key cider-repl-mode-map (kbd "C-c C-d") 'ac-cider-compliment-popup-doc) +(define-key cider-mode-map (kbd "C-c C-d") 'ac-cider-compliment-popup-doc) +(define-key cider-mode-map (kbd "C-c D") 'cider-doc) + +;; Org-mode agenda keys +(global-set-key (kbd "C-c a") 'org-agenda) + +(provide 'bindings) diff --git a/init/custom.el b/init/custom.el new file mode 100644 index 000000000000..18af68c890e0 --- /dev/null +++ b/init/custom.el @@ -0,0 +1,29 @@ +(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. + '(ac-auto-show-menu 0.8) + '(ac-delay 0.2) + '(custom-safe-themes (quote ("6a37be365d1d95fad2f4d185e51928c789ef7a4ccf17e7ca13ad63a8bf5b922f" "6e92ca53a22d9b0577ad0b16e07e2e020c8b621197e39fec454048e51b7954cb" default))) + '(frame-brackground-mode (quote dark)) + '(global-auto-complete-mode t) + '(magit-log-show-gpg-status t) + '(ns-alternate-modifier (quote none)) + '(ns-command-modifier (quote meta)) + '(org-agenda-files (quote ("~/source/spotify-puppet/modules/jira/TODO.org"))) + '(require-final-newline (quote visit-save))) +(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. + '(rainbow-delimiters-depth-1-face ((t (:foreground "#2aa198")))) + '(rainbow-delimiters-depth-2-face ((t (:foreground "#b58900")))) + '(rainbow-delimiters-depth-3-face ((t (:foreground "#268bd2")))) + '(rainbow-delimiters-depth-4-face ((t (:foreground "#dc322f")))) + '(rainbow-delimiters-depth-5-face ((t (:foreground "#859900")))) + '(rainbow-delimiters-depth-6-face ((t (:foreground "#268bd2")))) + '(rainbow-delimiters-depth-7-face ((t (:foreground "#cb4b16")))) + '(rainbow-delimiters-depth-8-face ((t (:foreground "#d33682")))) + '(rainbow-delimiters-depth-9-face ((t (:foreground "#839496"))))) diff --git a/init/eshell-setup.el b/init/eshell-setup.el new file mode 100644 index 000000000000..43b1c16b33d6 --- /dev/null +++ b/init/eshell-setup.el @@ -0,0 +1,92 @@ +;; EShell configuration + +(require 'eshell) + +;; Generic settings +;; Hide banner message ... +(setq eshell-banner-message "") + +(defun eshell-mode-hook-setup () + "Sets up EShell when it is loaded" + (setq eshell-path-env (concat + "/usr/local/bin:" + (concat home-dir "/bin:") + "/usr/local/share/python:" + "/opt/java/bin" + eshell-path-env)) + + (setenv "PATH" eshell-path-env)) + +(add-hook 'eshell-mode-hook 'eshell-mode-hook-setup) + +;; Prompt configuration + +(defun clean-pwd (path) + "Turns a path of the form /foo/bar/baz into /f/b/baz + (inspired by fish shell)" + (let* ((hpath (replace-regexp-in-string home-dir + "~" + path)) + (current-dir (split-string hpath "/")) + (cdir (last current-dir)) + (head (butlast current-dir))) + (concat (mapconcat (lambda (s) + (if (string= "" s) nil + (substring s 0 1))) + head + "/") + (if head "/" nil) + (car cdir)))) + +(defun vcprompt (&optional args) + "Call the external vcprompt command with optional arguments. + VCPrompt" + (replace-regexp-in-string + "\n" "" + (shell-command-to-string (concat "vcprompt" args)))) + +(defmacro with-face (str &rest properties) + `(propertize ,str 'face (list ,@properties))) + +(defun prompt-f () + "My EShell prompt displaying VC info and such" + (concat + (with-face (concat (clean-pwd (eshell/pwd)) " ") :foreground "#96a6c8") + ;(with-face (vcprompt " -f \"(%s:%b%a%m) \"") :foreground "#5f627f") + (if (= 0 (user-uid)) + (with-face "#" :foreground "#f43841") + (with-face "$" :foreground "#73c936")) + (with-face " " :foreground "#95a99f"))) + + +(setq eshell-prompt-function 'prompt-f) +(setq eshell-highlight-prompt nil) +(setq eshell-prompt-regexp "^.+? \\((\\(git\\|svn\\|hg\\|darcs\\|cvs\\|bzr\\):.+?) \\)?[$#] ") + +;; Ignore version control folders in autocompletion +(setq eshell-cmpl-cycle-completions nil + eshell-save-history-on-exit t + eshell-cmpl-dir-ignore "\\`\\(\\.\\.?\\|CVS\\|\\.svn\\|\\.git\\)/\\'") + +;; Load some EShell extensions +(eval-after-load 'esh-opt + '(progn + (require 'em-term) + (require 'em-cmpl) + ;; More visual commands! + (add-to-list 'eshell-visual-commands "ssh") + (add-to-list 'eshell-visual-commands "tail") + (add-to-list 'eshell-visual-commands "sl"))) + +(setq eshell-directory-name "~/.config/eshell/") + +;; EShell functions that come in handy + +;; clear in eshell +(defun eshell/clear () + "clear the eshell buffer." + (interactive) + (let ((inhibit-read-only t)) + (erase-buffer))) + +(provide 'eshell-setup) diff --git a/init/functions.el b/init/functions.el new file mode 100644 index 000000000000..e26e1f1bea62 --- /dev/null +++ b/init/functions.el @@ -0,0 +1,102 @@ +;; A few handy functions I use in init.el (or not, but they're nice to +;; have) + +(defun custom-download-theme (url filename) + "Downloads a theme through HTTP and places it in ~/.emacs.d/themes" + + ;; Ensure the directory exists + (unless (file-exists-p "~/.emacs.d/themes") + (make-directory "~/.emacs.d/themes")) + + ;; Adds the themes folder to the theme load path (if not already + ;; there) + (unless (member "~/.emacs.d/themes" custom-theme-load-path) + (add-to-list 'custom-theme-load-path "~/.emacs.d/themes")) + + ;; Download file if it doesn't exist. + + (let ((file + (concat "~/.emacs.d/themes/" filename))) + (unless (file-exists-p file) + (url-copy-file url file)))) + +(defun custom-download-script (url filename) + "Downloads an Elisp script, places it in ~/.emacs/other and then loads it" + + ;; Ensure the directory exists + (unless (file-exists-p "~/.emacs.d/other") + (make-directory "~/.emacs.d/other")) + + ;; Download file if it doesn't exist. + (let ((file + (concat "~/.emacs.d/other/" filename))) + (unless (file-exists-p file) + (url-copy-file url file)) + + (load file))) + +(defun keychain-password (account &optional keychain) + "Returns the password for the account, by default it's looked up in the Login.keychain but a + different keychain can be specified." + (let ((k (if keychain keychain "Login.keychain"))) + (replace-regexp-in-string + "\n" "" + (shell-command-to-string (concat "security find-generic-password -w -a " + account + " " + k))))) + +;; This clones a git repository to 'foldername in .emacs.d +;; if there isn't already a folder with that name +(defun custom-clone-git (url foldername) + "Clones a git repository to .emacs.d/foldername" + (let ((fullpath (concat "~/.emacs.d/" foldername))) + (unless (file-exists-p fullpath) + (async-shell-command (concat "git clone " url " " fullpath))))) + +(defun load-file-if-exists (filename) + (if (file-exists-p filename) + (load filename))) + +;; These come from magnars, he's got some awesome things. + +(defun goto-line-with-feedback () + "Show line numbers temporarily, while prompting for the line number input" + (interactive) + (unwind-protect + (progn + (linum-mode 1) + (call-interactively 'goto-line)) + (linum-mode -1))) + + +(defun untabify-buffer () + (interactive) + (untabify (point-min) (point-max))) + +(defun indent-buffer () + (interactive) + (indent-region (point-min) (point-max))) + +(defun cleanup-buffer () + "Perform a bunch of operations on the whitespace content of a buffer. +Including indent-buffer, which should not be called automatically on save." + (interactive) + (untabify-buffer) + (delete-trailing-whitespace) + (indent-buffer)) + +;; These come from the emacs starter kit + +(defun esk-add-watchwords () + (font-lock-add-keywords + nil '(("\\<\\(FIX\\(ME\\)?\\|TODO\\|DEBUG\\|HACK\\|REFACTOR\\|NOCOMMIT\\)" + 1 font-lock-warning-face t)))) + +(defun esk-sudo-edit (&optional arg) + (interactive "p") + (if (or arg (not buffer-file-name)) + (find-file (concat "/sudo:root@localhost:" (ido-read-file-name "File: "))) + (find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name)))) + +(provide 'functions) diff --git a/init/misc.el b/init/misc.el new file mode 100644 index 000000000000..940370493007 --- /dev/null +++ b/init/misc.el @@ -0,0 +1,9 @@ +;; For everything that doesn't fit anywhere else. + +;; Ignore .DS_Store files with ido mode +(add-to-list 'ido-ignore-files "\\.DS_Store") + +;; Use aspell for spell checking: brew install aspell --lang=en +(setq ispell-program-name "/usr/local/bin/aspell") + +(provide 'misc) diff --git a/init/modes.el b/init/modes.el new file mode 100644 index 000000000000..a28ece3e57f0 --- /dev/null +++ b/init/modes.el @@ -0,0 +1,80 @@ +(mapc 'require '(projectile ac-cider-compliment cider)) +;; Initializes modes I use. + +(add-hook 'prog-mode-hook 'esk-add-watchwords) +(add-hook 'prog-mode-hook 'idle-highlight-mode) + +;; Configure markdown-mode +(autoload 'markdown-mode "markdown-mode" + "Major mode for editing Markdown files" t) +(add-to-list 'auto-mode-alist '("\\.txt\\'" . markdown-mode)) +(add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode)) +(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode)) + +;; Use auto-complete as completion at point +(defun set-auto-complete-as-completion-at-point-function () + (setq completion-at-point-functions '(auto-complete))) + +(add-hook 'auto-complete-mode-hook + 'set-auto-complete-as-completion-at-point-function) + +;; Configure CIDER (Clojure REPL) and clojure-mode + +(defun cider-mode-setup () + "Activates paredit, rainbow delimiters and ac-nrepl" + (ac-cider-compliment-setup) + (ac-flyspell-workaround) + (paredit-mode)) + +(eval-after-load "auto-complete" + '(add-to-list 'ac-modes cider-mode)) + +(add-hook 'cider-repl-mode-hook 'cider-mode-setup) +(add-hook 'cider-interaction-mode-hook 'cider-mode-setup) +(eval-after-load "auto-complete" + '(add-to-list 'ac-modes 'cider-repl-mode)) + +;; Paredit in clojure +(add-hook 'clojure-mode-hook 'paredit-mode) + +;; eldoc in clojure +(add-hook 'cider-interaction-mode-hook + 'cider-turn-on-eldoc-mode) + +;; Don't annoy me +(setq cider-hide-special-buffers t) +(setq cider-popup-stacktraces nil) +(setq cider-repl-pop-to-buffer-on-connect nil) +(setq cider-repl-popup-stacktraces t) + +;; Enable projectile for all things programming +(add-hook 'prog-mode-hook 'projectile-mode) + +;; Enable rainbow-delimiters for all things programming +(add-hook 'prog-mode-hook 'rainbow-delimiters-mode) + +;; Enable Paredit in Emacs Lisp mode +(add-hook 'emacs-lisp-mode-hook 'paredit-mode) + +;; Configure Haskell mode +;; Indentation ... +(add-hook 'haskell-mode-hook 'hi2-mode) + +;; Always highlight matching brackets +(show-paren-mode 1) + +;; Represent undo-history as an actual tree (visualize with C-x u) +(setq undo-tree-mode-lighter "") +(require 'undo-tree) +(global-undo-tree-mode) + +;; Keep track of recent files +(recentf-mode) + +;; Easily navigate sillycased words +(global-subword-mode 1) + +;; Transparently open compressed files +(auto-compression-mode t) + +(provide 'modes) diff --git a/init/settings.el b/init/settings.el new file mode 100644 index 000000000000..8d1b7fbace5b --- /dev/null +++ b/init/settings.el @@ -0,0 +1,243 @@ +(require 'uniquify) +(require 'smart-mode-line) + +; ## Generic settings ## + +; Hide those ugly tool bars +(tool-bar-mode 0) +(scroll-bar-mode 0) + +(defun disable-scroll-bar () + (scroll-bar-mode 0)) + +; And remember to do it if I create a new frame. +(add-hook 'before-make-frame-hook 'disable-scroll-bar) + +;; Don't make any noises, don't flash, just leave me alone +(setq ring-bell-function 'ignore) + +;; Go away go away +(setq initial-scratch-message "") + +(flx-ido-mode 1) +(setq ido-use-faces nil) +(setq gc-cons-threshold 20000000) + +(setq uniquify-buffer-name-style 'forward) + +;;; Code: + +(add-to-list 'exec-path "/usr/local/bin") +(add-to-list 'exec-path (expand-file-name "~/bin")) + + +(when window-system + (setq frame-title-format '(buffer-file-name "%f" ("%b"))) + (tooltip-mode -1) + (mouse-wheel-mode t) + (blink-cursor-mode -1)) + +; Fix some defaults +(setq visible-bell nil + inhibit-startup-message t + color-theme-is-global t + sentence-end-double-space nil + shift-select-mode nil + mouse-yank-at-point t + uniquify-buffer-name-style 'forward + whitespace-style '(face trailing lines-tail tabs) + whitespace-line-column 80 + default-directory "~" + fill-column 80 + ediff-window-setup-function 'ediff-setup-windows-plain + ediff-diff-options "-w" + ediff-split-window-function 'split-window-horizontally + oddmuse-directory (concat user-emacs-directory "oddmuse") + save-place-file (concat user-emacs-directory "places") + backup-directory-alist `((,(concat user-emacs-directory "backups"))) + diff-switches "-u") + +;; Fix keys on Linux +(if is-linux + (setq x-super-keysym 'meta + x-alt-keysym 'alt)) + +(setq smex-save-file (concat user-emacs-directory ".smex-items")) +(setq smex-key-advice-ignore-menu-bar t) +(smex-initialize) +(global-set-key (kbd "M-x") 'smex) + +(add-to-list 'safe-local-variable-values '(lexical-binding . t)) +(add-to-list 'safe-local-variable-values '(whitespace-line-column . 80)) + +(set-default 'indent-tabs-mode nil) + +;; ido-mode is like magic pixie dust! +(ido-mode t) +(ido-ubiquitous t) +(setq ido-enable-prefix nil + ido-enable-flex-matching t + ido-auto-merge-work-directories-length nil + ido-create-new-buffer 'always + ido-use-filename-at-point 'guess + ido-use-virtual-buffers t + ido-handle-duplicate-virtual-buffers 2 + ido-max-prospects 10) + +;; Swedish! +(set-language-environment 'Swedish) + +;; UTF-8 please +(setq locale-coding-system 'utf-8) ; pretty +(set-terminal-coding-system 'utf-8) ; pretty +(set-keyboard-coding-system 'utf-8) ; pretty +(set-selection-coding-system 'utf-8) ; please +(prefer-coding-system 'utf-8) ; with sugar on top + +(require 'ffap) + +(defalias 'yes-or-no-p 'y-or-n-p) +(defalias 'auto-tail-revert-mode 'tail-mode) + +;; ## Look and feel ## + +;; Themes! I download and install the ones I like and default the one +;; I currently like most. This changes a lot because I hate +;; everything. (It's in my nature, don't judge) +(custom-download-theme + "https://raw.github.com/owainlewis/emacs-color-themes/master/themes/hickey-theme.el" + "hickey-theme.el") + +(custom-download-theme + "https://raw.github.com/rexim/gruber-darker-theme/master/gruber-darker-theme.el" + "gruber-darker-theme.el") + +(load-theme 'gruber-darker t) + +(global-hl-line-mode -1) + +(setq default-frame-alist '((font-backend . "xft") + (font . "Source Code Pro-12"))) + +(set-default-font "Source Code Pro 12") + +;; Don't make the nyan cat too long ... I have other stuff in the mode +;; bar as well! +(set-variable 'nyan-bar-length 15) +;; Not the real deal without this ... +(set-variable 'nyan-wavy-trail t) + +;; Style line numbers (shown with M-g g) +(setq linum-format + (lambda (line) + (propertize + (format (concat " %" + (number-to-string + (length (number-to-string + (line-number-at-pos (point-max))))) + "d ") + line) + 'face 'linum))) + +(eval-after-load 'diff-mode + '(progn + (set-face-foreground 'diff-added "green4") + (set-face-foreground 'diff-removed "red3"))) + +(eval-after-load 'magit + '(progn + (set-face-foreground 'magit-diff-add "green4") + (set-face-foreground 'magit-diff-del "red3"))) + +;; ## Mac specific settings ## + +;; Enable mouse support on OS X +(unless window-system + (require 'mouse) + (xterm-mouse-mode t) + (global-set-key [mouse-4] '(lambda () + (interactive) + (scroll-down 1))) + (global-set-key [mouse-5] '(lambda () + (interactive) + (scroll-up 1))) + (defun track-mouse (e)) + + (setq mouse-sel-mode t) +) + +;; Use clipboard properly +(setq x-select-enable-clipboard t) + +;; Settings for Emacs.app (Cocoa Emacs) +;; Menu bar doesn't take up additional space, so lets use it. +(menu-bar-mode 1) + +;; Auto refresh buffers +(global-auto-revert-mode 1) + +;; Also auto refresh dired, but be quiet about it +(setq global-auto-revert-non-file-buffers t) +(setq auto-revert-verbose nil) + +;; Show keystrokes in progress +(setq echo-keystrokes 0.1) + +;; Move files to trash when deleting +(setq delete-by-moving-to-trash t) + +;; Make emacs behave sanely (overwrite selected text) +(delete-selection-mode 1) + +;; ## Navigation and key bindings ## + +(setq windmove-wrap-around t) + +;; Load ace-jump-mode +(autoload + 'ace-jump-mode + "ace-jump-mode" + "Emacs quick move minor mode" + ) + +(define-key global-map [?] 'ace-jump-mode) + +;; Quick jump back +(autoload + 'ace-jump-mode-pop-mark + "ace-jump-mode" + "Ace jump back:-)" + ) + +(eval-after-load "ace-jump-mode" + '(ace-jump-mode-enable-mark-sync)) +(define-key global-map (kbd "C-x ö") 'ace-jump-mode-pop-mark) + +;; Keep your backup files in tmp, emacs! +(setq backup-directory-alist + `((".*" . ,temporary-file-directory))) +(setq auto-save-file-name-transforms + `((".*" ,temporary-file-directory t))) + +;; Eshell +;; Start/join +(global-set-key (kbd "C-x m") 'eshell) +;; Always start +(global-set-key (kbd "C-x M") (lambda () (interactive) (eshell t))) + +;; Git +(global-set-key (kbd "C-c g") 'magit-status) + +(remove-hook 'kill-buffer-query-functions 'server-kill-buffer-query-function) + +;; Display tabs as 4 spaces +(setq default-tab-width 4) + +;; Set up Java home & path +(setenv "JAVA_HOME" "/usr/lib/jvm/default") + +;; Use CUPS +(setq lpr-command "xpp") + + +(provide 'settings) |