Skip to content

Instantly share code, notes, and snippets.

@dbp
Created March 18, 2014 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbp/9627194 to your computer and use it in GitHub Desktop.
Save dbp/9627194 to your computer and use it in GitHub Desktop.
;; -*- 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
smex ; better M-x
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
flycheck
flycheck-haskell
))
(mapcar (lambda (p)
(when (not (package-installed-p p)) (package-install p)))
default-packages)
;; 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.
'(coq-prog-args (quote ("-I" "~/annex/code/cpdt/src")))
'(display-time-mode t)
'(git-state-modeline-decoration (quote git-state-decoration-large-dot))
'(org-agenda-files (quote ("~/annex/todos/school.org" "~/annex/todos/jacobin.org")))
'(safe-local-variable-values (quote ((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))
(add-to-list 'load-path "~/code/structured-haskell-mode/elisp")
(require 'shm)
(add-hook 'haskell-mode-hook 'structured-haskell-mode)
(set-face-background 'shm-current-face "#eee8d5")
(set-face-background 'shm-quarantine-face "lemonchiffon")
;; 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 "~/bin/uuidgen"))))
;; require proof general
(load-file "~/annex/code/ProofGeneral-4.2/generic/proof-site.el")
;; check syntax
(add-hook 'after-init-hook #'global-flycheck-mode)
(add-hook 'flycheck-mode-hook #'flycheck-haskell-setup)
;; load highlighting for pyret!
(when (file-exists-p "~/code/pyret-lang/src/emacs/pyret.el")
(load-file "~/code/pyret-lang/src/emacs/pyret.el")
(add-to-list 'auto-mode-alist '("\\.arr$" . pyret-mode))
(add-to-list 'file-coding-system-alist '("\\.arr\\'" . utf-8)))
;; require git-emacs
(add-to-list 'load-path "~/annex/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)
;; ido for smart completions
(require 'ido)
(ido-mode t)
;; match with gaps
(setq ido-enable-flex-matching t)
;; don't ever search for open buffers with the same name
(setq ido-auto-merge-delay-time 99999)
;; use smex, which is M-x + ido
(smex-initialize)
(global-set-key (kbd "M-x") 'smex)
(global-set-key (kbd "M-X") 'smex-major-mode-commands)
;; bind old M-x in case
(global-set-key (kbd "C-c C-c M-x") 'execute-extended-command)
;; tell geiser to not look for guile
;(setq geiser-active-implementations '(racket))
;; 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 ":")
;; set up auctex
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq TeX-save-query nil)
(setq TeX-PDF-mode t)
(setq TeX-output-view-style
(quote
(("^pdf$" "." "evince -f %o")
("^html?$" "." "iceweasel %o"))))
(setq TeX-show-compilation nil)
;; function to swap windows
(setq swapping-buffer nil)
(setq swapping-window nil)
(defun swap-buffers-in-windows ()
"Swap buffers between two windows"
(interactive)
(if (and swapping-window
swapping-buffer)
(let ((this-buffer (current-buffer))
(this-window (selected-window)))
(if (and (window-live-p swapping-window)
(buffer-live-p swapping-buffer))
(progn (switch-to-buffer swapping-buffer)
(select-window swapping-window)
(switch-to-buffer this-buffer)
(select-window this-window)
(message "Swapped buffers."))
(message "Old buffer/window killed. Aborting."))
(setq swapping-buffer nil)
(setq swapping-window nil))
(progn
(setq swapping-buffer (current-buffer))
(setq swapping-window (selected-window))
(message "Buffer and window marked for swapping."))))
(global-set-key (kbd "C-c p") 'swap-buffers-in-windows)
(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.
)
;; 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"))
;; don't use tabs, ever
(setq-default indent-tabs-mode nil)
;; use xpp to select printer
(setq lpr-command "xpp")
;; require mode for urweb
(add-to-list 'load-path "~/annex/code/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))
;; 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)
;; auto-open/close parens
;; (electric-pair-mode +1)
;; org mode
(setq org-directory "~/annex/todos/")
;; set up email
(add-to-list 'load-path "~/annex/code/notmuch")
(require 'notmuch)
(setq notmuch-command "notmuch")
;; (setq notmuch-command "~/annex/bin/notmuch")
;; use threaded interface
(load-file "~/annex/code/notmuch/notmuch-pick.el")
(require 'notmuch-pick nil t)
;; use Bcc instead of Fcc because our mail is remote
(setq notmuch-fcc-dirs nil)
(setq notmuch-always-prompt-for-sender t)
(add-hook 'message-header-setup-hook
(lambda () (insert (format "Bcc: %s <%s>\n"
(notmuch-user-name)
(notmuch-user-primary-email)))))
(setq smtpmail-starttls-credentials '(("dbpmail.net" 587 nil nil)) ; Must be set BEFORE loading smtpmail
smtpmail-auth-credentials (expand-file-name "~/.authinfo")
smtpmail-default-smtp-server "dbpmail.net"
smtpmail-smtp-server "dbpmail.net"
smtpmail-smtp-service 587
smtpmail-debug-info t ; change to nil once it works
smtpmail-debug-verb t)
(when (memq window-system '(mac ns))
(exec-path-from-shell-initialize)
(setq starttls-use-gnutls t)
(setq starttls-gnutls-program "gnutls-cli")
(setq starttls-extra-arguments nil)
)
;; sign messages by default
(add-hook 'message-setup-hook 'mml-secure-message-sign-pgpmime)
;; use the notmuch database for address autocompletion
(require 'notmuch-address)
(setq notmuch-address-command "addrlookup")
(notmuch-address-message-insinuate)
(setq starttls-use-gnutls t)
(setq notmuch-search-oldest-first nil)
(require 'smtpmail)
(setq message-send-mail-function 'smtpmail-send-it)
(require 'starttls)
;; a hack to import gpg pub keys on server, hopefully to be replaced
;; later by notmuch emacs functionality
(defun gpg-notmuch ()
"Import a pub key on server"
(interactive (let ((id (read-string "Key Id: " nil 'my-history)))
(shell-command-to-string (concat "ssh dbpmail gpg --recv-key " id))
(void))))
;; some tagging helpers
;; from http://notmuchmail.org/emacstips/#index8h2
(define-key notmuch-search-mode-map "S"
(lambda ()
"mark messages in thread as spam"
(interactive)
(notmuch-search-tag '("+spam" "-inbox" "-important"))
(notmuch-search-next-thread)))
;; display battery and time
(display-battery-mode 1)
(defun new-important-mail ()
"Return t if new important mail, else nil"
(if (string= (trim-whitespace (shell-command-to-string "~/annex/bin/notmuch count tag:inbox AND tag:unread")) "0")
nil
t))
(setq display-time-mail-function 'new-important-mail)
;;(display-time-mode 1)
(setq display-time-use-mail-icon t)
;; smart mode line
(require 'smart-mode-line)
(if after-init-time (sml/setup)
(add-hook 'after-init-hook 'sml/setup))
(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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment