(require 'package) (setq package-user-dir "~/.emacs.d/var/elpa") (setq package-archives (append package-archives '(("melpa" . "https://melpa.milkbox.net/packages/")))) (package-initialize) (setq package-enable-at-startup nil) (unless package-archive-contents (message "Refreshing ELPA package archives...") (package-refresh-contents)) (defvar package-list) (setq package-list '( ag ansible ansible-doc counsel exec-path-from-shell flycheck flycheck-pos-tip flyspell geiser go-eldoc go-mode helm magit markdown-mode material-theme projectile puppet-mode swiper thrift )) ;; Install any missing packages (dolist (package package-list) (unless (package-installed-p package) (package-install package))) ;; alias yes-or-no to y-or-n (fset 'yes-or-no-p 'y-or-n-p) ;; set utf-8 as the default encoding (prefer-coding-system 'utf-8-unix) ;; reload the buffer when a file changes (global-auto-revert-mode 1) (setq auto-save-default nil auto-save-list-file-prefix nil make-backup-files nil require-final-newline t vc-follow-symlinks t next-screen-context-lines 5 tab-always-indent 'complete) ;; turn off indent tabs (setq-default indent-tabs-mode nil) ;; nice font (set-face-attribute 'default nil :font "Source Code Pro" :height 130) (set-background-color "#FFFFD3") (set-face-attribute 'fringe nil :background "#FFFFD3") (set-face-background 'mode-line "#D8E6F3") ;; no menu (menu-bar-mode -1) ;; show parenthesis (show-paren-mode +1) ;; disable colors (global-font-lock-mode -1) ;; no startup screen (setq inhibit-startup-message t) (setq initial-scratch-message "") ;; no blink cursor (blink-cursor-mode -1) ;; show the column number in the mode-line (setq column-number-mode t) (when window-system (tool-bar-mode 0) ;;hide tool-bar (scroll-bar-mode 0) ;;hide scroll-bar (menu-bar-mode -1)) ;;hide menu-bar ;; no frindge on the right (fringe-mode '(4 . 0)) ;; auto close bracket insertion (electric-pair-mode 1) ;; if running in macos, load environment variables (when (memq window-system '(mac ns x)) (exec-path-from-shell-initialize) (exec-path-from-shell-copy-envs '("TMPDIR"))) ;; use dired and set default switches (require 'dired) (setq dired-listing-switches "-laGhv") ;; configure default path to save recent files (require 'recentf) (setq recentf-save-file "~/.emacs.d/var/recentf") ;; swiper (require 'swiper) (setq ivy-use-virtual-buffers t) (global-set-key (kbd "C-s") 'swiper) (ivy-mode) ;; counsel (require 'counsel) (setq counsel-find-file-at-point t) ;; helm (require 'helm) ;; interface to ag (the silver surfer) (require 'ag) ;; projectile (great for project management!) (require 'projectile) (setq projectile-enable-caching t) (setq projectile-completion-system 'ivy) (setq projectile-known-projects-file "~/.emacs.d/var/projectile-bookmarks.eld") (setq projectile-cache-file "~/.emacs.d/var/projectile.cache") (projectile-global-mode) ;; check my spelling, it can only help (require 'flyspell) (setq ispell-program-name "aspell" ispell-list-command "--list") (add-hook 'prog-mode-hook 'flyspell-prog-mode) (add-hook 'text-mode-hook 'turn-on-flyspell) (add-hook 'org-mode-hook 'turn-on-flyspell) ;; this makes emacs slow to work with source (delete 'Git vc-handled-backends) ;; magit! (require 'magit) (setq magit-completing-read-function 'ivy-completing-read magit-item-highlight-face 'bold) (global-set-key (kbd "C-x g") 'magit-status) ;; run magit in full screen ;; http://www.lunaryorn.com/2016/04/28/fullscreen-magit-status.html (add-to-list 'display-buffer-alist `(,(rx "*magit: ") (fcuny/display-buffer-fullframe) (reusable-frames . nil))) (defun fcuny/display-buffer-fullframe (buffer alist) "Display BUFFER in fullscreen. ALIST is a `display-buffer' ALIST. Return the new window for BUFFER." (let ((window (display-buffer-pop-up-window buffer alist))) (when window (delete-other-windows window)) window)) ;; pants related stuff (load-file "~/src/pants.el/pants.el") (require 'pants) (setq pants-source-tree-root "/Users/fcuny/src/source" pants-bury-compilation-buffer t) (global-set-key (kbd "C-c b") 'pants-find-build-file) (global-set-key (kbd "C-c r") 'pants-run-binary) (global-set-key (kbd "C-c t") 'pants-run-test) ;; validate the syntax on the fly (require 'flycheck) (defun check-source-predicate () (and (executable-find "check.pex") (buffer-file-name) (string-match "src/source/.*\.py$" (buffer-file-name)))) (add-hook 'prog-mode-hook 'flycheck-mode) (setq-default flycheck-disabled-checkers '(emacs-lisp-checkdoc)) (setq flycheck-mode-line '(:eval (pcase flycheck-last-status-change (`not-checked nil) (`no-checker (propertize " -" 'face 'warning)) (`running "") (`errored (propertize " ✘" 'face 'error)) (`finished (if flycheck-current-errors (let* ((error-counts (flycheck-count-errors flycheck-current-errors)) (no-errors (cdr (assq 'error error-counts))) (no-warnings (cdr (assq 'warning error-counts))) (flycheck-face (cond (no-errors 'error) (no-warnings 'warning)))) (propertize (format " [✗:%s/%s]" (or no-errors 0) (or no-warnings 0)) 'face flycheck-face)) (propertize " [✓]" 'face 'success))) (`interrupted " -") (`suspicious '(propertize " ?" 'face 'warning))))) (flycheck-define-checker source-check "A syntax checker for python source code in Source, using `check.pex'" :command ("check.pex" source) ;;; errors are reported like this: ;;; E241:ERROR : :error-patterns ((error line-start (id (1+ nonl)) ":ERROR" (1+ nonl) ":" line (message) line-end) (warning line-start (id (1+ nonl)) ":WARNING" (1+ nonl) ":" line (message) line-end)) :predicate check-source-predicate :modes (python-mode)) (add-to-list 'flycheck-checkers 'source-check) (require 'flycheck-pos-tip) (eval-after-load 'feature-flycheck '(setq-default flycheck-display-errors-function #'flycheck-pos-tip-error-messages)) ;; configuration for ansible (require 'ansible) (require 'ansible-doc) ;; configuration for puppet (when (memq window-system '(mac ns x)) (dolist (var '("GEM_HOME" "MY_RUBY_HOME")) (unless (getenv var) (exec-path-from-shell-copy-env var)))) (setq flycheck-puppet-lint-rc "/Users/fcuny/src/twitter-ops/utilities/puppet/.puppet-lint.rc") (require 'puppet-mode) (add-hook 'puppet-mode-hook 'flycheck-mode) ;; configuration for thrift (require 'thrift) ;; configuration for yaml (require 'yaml-mode) ;; configuration for go (when (memq window-system '(mac ns x)) (dolist (var '("GOPATH" "GO15VENDOREXPERIMENT")) (unless (getenv var) (exec-path-from-shell-copy-env var)))) (require 'go-mode) (add-hook 'go-mode-hook (lambda () (go-eldoc-setup) (add-hook 'before-save-hook 'gofmt-before-save))) ;; (bind-key "C-c C-f" 'gofmt go-mode-map) ;; (bind-key "C-c h" 'godoc go-mode-map) ;; (bind-key "C-c C-g" 'go-goto-imports go-mode-map) ;; (bind-key "C-c C-r" 'go-remove-unused-imports go-mode-map)) (require 'go-eldoc) (add-hook 'go-mode-hook 'go-eldoc-setup) ;; configuration for markdown (require 'markdown-mode) (let ((preferred-markdown-impl "peg-markdown")) (when (executable-find preferred-markdown-impl) (setq markdown-command preferred-markdown-impl))) ;; configuration for python (require 'python) (setq python-indent-offset 2) ;; (use-package python ;; :mode ("BUILD\\|\\(\\.\\(py\\|aurora\\)\\)$" . python-mode) ;; configuration for racket (require 'geiser) (setq geiser-active-implementations '(racket)) ;; configuration for shell (setq-default sh-basic-offset 2 sh-indentation 2) ;; some bindings (global-set-key (kbd "M-j") 'join-line) (global-set-key (kbd "C-x C-b") 'ibuffer) (global-set-key (kbd "") 'toggle-frame-fullscreen) (global-set-key (kbd "C-c s") 'fc/visit-term-buffer) (global-set-key (kbd "s-N") 'fc/switch-to-scratch) (define-key emacs-lisp-mode-map (kbd "C-c C-e") 'eval-buffer) ;; custom functions (defun fc/switch-to-scratch () "Switch to scratch, grab the region if it's active." (interactive) (let ((contents (and (region-active-p) (buffer-substring (region-beginning) (region-end))))) (switch-to-buffer "*scratch*") (if contents (progn (goto-char (buffer-end 1)) (insert contents))))) (defun fc/rename-this-buffer-and-file () "Renames current buffer and file it is visiting." (interactive) (let ((name (buffer-name)) (filename (buffer-file-name)) (read-file-name-function 'read-file-name-default)) (if (not (and filename (file-exists-p filename))) (error "Buffer '%s' is not visiting a file!" name) (let ((new-name (read-file-name "New name: " filename))) (cond ((get-buffer new-name) (error "A buffer named '%s' already exists!" new-name)) (t (rename-file filename new-name 1) (rename-buffer new-name) (set-visited-file-name new-name) (set-buffer-modified-p nil) (message "File '%s' successfully renamed to '%s'" name (file-name-nondirectory new-name)))))))) ;; start the server if not already running (require 'server) (unless (server-running-p) (server-start))