Initial commit (brand new NARF)

This commit is contained in:
Henrik Lissner 2015-06-06 06:40:33 -04:00
parent de70863bed
commit d0628e018a
105 changed files with 1837 additions and 16026 deletions

View file

@ -1,319 +1,234 @@
;;; The core of Narfy Emacs
;;; core.el --- The heart of the beast
;;
;;; Naming Conventions
;;; Naming conventions:
;;
;; narf/* public defun/variable
;; narf--* private defun/variable
;; narf|* hook defuns
;; narf:* interactive/keybind defuns
;; :* ex commands
;; narf-* A public variable/constant or function
;; narf--* A private variable or function (non-interactive)
;; narf/* An autoloaded interactive function
;; narf:* An ex command
;; narf|* A hook
;; @* Macro call
;;
;;; Bootstrap:
(setq package-enable-at-startup nil
debug-on-quit DEBUG-MODE)
(cd "~") ; instead of /
(require 'core-splash)
(fset '! 'eval-when-compile)
;; This is kept separate so it can jumpstart emacs; this prevents the unstyled
;; flash of emacs pre-makeover.
(load-theme (if window-system DEFAULT-THEME TERM-THEME) t)
(when window-system
(set-frame-font DEFAULT-FONT)
(scroll-bar-mode -1) ; no scrollbar
(tool-bar-mode -1) ; no toolbar
(menu-bar-mode -1)) ; no menubar
(defconst narf-emacs-dir user-emacs-directory)
(defconst narf-core-dir (! (concat narf-emacs-dir "core/")))
(defconst narf-modules-dir (! (concat narf-emacs-dir "modules/")))
(defconst narf-contrib-dir (! (concat narf-emacs-dir "contrib/")))
(defconst narf-private-dir (! (concat narf-emacs-dir "private/")))
(defconst narf-elpa-dir (! (concat narf-emacs-dir ".cask/" emacs-version "/elpa/")))
(defconst narf-temp-dir (concat narf-private-dir "cache/" (system-name) "/"))
(defconst narf-snippet-dirs (! (list (concat narf-private-dir "snippets/")
(concat narf-private-dir "templates/"))))
(! (defun --subdirs (path)
(let ((result '())
(paths (ignore-errors (directory-files path t "^[^.]" t))))
(dolist (file paths)
(when (file-directory-p file)
(add-to-list 'result file)))
result)))
;; Scan various folders to populate the load-dirs
(setq custom-theme-load-path
(! (append (--subdirs (concat narf-private-dir "themes/"))
custom-theme-load-path)))
(setq load-path
(! (setq load-path (append (list narf-core-dir narf-contrib-dir narf-modules-dir narf-private-dir)
(list (concat narf-core-dir "defuns"))
load-path
(--subdirs narf-contrib-dir)
(--subdirs narf-contrib-dir)))
(require 'cask)
(cask-initialize)
load-path))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(message ">> %s" "Are you pondering what I'm pondering, Pinky?")
(message "-----------------------------------------------------------------------------------")
(defun display-startup-echo-area-message ()
(message "-----------------------------------------------------------------------------------")
(message ">> %s\n>> Loaded in %s" (narf/random-comeback) (emacs-init-time)))
;; (require 'benchmark) ; records load times in `require-times'; also see `list-times'
(require 'autoloads nil t) ; generate autoloads with `make autoloads`
(require 'core-vars)
(require 'core-defuns)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(! (require 's)
(require 'dash)
(require 'f)
(add-to-list 'load-path (concat narf-core-dir "macros/"))
(setq use-package-verbose narf-debug-mode)
;; (setq use-package-expand-minimally (not narf-debug-mode))
(require 'use-package)
(defun use-package--add-keyword (keyword after)
(setq use-package-keywords
(-insert-at (-find-index (lambda (key) (eq key after)) use-package-keywords)
keyword use-package-keywords)))
(progn ; add :after to use-package
(use-package--add-keyword :after :load-path)
(setq use-package-keywords
(-insert-at (--find-index (eq it :load-path) use-package-keywords)
:after use-package-keywords))
(defalias 'use-package-normalize/:after 'use-package-normalize-symlist)
(defun use-package-handler/:after (name-symbol keyword arg rest state)
(let ((body (use-package-process-keywords name-symbol rest state)))
(if (null arg)
body
(use-package-concat
(use-package-process-keywords name-symbol
(use-package-sort-keywords (use-package-plist-maybe-put rest :defer t)) state)
(apply #'nconc
(mapcar (lambda (feature)
`(,(macroexpand `(@after ,feature (require ',name-symbol)))))
(delete-dups arg))))))))
(progn ; add :map for in-house key binding macro
(use-package--add-keyword :map :bind)
(defalias 'use-package-normalize/:map 'use-package-normalize-forms)
;; TODO: Write :map
(defun use-package-handler/:map (name-symbol keyword arg rest state)
(use-package-process-keywords name-symbol rest state))
)
)
(require 'diminish)
;; Emacs configuration ;;;;;;;;;;;;;;;;;
(defconst IS-MAC (eq system-type 'darwin))
(defconst IS-LINUX (eq system-type 'gnu/linux))
(defconst IS-WINDOWS (eq system-type 'windows-nt))
(require 'defuns)
;; NARF!
(defvar narf-mode-map (make-sparse-keymap))
(define-minor-mode narf-mode
"Narf, yoink, poit."
:global t :init-value t :lighter "NARF" :keymap narf-mode-map)
(defvar narf/leader-key ",")
(defvar narf/localleader-key "\\")
;; Make sure undo/backup folders exist
(defconst TMP-DIR-UNDO (expand-file-name "undo" TMP-DIR))
(defconst TMP-DIR-BACKUP (expand-file-name "backup" TMP-DIR))
(defconst TMP-DIR-AUTOSAVE (expand-file-name "autosave" TMP-DIR))
(unless (file-directory-p TMP-DIR)
(make-directory TMP-DIR-UNDO t)
(make-directory TMP-DIR-BACKUP t)
(make-directory TMP-DIR-AUTOSAVE t))
(fset 'yes-or-no-p 'y-or-n-p) ; y/n instead of yes/no
;;;; Sane defaults ;;;;;;;;;;;;;;;;;;;;;;;
(global-font-lock-mode t) ; Enable syntax highlighting for older emacs
(global-auto-revert-mode 1) ; revert buffers for changed files
;;; window layout undo/redo
(setq winner-boring-buffers '("*Completions*" "*Compile-Log*" "*inferior-lisp*"
"*Fuzzy Completions*" "*Apropos*" "*Help*" "*cvs*"
"*Buffer List*" "*Ibuffer*" "*esh command on file*"))
(winner-mode 1)
;;; UTF-8 please
(setq locale-coding-system 'utf-8) ; pretty
(set-terminal-coding-system 'utf-8) ; pretty
(set-keyboard-coding-system 'utf-8) ; pretty
(set-selection-coding-system 'utf-8) ; please
(prefer-coding-system 'utf-8) ; with sugar on top
(setq locale-coding-system 'utf-8) ; pretty
(set-terminal-coding-system 'utf-8) ; pretty
(set-keyboard-coding-system 'utf-8) ; pretty
(set-selection-coding-system 'utf-8) ; please
(prefer-coding-system 'utf-8) ; with sugar on top
;;; Show tab characters
;; (global-whitespace-mode 1)
(setq whitespace-style '(trailing face tabs tab-mark) ; needs to be re-set in every buffer
whitespace-display-mappings
'((tab-mark ?\t [?| ?\t] [?\\ ?\t])
(newline-mark 10 [36 10]))) ; for whitespace-newline-mode
(fset 'yes-or-no-p 'y-or-n-p) ; y/n instead of yes/no
;; avoid garbage collection (default is 400k)
(setq-default
gc-cons-threshold 20000000
confirm-kill-emacs nil
;; minibufferception? Yay!
enable-recursive-minibuffers t)
confirm-kill-emacs (lambda (prompt) (y-or-n-p ">> Gee, I dunno Brain... Are you sure?"))
;; Show me those keystrokes
(setq echo-keystrokes 0.02
gc-cons-threshold 20000000 ; avoid garbage collection
enable-recursive-minibuffers t ; minibufferception
echo-keystrokes 0.02 ; show me those keystrokes
ring-bell-function 'ignore ; silence of the bells!
ring-bell-function 'ignore
inhibit-startup-screen t ; don't show emacs start screen
inhibit-startup-echo-area-message "hlissner" ; username shuts up emacs
initial-major-mode 'text-mode ; initial scratch buffer mode
initial-scratch-message nil
inhibit-startup-screen t ; don't show EMACs start screen
inhibit-splash-screen t
;; inhibit-startup-message t
inhibit-startup-echo-area-message "hlissner"
;; inhibit-startup-buffer-menu t
compilation-always-kill t
compilation-ask-about-save nil
compilation-scroll-output t
initial-major-mode 'text-mode ; initial scratch buffer mode
initial-scratch-message nil
sentence-end-double-space nil ; sentences end with periods. period.
compilation-always-kill t
compilation-ask-about-save nil
compilation-scroll-output t
ediff-diff-options "-w"
ediff-split-window-function 'split-window-horizontally ; side-by-side diffs
ediff-window-setup-function 'ediff-setup-windows-plain ; no extra frames
sentence-end-double-space nil ; sentences end with periods. Period.
;; Don't save clipboard contents into kill-ring before replacing them
save-interprogram-paste-before-kill nil
ediff-diff-options "-w"
ediff-split-window-function 'split-window-horizontally ; side-by-side diffs
ediff-window-setup-function 'ediff-setup-windows-plain) ; no extra frames
;; Don't let the cursor go into minibuffer prompt
;; from Xah Lee: http://ergoemacs.org/emacs/emacs_stop_cursor_enter_prompt.html
minibuffer-prompt-properties
'(read-only t point-entered minibuffer-avoid-prompt face minibuffer-prompt)
;; Don't save clipboard contents into kill-ring before replacing them
(setq save-interprogram-paste-before-kill nil)
;; remove annoying ellipsis when printing sexp in message buffer
eval-expression-print-length nil
eval-expression-print-level nil
;; don't let the cursor go into minibuffer prompt
;; Tip taken from Xah Lee: http://ergoemacs.org/emacs/emacs_stop_cursor_enter_prompt.html
(setq minibuffer-prompt-properties
'(read-only t point-entered minibuffer-avoid-prompt face minibuffer-prompt))
history-length 1000
;; remove annoying ellipsis when printing sexp in message buffer
(setq eval-expression-print-length nil
eval-expression-print-level nil)
;; Backups ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Disable all backups (that's what git/dropbox are for)
bookmark-save-flag t
bookmark-default-file (! (concat narf-temp-dir "bookmarks"))
auto-save-default nil
auto-save-list-file-name (! (concat narf-temp-dir "autosave"))
;; In case I want to reactivate backup files
make-backup-files nil
create-lockfiles nil
backup-directory-alist `((".*" . ,(! (concat narf-temp-dir "backup/"))))
;; Remember undo history
undo-tree-auto-save-history t
undo-tree-history-directory-alist `(("." . ,(! (concat narf-temp-dir "undo/")))))
;; Make any folders needed
(! (dolist (file '("" "undo" "backup"))
(let ((path (concat narf-temp-dir file)))
(unless (file-exists-p path)
(make-directory path t)))))
;; Save cursor location across sessions. Only save for files that exist.
(use-package saveplace
:init (defvar save-place-file (concat TMP-DIR "saveplace"))
:config (add-hook! 'find-file-hook (if (file-exists-p (buffer-file-name)) (setq save-place t))))
(require 'saveplace)
(setq save-place-file (! (concat narf-temp-dir "saveplace")))
(@add-hook find-file (if (file-exists-p (buffer-file-name)) (setq save-place t)))
;; Save history across sessions
(use-package savehist
:config
(progn
(setq savehist-file (concat TMP-DIR "savehist") ; keep the home clean
history-length 1000
savehist-additional-variables '(kill-ring
global-mark-ring
search-ring
regexp-search-ring
extended-command-history))
(savehist-mode 1)))
(require 'savehist)
(setq savehist-file (! (concat narf-temp-dir "savehist"))
savehist-additional-variables
'(kill-ring global-mark-ring search-ring regexp-search-ring extended-command-history))
(savehist-mode 1)
(use-package recentf
:config
(progn
(setq recentf-save-file (concat TMP-DIR "recentf")
recentf-exclude '("/tmp/" "/ssh:" "\\.?ido\\.last$" "\\.revive$" "/TAGS$"
"/\\.cache/.+" "emacs\\.d/workgroups/.+$" ".emacs.workgroup"
"/company-statistics-cache.el$")
recentf-max-menu-items 0
recentf-max-saved-items 250
recentf-auto-cleanup 600)
(recentf-mode 1)))
;;;; Backup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Disable all backups (that's what git/dropbox are for)
(setq bookmark-save-flag t
bookmark-default-file (concat TMP-DIR "bookmarks")
auto-save-default nil
auto-save-list-file-name (concat TMP-DIR-AUTOSAVE "auto-save")
auto-save-file-name-transforms `((".*" ,TMP-DIR-AUTOSAVE t))
;; In case I want to reactivate backup files
make-backup-files nil
create-lockfiles nil
backup-directory-alist `((".*" . ,TMP-DIR-BACKUP)))
;;;; Undo Tree ;;;;;;;;;;;;;;;;;;;;;;;;;
(setq-default ; Remember undo history
undo-tree-auto-save-history t
undo-tree-history-directory-alist `(("." . ,TMP-DIR-UNDO)))
;; Keep region when undoing in region
(defadvice undo-tree-undo (around keep-region activate)
(if (use-region-p)
(let ((m (set-marker (make-marker) (mark)))
(p (set-marker (make-marker) (point))))
ad-do-it
(goto-char p)
(set-mark m)
(set-marker p nil)
(set-marker m nil))
ad-do-it))
;; Shut up undo-tree's constant complaining: http://youtu.be/Z6woIRLnbmE
(defadvice undo-tree-load-history-hook (around undo-tree-load-history-shut-up activate) (shut-up ad-do-it))
(defadvice undo-tree-save-history-hook (around undo-tree-save-history-shut-up activate) (shut-up ad-do-it))
;; Silences an annoying error: undo-tree-mapc: Wrong type argument: listp, \.\.\.
(defadvice undo-tree-position (around undo-tree-position-silence-type-error activate)
(when (listp (ad-get-args 1)) ad-do-it))
;;;; Editor behavior ;;;;;;;;;;;;;;;;
(setq-default ; spaces instead of tabs
indent-tabs-mode nil
tab-always-indent t
tab-width 4)
(setq require-final-newline t
delete-trailing-lines nil)
;; Automatic minor modes ;;;;;;;;;;;
(defvar narf/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 narf|enable-minor-mode-maybe ()
"Check file name against `narf/auto-minor-mode-alist'."
(when buffer-file-name
(let ((name buffer-file-name)
(remote-id (file-remote-p buffer-file-name))
(alist narf/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 'narf|enable-minor-mode-maybe)
;;;; Utility plugins ;;;;;;;;;;;;;;;;;;
(use-package smex
:functions (smex-initialize smex-update)
:commands (smex smex-major-mode-commands)
:config
(progn
(setq smex-save-file (expand-file-name "smex-items" TMP-DIR))
(smex-initialize)
;; Hook up smex to auto-update, rather than update on every run
(defun smex-update-after-load (unused)
(when (boundp 'smex-cache) (smex-update)))
(add-hook 'after-load-functions 'smex-update-after-load)))
(use-package popwin
:config
(progn ; popwin config
(popwin-mode 1)
(setq popwin:popup-window-height 0.45
popwin:special-display-config
(append '(("\\`\\*helm.*?\\*\\'" :regexp t :position bottom :height 15)
("^\\*Flycheck.*\\*$" :regexp t :position bottom :height 0.25 :noselect t)
(inf-enh-ruby-mode :position bottom :stick t)
(snippet-mode :position bottom :stick t)
("^\\*eclim.*\\*" :regexp t :position bottom :height 0.25)
("*ansi-term*" :position bottom :height 0.45 :stick t)
("*terminal*" :position bottom :height 0.45 :stick t)
("*Async Shell Command*" :position bottom)
("*Shell Command Output*" :position bottom :stick t :height 15)
("* Regexp Explain *" :position top :height 0.35)
("*anaconda-doc*" :position bottom :height 15 :noselect t)
("*anaconda-nav*" :position bottom :height 15 :stick t)
("^\\*Python.+\\*$" :regexp t :position bottom :height 20 :noselect t)
("*Pp Eval Output*" :position bottom :height 10 :noselect t)
("*eval*" :position bottom :noselect t)
(help-mode :height 25 :position bottom :stick t)
(compilation-mode :height 0.5 :position bottom :noselect t)
(diff-mode :position bottom :stick t)
("*Backtrace*")
("*Warnings*")
("*Process List*")
("*Compile-Log*" :height 0.3 :position bottom :noselect t)
(" *undo-tree*" :width 0.3 :position right)
("^\\*scratch\\*.*" :regexp t :stick t)
(image-mode))
popwin:special-display-config))
(defun popwin:toggle-popup-window ()
(interactive)
(if (popwin:popup-window-live-p)
(popwin:close-popup-window)
(popwin:popup-last-buffer)))))
(use-package semantic
:commands semantic-mode
:init
(progn
(add-hook 'c-mode-common-hook 'semantic-mode)
(defvar semanticdb-default-system-save-directory (concat TMP-DIR "semanticdb"))
(defvar semanticdb-default-save-directory (concat TMP-DIR "semanticdb")))
:config
(semantic-mode 1))
;; Improved help commands
(use-package help-fns+
:commands (describe-buffer
describe-command
describe-file
describe-keymap
describe-option
describe-option-of-type))
(use-package server
:config (unless (server-running-p) (server-start)))
(require 'recentf)
(setq recentf-save-file (! (concat narf-temp-dir "recentf"))
recentf-exclude '("/tmp/" "/ssh:" "\\.?ido\\.last$" "\\.revive$" "/TAGS$"
"/\\.cache/.+" "emacs\\.d/workgroups/.+$" ".emacs.workgroup"
"/company-statistics-cache.el$")
recentf-max-menu-items 0
recentf-max-saved-items 250
recentf-auto-cleanup 600)
(recentf-mode 1)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(cond (IS-MAC (require 'core-osx))
(IS-LINUX (require 'core-linux))
(IS-WINDOWS (require 'core-windows)))
;; Performance checks
(add-hook! 'find-file-hook
;; If file is oversized...
(when (> (buffer-size) (* 1024 1024))
(setq buffer-read-only t)
(buffer-disable-undo)
(fundamental-mode)
(visual-line-mode)))
(use-package help-fns+ ; Improved help commands
:commands (describe-buffer describe-command describe-file
describe-keymap describe-option describe-option-of-type))
(use-package popwin :config (popwin-mode 1))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(cond (IS-MAC (require 'core-os-osx))
(IS-LINUX (require 'core-os-linux))
(IS-WINDOWS (require 'core-os-win32)))
(require 'core-ui)
(require 'core-evil)
;; (require 'core-editor)
;; (require 'core-completion)
;; (require 'core-syntax-checker)
;; (require 'core-snippets)
;; (require 'core-templates)
;; (require 'core-project)
;; (require 'core-vcs)
;; (require 'core-sessions)
;; (require 'core-quickrun)
;; (@add-hook after-init
;; (use-package my-bindings)
;; (use-package my-commands))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package server :config (unless (server-running-p) (server-start)))
(provide 'core)