Skip to content

Instantly share code, notes, and snippets.

@dbp
Last active August 29, 2015 14:13
Show Gist options
  • Save dbp/3b8bb411cbbe7616ad80 to your computer and use it in GitHub Desktop.
Save dbp/3b8bb411cbbe7616ad80 to your computer and use it in GitHub Desktop.
.emacs
;; -*- mode: emacs-lisp -*- ;;
(require 'cl)
;; set up marmelade for package management
(require 'package)
(add-to-list 'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/") t)
;; (add-to-list 'package-archives
;; '("marmalade" .
;; "http://marmalade-repo.org/packages/") t)
(package-initialize)
;; install automatically any that aren't already
;; N.B.: this isn't working - right now it's just a record
(defvar default-packages
'(geiser ; scheme mode
magit ; git helper
haskell-mode ; self explanatory
auctex ; latex mode
highlight-parentheses ; self explanatory
rust-mode ; self explanatory
helm
helm-ag
projectile
helm-projectile
scss-mode ; self explanatory
haml-mode ; self explanatory
multi-web-mode ; a mode to support embedding javascript / css in html
markdown-mode ; self explanatory
multiple-cursors ; a package to allow better rectangular mode with multiple cursors
smart-mode-line
solarized-theme
ghc
company-ghc
tuareg
utop
merlin
))
(mapcar (lambda (p)
(when (not (package-installed-p p)) (package-install p)))
default-packages)
(type-break-mode)
(server-start)
(defun solarized-toggle ()
"Switch between solarized dark and light"
(interactive)
(if (eq dark-or-light 'light)
(progn (setq dark-or-light 'dark)
(load-theme 'solarized-dark t))
(progn (setq dark-or-light 'light)
(load-theme 'solarized-light t))))
(setq dark-or-light 'dark)
(solarized-toggle)
;; configure haskell mode indentation
(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.
'(background-color "#fdf6e3")
'(background-mode light)
'(company-ghc-show-info t)
'(completion-ignored-extensions (quote (".o" "~" ".bin" ".lbin" ".so" ".a" ".ln" ".blg" ".bbl" ".elc" ".lof" ".glo" ".idx" ".lot" ".svn/" ".hg/" ".git/" ".bzr/" "CVS/" "_darcs/" "_MTN/" ".fmt" ".tfm" ".class" ".fas" ".lib" ".mem" ".x86f" ".sparcf" ".dfsl" ".pfsl" ".d64fsl" ".p64fsl" ".lx64fsl" ".lx32fsl" ".dx64fsl" ".dx32fsl" ".fx64fsl" ".fx32fsl" ".sx64fsl" ".sx32fsl" ".wx64fsl" ".wx32fsl" ".fasl" ".ufsl" ".fsl" ".dxl" ".lo" ".la" ".gmo" ".mo" ".toc" ".aux" ".cp" ".fn" ".ky" ".pg" ".tp" ".vr" ".cps" ".fns" ".kys" ".pgs" ".tps" ".vrs" ".pyc" ".pyo" ".hi" ".dyn_hi" ".dyn_o")))
'(coq-prog-args (quote ("-I" "~/annex/code/cpdt/src")))
'(css-indent-offset 2)
'(cursor-color "#657b83")
'(custom-safe-themes (quote ("d677ef584c6dfc0697901a44b885cc18e206f05114c8a3b7fde674fce6180879" "8aebf25556399b58091e533e455dd50a6a9cba958cc4ebb0aab175863c25b9a4" "6a37be365d1d95fad2f4d185e51928c789ef7a4ccf17e7ca13ad63a8bf5b922f" "756597b162f1be60a12dbd52bab71d40d6a2845a3e3c2584c6573ee9c332a66e" default)))
'(display-time-mode t)
'(foreground-color "#657b83")
'(git-state-modeline-decoration (quote git-state-decoration-large-dot))
'(haskell-hoogle-command "hoogle")
'(haskell-process-auto-import-loaded-modules t)
'(haskell-process-log t)
'(haskell-process-type (quote cabal-repl))
'(helm-ag-base-command "ag --nocolor --nogroup --ignore-case")
'(helm-ag-insert-at-point (quote symbol))
'(helm-ag-source-type (quote file-line))
'(helm-buffers-fuzzy-matching t)
'(helm-ff-file-name-history-use-recentf t)
'(helm-ff-search-library-in-sexp t)
'(helm-locate-command "locate %s -e -A %s")
'(helm-match-plugin-mode t nil (helm-match-plugin))
'(helm-mode t)
'(helm-move-to-line-cycle-in-source t)
'(helm-quick-update t)
'(helm-scroll-amount 8)
'(helm-split-window-in-side-p t)
'(inferior-haskell-wait-and-jump t)
'(mm-text-html-renderer (quote w3m))
'(org-agenda-files (quote ("~/annex/todos/school.org" "~/annex/todos/jacobin.org")))
'(org-src-lang-modes (quote (("ocaml" . tuareg) ("elisp" . emacs-lisp) ("ditaa" . artist) ("asymptote" . asy) ("dot" . fundamental) ("sqlite" . sql) ("calc" . fundamental) ("C" . c) ("cpp" . c++) ("C++" . c++) ("screen" . shell-script) ("haskell-simple" . haskell))))
'(package-enable-at-startup t)
'(safe-local-variable-values (quote ((TeX-command-extra-options . "-shell-escape") (flycheck-ghc-search-path "/home/dbp/code/thistle/src") (flycheck-ghc-package-databases "/home/dbp/code/thistle/.cabal-sandbox/x86_64-linux-ghc-7.6.3-packages.conf.d/") (flycheck-ghc-search-path "/home/dbp/code/skilltree/src") (flycheck-ghc-package-databases "/home/dbp/code/skilltree/.cabal-sandbox/x86_64-linux-ghc-7.6.3-packages.conf.d/") (flycheck-ghc-search-path "/home/dbp/code/migrate/src") (flycheck-ghc-package-databases "/home/dbp/code/migrate/.cabal-sandbox/x86_64-linux-ghc-7.6.3-packages.conf.d/") (flycheck-ghc-search-path "/home/dbp/code/snap-testing/src") (flycheck-ghc-package-databases "/home/dbp/code/snap-testing/.cabal-sandbox/x86_64-linux-ghc-7.6.3-packages.conf.d/") (flycheck-ghc-search-path "/home/dbp/code/pcori/src") (flycheck-ghc-no-user-package-database . t) (flycheck-ghc-package-databases "/home/dbp/code/pcori/.cabal-sandbox/x86_64-linux-ghc-7.6.3-packages.conf.d/") (haml-indent-offset . 4) (auto-fill-mode . 1))))
'(sml/battery-format "%p ")
'(sml/replacer-regexp-list (quote (("^~/\\.emacs\\.d/" ":ED:") ("^/sudo:.*:" ":SU:") ("^~/code/pyret-lang/" ":PT:") ("^~/code/captain-teach/" ":CT:"))))
'(sml/show-time t)
'(type-break-interval 1800)
'(type-break-keystroke-threshold (quote (525 . 2625))))
(require 'company)
(if (file-directory-p "~/code/structured-haskell-mode/elisp")
(progn
(add-to-list 'load-path "~/code/structured-haskell-mode/elisp")
(require 'shm)
(add-to-list 'company-backends 'company-ghc)
(add-hook 'haskell-mode-hook 'structured-haskell-mode)
;(add-hook 'haskell-mode-hook 'company-mode)
(add-hook 'haskell-mode-hook (lambda () (ghc-init)))
(setq haskell-stylish-on-save t)
(set-face-background 'shm-current-face "#eee8d5")
(set-face-background 'shm-quarantine-face "lemonchiffon")
(eval-after-load "haskell-mode"
'(progn
(define-key haskell-mode-map (kbd "C-c C-l") 'haskell-process-load-or-reload)
(define-key haskell-mode-map (kbd "C-`") 'haskell-interactive-bring)
(define-key haskell-mode-map (kbd "C-c C-t") 'haskell-process-do-type)
(define-key haskell-mode-map (kbd "C-c C-i") 'haskell-process-do-info)
(define-key haskell-mode-map (kbd "C-c C-c") 'haskell-process-cabal-build)
(define-key haskell-mode-map (kbd "C-c C-k") 'haskell-interactive-mode-clear)
(define-key haskell-mode-map (kbd "C-c c") 'haskell-process-cabal)
(define-key haskell-mode-map (kbd "SPC") 'haskell-mode-contextual-space)))
;; NOTE(dbp 2014-11-07): overriding to get it to use helm. Not sure if there
;; is a better way to do this (racket's parametrize would be great!).
(defun shm/yank-pop ()
"Yank from the kill ring and insert indented with `shm-insert-indented'."
(interactive)
(shm-with-fallback
helm-show-kill-ring
(if (not (eq last-command 'yank))
(error "Previous command was not a yank (error from shm/yank-pop)"))
(shm-insert-indented #'yank-pop)))
))
;; for javascript, use 2 spaces
(setq js-indent-level 2)
;; from http://www.emacswiki.org/emacs/ElispCookbook#toc6
(defun trim-whitespace (str)
"Chomp leading and tailing whitespace from STR."
(while (string-match "\\`\n+\\|^\\s-+\\|\\s-+$\\|\n+\\'"
str)
(setq str (replace-match "" t t str)))
str)
;; uuids!
(defun uuid ()
"Insert a random universally unique identifier (UUID)."
(interactive)
(insert (trim-whitespace (shell-command-to-string "uuidgen"))))
;; require git-emacs
(if (file-directory-p "~/code/git-emacs")
(progn
(add-to-list 'load-path "~/code/git-emacs")
(require 'git-emacs)
(define-key git-global-map "r" (function
(lambda ()
(interactive)
(git-after-working-dir-change)
(git--update-all-state-marks))))
(add-hook 'git-comment-hook
(function (lambda ()
(turn-on-auto-fill))))
))
;; stop wasting screen real estate on buttons
(tool-bar-mode -1)
(menu-bar-mode -1)
;; don't display splash screen on startup
(setq inhibit-splash-screen t)
; better M-x
(global-set-key (kbd "M-x") 'helm-M-x)
;; return should indent as well
(global-set-key (kbd "RET") 'newline-and-indent)
;; this means you go to the beginning of the code, not the beginning of the line
(global-set-key (kbd "C-a") 'back-to-indentation)
; with shift, actually go to the beginning of line
(global-set-key (kbd "C-S-a") 'beginning-of-line)
;; handle auto-commenting better by rebinding C-; to comment/uncomment
(defun comment-or-uncomment-region-or-line ()
"Comments or uncomments the region or the current line if there's no active region."
(interactive)
(let (beg end)
(if (region-active-p)
(setq beg (region-beginning) end (region-end))
(setq beg (line-beginning-position) end (line-end-position)))
(comment-or-uncomment-region beg end)
(next-line)))
(global-set-key (kbd "M-;") 'comment-or-uncomment-region-or-line)
;; be able to open up compressed files
(auto-compression-mode 1)
;; show column number in modeline
(column-number-mode 1)
;; show parenthesis
(show-paren-mode 1)
;; short yes/no prompts
(fset 'yes-or-no-p 'y-or-n-p)
;; make buffers with the same file name use file:path/fragment to distinguish
(require 'uniquify)
(setq
uniquify-buffer-name-style 'post-forward
uniquify-separator ":")
;; for web editing
(setq mweb-default-major-mode 'html-mode)
(setq mweb-tags
'((php-mode "<\\?php\\|<\\? \\|<\\?=" "\\?>")
(js-mode "<script +\\(type=\"text/javascript\"\\|language=\"javascript\"\\)[^>]*>" "</script>")
(css-mode "<style +type=\"text/css\"[^>]*>" "</style>")))
(setq mweb-filename-extensions '("php" "htm" "html" "ctp" "phtml" "php4" "php5" "tpl"))
;; don't use tabs, ever
(setq-default indent-tabs-mode nil)
;; use xpp to select printer
(setq lpr-command "xpp")
;; require mode for urweb
(if (file-directory-p "~/dropbox/config/urweb-mode")
(progn
(add-to-list 'load-path "~/dropbox/config/urweb-mode")
(load "urweb-mode-startup")
))
;; setting up multiple cursors
(require 'multiple-cursors)
(global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines)
(global-set-key (kbd "C->") 'mc/mark-next-like-this)
(global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
(global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this)
;; heist templates are html
(add-to-list 'auto-mode-alist '("[.]tpl$" . multi-web-mode))
;; lss files are (close enough to) css
(add-to-list 'auto-mode-alist '("[.]lss$" . css-mode))
;; easily move text around, line by line; courtesy of
;; http://stackoverflow.com/questions/2423834/move-line-region-up-and-down-in-emacs#answer-2425753
(defun move-line-up ()
(interactive)
(transpose-lines 1)
(previous-line 2))
(global-set-key [M-up] 'move-line-up)
;; move line down
(defun move-line-down ()
(interactive)
(next-line 1)
(transpose-lines 1)
(previous-line 1))
(global-set-key [M-down] 'move-line-down)
(defun todo ()
"Insert a new dated TODO comment"
(interactive)
(when (region-active-p)
(delete-region (region-beginning) (region-end) )
)
(end-of-line)
(insert (format-time-string "TODO(dbp %Y-%m-%d): "))
(comment-or-uncomment-region-or-line)
(previous-line)
(end-of-line)
)
(defun note ()
"Insert a new dated NOTE comment"
(interactive)
(when (region-active-p)
(delete-region (region-beginning) (region-end) )
)
(end-of-line)
(insert (format-time-string "NOTE(dbp %Y-%m-%d): "))
(comment-or-uncomment-region-or-line)
(previous-line)
(end-of-line)
)
;; trailing whitespace is evil
(add-hook 'before-save-hook 'delete-trailing-whitespace)
;; no backup file vomit
(setq backup-directory-alist `(("." . "~/.saves")))
(setq backup-by-copying t)
(setq delete-old-versions t
kept-new-versions 6
kept-old-versions 2
version-control t)
(put 'downcase-region 'disabled nil)
(defun* get-closest-pathname (&optional (file "Makefile"))
"Determine the pathname of the first instance of FILE starting from the current directory towards root.
This may not do the correct thing in presence of links. If it does not find FILE, then it shall return the name
of FILE in the current directory, suitable for creation"
(let ((root (expand-file-name "/"))) ; the win32 builds should translate this correctly
(expand-file-name file
(loop
for d = default-directory then (expand-file-name ".." d)
if (file-exists-p (expand-file-name file d))
return d
if (equal d root)
return nil))))
(if (file-exists-p "/usr/share/emacs24/site-lisp/proofgeneral")
(load-file "/usr/share/emacs24/site-lisp/proofgeneral/generic/proof-site.el"))
(defun org-babel-execute:haskell-simple (body params)
(let* ((tangle (cdr (assoc :tangle params)))
(script-file
(if (string-equal tangle "no")
(org-babel-temp-file "org-babel-" ".hs")
tangle)))
(with-temp-file script-file
(insert body))
(let* ((pn (org-babel-process-file-name script-file))
(cmd (format "/home/dbp/ghc/bin/runghc %s" pn)))
(message cmd)
(shell-command-to-string cmd)
)))
(defun my-org-confirm-babel-evaluate (lang body)
(not (string= lang "haskell-simple")))
(setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate)
(defun org-babel-execute:ocaml (body params)
(let* ((tangle (cdr (assoc :tangle params)))
(script-file
(if (string-equal tangle "no")
(org-babel-temp-file "org-babel-" ".ml")
tangle)))
(with-temp-file script-file
(insert body))
(let* ((pn (org-babel-process-file-name script-file))
(cmd (format "/home/dbp/.opam/system/bin/coretop %s" pn)))
(message cmd)
(shell-command-to-string cmd)
)))
(defun my-org-confirm-babel-evaluate (lang body)
(not (or (string= lang "haskell-simple") (string= lang "ocaml"))))
(setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate)
(setq org-src-fontify-natively t)
;(setq org-src-window-setup 'current-window)
;; NOTE(dbp 2014-11-05): I want to be able to edit live, so don't steal arrow keys!
;; (define-key org-present-mode-keymap [right] 'right-char)
;; (define-key org-present-mode-keymap [left] 'left-char)
;; (define-key org-present-mode-keymap (kbd "C-n") 'org-present-next)
;; (define-key org-present-mode-keymap (kbd "C-p") 'org-present-prev)
(setq epresent-text-scale 5)
(require 'helm-config)
(global-set-key (kbd "C-c h") 'helm-command-prefix)
(global-unset-key (kbd "C-x c"))
;; (define-key helm-map (kbd "<tab>") 'helm-execute-persistent-action) ; rebihnd tab to do persistent action
;; (define-key helm-map (kbd "C-i") 'helm-execute-persistent-action) ; make TAB works in terminal
;; (define-key helm-map (kbd "C-z") 'helm-select-action) ; list actions using C-z
(setq helm-quick-update t ; do not display invisible candidates
helm-split-window-in-side-p t ; open helm buffer inside current window, not occupy whole other window
helm-buffers-fuzzy-matching t ; fuzzy matching buffer names when non--nil
helm-move-to-line-cycle-in-source t ; move to end or beginning of source when reaching top or bottom of source.
helm-ff-search-library-in-sexp t ; search for library in `require' and `declare-function' sexp.
helm-scroll-amount 8 ; scroll 8 lines other window using M-<next>/M-<prior>
helm-ff-file-name-history-use-recentf t)
(defun projectile-helm-ag ()
(interactive)
(helm-ag (projectile-project-root)))
(defun projectile-helm-do-ag ()
(interactive)
(helm-do-ag (projectile-project-root)))
(setq helm-ag-base-command "ag --nocolor --nogroup --ignore-case")
; (setq helm-ag-command-option "")
(setq helm-ag-insert-at-point 'symbol)
(setq helm-ag-source-type 'file-line)
(setq projectile-switch-project-action 'helm-my-mini)
(helm-mode 1)
(require 'helm-projectile)
(define-key helm-map (kbd "<tab>") 'helm-execute-persistent-action)
(define-key helm-map (kbd "C-i") 'helm-execute-persistent-action)
(define-key helm-map (kbd "C-z") 'helm-select-action)
(global-set-key (kbd "M-y") 'helm-show-kill-ring)
(global-set-key (kbd "C-c h o") 'helm-occur)
(global-set-key (kbd "C-c h s") 'projectile-helm-do-ag)
(defun helm-my-mini ()
(interactive)
(let ((helm-ff-transformer-show-only-basename nil))
(helm-other-buffer
(if (eq nil (ignore-errors (projectile-project-root)))
'(helm-c-source-buffers-list
helm-c-source-recentf
helm-c-source-files-in-current-dir
helm-source-buffer-not-found)
'(helm-source-projectile-buffers-list
helm-source-projectile-recentf-list
helm-source-projectile-files-list
helm-c-source-buffers-list
helm-c-source-recentf
helm-source-buffer-not-found))
"*helm-my-mini*")))
(global-set-key (kbd "C-x C-f") 'helm-find-files)
(global-set-key (kbd "C-x b") 'helm-my-mini)
(projectile-global-mode)
(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.
'(helm-selection-line ((t (:background "navajo white" :underline t)))))
(setq auto-mode-alist
(append '(("\\.ml[ily]?$" . tuareg-mode)
("\\.topml$" . tuareg-mode))
auto-mode-alist))
(autoload 'utop-setup-ocaml-buffer "utop" "Toplevel for OCaml" t)
(add-hook 'tuareg-mode-hook 'utop-setup-ocaml-buffer)
(add-hook 'tuareg-mode-hook 'merlin-mode)
; (setq merlin-use-auto-complete-mode t)
(setq opam-share (substring (shell-command-to-string "opam config var share") 0 -1))
(add-to-list 'load-path (concat opam-share "/emacs/site-lisp"))
(setq merlin-command 'opam)
;(require 'ocp-indent)
(add-to-list 'company-backends 'merlin-company-backend)
; Enable company on merlin managed buffers
(add-hook 'merlin-mode-hook 'company-mode)
(setq tramp-default-method "ssh")
(setq tramp-auto-save-directory "/tmp/tramp-autosave")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment