Skip to content

Instantly share code, notes, and snippets.

@travitch
Created July 14, 2013 17:02
Show Gist options
  • Save travitch/5994936 to your computer and use it in GitHub Desktop.
Save travitch/5994936 to your computer and use it in GitHub Desktop.
(setq custom-file "~/.emacs.d/custom.el")
(load custom-file 'noerror)
;; Speed startup
(setq inhibit-startup-message t)
(setq inhibit-startup-buffer-menu t)
(defconst gui-font (if (eq system-type 'darwin)
"Source Code Pro-14"
"Source Code Pro-12"))
;; Disable GUI stuff as early as possible
(when window-system
(add-to-list 'default-frame-alist `(font . ,gui-font))
(add-to-list 'default-frame-alist '(cursor-color . "white"))
(set-default-font gui-font)
(setq font-use-system-font nil)
(set-fontset-font "fontset-default" '(#x2500 . #x33ff) '("dejavu sans mono-11" . "unicode-bmp"))
(set-fontset-font "fontset-default" '(#xe000 . #xffff) '("dejavu sans mono-11" . "unicode-bmp"))
(set-fontset-font "fontset-default" '(#x0100 . #x24ff) '("dejavu sans mono-11" . "unicode-bmp"))
(set-fontset-font "fontset-default" 'ucs "dejavu sans mono-11")
;; Disable ctrl Z, but only in GUI mode. This is still useful
;; in a terminal
(global-unset-key "\^z")
;; Use a thin bar cursor instead of the block (X11 only)
; (bar-cursor-mode 1)
(scroll-bar-mode -1)
;; Disable toolbar
(tool-bar-mode -1))
;; Disable the useless menu bar
(menu-bar-mode -1)
(require 'package)
(package-initialize)
(add-to-list 'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/") t)
(defvar tr-packages
'(clojure-mode
go-mode
auctex
; cl-lib ;; Required by magit
haskell-mode
js3-mode
magit
markdown-mode
scala-mode2
lua-mode
rust-mode
fic-mode
gitignore-mode
gitconfig-mode
zenburn-theme
naquadah-theme
htmlize
muttrc-mode
git-commit-mode)
"A list of packages to ensure are installed at launch.")
;; Ensure that we have a package list available
(when (not package-archive-contents)
(package-refresh-contents))
;; Install any packages we want that are not on the system
(dolist (pkg tr-packages)
(when (and (not (package-installed-p pkg))
(assoc pkg package-archive-contents))
(package-install pkg)))
(load-theme 'zenburn)
(autoload 'turn-on-fic-mode "fic-mode")
;;; Fancy buffer and file finding
(autoload 'ido-mode "ido")
(add-hook 'after-init-hook
#'(lambda ()
(setq ido-everywhere t)
(ido-mode t)))
;; Let me use just y or n to answer prompts
(fset 'yes-or-no-p 'y-or-n-p)
;;; Set some buffer-local variables to sensible defaults
(setq-default indent-tabs-mode nil)
(setq-default tab-width 2)
(setq-default show-trailing-whitespace t)
(setq-default truncate-lines t)
;;; Set globals
(setq ispell-program-name "aspell")
(setq font-lock-maximum-decoration t)
(setq visible-bell t)
(setq column-number-mode t)
;; Set to t when debugging
(setq debug-on-error nil)
;; Highlight marked regions
(setq transient-mark-mode t)
(setq make-backup-files nil)
(setq split-height-threshold 50)
(setq compilation-window-height 8)
(setq compliation-scroll-output t)
;; Disable vc-mode (using magit)
(setq vc-handled-backends nil)
;; Make font locking quiet
(setq font-lock-verbose nil)
;; Tell uniquify how to mangle buffer names
(setq uniquify-buffer-name-style 'post-forward-angle-brackets)
;; Try to make auto-fill work a bit better in the context of bulleted lists.
(setq paragraph-start "\f\\|>*[ \t]*$\\|>*[ \t]*[-+*] \\|>*[ \t]*[0-9#]+\\. ")
(setq paragraph-separate "$")
;; Don't let the cursor hit the bottom line
(setq scroll-margin 3)
(setq x-select-enable-clipboard t)
;;; Customization requiring calls
(delete-selection-mode t)
(auto-compression-mode t)
(show-paren-mode t)
;; Enable syntax highlighting
(global-font-lock-mode 1)
;; Indicate file size in the modeline
(size-indication-mode 1)
;;; Mail stuff
(add-to-list 'auto-mode-alist '("/tmp/mutt.*" . mail-mode))
(add-hook 'mail-mode-hook
#'(lambda ()
(mail-text) ;; Jump to message body
(flyspell-mode 1) ;; Turn on spellcheck
(turn-on-auto-fill)))
(add-to-list 'auto-mode-alist '(".muttrc\\'" . muttrc-mode))
;;; General programming hooks
(add-hook 'prog-mode-hook 'flyspell-prog-mode)
(add-hook 'prog-mode-hook 'turn-on-fic-mode)
;;; Haskell mode
(add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode)
(add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
(setq haskell-font-lock-symbols nil)
;;; Python mode
(add-to-list 'auto-mode-alist '("SConstruct\\'" . python-mode))
(add-to-list 'auto-mode-alist '("SConscript\\'" . python-mode))
;;; C mode
(defconst tristan-c-style
'((c-tab-always-indent . t)
(c-echo-syntactic-information-p . t)
(tab-width . 2)
(c-basic-offset . 2)
(indent-tabs-mode . nil))
"My C Style")
(setq cpp-known-face 'default)
(setq cpp-unknown-face 'default)
(setq cpp-known-writable 't)
(setq cpp-unknown-writable 't)
(setq cpp-edit-list '(("0" font-lock-comment-face default both)
("1" default font-lock-comment-face both)))
(defun my-c-mode-font-lock-if0 (limit)
(cpp-highlight-buffer t)
nil)
(c-add-style "PERSONAL" tristan-c-style)
(defun my-c-mode-hook ()
(c-set-style "PERSONAL")
(local-set-key "\C-m" 'newline-and-indent)
(c-set-offset 'inline-open 0)
(c-set-offset 'member-init-intro 0)
(c-set-offset 'substatement-open 0)
(c-set-offset 'arglist-cont-nonempty '++)
(auto-fill-mode 1)
(font-lock-add-keywords
nil
'((my-c-mode-font-lock-if0 (0 font-lock-comment-face prepend)))
'add-to-end))
(add-hook 'c-mode-common-hook 'my-c-mode-hook)
(defun llvmize (&optional start end)
"Convert the current buffer or region (containing C code) to LLVM assembly via clang and opt"
(interactive)
(let ((start (if mark-active (region-beginning) (point-min)))
(end (if mark-active (region-end) (point-max)))
;; (major-mode 'llvm-mode)
(buf (generate-new-buffer "*llvm-asm*")))
;; (set-buffer-major-mode buf)
(shell-command-on-region start end "clang -emit-llvm -x c -c -o - - | opt -S -mem2reg -basicaa -gvn" buf)
(set-buffer buf)
(setq buffer-read-only t)
(switch-to-buffer-other-window buf)))
;;; Markdown
(add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
(setq markdown-command "pandoc")
(add-hook 'markdown-mode-hook 'flyspell-mode)
;;; TeX
(setq font-latex-fontify-script nil)
(setq font-latex-fontify-sectioning 'color)
(add-hook 'LaTeX-mode-hook
#'(lambda ()
(custom-set-faces '(font-latex-slide-title-face ((t (:inherit font-lock-type-face)))))
(font-lock-add-keywords nil
'(("\\(\\\\[Cc]ite.*\\)\\s-*{" 1 font-lock-keyword-face t)
("\\(\\\\[Cc]ref.*\\)\\s-*{" 1 font-lock-keyword-face t)
("\\(\\\\lstinline\\)\\s-*{" 1 font-lock-keyword-face t)))
(font-latex-update-sectioning-faces)))
;; Spell check tex documents
(add-hook 'LaTeX-mode-hook 'flyspell-mode)
(add-hook 'LaTeX-mode-hook 'turn-on-fic-mode)
;;; Tag support
(defun make-tags-hook ()
(when (boundp 'tag-builder)
(let ((project-root (locate-dominating-file buffer-file-name ".dir-locals.el")))
(let ((cmd (format "cd %s ; %s &" project-root tag-builder)))
(call-process "bash" nil 0 nil "-c" cmd)))))
(add-hook 'after-save-hook 'make-tags-hook)
(defun set-project-tags ()
(let ((project-root (locate-dominating-file buffer-file-name ".dir-locals.el")))
(let ((tags-file (format "%s/TAGS" project-root)))
(when (file-readable-p tags-file)
(visit-tags-table tags-file)))))
(add-hook 'find-file-hook 'set-project-tags)
;;; Compile support
(defun set-compile-command ()
"Set the compile command based on a `.dir-locals.el' build-method"
(when (boundp 'build-method)
(let ((project-root (locate-dominating-file buffer-file-name ".dir-locals.el")))
(setq compile-command (format "cd %s ; %s" project-root build-method)))))
(add-hook 'find-file-hook 'set-compile-command)
;;; Misc stuff
;; This key is "suspend-frame", which is close to "save-file" and
;; just blocks all input. arrgggg
(global-unset-key "\C-x\C-z")
;; Custom keybindings
(global-set-key (kbd "C-x g") 'magit-status)
(global-set-key (kbd "RET") 'newline-and-indent)
(global-set-key (kbd "C-x c") 'compile)
(global-set-key (kbd "M-/") 'hippie-expand)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment