initial commit

This commit is contained in:
syl20bnr 2012-12-18 00:48:12 -05:00
parent f2840078aa
commit 45a3323524
13 changed files with 299 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
auto-save-list/
config/
elpa/

50
init.el Normal file
View File

@ -0,0 +1,50 @@
(require 'cl)
(defvar user-home-directory
(expand-file-name (concat user-emacs-directory "../"))
"The user's home directory.")
(defvar user-projects-dir
(expand-file-name (concat user-home-directory "Projects/"))
"The directory containing the user's checked out source code.")
(defvar user-dropbox-directory
(expand-file-name (concat user-home-directory "Dropbox/"))
"The user's Dropbox root directory.")
(add-to-list 'load-path user-emacs-directory)
(require 'my-funcs)
;;number colon mode
(global-linum-mode t)
;;no tool bar
(tool-bar-mode 0)
(menu-bar-mode 0)
(scroll-bar-mode 0)
;; whitespace-mode
(setq-default show-trailing-whitespace t)
;; Inhibit startup message
(setq inhibit-startup-screen t)
;; Cursor, please do not blink
(blink-cursor-mode nil)
;; Do not make backup files
(setq make-backup-files nil)
;; When emacs asks for "yes" or "no", let "y" or "n" sufficide
(fset 'yes-or-no-p 'y-or-n-p)
;; Show column number in mode line
(setq column-number-mode t)
;; When point is on paranthesis, highlight the matching one
(show-paren-mode t)
;; auto-save
(add-hook 'before-save-hook (lambda () (delete-trailing-whitespace)))
;; Config files
(progn
(setq user-emacs-config-dir (concat user-emacs-directory "config/"))
(when (file-exists-p user-emacs-config-dir)
(dolist (l (directory-files user-emacs-config-dir nil "^[^#].*el$"))
(load (concat user-emacs-config-dir l)))))
(require 'my-packages)
(require 'my-keybindings)

87
my-funcs.el Normal file
View File

@ -0,0 +1,87 @@
(defun z:mac-p ()
"Truthy if the host OS is a Mac."
(string-match "apple-darwin" system-configuration))
(defun z:deduplicate-all-lines-region (start end)
"Find duplicate lines in region START to END keeping first occurrence."
(z:uniquify-all-lines-region start end))
(defun log-edit-mode ()
"HACK: Ergoemacs doesn't load properly unless this function is defined."
nil)
(defun z:deduplicate-all-lines-buffer ()
"Delete duplicate lines in buffer and keep first occurrence."
(z:uniquify-all-lines-buffer))
(defun z:uniquify-all-lines-region (start end)
"Find duplicate lines in region START to END keeping first occurrence."
(interactive "*r")
(save-excursion
(let ((end (copy-marker end)))
(while
(progn
(goto-char start)
(re-search-forward "^\\(.*\\)\n\\(\\(.*\n\\)*\\)\\1\n" end t))
(replace-match "\\1\n\\2")))))
(defun z:uniquify-all-lines-buffer ()
"Delete duplicate lines in buffer and keep first occurrence."
(interactive "*")
(z:uniquify-all-lines-region (point-min) (point-max)))
(defun z:set-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))
(defun z:switch-to-next-frame ()
"Select the next frame on current display, and raise it."
(interactive)
(other-frame 1))
(defun z:switch-to-previous-frame ()
"Select the previous frame on current display, and raise it."
(interactive)
(other-frame -1))
;; http://emacswiki.org/emacs/TransposeWindows
(defun z:rotate-windows ()
"Rotate your windows"
(interactive)
(cond
((not (> (count-windows) 1))
(message "You can't rotate a single window!"))
(t
(let ((i 1)
(num-windows (count-windows)))
(while (< i num-windows)
(let* ((w1 (elt (window-list) i))
(w2 (elt (window-list) (+ (% i num-windows) 1)))
(b1 (window-buffer w1))
(b2 (window-buffer w2))
(s1 (window-start w1))
(s2 (window-start w2)))
(set-window-buffer w1 b2)
(set-window-buffer w2 b1)
(set-window-start w1 s2)
(set-window-start w2 s1)
(setq i (1+ i))))))))
(defun z:smart-beginning-of-line ()
"Move point to first non-whitespace character or beginning-of-line.
Move point to the first non-whitespace character on this line.
If point was already at that position, move point to beginning of line."
(interactive) ; Use (interactive "^") in Emacs 23 to make shift-select work
(let ((oldpos (point)))
(beginning-of-line-text)
(and (= oldpos (point))
(beginning-of-line))))
(defun z:vagrant-shell ()
(interactive)
(let ((default-directory "/vagrant:/home/vagrant/projects"))
(shell "*vagrant-root*")))
(provide 'my-funcs)

58
my-keybindings.el Normal file
View File

@ -0,0 +1,58 @@
;;;; zane-keys.el --- Keyboard shortcuts.
;;;;
;;;; http://www.masteringemacs.org/articles/2011/02/08/mastering-key-bindings-emacs/
;;;; http://www.gnu.org/software/emacs/elisp/html_node/Key-Binding-Conventions.html
;;;; http://code.google.com/p/ergoemacs/wiki/adoption
;
;(setq mac-command-modifier 'meta)
;(setq mac-option-modifier 'alt)
;
;;; hash table to store the old key bindings
;(setq old-key-bindings (make-hash-table :test 'equal))
;
;;; shows a hint about the change of the key binding
;(defun show-hint-old-kbind (key)
; (let ((function-symbol (gethash key old-key-bindings)))
; (beep)
; (message "You typed: %s. For %s, use %s."
; key
; function-symbol
; (mapcar 'key-description (where-is-internal function-symbol)))))
;
;;; turns off a key binding, leaving a hint for the unbound command
;(defmacro global-unset-key-leave-hint (key)
; `(let ((function-symbol (global-key-binding ,key)))
; (when function-symbol
; (puthash ,key function-symbol old-key-bindings)
; (global-set-key (kbd ,key) (lambda() (interactive) (show-hint-old-kbind ,key))))))
;
;(global-unset-key (kbd "C-x C-k"))
;
;(global-set-key (kbd "C-s") 'save-buffer)
;(global-set-key (kbd "C-w") 'close-current-buffer)
;
;(global-set-key (kbd "C-c C-a") 'align-regexp)
;;(global-set-key (kbd "C-c C-o") 'sort-lines)
;(global-set-key (kbd "C-x y") 'bury-buffer)
;(if (z:mac-p) (global-set-key (kbd "M-RET") 'ns-toggle-fullscreen)) ; http://www.stratospark.com/blog/2010/fullscreen_emacs_on_osx.html
;;; (global-set-key (kbd "M-h") 'ns-do-hide-emacs)
;
;;; Tab key
;;; http://stackoverflow.com/questions/1792326/how-do-i-bind-a-command-to-c-i-without-changing-tab
;(keyboard-translate ?\C-i ?\H-i)
;
;;; Unset M-SPC because it's used by Alfred.app
;(global-unset-key (kbd "M-SPC"))
;(global-unset-key (kbd "M-TAB"))
;
;(global-unset-key (kbd "C-x RET"))
;(add-hook 'term-exec-hook
; (lambda ()
; (set-buffer-process-coding-system 'utf-8-unix
; 'utf-8-unix)))
;
;;; Occur
;;; http://www.masteringemacs.org/articles/2011/07/20/searching-buffers-occur-mode/
;(define-key isearch-mode-map (kbd "C-o") 'isearch-occur)
(provide 'my-keybindings)

View File

@ -0,0 +1,7 @@
(require 'erlang-start)
(add-to-list 'auto-mode-alist '("\\.erl?$" . erlang-mode))
(add-to-list 'auto-mode-alist '("\\.hrl?$" . erlang-mode))
(setq erlang-root-dir "/usr/local/lib/erlang/erts-5.9.2")
(add-to-list 'exec-path "/usr/local/lib/erlang/erts-5.9.2/bin")
(setq erlang-man-root-dir "/usr/local/lib/erlang/erts-5.9.2/man")

View File

@ -0,0 +1,17 @@
(setq evil-mode-line-format 'before)
(setq evil-want-C-u-scroll t)
(setq evil-emacs-state-cursor '("red" box))
(setq evil-normal-state-cursor '("red" box))
(setq evil-visual-state-cursor '("green" box))
(setq evil-insert-state-cursor '("green" bar))
(setq evil-motion-state-cursor '("gray" box))
(evil-mode 1)
;;Make evil-mode up/down operate in screen lines instead of logical lines
(define-key evil-normal-state-map (kbd "j") 'evil-next-visual-line)
(define-key evil-normal-state-map (kbd "k") 'evil-previous-visual-line)
;;Exit insert mode by pressing j and then k quickly
(setq key-chord-two-keys-delay 0.2)
(key-chord-define evil-insert-state-map "jk" 'evil-normal-state)
(key-chord-mode 1)

View File

@ -0,0 +1,17 @@
(require 'fill-column-indicator)
(defun turn-on-fill-column-indicator ()
(fci-mode 1)
(setq fci-rule-column 80)
(setq fci-rule-width 2)
(setq fci-rule-color "#073642"))
(let ((supported-modes '(emacs-lisp-mode-hook
clojure-mode-hook
javascript-mode-hook
lisp-mode-hook
python-mode-hook
erlang-mode-hook)))
(dolist (hook supported-modes)
(add-hook hook 'turn-on-fill-column-indicator)))

View File

@ -0,0 +1 @@
(powerline-default)

View File

@ -0,0 +1,13 @@
(defun turn-on-rainbow-delimiters-mode ()
(interactive)
(rainbow-delimiters-mode 1))
(setq-default frame-background-mode 'dark)
(let ((supported-modes '(emacs-lisp-mode-hook
clojure-mode-hook
javascript-mode-hook
lisp-mode-hook
python-mode-hook
erlang-mode-hook)))
(dolist (hook supported-modes)
(add-hook hook 'turn-on-rainbow-delimiters-mode)))

View File

View File

@ -0,0 +1 @@
(load-theme 'solarized-dark t)

View File

@ -0,0 +1 @@
(global-surround-mode 1)

44
my-packages.el Normal file
View File

@ -0,0 +1,44 @@
(require 'package)
(setq package-archives '(("ELPA" . "http://tromey.com/elpa/")
("gnu" . "http://elpa.gnu.org/packages/")
("melpa" . "http://melpa.milkbox.net/packages/")
("marmalade" . "http://marmalade-repo.org/packages/")
("melpa" . "http://melpa.milkbox.net/packages/")
("technomancy" . "http://repo.technomancy.us/emacs/")))
(package-initialize)
(defvar z:my-packages
'(
erlang
evil
fill-column-indicator
key-chord
powerline
rainbow-delimiters
smooth-scrolling
solarized-theme
surround
))
;;; install missing packages
(let ((not-installed (remove-if 'package-installed-p z:my-packages)))
(if not-installed
(if (y-or-n-p (format "there are %d packages to be installed. install them? " (length not-installed)))
(progn (package-refresh-contents)
(dolist (package z:my-packages)
(when (not (package-installed-p package))
(package-install package)))))))
;;; initialize packages
(setq z:package-init-dir (concat user-emacs-directory "my-package-init/"))
(message (format "initializing packages out of %s" z:package-init-dir))
(dolist (package (append (mapcar 'car package--builtins) package-activated-list))
(let* ((initfile (concat z:package-init-dir (format "init-%s.el" package))))
(if (and (package-installed-p package)
(file-exists-p initfile))
(progn (load initfile)
(message (format "loaded %s" initfile))))))
(when (memq window-system '(mac ns))
(exec-path-from-shell-initialize))
(provide 'my-packages)