Created
November 7, 2013 05:54
-
-
Save Hardtack/7349691 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
;;;; Base settings | |
;; Platform specific variables | |
(setq windows? (eq system-type 'windows-nt)) | |
(setq mac? (eq system-type 'darwin)) | |
(setq linux? (eq system-type 'gnu/linux)) | |
;; Load path | |
(unless (boundp 'emacs-dir)(setq-default emacs-dir (if windows? | |
(concat (getenv "HOMEPATH") "/Dropbox/Dev/emacs.d") | |
"~/.emacs.d"))) | |
(when windows? (add-to-list 'load-path emacs-dir)) | |
(add-to-list 'load-path (concat emacs-dir "/plugin")) | |
(add-to-list 'custom-theme-load-path (concat emacs-dir "/themes/solarized")) | |
;; Load package | |
(when windows? (setq package-user-dir (concat emacs-dir "/elpa"))) | |
(require 'package) | |
(package-initialize) | |
;;;; Theme | |
;; Solarized | |
(load-theme 'solarized-dark t) | |
(load "fix-color.el") | |
;; Copied from solarized-definitions.el and renamed | |
(defun solarized-find-color (name) | |
(let* ((index (if window-system | |
(if solarized-degrade | |
3 | |
(if solarized-broken-srgb 2 1)) | |
(case (display-color-cells) | |
(16 4) | |
(8 5) | |
(otherwise 3))))) | |
(nth index (assoc name solarized-colors)))) | |
;; Transparency | |
(defun transparency (value) | |
"Sets the transparency of the frame window. 0=transparent/100=opaque" | |
(interactive "nTransparency Value 0 - 100 opaque:") | |
(set-frame-parameter (selected-frame) 'alpha value)) | |
(transparency 100) | |
;; Font | |
(set-face-attribute 'default nil :foreground "white") | |
(set-face-attribute 'default nil :height (if mac? 130 120)) | |
(if (or windows? mac?) | |
(set-face-attribute 'default nil :family (if windows? "Consolas" "Monaco"))) | |
(set-face-attribute 'header-line nil :foreground "white") | |
(set-face-attribute 'menu nil :foreground "white") | |
;; Non-ASCII character font | |
(when windows? (set-fontset-font nil '(#x0100 . #xE0FFF) | |
(font-spec :family "Malgun Gothic"))) | |
(when mac? (set-fontset-font nil '(#x0100 . #xE0FFF) | |
(font-spec :family "Apple SD 산돌고딕 Neo"))) | |
(when linux? (set-fontset-font nil '(#x0100 . #xE0FFF) | |
(font-spec :family "NanumGothic"))) | |
;;;; Platform sepicific settings | |
;; Windows | |
(when windows? | |
(progn | |
;; Key bindings | |
(global-set-key (kbd "C-v") 'yank) | |
;; UTF-8 | |
(shell-command "chcp 65001") | |
(setenv "PYTHONIOENCODING" "utf-8") | |
;; Sets your shell to use cygwin's bash, if Emacs finds it's running | |
;; under Windows and c:\cygwin exists. Assumes that C:\cygwin\bin is | |
;; not already in your Windows Path (it generally should not be). | |
;; | |
(let* ((cygwin-root "c:/cygwin") | |
(cygwin-bin (concat cygwin-root "/bin"))) | |
(when (and (eq 'windows-nt system-type) | |
(file-readable-p cygwin-root)) | |
(setq exec-path (cons cygwin-bin exec-path)) | |
(setenv "PATH" (concat cygwin-bin ";" (getenv "PATH"))) | |
;; By default use the Windows HOME. | |
;; Otherwise, uncomment below to set a HOME | |
;; (setenv "HOME" (concat cygwin-root "/home/eric")) | |
;; NT-emacs assumes a Windows shell. Change to bash. | |
(setq shell-file-name "bash") | |
(setenv "SHELL" shell-file-name) | |
(setq explicit-shell-file-name shell-file-name) | |
;; This removes unsightly ^M characters that would otherwise | |
;; appear in the output of java applications. | |
(add-hook 'comint-output-filter-functions 'comint-strip-ctrl-m))))) | |
;; Mac OS X | |
(when mac? | |
(progn | |
;; Set command key as super | |
(setq mac-command-modifier 'super) | |
;; Share Mac OS X clipboard | |
(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)))) | |
(setq interprogram-cut-function 'paste-to-osx) | |
;; Full screen | |
(defun toggle-fullscreen () | |
"Toggle full screen" | |
(interactive) | |
(set-frame-parameter | |
nil 'fullscreen | |
(when (not (frame-parameter nil 'fullscreen)) 'fullboth))) | |
(global-set-key (kbd "M-RET") 'toggle-fullscreen) | |
;; Env variables | |
(setenv "IDEVICEINSTALLER" "/usr/local/ideviceinstaller/bin/ideviceinstaller") | |
(setenv "PATH" (mapconcat 'identity | |
`(,(getenv "PATH") | |
"/usr/local/bin:~/Development/bin" | |
"/Library/Frameworks/Python.framework/Versions/2.7/bin") ":")) | |
(mapc (lambda (x) (add-to-list 'exec-path x)) (split-string (getenv "PATH") ":")))) | |
;; Linux | |
(when linux? | |
(defun set-frame-menu-bar-lines (frame) | |
(let ((want-menu (memq (framep frame) '(x w32 ns)))) | |
(set-frame-parameter frame 'menu-bar-lines (if want-menu 1 0)))) | |
(add-hook 'after-make-frame-functions 'set-frame-menu-bar-lines) | |
;; Android | |
(let ((android-home "/usr/local/android-sdk-linux") | |
(android-ndk-home "/usr/local/android-ndk")) | |
(setenv "ANDROID_HOME" android-home) | |
(setenv "ANDROID_NDK_HOME" android-ndk-home) | |
(setenv "PATH" (mapconcat 'identity | |
`(,(getenv "PATH") | |
,(concat android-home "/tools") | |
,(concat android-home "/platform-tools") | |
,android-ndk-home) ":"))) | |
(mapc (lambda (x) (add-to-list 'exec-path x)) (split-string (getenv "PATH") ":"))) | |
;;;; Development | |
;; MMM | |
(require 'mmm-mode) | |
;; Auto complete | |
(require 'auto-complete) | |
(require 'auto-complete-config nil t) | |
;; Do What I Mean mode | |
(setq ac-dwim t) | |
(ac-config-default) | |
;; custom keybindings to use tab, enter and up and down arrows | |
(define-key ac-complete-mode-map "\t" 'ac-expand) | |
(define-key ac-complete-mode-map "\r" 'ac-complete) | |
(define-key ac-complete-mode-map "\M-n" 'ac-next) | |
(define-key ac-complete-mode-map "\M-p" 'ac-previous) | |
;; Project mode | |
(autoload 'project-mode "project-mode" "Project Mode" t) | |
;; Key bindings | |
(global-set-key (kbd "<f7>") 'compile) | |
;; 80 Columns base | |
(require 'column-marker) | |
;; Flymake | |
(eval-after-load 'flymake '(require 'flymake-cursor)) | |
; SSH | |
(require 'tramp) | |
(setq tramp-default-method "ssh") | |
;; Python | |
(require 'python) | |
(require 'pyflakes) | |
(require 'virtualenv) | |
(when mac? (setq virtualenv-root "~/Development/py-envs")) | |
;; Docstring | |
(setq mmm-global-mode 'maybe) | |
(mmm-add-classes | |
'((python-rst | |
:submode rst-mode | |
:front "^ *[ru]?\"\"\"[^\"]*$" | |
:back "^ *\"\"\"" | |
:include-front t | |
:include-back t | |
:end-not-begin t))) | |
(mmm-add-mode-ext-class 'python-mode nil 'python-rst) | |
;; 80 Columns | |
(add-hook 'python-mode-hook (lambda () (interactive) (column-marker-1 80))) | |
;; Python libraries | |
(let ((python-libs-path (concat emacs-dir "/python-libs")) | |
(python-path (getenv "PYTHONPATH"))) | |
(setenv "PYTHONPATH" | |
(if python-path | |
(concat python-path ":" python-libs-path) | |
python-libs-path)) | |
(setq jedi:server-args | |
(append `("--sys-path" ,python-libs-path) | |
(if mac? '("--virtual-env" "~/Development/py-envs/meety") '())))) | |
;; pytest | |
(require 'pytest) | |
(setq pytest-cmd-flags "-x -v --capture=no") | |
;; flymake using pyflakes | |
(when (load "flymake" t) | |
(defun flymake-pyflakes-init () | |
(let* ((temp-file (flymake-init-create-temp-buffer-copy | |
'flymake-create-temp-inplace)) | |
(local-file (file-relative-name | |
temp-file | |
(file-name-directory buffer-file-name)))) | |
(list "pyflakes" (list local-file)))) | |
(add-to-list 'flymake-allowed-file-name-masks | |
'("\\.py\\'" flymake-pyflakes-init))) | |
(add-hook 'python-mode-hook 'flymake-find-file-hook) | |
;; Jedi | |
(require 'jedi) | |
(add-hook 'python-mode-hook 'jedi:setup) | |
(setq jedi:setup-keys t) | |
(setq jedi:complete-on-dot t) | |
(setq python-indent-offset 4) | |
;; Key bindings | |
(defun set-py-keys() | |
(local-set-key (kbd "C-c d") 'jedi:show-doc)) | |
(add-hook 'python-mode-hook 'set-py-keys) | |
;; pdb | |
(setq gud-pdb-command-name | |
(if windows? "python -i -m pdb" "python -m pdb")) | |
;; C | |
;; Code convention | |
(setq c-default-style "linux" | |
c-basic-offset 4) | |
;; C key bindings | |
(add-hook 'c-mode 'set-c-keys) | |
(add-hook 'c++-mode-hook 'set-c-keys) | |
;;;; Customization for convinience | |
;; Key bindings | |
(global-set-key (kbd "RET") 'newline-and-indent) | |
(global-set-key (kbd "C-k") 'kill-line) | |
;; C-o M-o | |
(defun end-of-line-and-new-line () | |
(interactive) | |
(end-of-line) | |
(newline-and-indent)) | |
(defun beginning-of-line-and-new-line () | |
(interactive) | |
(beginning-of-line) | |
(newline) | |
(previous-line) | |
(indent-for-tab-command)) | |
(global-set-key (kbd "C-o") 'end-of-line-and-new-line) | |
(global-set-key (kbd "M-o") 'beginning-of-line-and-new-line) | |
;; iBuffer by default | |
(global-set-key (kbd "C-x C-b") 'ibuffer) | |
;; Copy-Cut-Paste from clipboard with Super-C Super-X Super-V | |
(global-set-key (kbd "s-x") 'clipboard-kill-region) ;;cut | |
(global-set-key (kbd "s-c") 'clipboard-kill-ring-save) ;;copy | |
(global-set-key (kbd "s-v") 'clipboard-yank) ;;paste | |
; code copied from http://stackoverflow.com/questions/2423834/move-line-region-up-and-down-in-emacs | |
(defun move-text-internal (arg) | |
(cond | |
((and mark-active transient-mark-mode) | |
(if (> (point) (mark)) | |
(exchange-point-and-mark)) | |
(let ((column (current-column)) | |
(text (delete-and-extract-region (point) (mark)))) | |
(forward-line arg) | |
(move-to-column column t) | |
(set-mark (point)) | |
(insert text) | |
(exchange-point-and-mark) | |
(setq deactivate-mark nil))) | |
(t | |
(let ((column (current-column))) | |
(beginning-of-line) | |
(when (or (> arg 0) (not (bobp))) | |
(forward-line) | |
(when (or (< arg 0) (not (eobp))) | |
(transpose-lines arg)) | |
(forward-line -1)) | |
(move-to-column column t))))) | |
(defun move-text-down (arg) | |
"Move region (transient-mark-mode active) or current line | |
arg lines down." | |
(interactive "*p") | |
(move-text-internal arg)) | |
(defun move-text-up (arg) | |
"Move region (transient-mark-mode active) or current line | |
arg lines up." | |
(interactive "*p") | |
(move-text-internal (- arg))) | |
(global-set-key (kbd "M-<up>") 'move-text-up) | |
(global-set-key (kbd "M-<down>") 'move-text-down) | |
;; Soft tab | |
(setq-default indent-tabs-mode nil) | |
;; Delete seleted text when typing | |
(delete-selection-mode 1) | |
;; Scroll smooth | |
(setq scroll-step 1 | |
scroll-conservatively 10000) | |
(line-number-mode t) | |
;; Highlight brackets | |
(show-paren-mode t) | |
;; Disable Shift-space to language conversion | |
(global-unset-key (kbd "S-SPC")) | |
;; Enable mouse | |
(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)) | |
;; ElScreen | |
(defmacro elscreen-create-automatically (ad-do-it) | |
(` (if (not (elscreen-one-screen-p)) | |
(, ad-do-it) | |
(elscreen-create) | |
(elscreen-notify-screen-modification 'force-immediately) | |
(elscreen-message "New screen is automatically created")))) | |
(defadvice elscreen-next (around elscreen-create-automatically activate) | |
(elscreen-create-automatically ad-do-it)) | |
(defadvice elscreen-previous (around elscreen-create-automatically activate) | |
(elscreen-create-automatically ad-do-it)) | |
(defadvice elscreen-toggle (around elscreen-create-automatically activate) | |
(elscreen-create-automatically ad-do-it)) | |
(defun elscreen-frame-title-update () | |
(when (elscreen-screen-modified-p 'elscreen-frame-title-update) | |
(let* ((screen-list (sort (elscreen-get-screen-list) '<)) | |
(screen-to-name-alist (elscreen-get-screen-to-name-alist)) | |
(title (mapconcat | |
(lambda (screen) | |
(format "%d%s %s" | |
screen (elscreen-status-label screen) | |
(get-alist screen screen-to-name-alist))) | |
screen-list " "))) | |
(if (fboundp 'set-frame-name) | |
(set-frame-name title) | |
(setq frame-title-format title))))) | |
(eval-after-load "elscreen" | |
'(add-hook 'elscreen-screen-update-hook 'elscreen-frame-title-update)) | |
(elscreen-start) | |
;; UTF-8 | |
(prefer-coding-system 'utf-8) | |
(set-default-coding-systems 'utf-8) | |
(set-terminal-coding-system 'utf-8) | |
(set-keyboard-coding-system 'utf-8) | |
;; backwards compatibility as default-buffer-file-coding-system | |
;; is deprecated in 23.2. | |
(if (boundp 'buffer-file-coding-system) | |
(setq-default buffer-file-coding-system 'utf-8) | |
(setq default-buffer-file-coding-system 'utf-8)) | |
;; Treat clipboard input as UTF-8 string first; compound text next, etc. | |
(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING)) | |
;; Redo | |
(require 'redo+) | |
(global-set-key (kbd "C-u") 'undo) | |
(global-set-key (kbd "C-r") 'redo) | |
;; ido | |
(require 'ido) | |
(ido-mode t) | |
(setq ido-enable-flex-matching t) ;; enable fuzzy matching | |
;; Linum | |
(require 'linum) | |
(global-linum-mode) | |
(setq linum-format "%3d ") | |
;; Yasnippet | |
(require 'yasnippet) | |
(setq yas/root-directory | |
`(,(concat emacs-dir "/snippets"))) | |
(mapc 'yas/load-directory yas/root-directory) | |
(setq yas/prompt-functions '(yas/dropdown-prompt yas/ido-prompt yas/x-prompt)) | |
(setq yas/wrap-around-region 'cua) | |
;Emacs customized values | |
(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. | |
'(help-at-pt-display-when-idle (quote (flymake-overlay)) nil (help-at-pt)) | |
'(help-at-pt-timer-delay 0.0) | |
'(package-archives (quote (("melpa" . "http://melpa.milkbox.net/packages/") ("gnu" . "http://elpa.gnu.org/packages/") ("Marmalade" . "http://marmalade-repo.org/packages/"))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment