Rewrote core initfiles: add mod-ac, mod-fly & mod-git

* mod-ac: fuzzy and unintrusive auto-complete
* mod-fly: on-the-fly syntax and spell checking
* mod-git: git-gutter and git-related modes
This commit is contained in:
Henrik Lissner 2014-07-17 02:59:23 -04:00
parent b53dfd6369
commit 30845199b5
12 changed files with 224 additions and 191 deletions

30
init.el
View file

@ -1,5 +1,4 @@
;;
;; [Emacs for the jaded vimmer]
;;; Emacs for the jaded vimmer
;;
;; Author: Henrik Lissner <henrik@lissner>
;; URL: https://github.com/hlissner/emacs.d
@ -7,9 +6,13 @@
;; These settings set up a very vim-like experience, with some of emacs goodness
;; squeezed in between the cracks.
;;
;;; Code:
(cd "~") ; Default directory, instead of /
(setq load-prefer-newer t) ; Always load newest byte code
;; (setq debug-on-error t)
;; Append homebrew's bin to emac's PATH
(setq exec-path (append exec-path '("/usr/local/bin")))
;; Global vars
(defvar my-dir (file-name-directory load-file-name))
@ -35,18 +38,22 @@
(dolist (module '(
core ; Emacs core settings
core-packages ; package init & management
core-packages ; Package init & management
core-ui ; Look and behavior of the emacs UI
core-editor ; Text/code editor settings and behavior
core-osx ; OSX-specific settings & functions
core-project ; Project navigation settings & packages
core-keymaps ; Global & local keybindings for all modes
;; Editor essentials
mod-ac ; Auto-complete engine & settings
mod-git ; GIT tools/settings
; mod-shell ; Goodies for running shell in emacs
mod-fly ; Syntax and spell checkers
; mod-webdev ; Webdev tools (sass, js, etc)
; mod-gamedev ; Gamedev tools (C++, love2D, html5)
; mod-shell ; Goodies for ansi-term
;; Must be last!
core-keymaps ; Global & local keybindings for all modes
))
(require module))
@ -54,10 +61,11 @@
;;;; Modes ;;;;;;;;;;;;;;;;;;;;;;;;
(associate-mode 'ruby-mode '(".rb" "RakeFile"))
(associate-mode 'markdown-mode '(".md" ".markdown"))
(associate-mode 'scss-mode ".scss")
;; (associate-mode 'lua-mode ".lua")
(associate-mode 'markdown-mode '(".md" ".markdown" "README"))
(associate-mode 'scss-mode '(".scss"))
(associate-mode 'org-mode '(".org" ".gtd") t)
(associate-mode 'js2-mode '(".js" ".json"))
(associate-mode 'web-mode '(".html" ".htm" ".phtml" ".tpl" ".tpl.php" ".erb"))
; (associate-mode 'lua-mode ".lua")
;; (associate-mode 'yaml-mode ".yml")
;; (associate-mode 'js2-mode '(".js" ".json"))
;; (associate-mode 'python-mode ".py")
;; (associate-mode 'web-mode '(".html" ".htm" ".phtml" ".tpl" ".tpl.php" ".erb"))

0
init/README.md Normal file
View file

View file

@ -11,21 +11,16 @@
evil-space ; mimics ; and , for f, F, t, T w/ space
evil-visualstar ; visual-based * and #
evil-ex-registers ; paste from registers in ex commands
auto-complete ; self-explanity
auto-complete-config ; its default config
fuzzy ; fuzzy search engine for auto-complete
autopair ; delimiter auto-closing
yasnippet ; snippets: expand with tab
rainbow-delimiters ; colored matching parenthesis
rainbow-mode ; highlight color codes
highlight-indentation ; visual indentation guides
diminish ; shrinks/removes modeline elements
saveplace ; restore cursor position on buffer load
volatile-highlights ; temporarily highlight changes on undo/yank
anzu ; display current + total matches searching
smex ; less M-x cruft
rotate-text ; like vim-switch
uniquify ; unique buffer names for identical filenames
recentf ; access to list of recent files
key-chord ; for mapping key chords in insert mode
ediff
@ -34,10 +29,6 @@
;;;; Editor behavior ;;;;;;;;;;;;;;;;
;;;#key-chord
(key-chord-mode 1)
(setq key-chord-two-keys-delay 0.5)
(electric-indent-mode +1)
(global-hl-line-mode +1) ; highlight the line
(setq blink-matching-paren nil) ; disable blink-matching-paren
@ -51,13 +42,19 @@
(setq truncate-partial-width-windows nil)
;; Prettify code-related major modes
(add-hook 'prog-mode-hook 'linum-on)
(add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
(add-hook 'prog-mode-hook #'highlight-indentation-mode)
;; Remove trailing whitespace
(add-hook 'before-save-hook 'delete-trailing-whitespace)
;;;; Init plugins ;;;;;;;;;;;;;;;;;;;
;;;#key-chord
(key-chord-mode 1)
(setq key-chord-two-keys-delay 0.5)
;;;#smex
(smex-initialize)
;; Hook up smex to auto-update, rather than update on every run
@ -65,12 +62,10 @@
(when (boundp 'smex-cache) (smex-update)))
(add-hook 'after-load-functions 'smex-update-after-load)
;;;; Init plugins ;;;;;;;;;;;;;;;;;;;
;;;#evil
(setq evil-want-C-i-jump t)
(setq evil-want-C-u-scroll t)
(setq evil-leader/in-all-states t)
(global-evil-leader-mode)
(global-evil-matchit-mode 1)
@ -88,31 +83,27 @@
;; Enable registers in ex-mode
(define-key evil-ex-completion-map (kbd "C-r") #'evil-ex-paste-from-register)
;;;#autopair
(autopair-global-mode)
(diminish 'autopair-mode)
(setq autopair-blink nil)
;;;#smartparens
; (require 'smartparens-config)
; (smartparens-global-mode t)
;;;#anzu
(global-anzu-mode)
(diminish 'anzu-mode)
;;;#ediff
(setq ediff-window-setup-function 'ediff-setup-windows-plain)
;;;#volatile-highlights
(volatile-highlights-mode t)
(diminish 'volatile-highlights-mode)
;;;#saveplace
(setq-default save-place t)
(setq save-place-file (expand-file-name "saveplace" my-tmp-dir))
;;;#savehist
(setq savehist-additional-variables
;; search entries
@ -123,77 +114,13 @@
savehist-file (expand-file-name "savehist" my-tmp-dir))
(savehist-mode 1)
;;;#diminish
(diminish 'undo-tree-mode)
(diminish 'highlight-indentation-mode)
;;;#uniquify
(setq uniquify-buffer-name-style 'forward)
(setq uniquify-separator "/")
(setq uniquify-after-kill-buffer-p t) ; rename after killing uniquified
(setq uniquify-ignore-buffers-re "^\\*") ; don't muck with special buffers
;;;#recentf
(recentf-mode 1)
(setq recentf-max-menu-items 25)
;;;#yasnippet
(yas-global-mode -1)
;;;; Auto-completion ;;;;;;;;;;;;;;
(ac-config-default)
(ac-linum-workaround) ; Fix line number flux bug
(diminish 'auto-complete-mode)
(add-hook 'prog-mode-hook 'enable-path-completion)
(setq ac-auto-show-menu nil ; Suggestions box must be invoked manually (see core-keymaps.el)
ac-use-menu-map t ; Enable ac-menu-map map when menu is open
ac-us-quick-help nil) ; Don't show tooltips unless invoked (see core-keymaps.el)
(defun enable-path-completion ()
(add-to-list 'ac-sources 'ac-source-filename)
(add-to-list 'ac-sources 'ac-source-files-in-current-dir))
;; Tell ido not to care about case
(setq completion-ignore-case t)
;;; Filters ido-matches setting acronynm matches in front of the results
(defadvice ido-set-matches-1 (after ido-smex-acronym-matches activate)
(if (and (fboundp 'smex-already-running) (smex-already-running)
(> (length ido-text) 1))
(let ((regex (concat "^" (mapconcat 'char-to-string ido-text "[^-]*-")))
(acronym-matches (list))
(remove-regexes '("-menu-")))
;; Creating the list of the results to be set as first
(dolist (item items)
(if (string-match (concat regex "[^-]*$") item) ;; strict match
(add-to-list 'acronym-matches item)
(if (string-match regex item) ;; appending relaxed match
(add-to-list 'acronym-matches item t))))
;; Filtering ad-return-value
(dolist (to_remove remove-regexes)
(setq ad-return-value
(delete-if (lambda (item)
(string-match to_remove item))
ad-return-value)))
;; Creating resulting list
(setq ad-return-value
(append acronym-matches
ad-return-value))
(delete-dups ad-return-value)
(reverse ad-return-value))))
;;
(provide 'core-editor)

View file

@ -1,5 +1,6 @@
;; Global keymaps ;;;;;;;;;;;;;;;
(gmap (kbd "<C-escape>") 'open-scratch-buffer)
(gmap (kbd "M-x") 'smex)
(gmap (kbd "M-X") 'smex-major-mode-commands)
(gmap (kbd "C-x C-p") 'package-list-packages)
@ -45,8 +46,6 @@
";" 'helm-imenu
"," 'ido-switch-buffer
"=" 'align-regexp
"x" 'kill-this-buffer
"X" 'kill-buffer-and-window
)
(nmap
@ -57,9 +56,13 @@
"k" 'evil-previous-visual-line
"X" 'evil-destroy ; Delete without yanking
"Y" 'copy-to-end-of-line ; nnoremap Y y$
"zz" 'kill-this-buffer ; Close buffer
; copy to end of line
"Y" (lambda()
(interactive)
(evil-yank (point) (point-at-eol)))
"zz" 'kill-this-buffer ; Close buffer
"]b" 'previous-buffer
"[b" 'next-buffer
@ -106,6 +109,10 @@
;; Rotate-text (see elisp/rotate-text.el)
(nmap (kbd "RET") 'rotate-word-at-point)
(vmap (kbd "RET") 'rotate-region)
;; (imap (kbd "RET") 'comment-indent-new-line)
;; Disable return for auto-completion, since tab does the trick
(define-key ac-completing-map (kbd "RET") nil)
(imap (kbd "<C-return>") 'indent-new-comment-line)
;; Enable TAB to do matchit
(evil-define-key 'normal evil-matchit-mode-map (kbd "TAB") 'evilmi-jump-items)
@ -113,7 +120,6 @@
;; Easy escape from insert mode
(ichmap "jj" 'evil-normal-state)
;;;; Org-Mode ;;;;;;;;;;;;;;;;;;;
(evil-define-key 'normal evil-org-mode-map
@ -167,8 +173,8 @@
;;;; Ex Commands ;;;;;;;;;;;;;;;;
; (cmap "e[dit]" 'find-file)
(cmap "git" 'magit-status)
;; (cmap "e[dit]" 'find-file)
;; (cmap "n[ew]" ')
;;;; Keymap fixes ;;;;;;;;;;;;;;;
@ -187,16 +193,18 @@
(global-set-key [escape] 'evil-exit-emacs-state)
;; Close help window with escape
(define-key global-map [escape] 'quit-window)
(define-key ag-mode-map [escape] 'quit-window)
;; Restore bash-esque C-w/C-a/C-e in insert mode and the minibuffer
(mapc (lambda (map)
(define-key map (kbd "C-w") 'backward-kill-word)
;; (define-key map (kbd "C-w") 'evil-delete-backward-word)
(define-key map (kbd "C-a") 'move-beginning-of-line)
(define-key map (kbd "C-e") 'move-end-of-line)
(define-key map (kbd "C-u") 'backward-kill-line))
(list minibuffer-local-map evil-insert-state-map))
(define-key evil-insert-state-map (kbd "C-w") 'backward-kill-word)
(define-key minibuffer-local-map (kbd "C-w") 'ido-delete-backward-word-updir)
(add-hook 'ido-setup-hook '(lambda ()
;; take that "Text is read-only" and stick it where emacs don't shine!
(define-key ido-completion-map (kbd "<backspace>") 'ido-delete-backward-updir)
@ -207,8 +215,7 @@
;; Auto-complete on tab/space (why is it called ido-exit-minibuffer?)
(define-key ido-completion-map " " 'ido-exit-minibuffer)
;; TAB, by default, inserts a literal \t ಠ_ಠ
(define-key ido-completion-map (kbd "TAB") 'ido-exit-minibuffer)))
))
;;
(provide 'core-keymaps)

View file

@ -2,13 +2,14 @@
(if (is-osx) (progn
;; Ignore .DS_Store files with ido mode
(add-to-list 'completion-ignored-extensions ".DS_Store")
(add-to-list 'ido-ignore-files ".DS_Store")
(if window-system (progn
(setq ns-use-native-fullscreen nil)
(global-set-key (kbd "s-<f12>") 'toggle-frame-fullscreen)
(x-focus-frame nil)
;; Don't open files from the workspace in a new frame
(setq ns-pop-up-frames nil)
))
@ -27,18 +28,19 @@
(defun send-to-launchbar () (open-with "LaunchBar"))
(defun send-dir-to-launchbar () (open-file-with default-directory "LaunchBar"))
(defun send-dir-to-finder () (open-file-with default-directory "Finder"))
(defun open-in-terminal () (ansi-term "/bin/zsh"))
;; (defun open-in-terminal () (ansi-term "/bin/zsh"))
(after 'evil
(gmap (kbd "s-/") 'evilnc-comment-or-uncomment-lines)
(gmap (kbd "s-w") 'evil-window-delete)
(gmap (kbd "s-w") 'kill-buffer)
(gmap (kbd "s-w") 'kill-buffer-and-window)
;; Fast scrolling
(nmap (kbd "s-j") "jjjjj")
(nmap (kbd "s-k") "kkkkk")
(nmap (kbd "s-j") "5j")
(nmap (kbd "s-k") "5k")
;; Newlines from insert mode
(imap (kbd "<s-return>") 'evil-open-below)
;; (imap (kbd "<s-return>") 'evil-open-below)
(imap (kbd "<S-s-return>") 'evil-open-above)
;; Fix OSX text navigation shortcuts

View file

@ -40,21 +40,16 @@
(if (not dont_load) (require package)))
;; Associate an extension with a mode, and install the necessary
;; package for it.
;;
;; TODO: Rewrite this
(defun associate-mode (mode ext &optional env-pkg)
;; package(s) for it. Also look for a modules/env-*.el modefile for
;; extra configuration.
(defun associate-mode (mode ext &optional only-load-env)
(let* ((mode_name (symbol-name mode))
(env_mode_name (major-mode-module-name))
(mode_path (major-mode-module-path)))
(env_mode_name (concat "env-" mode_name))
(mode_path (expand-file-name (concat env_mode_name ".el") my-modules-dir)))
(condition-case nil (init-package mode t) (error nil))
(autoload mode mode_name)
(if env-pkg
(require-package env-pkg)
(if (file-exists-p mode_path) (require-package (intern env_mode_name)))
))
(unless only-load-env (require-package mode))
(if (file-exists-p mode_path)
(require-package (intern env_mode_name))))
(if (typep ext 'list)
(dolist (e ext)

View file

@ -44,15 +44,6 @@
ido-enable-tramp-completion t
ido-enable-last-directory-history t)
(defadvice completion--file-name-table (after ignoring-backups-f-n-completion activate)
"Filter out results when they match `completion-ignored-extensions'."
(let ((res ad-return-value))
(if (and (listp res)
(stringp (car res))
(cdr res)) ; length > 1, don't ignore sole match
(setq ad-return-value
(completion-pcm--filename-try-filter res)))))
;;#projectile
(setq projectile-completion-system 'grizzl
projectile-enable-caching t)
@ -60,5 +51,8 @@
;;#sr-speedbar
(setq speedbar-use-images nil)
(add-to-list 'ido-ignore-buffers "\\`\\*[^s].*\\*")
(add-to-list 'ido-ignore-files "\\`.DS_Store\\'")
;;
(provide 'core-project)

View file

@ -1,48 +1,62 @@
(require-packages
'(uniquify ; unique buffer names for identical filenames
diminish ; shrinks/removes modeline elements
))
;;;; UI Behavior ;;;;;;;;;;;;;;;;;;;;;;
(setq inhibit-startup-screen t) ; don't show EMACs start screen
(fset 'yes-or-no-p 'y-or-n-p) ; y/n instead of yes/no
(global-linum-mode t) ; line numbers for everybody!
(setq inhibit-startup-screen t)
;; Shrink mode-line
(add-hook 'emacs-startup-hook
(lambda()
(diminish 'autopair-mode)
(diminish 'anzu-mode)
(diminish 'volatile-highlights-mode)
(diminish 'undo-tree-mode)
(diminish 'auto-complete-mode)
(diminish 'highlight-indentation-mode)
(diminish 'flyspell-mode " ?")
))
;; Sane scroll settings
(setq scroll-margin 3
scroll-conservatively 100000
scroll-preserve-screen-position 1)
;; mode line settings
;; Show line/col-no in mode-line
(line-number-mode t)
(column-number-mode t)
(size-indication-mode t)
;; y/n instead of yes/no
(fset 'yes-or-no-p 'y-or-n-p)
;; make the fringe unintrusive
(if (fboundp 'fringe-mode) (fringe-mode 8))
;; make the fringe (gutter) smaller
;; the argument is a width in pixels (the default is 8)
(if (fboundp 'fringe-mode)
(fringe-mode 4))
;; Dynamic linum with +1 padding
;; Line numbers with +1 left-padding
(defadvice linum-update-window (around linum-dynamic activate)
(let* ((w (length (number-to-string (count-lines (point-min) (point-max)))))
(linum-format (concat "%" (number-to-string (+ w 1)) "d "))) ad-do-it))
(linum-format (concat "%" (number-to-string (+ w 1)) "d" (if window-system "" " ")))) ad-do-it))
;;;#uniquify
(setq uniquify-buffer-name-style 'forward)
(setq uniquify-separator "/")
(setq uniquify-after-kill-buffer-p t) ; rename after killing uniquified
(setq uniquify-ignore-buffers-re "^\\*") ; don't muck with special buffers
;;;; GUI Settings ;;;;;;;;;;;;;;;;;;;;;
; (set-face-attribute 'default t :font 'my-font )
(add-to-list 'default-frame-alist `(font . ,my-font))
(add-to-list 'default-frame-alist '(width . 100))
(add-to-list 'default-frame-alist '(height . 75))
(add-to-list 'default-frame-alist '(alpha 98 95)) ; *slightly* transparent window
; (set-face-attribute 'mode-line nil :box '(:line-width 4 :color "#1f2g2a" ))
(if window-system (progn
(tool-bar-mode -1)
(scroll-bar-mode -1)
; Use system clipboard
(setq x-select-enable-clipboard t)
(setq-default line-spacing 1)
; (setq-default line-spacing 1)
(setq ring-bell-function 'ignore)
) (menu-bar-mode -1))

View file

@ -17,11 +17,13 @@
; window layout undo/redo, keymaps in init-evil.el
(when (fboundp 'winner-mode) (winner-mode 1))
(setq linum-delay t)
(defadvice save-buffers-kill-emacs (around no-query-kill-emacs activate)
"Prevent annoying \"Active processes exist\" query when you quit Emacs."
(flet ((process-list ())) ad-do-it))
;; Prevent prompts when trying to close window. If I'm closing the window,
;; I likely want it to close!
(defadvice save-buffers-kill-emacs (around no-y-or-n activate)
(flet ((yes-or-no-p (&rest args) t)
(y-or-n-p (&rest args) t))
ad-do-it))
;;;; My personal minor mode ;;;;;;;;
@ -51,6 +53,12 @@
(interactive)
(projectile-find-file-in-directory my-dir))
(defun open-scratch-buffer ()
(interactive)
(switch-to-buffer (get-buffer-create "*scratch*"))
(text-mode))
;; Open the modules/env-{major-mode-name}.el file
(defun open-major-mode-conf ()
(interactive)
@ -62,10 +70,6 @@
(message (concat "Mode (" (major-mode-name) ") doesn't have a module! Creating it..."))))))
;;
(defun copy-to-end-of-line ()
(interactive)
(evil-yank (point) (point-at-eol)))
(defun backward-kill-line ()
(interactive)
(evil-delete (point-at-bol) (point)))
@ -112,8 +116,7 @@
;;;; Defuns ;;;;;;;;;;;;;;;;;;;;;;;
(defun linum-on () (linum-mode 0))
(defun linum-off () (linum-mode 0))
(defun no-linum () (linum-mode 0))
;;

55
modules/mod-ac.el Normal file
View file

@ -0,0 +1,55 @@
(require-packages
'(auto-complete ; self-explanity
auto-complete-config ; its default config
fuzzy ; fuzzy search engine for auto-complete
))
;;;; Auto-completion ;;;;;;;;;;;;;;
(ac-config-default)
(ac-linum-workaround) ; Fix line number flux bug
(add-hook 'prog-mode-hook 'enable-path-completion)
(setq ac-auto-show-menu nil ; Suggestions box must be invoked manually (see core-keymaps.el)
ac-use-menu-map t ; Enable ac-menu-map map when menu is open
ac-us-quick-help nil ; Don't show tooltips unless invoked (see core-keymaps.el)
ac-fuzzy-cursor-color nil)
(defun enable-path-completion ()
(add-to-list 'ac-sources 'ac-source-filename)
(add-to-list 'ac-sources 'ac-source-files-in-current-dir))
;; Tell ido not to care about case
(setq completion-ignore-case t)
;;; Filters ido-matches setting acronynm matches in front of the results
(defadvice ido-set-matches-1 (after ido-smex-acronym-matches activate)
(if (and (fboundp 'smex-already-running) (smex-already-running)
(> (length ido-text) 1))
(let ((regex (concat "^" (mapconcat 'char-to-string ido-text "[^-]*-")))
(acronym-matches (list))
(remove-regexes '("-menu-")))
;; Creating the list of the results to be set as first
(dolist (item items)
(if (string-match (concat regex "[^-]*$") item) ;; strict match
(add-to-list 'acronym-matches item)
(if (string-match regex item) ;; appending relaxed match
(add-to-list 'acronym-matches item t))))
;; Filtering ad-return-value
(dolist (to_remove remove-regexes)
(setq ad-return-value
(delete-if (lambda (item)
(string-match to_remove item))
ad-return-value)))
;; Creating resulting list
(setq ad-return-value
(append acronym-matches
ad-return-value))
(delete-dups ad-return-value)
(reverse ad-return-value))))
;;
(provide 'mod-ac)

17
modules/mod-fly.el Normal file
View file

@ -0,0 +1,17 @@
(require-packages
'(flycheck ; syntax checker
flyspell ; spell checker
))
(setq ispell-program-name "aspell")
(setq ispell-list-command "--list")
(setq flycheck-indication-mode 'right-fringe)
(setq-default flycheck-disabled-checkers '(emacs-lisp-checkdoc))
(add-hook 'prog-mode-hook #'global-flycheck-mode)
(add-hook 'text-mode-hook (lambda () (flyspell-mode 1)))
(add-hook 'conf-mode-hook (lambda () (flyspell-mode 1)))
;;
(provide 'mod-fly)

View file

@ -6,9 +6,20 @@
git-gutter-fringe
))
(global-git-gutter-mode t)
(setq git-gutter-fr:side 'right-fringe)
;; (diminish 'git-gutter-mode)
(custom-set-variables '(git-gutter:lighter " !"))
(custom-set-variables '(git-gutter:verbosity 0))
(set-face-foreground 'git-gutter-fr:modified "#555555")
(set-face-background 'git-gutter-fr:modified "#444444")
(set-face-foreground 'git-gutter-fr:deleted "#995555")
(set-face-background 'git-gutter-fr:deleted "#884444")
(set-face-foreground 'git-gutter-fr:added "#559955")
(set-face-background 'git-gutter-fr:added "#448844")
; (setq git-gutter-fr:side 'right-fringe)
(global-git-gutter-mode t)
(add-hook 'git-gutter-mode-on-hook
(lambda() (fringe-mode '(4 . 8))))
;;
(provide 'mod-git)