Created
June 25, 2018 21:30
-
-
Save adammichaelwood/c7bf9d8b4a5adc5ecbb39d3bfc3a2dfd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; amw_init --- Summary | |
;; My shit. | |
;;; Commentary: | |
;; This is all my things. | |
;;; Code: | |
(package-initialize) | |
(elpy-enable) | |
;; MELPA | |
(require 'package) | |
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos)) | |
(not (gnutls-available-p)))) | |
(proto (if no-ssl "http" "https"))) | |
;; Comment/uncomment these two lines to enable/disable MELPA and MELPA Stable as desired | |
;; (add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t) | |
(add-to-list 'package-archives (cons "melpa-stable" (concat proto "://stable.melpa.org/packages/")) t) | |
(when (< emacs-major-version 24) | |
;; For important compatibility libraries like cl-lib | |
(add-to-list 'package-archives '("gnu" . (concat proto "://elpa.gnu.org/packages/"))))) | |
(package-initialize) | |
;; Interactively do things | |
(require 'ido) | |
(ido-mode t) | |
(require 'ido-vertical-mode) | |
(ido-mode 1) | |
(ido-vertical-mode 1) | |
(setq ido-vertical-define-keys 'C-n-and-C-p-only) | |
;; smex | |
(require 'smex) | |
(smex-initialize) | |
(global-set-key (kbd "M-x") 'smex) | |
(global-set-key (kbd "M-X") 'smex-major-mode-commands) | |
;; This is your old M-x. | |
(global-set-key (kbd "C-c C-c M-x") 'execute-extended-command) | |
;; Added on installation of autocomplete | |
(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. | |
'(elpy-mode-hook (quote (subword-mode hl-line-mode))) | |
'(git-gutter:added-sign "+") | |
'(git-gutter:deleted-sign "-") | |
'(git-gutter:modified-sign "*") | |
'(git-gutter:update-interval 2) | |
'(package-selected-packages | |
(quote | |
(visual-fill-column git-gutter-fringe git-gutter fringe-helper flycheck exec-path-from-shell expand-region smooth-scroll sx dimmer rainbow-mode rainbow-delimiters smex ido-vertical-mode color-theme-modern elpy virtualenvwrapper fill-column-indicator auto-complete)))) | |
(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. | |
) | |
; Autocomplete | |
(require 'auto-complete) | |
(require 'auto-complete-config) | |
(ac-config-default) | |
(global-auto-complete-mode t) | |
;; THIS IS A BAD ONE | |
;; fill-column-indicator | |
;; (require 'fill-column-indicator) | |
;; (define-globalized-minor-mode | |
;; global-fci-mode fci-mode (lambda () (fci-mode 1))) | |
;; (global-fci-mode t) | |
; virtualenvironment | |
(require 'virtualenvwrapper) | |
(venv-initialize-interactive-shells) | |
(venv-initialize-eshell) | |
(setq venv-location "~/pys/") | |
(global-set-key (kbd "C-x v") 'venv-workon) | |
;--------------------; | |
;;; User Interface ;;; | |
;--------------------; | |
;; the font | |
(set-default-font "-*-Classic Console-normal-normal-normal-*-40-*-*-*-m-0-iso10646-1") | |
; always use spaces, not tabs, when indenting | |
(setq indent-tabs-mode nil) | |
; ignore case when searching | |
(setq case-fold-search t) | |
; require final newlines in files when they are saved | |
(setq require-final-newline t) | |
; set the keybinding so that you can use f4 for goto line | |
(global-set-key [f4] 'goto-line) | |
; language | |
(setq current-language-environment "English") | |
; don't show the startup screen | |
(setq inhibit-startup-screen 1) | |
; don't show the menu bar | |
(menu-bar-mode 0) | |
; don't show the tool bar | |
(require 'tool-bar) | |
(tool-bar-mode 0) | |
; don't show the scroll bar | |
(if window-system (scroll-bar-mode 0)) | |
; turn on mouse wheel support for scrolling | |
(require 'mwheel) | |
(mouse-wheel-mode 1) | |
; number of characters until the fill column | |
(require `visual-fill-column) | |
(set-fill-column 80) | |
(setq-default fill-column 80) | |
(setq visual-fill-column-width 80) | |
(require 'visual-fill-column) | |
(add-hook 'visual-line-mode-hook 'visual-fill-column-mode) | |
(global-visual-line-mode t) | |
(global-visual-fill-column-mode t) | |
; ignore case when searching | |
(setq-default case-fold-search 1) | |
; show the current line and column numbers in the stats bar as well | |
(line-number-mode 1) | |
(column-number-mode 1) | |
;; line numbers | |
(defun linum-format-func (line) | |
(let ((w (length (number-to-string (count-lines (point-min) (point-max)))))) | |
(propertize (format (format "%%%dd " w) line) 'face 'linum))) | |
(setq linum-format "%d ") | |
(add-hook 'find-file-hook 'linum-mode) | |
(add-hook 'text-mode-hook 'linum-mode) | |
(add-hook 'prog-mode-hook 'linum-mode) | |
;; flycheck all the things | |
(add-hook 'text-mode-hook 'flycheck-mode) | |
(add-hook 'prog-mode-hook 'flycheck-mode) | |
;; use aspell instead of ispell | |
(setq ispell-program-name "aspell") | |
(setq ispell-list-command "--list") | |
;; ... and then set flyspell on for text mode | |
(add-hook 'text-mode-hook 'flyspell-mode) | |
;; Python | |
(setq-default py-shell-name "ipython") | |
(setq-default py-which-bufname "IPython") | |
(setq elpy-rpc-backend "jedi") | |
(electric-indent-mode +1) | |
;; | |
; (setq python-check-command "pep8") | |
(defun amw-python-mode-hook () | |
(setq indent-tabs-mode nil) | |
(setq python-indent 4) | |
(setq tab-width 4)) | |
(add-hook 'python-mode-hook 'amw-python-mode-hook) | |
(add-hook 'python-mode-hook 'elpy-mode) | |
(add-hook 'python-mode-hook 'flycheck-mode) | |
(with-eval-after-load 'elpy | |
(remove-hook 'elpy-modules 'elpy-module-flymake) | |
(add-hook 'elpy-mode-hook 'flycheck-mode)) | |
(add-hook 'elpy-mode-hook 'elpy-use-ipython) | |
(add-hook 'elpy-mode-hook 'py-autopep8-enable-on-save) | |
;; theme | |
(load-theme 'clarity t t) | |
(enable-theme 'clarity) | |
;-------------------------; | |
;;; Syntax Highlighting ;;; | |
;-------------------------; | |
; text decoration | |
(require 'font-lock) | |
(setq font-lock-maximum-decoration t) | |
(global-font-lock-mode t) | |
(global-hi-lock-mode nil) | |
(setq jit-lock-contextually t) | |
(setq jit-lock-stealth-verbose t) | |
; if there is size information associated with text, change the text | |
; size to reflect it | |
(size-indication-mode t) | |
; highlight parentheses when the cursor is next to them | |
(require 'paren) | |
(show-paren-mode t) | |
;; rainbow parens | |
(add-hook 'prog-mode-hook #'rainbow-delimiters-mode) | |
;; git diff notice in fringe | |
(require 'git-gutter-fringe) | |
(setq git-gutter-fr:side 'right-fringe) | |
(set-face-foreground 'git-gutter:modified "purple") ;; background color | |
(set-face-foreground 'git-gutter:added "green") | |
(set-face-foreground 'git-gutter:deleted "red") | |
;; dimmer mode | |
(dimmer-mode) | |
;; smooth scroll | |
(require 'smooth-scroll) | |
(smooth-scroll-mode t) | |
;; polymode | |
;; https://emacs.stackexchange.com/questions/27679/ergonomic-way-to-edit-source-code-inside-rest-or-markdown-code-blocks/27695#27695 | |
(setq load-path | |
(append '("~/.emacs.d/polymode/" "~/.emacs.d/polymode/modes") | |
load-path)) | |
;; (require 'rst-mode) | |
(require 'polymode) | |
(defcustom pm-host/ReST | |
(pm-bchunkmode "ReST" | |
:mode 'rst-mode | |
:init-functions '(poly-rest-fixes)) | |
"Restructued Text host chunkmode." | |
:group 'hostmodes | |
:type 'object) | |
(defvar pm-ReST-code-regexp | |
(regexp-opt '("code" "code-block" "sourcecode" "highlight")) | |
"Regular expression to match all possible ReST code blocks.") | |
(defvar pm-ReST-head-regexp | |
(concat "^[^ ]*\\( *\.\. +" pm-ReST-code-regexp "::.*\n" | |
"\\(?: +:.+\n\\)*\\)") ;; Match 0 or more option lines. | |
"Regular expression to match the `head' of a ReST code block.") | |
(defvar pm-ReST-retriever-regexp | |
(concat "^[^ ]*\\(?: *\.\. +" pm-ReST-code-regexp ":: \\(.+\\)\\)$") | |
"Regular expression to retrieve the mode of the code block.") | |
(pm-create-indented-block-matchers "ReST" pm-ReST-head-regexp) | |
(defcustom pm-inner/ReST-code | |
(pm-hbtchunkmode-auto "ReST" | |
:head-reg #'pm-ReST-head-matcher | |
:tail-reg #'pm-ReST-tail-matcher | |
:head-mode 'host | |
:tail-mode 'host | |
:retriever-regexp pm-ReST-retriever-regexp | |
:font-lock-narrow t) | |
"Restructured Text inner code block mode." | |
:group 'innermodes | |
:type 'object) | |
(defcustom pm-poly/ReST | |
(pm-polymode-multi-auto "ReST" | |
:hostmode 'pm-host/ReST | |
:auto-innermode 'pm-inner/ReST-code) | |
"Restructured Text typical `polymode' configuration." | |
:group 'polymodes | |
:type 'object) | |
;;; ###autoload (autoload #'poly-rest-mode "poly-rest-mode") | |
(define-polymode poly-rest-mode pm-poly/ReST) | |
(defun poly-rest-fixes () | |
"Fix various minor issues that can occur in the poly-ReST-mode." | |
(remove-hook 'prog-mode-hook #'whitespace-mode) | |
(remove-hook 'python-mode-hook #'mmm-mode)) | |
(provide 'poly-rest-mode) | |
(add-to-list 'auto-mode-alist '("\\.rst\\'" . poly-rest-mode)) | |
;; expand-region | |
(require 'expand-region) | |
(global-set-key (kbd "C-c =") 'er/expand-region) | |
;; sets shell path same as terminal | |
(when (memq window-system '(mac ns x)) | |
(exec-path-from-shell-initialize)) | |
;; Sets flychecker in rst-mode to use Sphinx | |
;; and only check on save | |
;;(add-hook 'poly-rest-mode-hook | |
;; (lambda () (setq-local flycheck-disabled-checkers '(rst) | |
;; flycheck-check-syntax-automatically '(save ;;mode-enabled)))) | |
;;; Language specific stuff | |
;; RST | |
(add-hook 'rst-mode-hook (setq-local flycheck-disabled-checkers '(rst) )) | |
;; turn off electric indent | |
(add-hook 'rst-mode-hook (electric-indent-local-mode -1)) | |
;; my preferred indentation style | |
(defun amw-indent () | |
"New line, then indent based on previous line." | |
(interactive) | |
(newline) | |
(indent-relative-maybe)) | |
;;(add-hook 'rst-mode-hook | |
(define-key text-mode-map (kbd "RET") (lambda() (interactive) (newline) (indent-relative-maybe))) | |
;;) | |
;;;;;;;;;;;;;;;;;;;;; | |
;;; PROJECTS ;;;;;;;; | |
;;;;;;;;;;;;;;;;;;;;; | |
;; ODK STUFF ;; | |
(defun odk-ss (img-name) | |
"Takes a screenshot, using the ss.py utility in odk-docss, | |
saves it to /img/, and inserts a ref in the rst doc." | |
(interactive "sImage name: ") | |
(insert-before-markers (format ".. image:: /img/%s/%s.* \n :alt:" (file-name-base) img-name) | |
) | |
(shell-command (format "python ../ss.py %s/%s -s" (file-name-base) img-name)) | |
) | |
(eval-after-load 'rst | |
'(define-key rst-mode-map (kbd "M-.") 'odk-ss)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment