Refactor core initfiles

This commit is contained in:
Henrik Lissner 2015-01-09 21:47:51 -05:00
parent 2a7dac1a4e
commit 8e7cd74e07
8 changed files with 157 additions and 176 deletions

View file

@ -1,4 +1,4 @@
;; Global editor behavior (+ evil)
;; Global editor behavior
(use-package expand-region
:commands (er/expand-region er/contract-region))

View file

@ -6,7 +6,7 @@
(setq evil-want-visual-char-semi-exclusive t
evil-search-module 'evil-search
evil-search-wrap nil
evil-magic 'very-magic
evil-magic 'magic
evil-want-C-u-scroll t ; enable C-u for scrolling
evil-ex-visual-char-range t ; column range for ex commands
evil-ex-search-vim-style-regexp t
@ -15,7 +15,6 @@
evil-normal-state-cursor '("white" box)
evil-emacs-state-cursor '("cyan" bar)
evil-insert-state-cursor '("white" bar)
evil-god-state-cursor '("orange" box)
evil-visual-state-cursor 'hollow
ace-jump-mode-scope 'window
@ -50,12 +49,11 @@
(evil-set-initial-state `,(car mode-map) `,(cdr mode-map)))
(progn ; evil plugins
(use-package evil-space :init (evil-space-default-setup))
(use-package evil-exchange
:config
(defadvice evil-force-normal-state (before evil-esc-quit-exchange activate)
(shut-up (evil-exchange-cancel))))
(when evil-exchange--overlays
(evil-exchange-cancel))))
(use-package evil-ex-registers)
@ -63,19 +61,8 @@
(use-package evil-numbers)
(use-package evil-god-state)
(use-package evil-matchit :init (global-evil-matchit-mode 1))
(use-package evil-snipe
:disabled t
:init (global-evil-snipe-mode 1)
:config
(progn
(evil-snipe-override-surround)
(setq evil-snipe-search-highlight t)
(setq evil-snipe-search-incremental-highlight t)))
(use-package evil-surround
:init (global-evil-surround-mode 1))
@ -94,10 +81,10 @@
:init (global-evil-snipe-mode)
:config
(progn
(bind 'visual "z" 'evil-snipe-f)
(bind 'visual "Z" 'evil-snipe-F)
(setq evil-snipe-enable-highlight t
evil-snipe-enable-incremental-highlight t)))
(evil-snipe-replace-evil)
;; (evil-snipe-enable-sS)
(bind 'visual "z" 'evil-snipe-s)
(bind 'visual "Z" 'evil-snipe-S)))
(use-package ace-window
:config (setq aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l)))
@ -220,20 +207,31 @@
file-name))
(progn ; ex-commands
(evil-ex-define-cmd "echo" 'my:echo)
(evil-ex-define-cmd "pres[ent]" 'toggle-presentation-mode)
(evil-ex-define-cmd "togglet[heme]" 'toggle-theme)
(evil-ex-define-cmd "full[scr]" 'toggle-frame-fullscreen)
(evil-ex-define-cmd "k[ill]" 'kill-this-buffer) ; Kill current buffer
(evil-ex-define-cmd "k[ill]o" 'my-cleanup-buffers) ; Kill current project buffers
(evil-ex-define-cmd "k[ill]all" 'my:kill-buffers) ; Kill all buffers (bang = project buffers only)
(evil-ex-define-cmd "k[ill]buried" 'my:kill-buried-buffers) ; Kill all buffers (bang = project buffers only)
(evil-ex-define-cmd "ini" 'my:init-files)
(evil-ex-define-cmd "n[otes]" 'my:notes)
(evil-ex-define-cmd "recompile" 'my:byte-compile)
(evil-ex-define-cmd "cd" 'my:cd)
(evil-ex-define-cmd "en[ew]" 'my:create-file)
(evil-ex-define-cmd "ren[ame]" 'my:rename-this-file) ; Rename file . Bang: Delete old one
(evil-ex-define-cmd "al[ign]" 'my:align)
(evil-ex-define-cmd "retab" 'my:retab)
(evil-ex-define-cmd "sq[uint]" 'my:narrow-indirect) ; Narrow buffer to selection
(evil-ex-define-cmd "x" 'my:scratch-buffer)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(evil-ex-define-cmd "echo" 'my:echo)
(evil-define-command my:echo (&optional output)
(interactive "<a>")
(message "%s" output))
(evil-ex-define-cmd "k[ill]all" 'my:kill-buffers) ; Kill all buffers (bang = project buffers only)
(evil-define-command my:kill-buffers (&optional bang)
:repeat nil
(interactive "<!>")
@ -242,14 +240,12 @@
(mapc 'kill-buffer (buffer-list)))
(delete-other-windows))
(evil-ex-define-cmd "k[ill]buried" 'my:kill-buried-buffers) ; Kill all buffers (bang = project buffers only)
(evil-define-command my:kill-buried-buffers (&optional bang)
:repeat nil
(interactive "<!>")
(mapc 'kill-buffer
(my-living-buffer-list (if bang (projectile-project-buffers) (buffer-list)))))
(evil-ex-define-cmd "ini" 'my:init-files)
(evil-define-command my:init-files (&optional bang)
:repeat nil
(interactive "<!>")
@ -257,13 +253,11 @@
(ido-find-file-in-dir my-modules-dir)
(ido-find-file-in-dir my-dir)))
(evil-ex-define-cmd "n[otes]" 'my:notes)
(evil-define-command my:notes ()
:repeat nil
(interactive)
(ido-find-file-in-dir org-directory))
(evil-ex-define-cmd "recompile" 'my:byte-compile)
(evil-define-command my:byte-compile (&optional bang)
:repeat nil
(interactive "<!>")
@ -271,14 +265,12 @@
(byte-recompile-directory (concat my-dir ".cask") 0 t)
(byte-recompile-directory my-dir 0 t)))
(evil-ex-define-cmd "cd" 'my:cd)
(evil-define-command my:cd (dir)
:repeat nil
(interactive "<f>")
(cd (if (zerop (length dir)) "~" dir)))
(defun --save-exit() (save-buffer) (kill-buffer) (remove-hook 'yas-after-exit-snippet-hook '--save-exit))
(evil-ex-define-cmd "en[ew]" 'my:create-file)
(evil-define-command my:create-file (path &optional bang)
"Deploy files (and their associated templates) quickly. Will prompt
you to fill in each snippet field before buffer closes unless BANG is
@ -297,7 +289,6 @@ provided."
(if bang (--save-exit)))
(error "Directory doesn't exist: %s" dir))))
(evil-ex-define-cmd "ren[ame]" 'my:rename-this-file) ; Rename file . Bang: Delete old one
(evil-define-command my:rename-this-file (new-name &optional bang)
"Renames current buffer and file it is visiting. Replaces %, # and other
variables (see `evil-ex-replace-special-filenames')"
@ -323,7 +314,6 @@ provided."
(message "File '%s' successfully renamed to '%s'"
name (file-name-nondirectory new-name)))))))
(evil-ex-define-cmd "x" 'my:scratch-buffer)
(evil-define-operator my:scratch-buffer (beg end &optional bang)
"Send a selection to the scratch buffer. If BANG, then send it to org-capture
instead."
@ -349,7 +339,6 @@ provided."
(if text (insert text))
(funcall mode))))))
(evil-ex-define-cmd "al[ign]" 'my:align)
(evil-define-command my:align (beg end &optional regexp bang)
:repeat nil
(interactive "<r><a><!>")
@ -357,7 +346,6 @@ provided."
(align-regexp beg end
(concat "\\(\\s-*\\)" (rxt-pcre-to-elisp regexp)) 1 1)))
(evil-ex-define-cmd "retab" 'my:retab)
(evil-define-operator my:retab (beg end)
"Akin to vim's :retab, this changes all tabs-to-spaces or spaces-to-tabs,
depending on `indent-tab-mode'. Untested."
@ -372,7 +360,6 @@ provided."
(tabify beg end)
(untabify beg end)))
(evil-ex-define-cmd "sq[uint]" 'my:narrow-indirect) ; Narrow buffer to selection
(evil-define-operator my:narrow-indirect (beg end)
"Indirectly narrow the region from BEG to END."
:move-point nil

View file

@ -1,5 +1,4 @@
;; Mac-specific settings
(provide 'core-osx)
;; Use a shared clipboard
(setq x-select-enable-clipboard t)
@ -8,8 +7,6 @@
;; Don't open files from the workspace in a new frame
(setq ns-pop-up-frames nil)
;; (setq ns-auto-hide-menu-bar t)
;; fix emacs PATH on OSX (GUI only)
(use-package exec-path-from-shell
:if (memq window-system '(mac ns))
@ -47,7 +44,5 @@
(defun my-send-dir-to-finder ()
(interactive) (my--open-file-with default-directory "Finder"))
(defun my-osx-psuedo-fullscreen ()
(interactive)
(set-frame-position nil 0 0)
(set-frame-size nil 362 112))
(provide 'core-osx)

View file

@ -1,10 +1,14 @@
(cd "~") ; instead of /
(defconst is-mac (eq system-type 'darwin))
(defconst is-linux (eq system-type 'gnu/linux))
(when is-linux (add-to-list 'load-path "~/.cask"))
(require 'cask)
(cask-initialize)
(defconst is-mac (eq system-type 'darwin))
(defconst is-linux (eq system-type 'gnu/linux))
(cd "~") ; instead of /
(require 'use-package) ; Package management bootstrap
(setq use-package-verbose DEBUG-MODE)
;; Make sure undo/backup folders exist
(defconst my-tmp-dir-undo (expand-file-name "undo" my-tmp-dir))
@ -42,7 +46,7 @@
(set-selection-coding-system 'utf-8) ; please
(prefer-coding-system 'utf-8) ; with sugar on top
(fset 'yes-or-no-p 'y-or-n-p) ; y/n instead of yes/no
(fset 'yes-or-no-p 'y-or-n-p) ; y/n instead of yes/no
;;; Show tab characters
;; (global-whitespace-mode 1)
@ -114,24 +118,28 @@
(setq-default undo-tree-history-directory-alist `(("." . ,my-tmp-dir-undo)))
;;;; Save history across sessions
(setq savehist-additional-variables '(search ring regexp-search-ring))
(setq savehist-file (f-expand "savehist" my-tmp-dir)) ; keep the home clean
(setq savehist-file (concat my-tmp-dir "savehist")) ; keep the home clean
(savehist-mode 1)
;; Save cursor location across sessions
(require 'saveplace)
(setq save-place-file (f-expand "saveplace" my-tmp-dir))
(add-hook 'find-file-hook ; activate save-place for files that exist
(lambda()
(if (file-exists-p buffer-file-name)
(setq save-place t))))
(use-package saveplace
:init
(add-hook 'find-file-hook ; activate save-place for files that exist
(lambda()
(if (file-exists-p buffer-file-name)
(setq save-place t))))
:config
(setq save-place-file (concat my-tmp-dir "saveplace")))
(require 'recentf)
(setq recentf-max-menu-items 0)
(setq recentf-max-saved-items 1000)
(setq recentf-auto-cleanup 'never)
(setq recentf-save-file (concat my-tmp-dir "recentf"))
(setq recentf-exclude '("/tmp/" "/ssh:" "\\.?ido\\.last\\'" "\\.revive\\'", "/TAGS\\'"))
(recentf-mode 1)
(use-package recentf
:config
(progn
(setq recentf-max-menu-items 0)
(setq recentf-max-saved-items 1000)
(setq recentf-auto-cleanup 'never)
(setq recentf-save-file (concat my-tmp-dir "recentf"))
(setq recentf-exclude '("/tmp/" "/ssh:" "\\.?ido\\.last\\'" "\\.revive\\'", "/TAGS\\'"))
(recentf-mode 1)))
;; What we do every night, Pinkie...
(defun display-startup-echo-area-message ()
@ -144,19 +152,21 @@
(setq-default tab-always-indent nil)
(setq-default tab-width 4)
(setq require-final-newline t)
(setq delete-trailing-lines nil)
(add-hook 'makefile-mode-hook 'indent-tabs-mode) ; Use normal tabs in makefiles
;; Make sure scratch buffer is always "in a project"
(add-hook 'find-file-hook
(lambda()
(let ((buffer (get-buffer "*scratch*"))
(pwd (my--project-root)))
(when (buffer-live-p buffer)
(save-window-excursion
(switch-to-buffer buffer)
(unless (eq (my--project-root) pwd)
(cd pwd)
(rename-buffer (format "*scratch* (%s)" (file-name-base (directory-file-name pwd))))))))))
(lambda()
(let ((buffer (get-buffer "*scratch*"))
(pwd (my--project-root)))
(when (buffer-live-p buffer)
(save-window-excursion
(switch-to-buffer buffer)
(unless (eq (my--project-root) pwd)
(cd pwd)
(rename-buffer (format "*scratch* (%s)" (file-name-base (directory-file-name pwd))))))))))
;; My own minor mode!
(define-minor-mode my-mode :global t :keymap (make-sparse-keymap))
@ -186,52 +196,9 @@
ad-do-it))
;;;; Automatic minor modes ;;;;;;;;;;;;;;;
(defvar auto-minor-mode-alist ()
"Alist of filename patterns vs correpsonding minor mode functions,
see `auto-mode-alist' All elements of this alist are checked, meaning
you can enable multiple minor modes for the same regexp.")
(defun enable-minor-mode-based-on-extension ()
"check file name against auto-minor-mode-alist to enable minor modes
the checking happens for all pairs in auto-minor-mode-alist"
(when buffer-file-name
(let ((name buffer-file-name)
(remote-id (file-remote-p buffer-file-name))
(alist auto-minor-mode-alist))
;; Remove backup-suffixes from file name.
(setq name (file-name-sans-versions name))
;; Remove remote file name identification.
(when (and (stringp remote-id)
(string-match-p (regexp-quote remote-id) name))
(setq name (substring name (match-end 0))))
(while (and alist (caar alist) (cdar alist))
(if (string-match (caar alist) name)
(funcall (cdar alist) 1))
(setq alist (cdr alist))))))
(add-hook 'find-file-hook 'enable-minor-mode-based-on-extension)
;;;; Utility plugins ;;;;;;;;;;;;;;;;;;
(require 'defuns) ; all the defuns
(require 'use-package) ; Package management bootstrap
(setq use-package-verbose DEBUG-MODE)
;;(require 'hide-mode-line)
;; Generate autoloads if necessary
(defun my-update-autoloads (&optional forcep)
(interactive)
(setq generated-autoload-file (concat my-core-dir "autoloads.el"))
(when (or forcep (not (file-exists-p generated-autoload-file)))
(if forcep (delete-file generated-autoload-file))
(update-directory-autoloads my-core-dir my-modules-dir my-elisp-dir))
(require 'autoloads))
(my-update-autoloads)
;; Add elisp dirs to load-path
(let ((default-directory my-elisp-dir))
(normal-top-level-add-to-load-path '("."))
(normal-top-level-add-subdirs-to-load-path))
(require 'defuns)
(require 'autoloads) ; use make autoloads to generate autoloads file
(use-package smex
:commands (smex smex-major-mode-commands)
@ -271,13 +238,16 @@ the checking happens for all pairs in auto-minor-mode-alist"
;;;; Start the party ;;;;;;;;;;;;;;;;;;;
(if is-mac (require 'core-osx))
;; (if is-linux (require 'core-linux))
(require 'core-ui)
(require 'core-evil)
(require 'core-editor)
(require 'server)
(unless (server-running-p)
(server-start)))
(use-package server
:config
(unless (server-running-p)
(server-start))))
(provide 'core)

View file

@ -12,14 +12,6 @@
(defmacro f--exists? (file dir)
`(f-exists? (expand-file-name ,file ,dir))))
;;;###autoload
(after "projectile"
(defun my--project-root (&optional force-pwd)
(if (and (not force-pwd)
(projectile-project-p))
(projectile-project-root)
default-directory)))
;; Misc Defuns ;;;;;;;;;;;;;;;;;;;;;;;;;
;;;###autoload
(defun what-face (pos)

View file

@ -1,5 +1,3 @@
(provide 'defuns)
;; Convenience ;;;;;;;;;;;;;;;;;;;;;
(defun associate-mode (match mode)
(add-to-list 'auto-mode-alist (cons match mode)))
@ -7,6 +5,30 @@
(defun associate-minor-mode (match mode)
(add-to-list 'auto-minor-mode-alist (cons match mode)))
;; Automatic minor modes ;;;;;;;;;;;
(defvar auto-minor-mode-alist ()
"Alist of filename patterns vs correpsonding minor mode functions,
see `auto-mode-alist' All elements of this alist are checked, meaning
you can enable multiple minor modes for the same regexp.")
(defun enable-minor-mode-based-on-extension ()
"check file name against auto-minor-mode-alist to enable minor modes
the checking happens for all pairs in auto-minor-mode-alist"
(when buffer-file-name
(let ((name buffer-file-name)
(remote-id (file-remote-p buffer-file-name))
(alist auto-minor-mode-alist))
;; Remove backup-suffixes from file name.
(setq name (file-name-sans-versions name))
;; Remove remote file name identification.
(when (and (stringp remote-id)
(string-match-p (regexp-quote remote-id) name))
(setq name (substring name (match-end 0))))
(while (and alist (caar alist) (cdar alist))
(if (string-match (caar alist) name)
(funcall (cdar alist) 1))
(setq alist (cdr alist))))))
(add-hook 'find-file-hook 'enable-minor-mode-based-on-extension)
(defmacro λ (&rest body)
`(lambda () (interactive) ,@body))
@ -30,6 +52,13 @@
'with-no-warnings)
(with-eval-after-load ',feature ,@forms)))
(after "projectile"
(defun my--project-root (&optional force-pwd)
(if (and (not force-pwd)
(projectile-project-p))
(projectile-project-root)
default-directory)))
;; Keybindings ;;;;;;;;;;;;;;;;;;;;;;;;;
(defun bind (state &rest keys)
@ -108,3 +137,6 @@ to abort the minibuffer."
(when (get-buffer "*Completions*")
(delete-windows-on "*Completions*"))
(abort-recursive-edit)))
(provide 'defuns)

90
init.el
View file

@ -38,54 +38,56 @@
(add-to-list 'load-path my-core-dir)
(add-to-list 'load-path my-modules-dir)
(add-to-list 'load-path my-elisp-dir)
;; Add elisp dirs to load-path
(let ((default-directory my-elisp-dir))
(normal-top-level-add-subdirs-to-load-path))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Just the... bear necessities...
(defconst my-modules
;; ls -1 init/{init,my}* | xargs basename | sed -e 's/\..*$//'
'(core
(mapc 'require
;; ls init/{init,my}* | xargs basename | sed -e 's/\..*$//'
'(core
;; init-auto-complete
init-auto-insert ; for the lazy typis
init-company ; see above
init-cc ; C/C++/Obj-C madness
;; init-d ; D - It's C, but better!
;; init-cscope
;; init-csharp
init-dev ; general dev tools/settings
init-elisp ; emacs lisp
;; init-eshell
init-floobits ; when I'm feeling lonely
init-fly ; fly(check|spell)
init-git ; git-gutter + modes
;; init-go
init-helm ; when you forget where you put your constellation
init-ido ; when you forget where you put your keys
init-java ; the mascot language of carpal tunnel syndome
init-js ; alert("Oh, sure dude, I know java")
init-lua ; zero-based indices? Zero-based indices.
init-org ; for fearless leader (who is organized)
init-php ; making php less painful to work with
init-project ; project tools - dired, perspective, neotree
init-projectile ; when you forget where you put your house
init-python ; beautiful is better than ugly
init-regex ; /^[^\s](meaning)[^\n]*life/
init-ruby ; I frakking love ruby
init-scss ; @include magic;
init-sh ; #!/bin/bash_your_head_in
init-swift ; ever wanted to name a variable an emoticon?
init-text ; I got nothing...
init-tmux
;; init-rust
init-web
init-yasnippet ; type for me
;; init-auto-complete
init-auto-insert ; for the lazy typis
init-company ; see above
init-cc ; C/C++/Obj-C madness
;; init-d ; D - It's C, but better!
;; init-cscope
init-csharp
init-dev ; general dev tools/settings
init-lisp ; all things lisp; elisp, clojure
;; init-erlang
;; init-eshell
;; init-floobits ; when I'm feeling lonely
init-fly ; fly(check|spell)
init-git ; git-gutter + modes
;; init-go
init-helm ; when you forget where you put your constellation
init-ido ; when you forget where you put your keys
init-java ; the poster child for carpal tunnel syndome
init-js ; alert("not java, javascript!")
init-lua ; zero-based indices? Zero-based indices.
;; init-org ; for fearless leader (who is organized)
init-php ; making php less painful to work with
init-project ; project tools - dired, perspective, neotree
init-projectile ; when you forget where you put your house
init-python ; beautiful is better than ugly
init-regex ; /^[^\s](meaning)[^\n]*/
init-ruby ; <3
init-scss ; @include magic;
init-sh ; #!/bin/bash_your_head_in
init-swift ; yay, emoji variables!
init-text ; I got nothing...
init-tmux
;; init-rust
init-web
init-yasnippet ; type for me
my-bindings
my-settings
))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Load them in
(setq after-init-hook '((lambda() (mapc 'require my-modules))))
my-bindings
my-settings
))
;; I've created a monster!

View file

@ -1,12 +1,12 @@
;; Elisp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun remove-elc-on-save ()
"If you're saving an elisp file, likely the .elc is no longer valid."
(make-local-variable 'after-save-hook)
(add-hook 'after-save-hook
(lambda ()
(if (file-exists-p (concat buffer-file-name "c"))
(delete-file (concat buffer-file-name "c"))))))
(add-hook! 'after-save-hook
(if (file-exists-p (concat buffer-file-name "c"))
(delete-file (concat buffer-file-name "c")))))
(add-hook 'after-save-hook 'remove-elc-on-save)
(add-hook 'emacs-lisp-mode-hook 'remove-elc-on-save)
(add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
(evil-define-operator my:elisp-eval (beg end)
@ -28,6 +28,9 @@
(bind 'motion emacs-lisp-mode-map "g r" 'my:elisp-eval)
;; TODO Add clojure support
;; TODO Add scheme support
(provide 'init-elisp)
(provide 'init-lisp)
;;; init-elisp.el ends here