diff options
-rw-r--r-- | emacs.d/init.el | 506 | ||||
-rw-r--r-- | emacs.d/lib/my-functions.el | 38 | ||||
-rw-r--r-- | emacs.d/lib/my-settings.el | 53 | ||||
-rw-r--r-- | emacs.d/lib/org-settings.el | 43 |
4 files changed, 332 insertions, 308 deletions
diff --git a/emacs.d/init.el b/emacs.d/init.el index 50b74f7..5a2430c 100644 --- a/emacs.d/init.el +++ b/emacs.d/init.el @@ -19,319 +19,209 @@ (require 'use-package) -;; the list of packages I want to be installed -(defvar package-list) -(setq package-list - '( - ag - ansible - ansible-doc - counsel - exec-path-from-shell - flycheck - flycheck-pos-tip - flyspell - geiser - go-eldoc - gist - 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) - -;; global settings for built-in emacs parameters -(setq - auto-save-default nil - auto-save-list-file-prefix nil - inhibit-startup-screen t - initial-scratch-message nil - make-backup-files nil - require-final-newline t - vc-follow-symlinks t - next-screen-context-lines 5 - column-number-mode t - ring-bell-function 'ignore - tab-always-indent 'complete) - -;; Set default font -(set-face-attribute 'default nil :family "Droid Sans Mono" :height 130 :weight 'normal :width 'normal) - -;; turn off indent tabs -(setq-default indent-tabs-mode nil) - -;; highlight current line - -(global-hl-line-mode 1) -;; no menu -(menu-bar-mode -1) - -;; show parenthesis -(show-paren-mode +1) - -;; no blink cursor -(blink-cursor-mode -1) - -(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 -(add-hook 'prog-mode-hook - (lambda () (setq show-trailing-whitespace t))) - -(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 -(add-to-list 'load-path (expand-file-name "~/src/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 <file name>:<line> <message> - :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) -(require 'go-eldoc) - -(add-hook 'go-mode-hook (lambda () - (go-eldoc-setup) - (setq tab-width 4) - (add-hook 'before-save-hook 'gofmt-before-save))) - -;; configuration for markdown -(autoload 'gfm-mode "markdown-mode" nil t) -(add-to-list 'auto-mode-alist '("\\.md" . gfm-mode)) -(setq markdown-command "pandoc -f markdown_github") - -;; configuration for python -(require 'python) -(setq python-indent-offset 2) -(add-to-list 'auto-mode-alist '("\\.aurora\\'" . python-mode)) - -;; configuration for gist -(require 'gist) - - -;; configuration for racket -(require 'geiser) -(setq geiser-active-implementations '(racket)) - -;; configuration for shell -(setq-default - sh-basic-offset 2 - sh-indentation 2) +(eval-and-compile + (add-to-list 'load-path (expand-file-name "lib" user-emacs-directory))) + +(use-package my-settings) + +;; other packages +(use-package ag) + +(use-package counsel + :ensure t + :config + (setq counsel-find-file-at-point t)) + +(use-package dired + :config + (setq dired-listing-switches "-laGhv")) + +(use-package exec-path-from-shell + :ensure t + :config + (when (memq window-system '(mac ns)) + (exec-path-from-shell-initialize))) + +(use-package flycheck + :ensure t + :config + (use-package flycheck-pos-tip + :config + (setq flycheck-display-errors-function #'flycheck-pos-tip-error-messages)) + + (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 <file name>:<line> <message> + :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 flyspell + :ensure t + :diminish flyspell-mode + :init + (setq ispell-program-name "aspell" + ispell-list-command "--list")) + +(use-package geiser + :config + (progn + (setq geiser-active-implementations '(racket)))) + +(use-package gist + :ensure t + :bind ("C-c G" . gist-region-or-buffer)) + +(use-package go-mode + :init + (progn + (use-package go-eldoc) + (add-hook 'go-mode-hook + (lambda () + (setenv "GO15VENDOREXPERIMENT" "1") + (go-eldoc-setup) + (add-hook 'before-save-hook 'gofmt-before-save) + (setq tab-width 4))))) + +(use-package helm) + +(use-package ibuffer + :bind ("C-x C-b" . ibuffer)) + +(use-package json-mode + :ensure t + :mode "\\.json\\'" + :config + (setq json-reformat:indent-width 2)) + +(use-package magit + :bind ("C-x g" . magit-status) + :config + (add-hook 'magit-log-edit-mode-hook + #'(lambda () + (set-fill-column 72) + (flyspell-mode)))) + +(use-package markdown-mode + :commands (markdown-mode gfm-mode) + :mode (("\\.md\\'" . gfm-mode) + ("\\.markdown\\'" . gfm-mode)) + :init (setq markdown-command "pandoc -f markdown_github")) + +(use-package midnight) + +(use-package org-settings) + +(use-package pants + :load-path (lambda () (expand-file-name "~/src/pants.el/")) + + :config + (setq pants-source-tree-root "/Users/fcuny/src/source" + pants-bury-compilation-buffer t + pants-extra-args "-q") + + :bind (("C-c b" . pants-find-build-file) + ("C-c r" . pants-run-binary) + ("C-c t" . pants-run-test))) + +(use-package projectile + :diminish projectile-mode + :bind-keymap ("C-c p" . projectile-command-map) + + :config + (setq projectile-enable-caching t + projectile-completion-system 'ivy + projectile-known-projects-file "~/.emacs.d/var/projectile-bookmarks.eld" + projectile-cache-file "~/.emacs.d/var/projectile.cache") + (projectile-global-mode)) + +(use-package puppet-mode + :mode ("\\.pp\\'" . puppet-mode) + :init (add-hook 'puppet-mode-hook 'flycheck-mode) + :config + (setq flycheck-puppet-lint-rc "/Users/fcuny/src/twitter-ops/utilities/puppet/.puppet-lint.rc")) + +(use-package python + :mode ("\\.aurora$" . python-mode) + ("BUILD$" . python-mode) + :interpreter ("python" . python-mode) + + :init + (setq-default indent-tabs-mode nil) + + :config + (setq python-indent-offset 2) + (add-hook 'python-mode-hook 'color-identifiers-mode)) + +(use-package recentf + :config + (setq recentf-save-file "~/.emacs.d/var/recentf")) + +(use-package sh-script + :config + (defun set-sh-mode-indent () + (setq sh-basic-offset 2 + sh-indentation 2)) + (add-hook 'sh-mode-hook 'set-sh-mode-indent)) + +(use-package swiper + :ensure t + :diminish ivy-mode + :bind ("C-s" . swiper) + :config + (setq ivy-use-virtual-buffers t) + (ivy-mode)) + +(use-package thrift + :ensure t + :mode ("\\.thrift\\'" . thrift-mode) + :config + (setq thrift-indent-level 2)) + +(use-package yaml-mode + :mode ("\\.ya?ml\\'" . yaml-mode)) + +;; ;; 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)))) ;; some bindings (global-set-key (kbd "M-j") 'join-line) -(global-set-key (kbd "C-x C-b") 'ibuffer) (global-set-key (kbd "<s-return>") '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) -(global-set-key (kbd "s-<left>") 'next-buffer) -(global-set-key (kbd "s-<right>") 'previous-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)))))))) - -;; clean up buffers once in a while -(require 'midnight) ;; start the server if not already running (require 'server) diff --git a/emacs.d/lib/my-functions.el b/emacs.d/lib/my-functions.el new file mode 100644 index 0000000..e661a01 --- /dev/null +++ b/emacs.d/lib/my-functions.el @@ -0,0 +1,38 @@ +;; jump to the scratch buffer +(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))))) + +(global-set-key (kbd "s-N") 'fc/switch-to-scratch) + +;; rename a buffer +(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)))))))) + + + +(provide 'my-functions) diff --git a/emacs.d/lib/my-settings.el b/emacs.d/lib/my-settings.el new file mode 100644 index 0000000..2e7e331 --- /dev/null +++ b/emacs.d/lib/my-settings.el @@ -0,0 +1,53 @@ +;; auto close bracket insertion +(electric-pair-mode 1) + +;; ? +(add-hook 'prog-mode-hook + (lambda () (setq show-trailing-whitespace t))) + +;; this makes emacs slow to work with source +(delete 'Git vc-handled-backends) + +;; 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) + +;; global settings for built-in emacs parameters +(setq auto-save-default nil + auto-save-list-file-prefix nil + inhibit-startup-screen t + initial-scratch-message nil + make-backup-files nil + require-final-newline t + vc-follow-symlinks t + next-screen-context-lines 5 + column-number-mode t + ring-bell-function 'ignore + tab-always-indent 'complete) + +(setq-default indent-tabs-mode nil + create-lockfiles nil) + +;; show parenthesis +(show-paren-mode +1) + +;; no blink cursor +(blink-cursor-mode -1) + +(when window-system + (tool-bar-mode 0) + (scroll-bar-mode 0) + (menu-bar-mode -1)) + +;; I don't want a frindge on the right +(fringe-mode '(4 . 0)) + +;; Set default font +(set-face-attribute 'default nil :family "Droid Sans Mono" :height 130 :weight 'normal :width 'normal) + +(provide 'my-settings) diff --git a/emacs.d/lib/org-settings.el b/emacs.d/lib/org-settings.el new file mode 100644 index 0000000..ba67503 --- /dev/null +++ b/emacs.d/lib/org-settings.el @@ -0,0 +1,43 @@ +(use-package org-mode + :bind (("C-c a" . org-agenda) + ("C-c c" . org-capture) + ("C-c o" . org-iswitchb)) + + :config + (progn + (setq org-startup-indented t + org-indent-mode t + org-return-follows-link t + org-blank-before-new-entry nil))) + +(setq org-todo-keywords + '((sequence "TODO" "IN-PROGRESS" "WAITING" "DONE"))) + +(setq org-link-abbrev-alist + '(("src" . "~/src/%s") + ("jira" . "https://jira.twitter.biz/browse/%s") + ("rb" . "https://reviewboard.twitter.biz/r/%s") + ("go" . "http://go/%s"))) + +(setq org-default-notes-file "~/src/notes/org/inbox.org") + +(setq org-agenda-files (list "~/src/notes/org/personal.org" + "~/src/notes/org/work.org" + "~/src/notes/org/inbox.org")) + +;; org-startup-indented +(add-hook 'org-mode-hook (lambda () (setq truncate-lines nil))) + +(setq org-capture-templates + '(("t" "Todo" entry (file+headline "~/src/notes/org/inbox.org" "Tasks") + "* TODO %?\n%a") + ("j" "Journal" entry (file+datetree "~/src/notes/org/journal.org") + "* %T\n%?") + ("m" "Meeting" entry (file+headline "~/src/notes/org/inbox.org" "Meetings") + "* %^{prompt} %U\n%?"))) + +(setq org-refile-targets + '(("~/src/notes/org/work.org" :maxlevel . 2) + ("~/src/notes/org/personal.org" :maxlevel . 2))) + +(provide 'org-settings) |