Skip to content

Instantly share code, notes, and snippets.

@gnuvince
Created February 20, 2012 13:07
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gnuvince/1869094 to your computer and use it in GitHub Desktop.
Save gnuvince/1869094 to your computer and use it in GitHub Desktop.
;; init.el
;; Vincent Foley - vfoley@gmail.com
(require 'cl)
(defmacro when-package-installed (package-name &rest body)
`(if (package-installed-p ,package-name)
(progn ,@body)
(warn "package %s is not installed" ,package-name)))
(setplist 'when-package-installed '(lisp-indent-function defun))
;; Load paths
(defvar *emacs-dir* (file-name-as-directory "~/.emacs.d"))
(add-to-list 'load-path *emacs-dir*)
(let ((paths '("themes"
"scala"
"fsharp"
)))
(dolist (path paths)
(add-to-list 'load-path (concat *emacs-dir* path))))
(defun buffer-exists (bufname)
(some #'(lambda (b) (string-equal (buffer-name b) bufname))
(buffer-list)))
;; Emacs server
(server-start)
;; Load ELPA
(require 'package)
(package-initialize)
(add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))
(require 'color-theme)
;(color-theme-initialize)
;(require 'color-theme-zenburn)
;(color-theme-zenburn)
(require 'color-theme-tangotango)
(color-theme-tangotango)
;; Disable some GUI features
(when (featurep 'tool-bar) (tool-bar-mode -1))
(when (featurep 'tooltip) (tooltip-mode -1))
;; (when (featurep 'menu-bar) (menu-bar-mode -1))
(blink-cursor-mode -1)
;; Enable mouse wheel
(mouse-wheel-mode 1)
;; UTF-8
;(set-terminal-coding-system 'utf-8)
;(set-keyboard-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
;; Syntax highlighting
(global-font-lock-mode 1)
;; General settings
(setq user-full-name "Vincent Foley"
user-mail-address "vfoley@gmail.com"
inhibit-startup-message t
initial-scratch-message nil
major-mode 'fundamental-mode
next-line-add-newlines nil
scroll-step 1
scroll-conservatively 1
font-lock-maximum-decoration t
require-final-newline t
truncate-partial-width-windows nil
shift-select-mode nil
echo-keystrokes 0.1
x-select-enable-clipboard t
mouse-yank-at-point t
custom-unlispify-tag-names nil
ring-bell-function '(lambda ()))
;; Display line, column and time (24h format)
(line-number-mode t)
(column-number-mode t)
(display-battery-mode 1)
(size-indication-mode t)
(display-time)
(setq display-time-24hr-format t)
;(global-linum-mode 1)
;(global-visual-line-mode 1)
(global-hi-lock-mode 1)
(put 'downcase-region 'disabled nil)
(put 'upcase-region 'disabled nil)
(put 'narrow-to-region 'disabled nil)
(windmove-default-keybindings)
;; Hooks
(add-hook 'before-save-hook 'delete-trailing-whitespace)
;; Transient mark mode
(transient-mark-mode 1)
(delete-selection-mode 1)
(setenv "EDITOR" "emacsclient")
(when-package-installed 'magit
(require 'magit)
(global-set-key (kbd "C-x s") 'magit-status))
;; Indentation is 4 spaces.
(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
;; (electric-pair-mode 1)
;; (electric-indent-mode 1)
;; (electric-layout-mode 1)
(require 'tramp)
;; Ido mode
(require 'ido)
(ido-mode 1)
(ido-everywhere 1)
(setq confirm-nonexistent-file-or-buffer nil
ido-create-new-buffer 'always
ido-enable-prefix nil
ido-enable-flex-matching nil
;; never try to find a file in another directory
ido-auto-merge-inhibit-characters-regexp "."
)
;; Uniquify
(require 'uniquify)
(setq uniquify-buffer-name-style 'forward)
;; Smex
(when-package-installed 'smex
(require 'smex)
(smex-initialize)
(global-set-key (kbd "M-x") 'smex)
(global-set-key (kbd "M-X") 'execute-extended-command))
;; Anything
(when-package-installed 'anything
(require 'anything)
(require 'anything-config)
(defun my-anything ()
(interactive)
(anything-other-buffer
'(anything-c-source-buffers
;anything-c-source-buffer-not-found
anything-c-source-file-name-history
anything-c-source-files-in-current-dir
;anything-c-source-occur
;anything-c-source-bookmarks
;anything-c-source-info-pages
;anything-c-source-info-elisp
;anything-c-source-man-pages
;anything-c-source-locate
anything-c-source-emacs-commands
;anything-c-source-emacs-functions
;anything-c-source-kill-ring
anything-c-source-recentf
)
" *my-anything*"))
(global-set-key (kbd "C-=") 'my-anything))
(require 'recentf)
(recentf-mode 1)
;; Breadcrumb
(require 'breadcrumb)
(setq bc-bookmark-file nil)
(global-set-key [(f2)] 'bc-set)
(global-set-key [(ctrl f2)] 'bc-previous)
(global-set-key [(shift f2)] 'bc-next)
(global-set-key [(meta f2)] 'bc-list)
;; Hippie expand
(setq hippie-expand-try-functions-list
'(try-expand-dabbrev
try-expand-dabbrev-all-buffers
try-expand-dabbrev-from-kill
try-complete-file-name-partially
try-complete-file-name)
hippie-expand-dabbrev-as-symbol t)
;; Kill ring browser, bind it to M-y
(when-package-installed 'browse-kill-ring
(require 'browse-kill-ring)
(browse-kill-ring-default-keybindings))
;; Always answer 'y' or 'n'
(fset 'yes-or-no-p 'y-or-n-p)
;; Show paren matches
(show-paren-mode t)
;; Open compressed files transparently
(auto-compression-mode t)
;; Save backup files in ~/tmp/
(add-to-list 'backup-directory-alist '(".*" . "~/tmp"))
;; Get rid of recovery files (#file#)
(add-hook 'kill-emacs-hook
'(lambda ()
(mapcar (lambda (buf)
(with-current-buffer buf
(delete-auto-save-file-if-necessary t)))
(buffer-list))))
;; Cache the gnupg passphrase for symmetric encryption
(setq epa-file-cache-passphrase-for-symmetric-encryption t)
;; hook+advice so that isearch-forward exits search at the beginning
;; of the search string instead of at the end
(add-hook 'isearch-mode-end-hook '(lambda ()
(when isearch-forward (goto-char isearch-other-end))))
(defadvice isearch-exit (after my-goto-match-beginning activate)
"Go to beginning of match."
(when isearch-forward (goto-char isearch-other-end)))
;; text-mode
(add-hook 'text-mode-hook 'turn-on-auto-fill)
;; Python
(require 'python)
(add-to-list 'auto-mode-alist '("\\.py$" . python-mode))
(add-to-list 'interpreter-mode-alist '("python" . python-mode))
(autoload 'python-mode "python-mode" "Python mode" t)
;; Haskell
(add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode)
(add-hook 'haskell-mode-hook 'turn-on-haskell-indent)
;; C
(setq c-default-style "k&r")
(setq-default c-basic-offset 4)
(add-hook 'c-mode-hook
'(lambda ()
(subword-mode)))
;; Perl
(require 'cperl-mode)
(defalias 'perl-mode 'cperl-mode)
(add-to-list 'auto-mode-alist '("\\.p[lm]$" . cperl-mode))
(add-to-list 'auto-mode-alist '("\\.t$" . cperl-mode))
(setq cperl-close-paren-offset -4
cperl-continued-statement-offset 4
cperl-indent-level 4
cperl-indent-parens-as-block t
cperl-tab-always-indent t
cperl-label-offset 0)
;; Scala
(require 'scala-mode-auto)
(require 'scala-mode)
(add-to-list 'auto-mode-alist '("\\.scala$" . scala-mode))
(defun scala-newline-and-indent ()
(interactive)
(scala-newline)
(scala-indent-line))
(define-key scala-mode-map (kbd "RET") 'scala-newline-and-indent)
;; OCaml
(when-package-installed 'tuareg
(require 'tuareg)
(add-to-list 'auto-mode-alist '("\\.mli?$" . tuareg-mode)))
;; F#
(require 'fsharp)
(add-to-list 'auto-mode-alist '("\\.fs$" . fsharp-mode))
;; org-mode
(add-to-list 'auto-mode-alist '("\\.org$" . org-mode))
(setq org-log-done t)
(setq org-startup-indented nil)
(setq org-startup-folded nil)
(setq org-src-fontify-natively t)
(setq org-agenda-files (list "~/org/school.org"
"~/org/mapgears.org"))
;; Scheme
;; (autoload 'gambit-inferior-mode "gambit" "Hook Gambit mode into cmuscheme.")
;; (autoload 'gambit-mode "gambit" "Hook Gambit mode into scheme.")
;; (add-hook 'inferior-scheme-mode-hook (function gambit-inferior-mode))
;; (add-hook 'scheme-mode-hook (function gambit-mode))
;; (setq gambit-repl-command-prefix "\e")
(setq scheme-program-name "~/g4/bin/gsi -:d-")
;; Django
(require 'django-html-mode)
;; Go
(when-package-installed 'go-mode
(require 'go-mode)
(add-to-list 'auto-mode-alist '("\\.go$" . go-mode)))
;; Dot/Graphviz
(when-package-installed 'graphviz-dot-mode
(add-to-list 'auto-mode-alist '("\\.gv$" . graphviz-dot-mode)))
;; Antlr
(setq antlr-tool-command "antlr3")
;; SQL
(setq sql-sqlite-program "sqlite3")
;; LaTeX
(when-package-installed 'auctex
(setq-default TeX-PDF-mode t))
;; My custom keybindings
(global-set-key (kbd "<home>") 'beginning-of-line)
(global-set-key (kbd "<end>") 'end-of-line)
(global-set-key (kbd "<del>") 'delete-char)
(global-set-key (kbd "C-m") 'newline-and-indent)
(global-set-key (kbd "M-g") 'goto-line)
(global-set-key (kbd "C-s") 'isearch-forward)
(global-set-key (kbd "C-r") 'isearch-backward)
(global-set-key (kbd "C-M-s") 'isearch-forward-regexp)
(global-set-key (kbd "C-M-r") 'isearch-backward-regexp)
;;(global-set-key (kbd "M-#") 'dabbrev-expand)
(global-set-key (kbd "M-#") 'hippie-expand)
(global-set-key (kbd "C-z") 'undo)
(global-set-key (kbd "M-o") 'occur)
(global-set-key (kbd "C-x C-a") 'org-agenda)
(global-set-key (kbd "C-x m") '(lambda ()
(interactive)
(if (buffer-exists "*ansi-term*")
(switch-to-buffer-other-window "*ansi-term*")
(ansi-term (getenv "SHELL")))))
(global-set-key (kbd "C-x C-b") 'ibuffer)
(global-set-key (kbd "C-x y") 'bury-buffer)
(global-set-key (kbd "C-o") ; Works like O in vi
'(lambda ()
(interactive)
(beginning-of-line)
(open-line 1)
(indent-according-to-mode)))
(global-set-key (kbd "C-x C-j")
'(lambda ()
(interactive)
(join-line 1)))
(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.
'(safe-local-variable-values (quote ((encoding . utf-8))))
'(send-mail-function (quote smtpmail-send-it))
'(smtpmail-smtp-server "smtp.gmail.com")
'(smtpmail-smtp-service "smtp"))
(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