Skip to content

Instantly share code, notes, and snippets.

@chuckadams
Last active December 4, 2018 13:01
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 chuckadams/c9c925c83501a647d712f15279212b42 to your computer and use it in GitHub Desktop.
Save chuckadams/c9c925c83501a647d712f15279212b42 to your computer and use it in GitHub Desktop.
My .emacs file
;;
;; .emacs file of Chuck Adams <cja987@gmail.com>
;;
;; Anyone is free to use any part of this file, and I try to keep it
;; helpfully commented, but they should know that I haven't kept
;; portability foremost. It's really only designed to work on my
;; machine, with its own set of customizations. Caveat Hacker.
;;
;;;;;;;;;;;;;;;; First Things First
(add-to-list 'load-path "~/.emacs.d/lisp/")
;; Emacs launched from a GUI often has a stripped-down PATH
(add-to-list 'exec-path (expand-file-name "/usr/local/bin"))
(add-to-list 'exec-path (expand-file-name "~/bin"))
(package-initialize)
(add-to-list 'package-archives
'("melpa-stable" . "http://melpa-stable.milkbox.net/packages/") t)
;; I recommend only uncommenting this if you need bleeding edge stuff
;; (add-to-list 'package-archives
;; '("melpa" . "http://melpa.org/packages/") t)
;;;;;;;;;;;;;;;; Global keybinds
;; "hyper" key is shift-ctrl-opt-cmd mapped to capslock in Karabiner.
(defmacro hyper-key (key) `[(control shift meta super ,key)])
(global-set-key [(control x) (control l)] 'find-library)
(global-set-key [(super up)] 'previous-error)
(global-set-key (hyper-key up) 'previous-error)
(global-set-key [(super down)] 'next-error)
(global-set-key (hyper-key down) 'next-error)
(global-set-key (kbd "C-z") 'undo)
(global-set-key (kbd "M-/") 'hippie-expand)
;; This key combo won't even register in MacOS
;; (global-set-key (hyper-key /) 'hippie-expand)
;; emacs won't accept this for some stupid reason...
;; (global-set-key (hyper-key SPC) 'hippie-expand)
(global-set-key (kbd "C-M-S-s-SPC") 'hippie-expand)
;; cmd-click like most IDEs. shift-cmd-click is my extension.
(define-key key-translation-map [(super mouse-1)] [(meta .)])
(define-key key-translation-map [(super shift mouse-1)] [(meta *)])
;; search with regexes, crappy as they are in emacs...
;; I'm using swiper instead now
;; (global-set-key (kbd "C-s") 'isearch-forward-regexp)
;; (global-set-key (kbd "C-r") 'isearch-backward-regexp)
;; (global-set-key (kbd "C-M-s") 'isearch-forward)
;; (global-set-key (kbd "C-M-r") 'isearch-backward)
;;;;;;;;;;;;;;;; Utilities
;; The dim docs suggest another way, but this works better.
(defun silence-mode-indicator (sym)
"Prevents the given mode from showing up on the modeline"
(when (require 'dim nil t)
(dim-major-name sym "")
(dim-minor-name sym "")))
;;;;;;;;;;;;;;;; Fonts
;; Burn me at the stake if you like, but I like ligatures in coding fonts.
(when (window-system)
(set-frame-font "Fira Code 14"))
(let ((alist '((33 . ".\\(?:\\(?:==\\|!!\\)\\|[!=]\\)")
(35 . ".\\(?:###\\|##\\|_(\\|[#(?[_{]\\)")
(36 . ".\\(?:>\\)")
(37 . ".\\(?:\\(?:%%\\)\\|%\\)")
(38 . ".\\(?:\\(?:&&\\)\\|&\\)")
(42 . ".\\(?:\\(?:\\*\\*/\\)\\|\\(?:\\*[*/]\\)\\|[*/>]\\)")
(43 . ".\\(?:\\(?:\\+\\+\\)\\|[+>]\\)")
(45 . ".\\(?:\\(?:-[>-]\\|<<\\|>>\\)\\|[<>}~-]\\)")
(46 . ".\\(?:\\(?:\\.[.<]\\)\\|[.=-]\\)")
(47 . ".\\(?:\\(?:\\*\\*\\|//\\|==\\)\\|[*/=>]\\)")
(48 . ".\\(?:x[a-zA-Z]\\)")
(58 . ".\\(?:::\\|[:=]\\)")
(59 . ".\\(?:;;\\|;\\)")
(60 . ".\\(?:\\(?:!--\\)\\|\\(?:~~\\|->\\|\\$>\\|\\*>\\|\\+>\\|--\\|<[<=-]\\|=[<=>]\\||>\\)\\|[*$+~/<=>|-]\\)")
(61 . ".\\(?:\\(?:/=\\|:=\\|<<\\|=[=>]\\|>>\\)\\|[<=>~]\\)")
(62 . ".\\(?:\\(?:=>\\|>[=>-]\\)\\|[=>-]\\)")
(63 . ".\\(?:\\(\\?\\?\\)\\|[:=?]\\)")
(91 . ".\\(?:]\\)")
(92 . ".\\(?:\\(?:\\\\\\\\\\)\\|\\\\\\)")
(94 . ".\\(?:=\\)")
(119 . ".\\(?:ww\\)")
(123 . ".\\(?:-\\)")
(124 . ".\\(?:\\(?:|[=|]\\)\\|[=>|]\\)")
(126 . ".\\(?:~>\\|~~\\|[>=@~-]\\)")
)
))
(dolist (char-regexp alist)
(set-char-table-range composition-function-table (car char-regexp)
`([,(cdr char-regexp) 0 font-shape-gstring]))))
;;;;;;;;;;;;;;;; Global Modes
;;;; Company: the least crappy autocomplete around. It still needs fixing...
(when (require 'company nil t)
(add-hook 'after-init-hook 'global-company-mode)
(with-eval-after-load 'company
(silence-mode-indicator 'company-mode)
(silence-mode-indicator 'global-company-mode)
(global-set-key (kbd "C-c /") 'company-files)
(defun company--my-insert-spc() (interactive) (company-abort)(insert-char #10r32))
(defun company--my-insert-dot() (interactive) (company-abort)(insert-char #10r46))
(define-key company-active-map (kbd "SPC") 'company--my-insert-spc)
(define-key company-active-map (kbd ".") 'company--my-insert-dot)))
;; discover-my-major: major mode help that's actually useful
(when (require 'discover-my-major nil t)
(global-set-key (kbd "C-h C-m") 'discover-my-major))
;; helpful: more, uh, helpful help.
;; https://github.com/wilfred/helpful
(when (require 'helpful nil t)
(global-set-key (kbd "C-h f") #'helpful-callable)
(global-set-key (kbd "C-h v") #'helpful-variable)
(global-set-key (kbd "C-h k") #'helpful-key)
(global-set-key (kbd "C-c C-d") #'helpful-at-point)
(global-set-key (kbd "C-h F") #'helpful-function)
(global-set-key (kbd "C-h C") #'helpful-command))
;; smex: what meta-x should be, and still better completion than amx.
(when (require 'smex nil t)
(global-set-key (kbd "M-x") 'smex)
(global-set-key (kbd "M-X") 'smex-major-mode-commands))
;; swiper: isearch with preview
(when (require 'swiper nil t)
(global-set-key [(control s)] 'swiper))
;; undo-tree
(when (require 'undo-tree nil t)
(global-set-key [(control x) (control z)] 'undo-tree-visualize)
(define-key undo-tree-visualizer-mode-map
(kbd "RET") 'undo-tree-visualizer-quit))
;;;;;;;;;;;;;;;; Haskell
;; I recommend using bleeding-edge intero from melpa, not melpa-stable
(add-hook 'haskell-mode-hook 'intero-mode)
;;;;;;;;;;;;;;;; Idris
(defun my-idris-mode-hook ()
(interactive)
(define-key idris-mode-map (hyper-key l) 'idris-load-file)
(define-key idris-mode-map (hyper-key t) 'idris-type-at-point)
(require 'flycheck)
;; Redefines the flychecker from idris-mode.el to recognize
;; the newer error message format with column ranges. Yay.
(flycheck-define-checker idris
"An Idris syntax and type checker."
:command ("idris"
"--check" "--nocolor" "--warnpartial"
;; Compute the command-line options similarly to inferior-idris
(eval (idris-compute-flags))
source)
:error-patterns
;; Original
;; ((warning line-start (file-name) ":" line ":" column ":Warning - "
;; (message (and (* nonl) (* "\n" (not (any "/" "~")) (* nonl)))))
;; (error line-start (file-name) ":" line ":" column ":"
;; (message (and (* nonl) (* "\n" (not (any "/" "~")) (* nonl))))))
;; Patched to support ranges like "foo.idr:3:4-10:"
;; Uses the 'rx' macro -- see its doc for syntax
((warning line-start (file-name) ":" line ":" column (? "-" (+ digit)) ":Warning - "
(message (and (* nonl) (* "\n" (not (any "/" "~")) (* nonl)))))
(error line-start (file-name) ":" line ":" column (? "-" (+ digit)) ":"
(message (and (* nonl) (* "\n" (not (any "/" "~")) (* nonl))))))
:modes idris-mode)
(flycheck-mode t))
(add-hook 'idris-mode-hook 'my-idris-mode-hook)
;;;;;;;;;;;;;;;; Scheme
;;(require 'geiser nil t)
;;(require 'quack nil t)
;;;;;;;;;;;;;;;; Other Modes
;;;; html and other web stuff
(when (locate-library "emmet-mode")
(add-hook 'sgml-mode-hook 'emmet-mode)
(add-hook 'html-mode-hook 'emmet-mode)
(add-hook 'css-mode-hook 'emmet-mode))
;;;; package-mode
(add-hook 'package-menu-mode-hook 'hl-line-mode)
;; All this just to widen one column. Sigh.
(define-derived-mode package-menu-mode tabulated-list-mode "Package Menu"
"Major mode for browsing a list of packages.
Letters do not insert themselves; instead, they are commands.
\\<package-menu-mode-map>
\\{package-menu-mode-map}"
(setq tabulated-list-format
`[("Package" 24 package-menu--name-predicate)
("Version" 12 nil)
("Status" 10 package-menu--status-predicate)
,@(if (cdr package-archives)
'(("Archive" 10 package-menu--archive-predicate)))
("Description" 0 nil)])
(setq tabulated-list-padding 2)
(setq tabulated-list-sort-key (cons "Status" nil))
(add-hook 'tabulated-list-revert-hook 'package-menu--refresh nil t)
(tabulated-list-init-header))
;;;;;;;;;;;;;;;; Misc
(setq apropos-do-all t)
(setq ediff-window-setup-function 'ediff-setup-windows-plain)
(setq line-number-display-limit-width 100000)
(fset 'yes-or-no-p 'y-or-n-p)
;; Keep backups and autosaves in ~/.emacs.d/backups
(setq backup-directory-alist
`(("." . ,(concat user-emacs-directory "backups"))))
(setq auto-save-file-name-transforms
`((".*" , (concat user-emacs-directory "backups"))))
;; suppress the split behavior when loading multiple files
(setq inhibit-startup-buffer-menu t)
(add-hook 'emacs-startup-hook 'delete-other-windows)
;;;;;;;;;;;;;;;; Automatic stuff
;; I left this here for example, but I like everything in one place
;; (setq custom-file (concat user-emacs-directory "custom.el"))
;; (when (file-exists-p custom-file)
;; (load custom-file))
(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.
'(amx-backend (quote ido))
'(apropos-do-all t t)
'(blink-cursor-mode nil)
'(column-number-mode t)
'(company-auto-complete (quote (quote company-explicit-action-p)))
'(company-minimum-prefix-length 2)
'(company-show-numbers t)
'(custom-safe-themes t)
'(custom-theme-directory "~/.emacs.d/")
'(custom-unlispify-remove-prefixes t)
'(emmet-indentation 2)
'(emmet-preview-default t)
'(flx-ido-mode t)
'(fringe-mode 0 nil (fringe))
'(gc-cons-percentage 0.3)
'(gc-cons-threshold 24000000)
'(global-undo-tree-mode t)
'(ido-use-faces t)
'(ido-use-virtual-buffers (quote auto))
'(indent-tabs-mode nil)
'(inhibit-startup-screen t)
'(intero-package-version "0.1.34")
'(js-indent-level 2)
'(line-move-visual nil)
'(line-number-display-limit-width 100000)
'(load-prefer-newer t)
'(mouse-yank-at-point t)
'(package-selected-packages
(quote
(undo-tree js2-mode smex popwin flycheck-hdevtools flycheck-haskell helpful hasky-stack intero swiper idris-mode reveal-in-osx-finder sass-mode scss-mode osx-browse osx-clipboard osx-trash owdriver neotree noccur modalka mykie markdown-mode markdown-preview-mode markdown-toc mc-extras highlight-blocks idle-highlight-mode ido-complete-space-or-hyphen ido-completing-read+ ido-grid-mode ido-occur ido-ubiquitous import-js ioccur jade-mode key-combo keydef lentic less-css-mode list-packages-ext magit magit-filenotify magit-find-file magit-gitflow deft diff-hl discover-my-major flycheck-pos-tip flycheck-tip flymake-easy flymake-gjshint fm ggtags git-link goto-last-change guide-key guide-key-tip helm helm-ag helm-c-yasnippet helm-descbinds helm-flycheck helm-git-grep helm-gtags helm-swoop helm-unicode ctags-update company-statistics company-tern company-ycmd company charmap bury-successful-compilation auto-yasnippet multiple-cursors yasnippet ag projectile dim helm-projectile flx-ido flx-isearch company-flx company-quickhelp company-restclient company-shell company-web company-go ac-html ac-html-angular ac-html-bootstrap ac-html-csswatcher emmet-mode flycheck flycheck-color-mode-line auto-complete web-mode)))
'(paradox-github-token t)
'(projectile-mode-line nil)
'(quack-default-program "/Users/chuck/opt/racket/bin/racket")
'(quack-programs
(quote
("/Users/chuck/opt/racket/bin/racket" "bigloo" "csi" "csi -hygienic" "gosh" "gracket" "gsi" "gsi ~~/syntax-case.scm -" "guile" "kawa" "mit-scheme" "racket" "racket -il typed/racket" "rs" "scheme" "scheme48" "scsh" "sisc" "stklos" "sxi")))
'(require-final-newline t)
'(save-place-mode t)
'(scroll-bar-mode nil)
'(show-paren-mode t)
'(show-paren-style (quote expression))
'(size-indication-mode t)
'(special-display-regexps
(quote
("[ ]?[*][^*]+[*]XXXDISABLED" "[ ]?[*]idris-[^*]+[*]")))
'(tool-bar-mode nil)
'(undo-tree-mode-lighter ""))
(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.
'(show-paren-match ((t (:background "#cfa"))))
'(show-paren-mismatch ((t (:background "#fab")))))
;;;;;;;;;;;;;;;; Last Things Last
;; Allow a local.el file to override anything here.
(let ((local-el (concat user-emacs-directory "local.el")))
(when (file-exists-p local-el)
(load local-el)))
(put 'upcase-region 'disabled nil)
(put 'narrow-to-region 'disabled nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment