(require 'package) (setq package-user-dir "~/.emacs.d/var/elpa") ;;; Code: (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)) (unless (package-installed-p 'use-package) (message "`use-package' not found. Installing...") (package-install 'use-package)) (require 'use-package) (setq use-package-minimum-reported-time 0 use-package-verbose t) ;; 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 "#FFFFE4") (set-face-attribute 'fringe nil :background "#FFFFE5") (set-face-background 'mode-line "#E5FFFF") ;; 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 (set-fringe-mode 0) ;; auto close bracket insertion (electric-pair-mode 1) ;; if running in macos, load environment variables (when (memq window-system '(mac ns x)) (use-package exec-path-from-shell :ensure t :init (setq exec-path-from-shell-debug +1) :config (exec-path-from-shell-initialize) (exec-path-from-shell-copy-envs '("TMPDIR")))) ;; I want dired (use-package dired :commands dired :init (setq dired-listing-switches "-laGhv")) ;; install recentf (use-package recentf :config (setq recentf-save-file "~/.emacs.d/var/recentf")) ;; get counsel and swiper (use-package swiper :ensure t :bind (("C-s" . swiper)) :config (setq ivy-use-virtual-buffers t) (ivy-mode)) (use-package counsel :ensure t :config (setq counsel-find-file-at-point t)) ;; I need helm (use-package helm :ensure t) ;; interface to ag (use-package ag :ensure t :defer t) ;; get projectile (use-package projectile :ensure t :init (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") :config (projectile-global-mode)) ;; check my spelling, it can only help (use-package flyspell :ensure t :init (progn (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) (use-package magit :ensure t :bind ("C-x g" . magit-status) :config (progn (setq magit-completing-read-function 'ivy-completing-read) (setq magit-item-highlight-face 'bold))) ;; 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") (use-package pants :bind (("C-c b" . pants-find-build-file) ("C-c r" . pants-run-binary) ("C-c t" . pants-run-test)) :config (progn (setq pants-source-tree-root "/Users/fcuny/src/source" pants-bury-compilation-buffer t))) ;; validate the syntax on the fly (use-package flycheck :ensure t :defer t :preface (progn (defun check-source-predicate () (and (executable-find "check.pex") (buffer-file-name) (string-match "src/source/.*\.py$" (buffer-file-name))))) :init (progn (add-hook 'prog-mode-hook 'flycheck-mode) (setq-default flycheck-disabled-checkers '(emacs-lisp-checkdoc))) :config (progn (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))))) (setq flycheck-puppet-lint-rc "/Users/fcuny/src/twitter-ops/utilities/puppet/.puppet-lint.rc") (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))) (use-package flycheck-pos-tip :defer t :init (progn (eval-after-load 'feature-flycheck '(setq-default flycheck-display-errors-function #'flycheck-pos-tip-error-messages))) :ensure t) ;; configuration for ansible (use-package ansible :ensure t) (use-package ansible-doc :ensure t) ;; 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)))) (use-package puppet-mode :ensure t :mode ("\\.pp$" . puppet-mode) :init (progn (add-hook 'puppet-mode-hook 'flycheck-mode))) ;; configuration for thrift (use-package thrift :ensure t :defer t) ;; configuration for yaml (use-package yaml-mode :mode ("\\.\\(yml\\|yaml\\)\\'" . yaml-mode) :ensure t :defer t) ;; configuration for go (when (memq window-system '(mac ns x)) (dolist (var '("GOPATH" "GO15VENDOREXPERIMENT")) (unless (getenv var) (exec-path-from-shell-copy-env var)))) (use-package go-mode :ensure t :defer t :config (progn (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)) :init (progn (add-hook 'go-mode-hook (lambda () (go-eldoc-setup) (add-hook 'before-save-hook 'gofmt-before-save))))) (use-package go-eldoc :ensure t :defer t :init (add-hook 'go-mode-hook 'go-eldoc-setup)) ;; configuration for markdown (use-package markdown-mode :ensure t :mode ("\\.\\(m\\(ark\\)?down\\|md\\)$" . markdown-mode) :config (progn (let ((preferred-markdown-impl "peg-markdown")) (when (executable-find preferred-markdown-impl) (setq markdown-command preferred-markdown-impl))))) ;; configuration for python (use-package python :mode ("BUILD\\|\\(\\.\\(py\\|aurora\\)\\)$" . python-mode) :config (progn (setq python-indent-offset 2))) ;; configuration for racket (use-package geiser :config (setq geiser-active-implementations '(racket)) :ensure t) ;; 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 (use-package server :config (unless (server-running-p) (server-start)))