Skip to content

Instantly share code, notes, and snippets.

@reuven
Created January 10, 2013 12:26
Show Gist options
  • Save reuven/4501716 to your computer and use it in GitHub Desktop.
Save reuven/4501716 to your computer and use it in GitHub Desktop.
;;; Reuven's .emacs.el file
;;; ------------------------------------------------------------
;;; Load packages
;;; ------------------------------------------------------------
(add-to-list 'load-path "~/.emacs.d")
(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))
(add-to-list 'auto-mode-alist '("\\.js.erb$" . js2-mode))
(add-to-list 'auto-mode-alist '("\\.pl$" . cperl-mode))
(add-to-list 'auto-mode-alist '("\\.pm$" . cperl-mode))
(add-to-list 'auto-mode-alist '("\\.rhtml$" . html-mode))
(add-to-list 'auto-mode-alist '("\\.sass$" . sass-mode))
(add-to-list 'exec-path "/usr/local/bin")
(add-to-list 'exec-path "/usr/textbin/bin")
(add-to-list 'exec-path "/usr/local/share/python")
(add-to-list 'Info-default-directory-list
(expand-file-name (expand-file-name "~/.emacs.d/org-mode/info")))
(require 'auto-install)
(require 'browse-kill-ring)
(require 'calendar)
(require 'filecache)
(require 'flymake)
(require 'haml-mode nil 't)
(require 'imenu)
(require 'mmm-auto)
(require 'mmm-mode)
(require 'org)
(require 'package)
(require 'paren)
(require 'remember)
(require 'ruby-electric)
(require 'ruby-mode)
(require 'sass-mode nil 't)
(require 'savehist)
(require 'speedbar)
(require 'time)
(require 'time-stamp)
(require 'tramp)
(require 'yasnippet)
(add-to-list 'package-archives '("marmalade" .
"http://marmalade-repo.org/packages/"))
(add-to-list 'package-archives '("tromey" .
"http://tromey.com/elpa/"))
;;; ------------------------------------------------------------
;;; General settings
;;; ------------------------------------------------------------
(if window-system
(progn
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(setq default-frame-alist '((width . 110)
(height . 49)
(top . 0)
(left . 1)
(cursor-color . "orange")
(background-color . "black")
(foreground-color . "yellow")))
(setq minibuffer-frame-alist '((width . 80)
(height . 2)
(cursor-color . "orange")
(foreground-color . "Goldenrod")))
(show-paren-mode t)
(delete-selection-mode t)
(make-face 'garish-highlight)
(set-face-foreground 'garish-highlight "black")
(set-face-background 'garish-highlight "turquoise")
(set-face-foreground 'modeline "Goldenrod")
(set-face-background 'modeline "maroon")
(set-face-foreground 'region "black")
(set-face-background 'region "forestgreen")
))
(global-font-lock-mode 1)
(setq delete-old-versions t)
(setq dired-listing-switches "-aBl")
(setq display-time-day-and-date t)
(setq highlight-nonselected-windows nil)
(setq inhibit-startup-message t)
(setq insert-directory-program "/usr/local/bin/ls")
(setq kept-new-versions 1)
(setq kill-ring-max 150)
(setq major-mode 'text-mode)
(setq minibuffer-prompt-properties '(read-only t point-entered minibuffer-avoid-prompt))
(setq page-delimiter " ")
(setq query-replace-highlight t)
(setq search-highlight t)
(setq-default filladapt-mode t)
(which-function-mode t)
(add-hook 'write-file-hooks 'time-stamp)
(add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p)
;;; ------------------------------------------------------------
;;; Global key bindings
;;; ------------------------------------------------------------
(global-set-key "\C-cm" 'magit-status)
(global-set-key "\ei" 'indent-buffer)
(global-set-key "\e\C-h" 'backward-kill-word)
(global-set-key "\C-x\C-b" 'buffer-menu)
(global-set-key "\egb" 'gist-buffer)
(browse-kill-ring-default-keybindings)
(setq browse-kill-ring-quit-action 'save-and-restore)
;;; ------------------------------------------------------------
;;; Disable commands
;;; ------------------------------------------------------------
(put 'upcase-region 'disabled t) ;dangerous
(put 'capitalize-region 'disabled t) ;dangerous
(put 'eval-expression 'disabled nil) ;I like to use this
(put 'rnews 'disabled t) ;Inferior netnews reader
(put 'narrow-to-page 'disabled nil) ;Nice nifty handy routine
(put 'narrow-to-region 'disabled nil) ;Nice nifty handy routine
(put 'rmail 'disabled t) ;Old mail-reading program
(put 'set-goal-column 'disabled t) ;Annoying function
(put 'free-space-checker 'disabled t) ;Uses up the mode line
;;; ------------------------------------------------------------
;;; C (really cc) mode
;;; ------------------------------------------------------------
(add-hook 'c-mode-hook
'(lambda ()
(interactive)
(setq c-default-style "java")
(c-toggle-auto-state t)))
;;; ------------------------------------------------------------
;;; Calendar mode
;;; ------------------------------------------------------------
(setq diary-file "~/.diary")
(setq holiday-christian-holidays nil)
(setq holiday-islamic-holidays nil)
(setq calendar-hebrew-all-holidays-flag t)
;;; ------------------------------------------------------------
;;; Emacs-lisp mode
;;; ------------------------------------------------------------
(define-key emacs-lisp-mode-map "\e\C-c" 'byte-compile-buffer)
(add-hook 'emacs-lisp-mode-hook
'(lambda()
(interactive)
))
;;; ------------------------------------------------------------
;;; Flymake mode
;;; ------------------------------------------------------------
(defun flymake-create-temp-intemp (file-name prefix)
"Return file name in temporary directory for checking FILE-NAME.
This is a replacement for `flymake-create-temp-inplace'. The
difference is that it gives a file name in
`temporary-file-directory' instead of the same directory as
FILE-NAME.
For the use of PREFIX see that function.
Note that not making the temporary file in another directory
\(like here) will not if the file you are checking depends on
relative paths to other files \(for the type of checks flymake
makes)."
(unless (stringp file-name)
(error "Invalid file-name"))
(or prefix
(setq prefix "flymake"))
(let* ((name (concat
(file-name-nondirectory
(file-name-sans-extension file-name))
"_" prefix))
(ext (concat "." (file-name-extension file-name)))
(temp-name (make-temp-file name nil ext))
)
(flymake-log 3 "create-temp-intemp: file=%s temp=%s" file-name temp-name)
temp-name))
(defun flymake-erb-init ()
(let* ((check-buffer (current-buffer))
(temp-file (flymake-create-temp-inplace (buffer-file-name) "flymake"))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(save-excursion
(save-restriction
(widen)
(with-temp-file temp-file
(let ((temp-buffer (current-buffer)))
(set-buffer check-buffer)
(call-process-region (point-min) (point-max) "erb" nil temp-buffer nil "-x"))))
(setq flymake-temp-source-file-name temp-file)
(list "ruby" (list "-c" local-file)))))
(eval-after-load "flymake"
'(progn
(push '(".+\\.\\(rhtml\\|erb\\)$" flymake-erb-init) flymake-allowed-file-name-masks)
(push '("^\\(.*\\):\\([0-9]+\\): \\(.*\\)$" 1 2 nil 3) flymake-err-line-patterns)))
(defun turn-on-flymake-for-erb-files ()
(when (string-match "\.erb$" (buffer-file-name))
(flymake-mode 1)))
(add-hook 'find-file-hook 'turn-on-flymake-for-erb-files)
;;; ------------------------------------------------------------
;;; Haml mode
;;; ------------------------------------------------------------
(add-hook 'haml-mode-hook
'(lambda()
(interactive)
(local-set-key (kbd "TAB") 'haml-indent-line)))
;;; ------------------------------------------------------------
;;; Java mode
;;; ------------------------------------------------------------
(add-hook 'java-mode-hook 'my-java-mode-hook
'(lambda()
(interactive)
(setq tab-width 4)
(setq indent-tabs-mode t)
(local-set-key (kbd "RET") 'newline-and-indent)
(c-add-style
"netlogo-java"
'(
(c-basic-offset . 4)
(c-comment-only-line-offset . 0)
(c-hanging-comment-starter-p . nil)
(c-offsets-alist . ((substatement-open . 0)
(inline-open . 0)
(inline-close . 0)
(case-label . +)))))
(c-set-style "netlogo-java")))
;;; ------------------------------------------------------------
;;; JavaScript mode
;;; ------------------------------------------------------------
(autoload 'js2-mode "js2" nil t)
(add-hook 'js2-mode-hook
'(lambda()
(interactive)
(setq js2-bounce-indent-p nil)
))
;;; ------------------------------------------------------------
;;; Mail mode
;;; ------------------------------------------------------------
(setq user-mail-address "[email protected]")
(setq user-full-name "Reuven M. Lerner")
(add-hook 'message-mode-hook
'(lambda()
(interactive)
(turn-on-auto-fill)
(setq mail-self-blind nil)
(setq send-mail-function
(function
(lambda ()
(interactive)
(if (y-or-n-p "Send message? ")
(sendmail-send-it)
(error "Send Aborted")))))))
;;; ------------------------------------------------------------
;;; MMM mode
;;; ------------------------------------------------------------
(setq mmm-global-mode 'maybe)
(setq mmm-submode-decoration-level 2)
(set-face-background 'mmm-output-submode-face "Brown")
(set-face-background 'mmm-code-submode-face "MediumSlateBlue")
(set-face-background 'mmm-comment-submode-face "DarkOliveGreen")
(mmm-add-classes
'((erb-code
:submode ruby-mode
:match-face (("<%#" . mmm-comment-submode-face)
("<%=" . mmm-output-submode-face)
("<%" . mmm-code-submode-face))
:front "<%[#=]?"
:back "-?%>"
:insert ((?% erb-code nil @ "<%" @ " " _ " " @ "%>" @)
(?# erb-comment nil @ "<%#" @ " " _ " " @ "%>" @)
(?= erb-expression nil @ "<%=" @ " " _ " " @ "%>" @))
)))
(add-hook 'html-mode-hook
(lambda ()
(setq mmm-classes '(erb-code))
(mmm-mode-on)))
;;; ------------------------------------------------------------
;;; org-mode
;;; ------------------------------------------------------------
(require 'org-install)
(add-to-list 'auto-mode-alist '("\\.org$" . org-mode))
(define-key global-map "\C-cl" 'org-store-link)
(define-key global-map "\C-ca" 'org-agenda)
(setq org-log-done t)
(add-hook 'org-mode-hook
(lambda ()
(org-indent-mode t)
(visual-line-mode t))
(org-babel-do-load-languages
'org-babel-load-languages
'((R . t)
(emacs-lisp . t)
(python . t)
(sh . t)
(ruby . t)
))
)
;;; ------------------------------------------------------------
;;; Perl (really cperl) mode
;;; ------------------------------------------------------------
(autoload 'cperl-mode "cperl-mode" "Perl editing mode." t)
(add-hook 'cperl-mode-hook
'(lambda()
(interactive)
(cperl-set-style "C++")))
;;; ------------------------------------------------------------
;;; Python mode
;;; ------------------------------------------------------------
(add-hook 'python-mode-hook '(lambda ()
(define-key python-mode-map "\C-m" 'newline-and-indent)
(linum-mode)
(flymake-python-pyflakes-load)
(flymake-mode)))
;;; ------------------------------------------------------------
;;; Ruby mode
;;; ------------------------------------------------------------
(add-hook 'ruby-mode-hook
'(lambda ()
(interactive)
(require 'ruby-block)
(turn-on-font-lock)
(ruby-electric-mode t)
(rvm-activate-corresponding-ruby)
(ruby-block-mode t)
(setq ruby-block-highlight-toggle t)
(linum-mode 1)
(add-to-list 'hs-special-modes-alist
'(ruby-mode
"\\(def\\|do\\|{\\)" "\\(end\\|end\\|}\\)" "#"
(lambda (arg) (ruby-end-of-block)) nil))
;; Don't want flymake mode for ruby regions in rhtml files and also on read only files
(if (and (not (null buffer-file-name))
(file-writable-p buffer-file-name)
;; No flymake mode for JRuby
(not (string-match "jruby" rvm--current-ruby-binary-path)))
(flymake-mode))
))
(defun flymake-ruby-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-intemp))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(list "ruby" (list "-c" local-file))))
(push '(".+\\.rb$" flymake-ruby-init) flymake-allowed-file-name-masks)
(push '("Rakefile$" flymake-ruby-init) flymake-allowed-file-name-masks)
(push '("^\\(.*\\):\\([0-9]+\\): \\(.*\\)$" 1 2 nil 3) flymake-err-line-patterns)
(defconst ruby-block-end-re "end")
(defun ruby-end-of-defun (&optional arg)
"Move forward to next end of defun.
An end of a defun is found by moving forward from the beginning of one."
(interactive "p")
(and (re-search-forward (concat "^\\(" ruby-block-end-re "\\)\\($\\|\\b[^_]\\)")
nil 'move (or arg 1))
(progn (beginning-of-line) t))
(forward-line 1))
;;; ------------------------------------------------------------
;;; Savehist
;;; ------------------------------------------------------------
(savehist-mode 1)
;;; ------------------------------------------------------------
;;; SQL mode
;;; ------------------------------------------------------------
(add-hook 'sql-mode-hook
'(lambda ()
(interactive)
))
;;; ------------------------------------------------------------
;;; Text mode
;;; ------------------------------------------------------------
(add-hook 'text-mode-hook
'(lambda()
(interactive)
(turn-on-auto-fill)))
;;; ------------------------------------------------------------
;;; YASnippet
;;; ------------------------------------------------------------
(setq yas/root-directory "~/.emacs.d/snippets")
(yas/load-directory yas/root-directory)
(yas/global-mode)
;;; ------------------------------------------------------------
;;; Define new functions
;;; ------------------------------------------------------------
(defun indent-buffer (&optional which-buffer)
"Indents a buffer (default is current)."
(interactive "bBuffer to indent: ")
(indent-region (point-min) (point-max) nil)
(beep)
(message "Done indenting"))
(defun byte-compile-buffer (&optional which-buffer)
"Byte-compiles a buffer (default is current)."
(interactive "bBuffer to byte-compile: ")
(progn
(save-some-buffers t)
(byte-compile-file buffer-file-name)
(beep)
(message "Done byte-compiling")))
;;; ------------------------------------------------------------
;;; Start-up routine
;;; ------------------------------------------------------------
(if (boundp 'already-evaluated)
(redraw-display)
(progn
(defvar already-evaluated t
"Set to `t' if Reuven has already evaluated his .emacs file.")
(display-time)
(column-number-mode 1)
(auto-compression-mode 1)
(server-start)
))
(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.
'(major-mode (quote text-mode))
'(python-check-command "/usr/local/share/python/epylint "))
(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.
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment