├── .gitmodules ├── mode-inits ├── init-rainbowdelimiters.el ├── init-company-mode.el ├── init-scala-mode2.el ├── init-textile-mode.el ├── init-rubocop-mode.el ├── init-flycheck.el ├── init-dash-at-point.el ├── init-toml.el ├── init-mo-git-blame.el ├── init-yaml-mode.el ├── init-dockerfile.el ├── init-flx.el ├── init-clojure-mode.el ├── init-rust-mode.el ├── init-inf-ruby.el ├── init-smex.el ├── init-smartparens.el ├── init-haskell-mode.el ├── init-projectile.el ├── init-ruby-mode.el ├── init-cider.el ├── init-dired+.el ├── init-solarize-theme.el ├── init-markdown-mode.el ├── init-magit.el ├── init-cmake.el ├── init-smart-mode-line.el ├── init-go-mode.el └── init-webmode.el ├── linux-customizations ├── my-linux-ui.el └── my-linux-keys.el ├── customizations ├── my-shell.el ├── my-keys.el ├── my-ui.el ├── my-editing.el └── my-buffers.el ├── utilities ├── indent-whole-buffer.el ├── delete-this-file.el ├── move-lines.el ├── comment-or-uncomment-region-or-line.el ├── vendor.el ├── count-words.el ├── rename-file-and-buffer.el ├── chomp.el ├── slick-copy.el ├── visit-ansi-term.el ├── jekyll.el └── load-directory.el ├── .gitignore ├── mac-customizations ├── my-mac-ui.el ├── my-mac-tweaks.el └── my-mac-keys.el ├── custom.el ├── README.md ├── Cask └── init.el /.gitmodules: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /mode-inits/init-rainbowdelimiters.el: -------------------------------------------------------------------------------- 1 | (require 'rainbow-delimiters) 2 | -------------------------------------------------------------------------------- /mode-inits/init-company-mode.el: -------------------------------------------------------------------------------- 1 | (add-hook 'after-init-hook 'global-company-mode) 2 | -------------------------------------------------------------------------------- /mode-inits/init-scala-mode2.el: -------------------------------------------------------------------------------- 1 | (add-to-list 'auto-mode-alist '("\\.scala$" . scala-mode)) 2 | -------------------------------------------------------------------------------- /mode-inits/init-textile-mode.el: -------------------------------------------------------------------------------- 1 | (add-to-list 'auto-mode-alist '("\\.textile\\'" . textile-mode)) 2 | -------------------------------------------------------------------------------- /mode-inits/init-rubocop-mode.el: -------------------------------------------------------------------------------- 1 | (require 'flycheck) 2 | 3 | (add-hook 'ruby-mode-hook 'rubocop-mode) 4 | -------------------------------------------------------------------------------- /mode-inits/init-flycheck.el: -------------------------------------------------------------------------------- 1 | (autoload 'flycheck "flycheck" nil t) 2 | (add-hook 'after-init-hook 'global-flycheck-mode) 3 | -------------------------------------------------------------------------------- /mode-inits/init-dash-at-point.el: -------------------------------------------------------------------------------- 1 | (autoload 'dash-at-point "dash-at-point" nil t) 2 | 3 | (global-set-key "\C-cd" 'dash-at-point) 4 | -------------------------------------------------------------------------------- /mode-inits/init-toml.el: -------------------------------------------------------------------------------- 1 | (autoload 'toml-mode "toml-mode" nil t) 2 | (add-to-list 'auto-mode-alist '("\\.toml\\'" . toml-mode)) 3 | -------------------------------------------------------------------------------- /mode-inits/init-mo-git-blame.el: -------------------------------------------------------------------------------- 1 | (autoload 'mo-git-blame-file "mo-git-blame" nil t) 2 | (autoload 'mo-git-blame-current "mo-git-blame" nil t) 3 | -------------------------------------------------------------------------------- /mode-inits/init-yaml-mode.el: -------------------------------------------------------------------------------- 1 | (add-to-list 'auto-mode-alist '("\\.yaml$" . yaml-mode)) 2 | (add-to-list 'auto-mode-alist '("\\.yml$" . yaml-mode)) 3 | -------------------------------------------------------------------------------- /mode-inits/init-dockerfile.el: -------------------------------------------------------------------------------- 1 | (autoload 'dockerfile-mode "dockerfile-mode" nil t) 2 | (add-to-list 'auto-mode-alist '("Dockerfile\\'" . dockerfile-mode)) 3 | -------------------------------------------------------------------------------- /mode-inits/init-flx.el: -------------------------------------------------------------------------------- 1 | (require 'flx-ido) 2 | 3 | (ido-mode 1) 4 | (ido-everywhere 1) 5 | (flx-ido-mode 1) 6 | 7 | ;; disable ido faces to see flx highlights. 8 | (setq ido-use-faces nil) 9 | -------------------------------------------------------------------------------- /linux-customizations/my-linux-ui.el: -------------------------------------------------------------------------------- 1 | ; nice font 2 | (set-default-font "-unknown-DejaVu Sans Mono-medium-normal-normal-*-20-*-*-*-m-0-iso10646-1") 3 | 4 | ; no menu bar 5 | (menu-bar-mode -1) 6 | -------------------------------------------------------------------------------- /mode-inits/init-clojure-mode.el: -------------------------------------------------------------------------------- 1 | (autoload 'clojure-mode "clojure-mode" nil t) 2 | 3 | (add-hook 'clojure-mode-hook 'smartparens-strict-mode) 4 | (add-hook 'clojure-mode-hook 'rainbow-delimiters-mode) 5 | -------------------------------------------------------------------------------- /customizations/my-shell.el: -------------------------------------------------------------------------------- 1 | ; can't write over prompt, that would be weird 2 | (setq comint-prompt-read-only) 3 | 4 | ; colorful shell 5 | (require 'ansi-color) 6 | (add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on) 7 | -------------------------------------------------------------------------------- /mode-inits/init-rust-mode.el: -------------------------------------------------------------------------------- 1 | (autoload 'rust-mode "rust-mode" nil t) 2 | (add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode)) 3 | 4 | (eval-after-load 'flycheck 5 | '(add-hook 'flycheck-mode-hook #'flycheck-rust-setup)) 6 | -------------------------------------------------------------------------------- /mode-inits/init-inf-ruby.el: -------------------------------------------------------------------------------- 1 | (autoload 'inf-ruby-minor-mode "inf-ruby" "Run an inferior Ruby process" t) 2 | (add-hook 'ruby-mode-hook 'inf-ruby-minor-mode) 3 | 4 | (setq 5 | ruby-deep-indent-paren nil 6 | ruby-deep-arglist nil) 7 | -------------------------------------------------------------------------------- /utilities/indent-whole-buffer.el: -------------------------------------------------------------------------------- 1 | (defun indent-whole-buffer () 2 | "indent whole buffer" 3 | (interactive) 4 | (delete-trailing-whitespace) 5 | (indent-region (point-min) (point-max) nil) 6 | (untabify (point-min) (point-max))) -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *~ 3 | .emacs-opened-files 4 | .savehist 5 | .saveplace 6 | tramp 7 | *.elc 8 | .ensime 9 | ac-comphist.dat 10 | el-get 11 | elpa 12 | var 13 | auto-save-list 14 | projectile-bookmarks.eld 15 | .cask 16 | projectile.cache -------------------------------------------------------------------------------- /mac-customizations/my-mac-ui.el: -------------------------------------------------------------------------------- 1 | ; nice font 2 | (defun fontify-frame (frame) 3 | (set-frame-parameter frame 'font "Hack-16")) 4 | 5 | ; fontify this and all future frames 6 | (fontify-frame nil) 7 | (push 'fontify-frame after-make-frame-functions) 8 | -------------------------------------------------------------------------------- /mode-inits/init-smex.el: -------------------------------------------------------------------------------- 1 | ;; lets you M-x without meta 2 | ;; yes, this overwrites the usual way of exiting Emacs 3 | (global-set-key (kbd "C-x C-c") 'smex) 4 | (global-set-key (kbd "C-x c") 'smex) 5 | (global-set-key (kbd "C-x m") 'smex-major-mode-commands) 6 | -------------------------------------------------------------------------------- /utilities/delete-this-file.el: -------------------------------------------------------------------------------- 1 | (defun delete-this-file () 2 | (interactive) 3 | (or (buffer-file-name) (error "no file is currently being edited")) 4 | (when (yes-or-no-p "Really delete this file?") 5 | (delete-file (buffer-file-name)) 6 | (kill-this-buffer))) -------------------------------------------------------------------------------- /mode-inits/init-smartparens.el: -------------------------------------------------------------------------------- 1 | (smartparens-global-mode t) 2 | (show-smartparens-global-mode +1) 3 | 4 | (sp-local-pair 'clojure-mode "'" nil :actions nil) 5 | 6 | (sp-local-pair 'markdown-mode "'" nil :actions nil) 7 | (sp-local-pair 'markdown-mode "\"" nil :actions nil) 8 | -------------------------------------------------------------------------------- /mac-customizations/my-mac-tweaks.el: -------------------------------------------------------------------------------- 1 | ; use default Mac browser 2 | (setq browse-url-browser-function 'browse-url-default-macosx-browser) 3 | 4 | ; delete files by moving them to the OS X trash 5 | (setq delete-by-moving-to-trash t) 6 | 7 | (setenv "GOPATH" "/Users/al3x/src/mygo") 8 | -------------------------------------------------------------------------------- /mode-inits/init-haskell-mode.el: -------------------------------------------------------------------------------- 1 | (autoload 'haskell-mode "haskell-mode" nil t) 2 | (autoload 'haskell-mode "ghc" nil t) 3 | 4 | (add-to-list 'auto-mode-alist '("\\.hs$" . haskell-mode)) 5 | (add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode) 6 | (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation) 7 | -------------------------------------------------------------------------------- /mode-inits/init-projectile.el: -------------------------------------------------------------------------------- 1 | (projectile-global-mode) 2 | 3 | (define-key projectile-mode-map [?\s-F] 'projectile-ag) 4 | (define-key projectile-mode-map [?\s-p] 'projectile-switch-project) 5 | (define-key projectile-mode-map [?\s-t] 'projectile-find-file) 6 | (define-key projectile-mode-map [?\s-d] 'projectile-find-dir) 7 | -------------------------------------------------------------------------------- /utilities/move-lines.el: -------------------------------------------------------------------------------- 1 | (defun move-line-up () 2 | "Move up the current line." 3 | (interactive) 4 | (transpose-lines 1) 5 | (forward-line -2) 6 | (indent-according-to-mode)) 7 | 8 | (defun move-line-down () 9 | "Move down the current line." 10 | (interactive) 11 | (forward-line 1) 12 | (transpose-lines 1) 13 | (forward-line -1) 14 | (indent-according-to-mode)) 15 | -------------------------------------------------------------------------------- /mode-inits/init-ruby-mode.el: -------------------------------------------------------------------------------- 1 | (add-to-list 'auto-mode-alist '("\\.rb$" . ruby-mode)) 2 | (setq auto-mode-alist (cons '("Rakefile" . ruby-mode) auto-mode-alist)) 3 | (setq auto-mode-alist (cons '("Capfile" . ruby-mode) auto-mode-alist)) 4 | (setq auto-mode-alist (cons '("Gemfile" . ruby-mode) auto-mode-alist)) 5 | (setq auto-mode-alist (cons '("\\.rake" . ruby-mode) auto-mode-alist)) 6 | 7 | (add-hook 'ruby-mode-hook 'minitest-mode) 8 | -------------------------------------------------------------------------------- /utilities/comment-or-uncomment-region-or-line.el: -------------------------------------------------------------------------------- 1 | (defun comment-or-uncomment-region-or-line () 2 | "Comments or uncomments the region or the current line if there's no active region." 3 | (interactive) 4 | (let (beg end) 5 | (if (region-active-p) 6 | (setq beg (region-beginning) end (region-end)) 7 | (setq beg (line-beginning-position) end (line-end-position))) 8 | (comment-or-uncomment-region beg end))) 9 | -------------------------------------------------------------------------------- /mode-inits/init-cider.el: -------------------------------------------------------------------------------- 1 | (require 'cider) 2 | 3 | ; settings 4 | (setq nrepl-hide-special-buffers t) 5 | (setq cider-repl-popup-stacktraces t) 6 | (setq cider-auto-select-error-buffer t) 7 | (setq cider-repl-history-file "~/.cider-repl-history") 8 | 9 | ; hooks 10 | (add-hook 'cider-mode-hook 'cider-turn-on-eldoc-mode) 11 | (add-hook 'cider-repl-mode-hook 'rainbow-delimiters-mode) 12 | (add-hook 'cider-repl-mode-hook 'smartparens-strict-mode) 13 | (add-hook 'cider-repl-mode-hook 'subword-mode) 14 | -------------------------------------------------------------------------------- /utilities/vendor.el: -------------------------------------------------------------------------------- 1 | ; for loading libraries in from the vendor directory 2 | (defun vendor (library) 3 | (let* ((file (symbol-name library)) 4 | (normal (concat "~/.emacs.d/vendor/" file)) 5 | (suffix (concat normal ".el"))) 6 | (cond 7 | ((file-directory-p normal) 8 | (add-to-list 'load-path normal) 9 | (require library)) 10 | ((file-directory-p suffix) 11 | (add-to-list 'load-path suffix) 12 | (require library)) 13 | ((file-exists-p suffix) 14 | (require library))))) -------------------------------------------------------------------------------- /mode-inits/init-dired+.el: -------------------------------------------------------------------------------- 1 | (require 'dired+) 2 | 3 | (toggle-diredp-find-file-reuse-dir 1) 4 | 5 | (defun mydired-sort () 6 | "Sort dired listings with directories first." 7 | (save-excursion 8 | (let (buffer-read-only) 9 | (forward-line 2) ;; beyond dir. header 10 | (sort-regexp-fields t "^.*$" "[ ]*." (point) (point-max))) 11 | (set-buffer-modified-p nil))) 12 | 13 | (defadvice dired-readin 14 | (after dired-after-updating-hook first () activate) 15 | "Sort dired listings with directories first before adding marks." 16 | (mydired-sort)) 17 | -------------------------------------------------------------------------------- /utilities/count-words.el: -------------------------------------------------------------------------------- 1 | ;---------------------------------------------------------------------------- 2 | ; Easily count words (http://emacs-fu.blogspot.com/2009/01/counting-words.html) 3 | ;---------------------------------------------------------------------------- 4 | (defun count-words (&optional begin end) 5 | "count words between BEGIN and END (region); if no region defined, count words in buffer" 6 | (interactive "r") 7 | (let ((b (if mark-active begin (point-min))) 8 | (e (if mark-active end (point-max)))) 9 | (message "Word count: %s" (how-many "\\w+" b e)))) -------------------------------------------------------------------------------- /utilities/rename-file-and-buffer.el: -------------------------------------------------------------------------------- 1 | (defun rename-file-and-buffer (new-name) 2 | (interactive "sNew name: ") 3 | (let ((name (buffer-name)) 4 | (filename (buffer-file-name))) 5 | (if (not filename) 6 | (message "Buffer '%s' is not visiting a file!" name) 7 | (if (get-buffer new-name) 8 | (message "A buffer named '%s' already exists!" new-name) 9 | (progn 10 | (rename-file name new-name 1) 11 | (rename-buffer new-name) 12 | (set-visited-file-name new-name) 13 | (set-buffer-modified-p nil)))))) -------------------------------------------------------------------------------- /mode-inits/init-solarize-theme.el: -------------------------------------------------------------------------------- 1 | (setq my-themes '(solarized-dark solarized-light)) 2 | 3 | (setq my-cur-theme nil) 4 | (defun cycle-my-theme () 5 | "Cycle through a list of preferred themes" 6 | (interactive) 7 | (when my-cur-theme 8 | (disable-theme my-cur-theme) 9 | (setq my-themes (append my-themes (list my-cur-theme)))) 10 | (setq my-cur-theme (pop my-themes)) 11 | (load-theme my-cur-theme t)) 12 | 13 | ;; switch to the first theme in the list above: solarized-dark 14 | (cycle-my-theme) 15 | 16 | ;; bind theme switching to F12 17 | (global-set-key (kbd "") 'cycle-my-theme) 18 | -------------------------------------------------------------------------------- /customizations/my-keys.el: -------------------------------------------------------------------------------- 1 | ; Make yes-or-no questions answerable with 'y' or 'n' 2 | (fset 'yes-or-no-p 'y-or-n-p) 3 | 4 | ; C-x without going all the way to 'x', 5 | ; which sucks on Dvorak 6 | (keyboard-translate ?\C-t ?\C-x) 7 | 8 | ; Always indent 9 | (electric-indent-mode 1) 10 | 11 | ; TextMate-style commenting 12 | (global-set-key (kbd "s-/") 'comment-or-uncomment-region-or-line) 13 | 14 | ; Easily move lines up and down using utility functions 15 | (global-set-key [(meta up)] 'move-line-up) 16 | (global-set-key [(meta down)] 'move-line-down) 17 | 18 | ; Compile 19 | (global-set-key (kbd "C-c c") 'compile) 20 | -------------------------------------------------------------------------------- /utilities/chomp.el: -------------------------------------------------------------------------------- 1 | (defun chomp (str) 2 | "..." 3 | (let ((s (if (symbolp str)(symbol-name str) str))) 4 | (save-excursion 5 | (while (and 6 | (not (null (string-match "^\\( \\|\f\\|\t\\|\n\\)" s))) 7 | (> (length s) (string-match "^\\( \\|\f\\|\t\\|\n\\)" s))) 8 | (setq s (replace-match "" t nil s))) 9 | (while (and 10 | (not (null (string-match "\\( \\|\f\\|\t\\|\n\\)$" s))) 11 | (> (length s) (string-match "\\( \\|\f\\|\t\\|\n\\)$" s))) 12 | (setq s (replace-match "" t nil s)))) 13 | s)) -------------------------------------------------------------------------------- /mode-inits/init-markdown-mode.el: -------------------------------------------------------------------------------- 1 | (autoload 'markdown-mode "markdown-mode" 2 | "Major mode for editing Markdown files" t) 3 | 4 | (add-to-list 'auto-mode-alist '("\\.markdown$" . markdown-mode)) 5 | (add-to-list 'auto-mode-alist '("\\.mkd$" . markdown-mode)) 6 | (add-to-list 'auto-mode-alist '("\\.md$" . markdown-mode)) 7 | 8 | (defun markdown-preview-file () 9 | "run Marked on the current file and revert the buffer" 10 | (interactive) 11 | (shell-command 12 | (format "open -a '/Applications/Marked 2.app' %s" 13 | (shell-quote-argument (buffer-file-name)))) 14 | ) 15 | 16 | (global-set-key "\C-cm" 'markdown-preview-file) 17 | -------------------------------------------------------------------------------- /utilities/slick-copy.el: -------------------------------------------------------------------------------- 1 | (defadvice kill-ring-save (before slick-copy activate compile) 2 | "When called interactively with no active region, copy a single line instead." 3 | (interactive 4 | (if mark-active (list (region-beginning) (region-end)) 5 | (message "Copied line") 6 | (list (line-beginning-position) 7 | (line-beginning-position 2))))) 8 | (defadvice kill-region (before slick-cut activate compile) 9 | "When called interactively with no active region, kill a single line instead." 10 | (interactive 11 | (if mark-active (list (region-beginning) (region-end)) 12 | (list (line-beginning-position) 13 | (line-beginning-position 2))))) 14 | 15 | -------------------------------------------------------------------------------- /customizations/my-ui.el: -------------------------------------------------------------------------------- 1 | ; don't display startup message 2 | (setq inhibit-startup-message t) 3 | 4 | ; no scrollbar 5 | (scroll-bar-mode -1) 6 | 7 | ; no toolbar 8 | (tool-bar-mode -1) 9 | 10 | ; blink cursor 11 | (blink-cursor-mode t) 12 | 13 | ; highlight current line 14 | (global-hl-line-mode t) 15 | 16 | ; force new frames into existing window 17 | (setq ns-pop-up-frames nil) 18 | 19 | ; no bell 20 | (setq ring-bell-function 'ignore) 21 | 22 | ;; scroll one line at a time (less "jumpy" than defaults) 23 | (setq mouse-wheel-scroll-amount '(1 ((shift) . 1))) 24 | 25 | ;; don't accelerate scrolling 26 | (setq mouse-wheel-progressive-speed nil) 27 | 28 | ;; scroll window under mouse 29 | (setq mouse-wheel-follow-mouse 't) 30 | 31 | ;; scroll window under mous 32 | (setq scroll-step 1) 33 | -------------------------------------------------------------------------------- /mode-inits/init-magit.el: -------------------------------------------------------------------------------- 1 | (autoload 'magit "magit" nil t) 2 | (autoload 'magit-status "magit-status" nil t) 3 | 4 | ; keys 5 | (global-set-key (kbd "C-c i") 'magit-status) 6 | 7 | ; better colors for diff-mode 8 | (custom-set-faces 9 | '(diff-added ((t (:foreground "#559944")))) 10 | '(diff-context ((t nil))) 11 | '(diff-file-header ((((class color) (min-colors 88) (background dark)) (:foreground "RoyalBlue1")))) 12 | '(diff-function ((t (:foreground "#00bbdd")))) 13 | '(diff-header ((((class color) (min-colors 88) (background dark)) (:foreground "RoyalBlue1")))) 14 | '(diff-hunk-header ((t (:foreground "#fbde2d")))) 15 | '(diff-nonexistent ((t (:inherit diff-file-header :strike-through nil)))) 16 | '(diff-refine-change ((((class color) (min-colors 88) (background dark)) (:background "#182042")))) 17 | '(diff-removed ((t (:foreground "#de1923"))))) 18 | -------------------------------------------------------------------------------- /mode-inits/init-cmake.el: -------------------------------------------------------------------------------- 1 | (setq auto-mode-alist 2 | (append '(("CMakeLists\\.txt\\'" . cmake-mode) 3 | ("\\.cmake\\'" . cmake-mode)) 4 | auto-mode-alist)) 5 | 6 | (add-hook 'c-mode-common-hook 7 | (lambda () 8 | (if (derived-mode-p 'c-mode 'c++-mode) 9 | (cppcm-reload-all) 10 | ))) 11 | ;; OPTIONAL, somebody reported that they can use this package with Fortran 12 | (add-hook 'c90-mode-hook (lambda () (cppcm-reload-all))) 13 | ;; OPTIONAL, avoid typing full path when starting gdb 14 | (global-set-key (kbd "C-c C-g") 15 | '(lambda ()(interactive) (gud-gdb (concat "gdb --fullname " (cppcm-get-exe-path-current-buffer))))) 16 | ;; OPTIONAL, some users need specify extra flags forwarded to compiler 17 | (setq cppcm-extra-preprocss-flags-from-user '("-I/usr/src/linux/include" "-DNDEBUG")) 18 | -------------------------------------------------------------------------------- /mode-inits/init-smart-mode-line.el: -------------------------------------------------------------------------------- 1 | (setq sml/theme 'respectful) 2 | (sml/setup) 3 | 4 | (setq sml/shorten-directory t) 5 | (setq sml/shorten-modes t) 6 | (setq sml/name-width 25) 7 | (setq sml/mode-width 'full) 8 | 9 | (add-to-list 'sml/hidden-modes " SP") 10 | (add-to-list 'sml/hidden-modes " company") 11 | (add-to-list 'sml/hidden-modes " vl") 12 | (add-to-list 'sml/hidden-modes " Wrap") 13 | (add-to-list 'sml/hidden-modes " AC") 14 | (add-to-list 'sml/hidden-modes " FlyC") 15 | (add-to-list 'sml/hidden-modes " ElDoc") 16 | (add-to-list 'sml/hidden-modes " oracle") 17 | 18 | (add-to-list 'sml/replacer-regexp-list '("^~/src/dobt/" ":DOBT:")) 19 | 20 | (custom-set-variables 21 | '(custom-safe-themes (quote ("9527feeeec43970b1d725bdc04e97eb2b03b15be982ac50089ad223d3c6f2920" default)))) 22 | (custom-set-faces) 23 | 24 | (defadvice sml/setup (after load-theme-again activate) 25 | "Load the damn theme again." 26 | (load-theme my-cur-theme t)) 27 | 28 | (ad-activate 'sml/setup) 29 | -------------------------------------------------------------------------------- /mode-inits/init-go-mode.el: -------------------------------------------------------------------------------- 1 | (defun my-go-mode-hook () 2 | ; Use goimports instead of go-fmt 3 | (setq gofmt-command "goimports") 4 | ; Call Gofmt before saving 5 | (add-hook 'before-save-hook 'gofmt-before-save) 6 | ; Customize compile command to run go build 7 | (if (not (string-match "go" compile-command)) 8 | (set (make-local-variable 'compile-command) 9 | "go build -v && go test -v && go vet")) 10 | ; Godef jump key binding 11 | (local-set-key (kbd "M-.") 'godef-jump)) 12 | (add-hook 'go-mode-hook 'my-go-mode-hook) 13 | 14 | ; Ergh should really package this up to put in Cask 15 | (load "$GOPATH/src/code.google.com/p/go.tools/cmd/oracle/oracle.el") 16 | (add-hook 'go-mode-hook 'go-oracle-mode) 17 | 18 | (add-hook 'go-mode-hook 'company-mode) 19 | (add-hook 'go-mode-hook (lambda () 20 | (set (make-local-variable 'company-backends) '(company-go)) 21 | (company-mode))) 22 | 23 | (add-hook 'go-mode-hook 'go-eldoc-setup) 24 | 25 | (autoload 'go-mode "go-mode" nil t) 26 | (require 'go-projectile) 27 | -------------------------------------------------------------------------------- /linux-customizations/my-linux-keys.el: -------------------------------------------------------------------------------- 1 | ; switch to shell 2 | (global-set-key (kbd "M-0") 'ansi-term) 3 | 4 | ; search with ack 5 | (global-set-key (kbd "M-F") 'ack) 6 | 7 | ; open file 8 | (global-set-key (kbd "M-o") 'find-file) 9 | 10 | ; buffer switching 11 | (global-set-key (kbd "M-{") 'previous-buffer) 12 | (global-set-key (kbd "M-}") 'next-buffer) 13 | 14 | ; window switching 15 | (global-set-key (kbd "M-`") 'other-window) 16 | 17 | ; close window 18 | (global-set-key (kbd "M-w") (lambda () 19 | (interactive) 20 | (kill-buffer (current-buffer) 21 | ))) 22 | 23 | ; save buffer 24 | (global-set-key (kbd "M-s") 'save-buffer) 25 | 26 | ; navigating through errors 27 | (global-set-key (kbd "M-n") 'next-error) 28 | (global-set-key (kbd "M-p") 'previous-error) 29 | 30 | ; paste 31 | (global-set-key (kbd "M-v") 'yank) 32 | 33 | ; undo 34 | (global-set-key (kbd "M-z") 'undo) 35 | 36 | ; run Ruby tests, TextMate-style 37 | (add-hook 'rinari-minor-mode-hook 38 | (lambda () 39 | (define-key rinari-minor-mode-map (kbd "M-r") 'rinari-test))) 40 | -------------------------------------------------------------------------------- /utilities/visit-ansi-term.el: -------------------------------------------------------------------------------- 1 | (require 'term) 2 | (defun visit-ansi-term () 3 | "If the current buffer is: 4 | 1) a running ansi-term named *ansi-term*, rename it. 5 | 2) a stopped ansi-term, kill it and create a new one. 6 | 3) a non ansi-term, go to an already running ansi-term 7 | or start a new one while killing a defunt one" 8 | (interactive) 9 | (let ((is-term (string= "term-mode" major-mode)) 10 | (is-running (term-check-proc (buffer-name))) 11 | (term-cmd "/bin/bash") 12 | (anon-term (get-buffer "*ansi-term*"))) 13 | (if is-term 14 | (if is-running 15 | (if (string= "*ansi-term*" (buffer-name)) 16 | (call-interactively 'rename-buffer) 17 | (if anon-term 18 | (switch-to-buffer "*ansi-term*") 19 | (ansi-term term-cmd))) 20 | (kill-buffer (buffer-name)) 21 | (ansi-term term-cmd)) 22 | (if anon-term 23 | (if (term-check-proc "*ansi-term*") 24 | (switch-to-buffer "*ansi-term*") 25 | (kill-buffer "*ansi-term*") 26 | (ansi-term term-cmd)) 27 | (ansi-term term-cmd))))) 28 | -------------------------------------------------------------------------------- /customizations/my-editing.el: -------------------------------------------------------------------------------- 1 | ; tabs and indentation 2 | (setq standard-indent 2) 3 | (setq-default tab-width 2) 4 | (setq-default indent-tabs-mode nil) 5 | 6 | ; always a newline at the end 7 | (setq require-final-newline t) 8 | 9 | ; mousing 10 | (setq mac-emulate-three-button-mouse nil) 11 | 12 | ; UTF-8 everywhere 13 | (prefer-coding-system 'utf-8) 14 | (set-language-environment 'utf-8) 15 | (set-default-coding-systems 'utf-8) 16 | (set-terminal-coding-system 'utf-8) 17 | (set-selection-coding-system 'utf-8) 18 | (setq coding-system-for-read 'utf-8) 19 | (setq coding-system-for-write 'utf-8) 20 | 21 | ; whitespace 22 | (add-hook 'before-save-hook 'delete-trailing-whitespace) 23 | 24 | ; show column number in bar 25 | (column-number-mode t) 26 | 27 | ; highlight URLs in comments/strings 28 | (add-hook 'find-file-hooks 'goto-address-prog-mode) 29 | 30 | ; selection 31 | (delete-selection-mode t) 32 | 33 | ; show marks as selections 34 | (setq transient-mark-mode t) 35 | 36 | ; highlight matching parens 37 | (show-paren-mode t) 38 | 39 | ; highlight incremental search 40 | (defconst search-highlight t) 41 | 42 | ; no newlines past EOF 43 | (setq next-line-add-newlines nil) 44 | 45 | ; apply syntax highlighting to all buffers 46 | (global-font-lock-mode t) 47 | 48 | ; wrap lines in a tasteful way 49 | (global-visual-line-mode 1) 50 | -------------------------------------------------------------------------------- /custom.el: -------------------------------------------------------------------------------- 1 | (custom-set-variables 2 | ;; custom-set-variables was added by Custom. 3 | ;; If you edit it by hand, you could mess it up, so be careful. 4 | ;; Your init file should contain only one such instance. 5 | ;; If there is more than one, they won't work right. 6 | '(custom-safe-themes 7 | (quote 8 | ("c74e83f8aa4c78a121b52146eadb792c9facc5b1f02c917e3dbb454fca931223" "9527feeeec43970b1d725bdc04e97eb2b03b15be982ac50089ad223d3c6f2920" default)))) 9 | (custom-set-faces 10 | ;; custom-set-faces was added by Custom. 11 | ;; If you edit it by hand, you could mess it up, so be careful. 12 | ;; Your init file should contain only one such instance. 13 | ;; If there is more than one, they won't work right. 14 | '(diff-added ((t (:foreground "#559944")))) 15 | '(diff-context ((t nil))) 16 | '(diff-file-header ((((class color) (min-colors 88) (background dark)) (:foreground "RoyalBlue1")))) 17 | '(diff-function ((t (:foreground "#00bbdd")))) 18 | '(diff-header ((((class color) (min-colors 88) (background dark)) (:foreground "RoyalBlue1")))) 19 | '(diff-hunk-header ((t (:foreground "#fbde2d")))) 20 | '(diff-nonexistent ((t (:inherit diff-file-header :strike-through nil)))) 21 | '(diff-refine-change ((((class color) (min-colors 88) (background dark)) (:background "#182042")))) 22 | '(diff-removed ((t (:foreground "#de1923"))))) 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Introduction 2 | 3 | This is the Emacs configuration that [Alex Payne](http://al3x.net/) ([@al3x](https://github.com/al3x)) uses. It's not a "starter kit" or "configuration framework" or anything like that. 4 | 5 | ## Overview 6 | 7 | * Packages are managed with [Cask](https://github.com/cask/cask) and [Pallet](https://github.com/rdallasgray/pallet). 8 | * Works on Mac OS X. I install Emacs on OS X via [Homebrew](http://brew.sh/). 9 | * Previously worked on Linux (Emacs 23 GTK on Ubuntu), but _not actively maintained for Linux_. 10 | * Has some useful accommodations for Dvorak typists, such as `C-t` being mapped to `C-x`, and being able to `C-x c` (actually `C-t c`) to do a `M-x`. 11 | * Note that all of the above are way more comfortable if you set caps lock to act as ctrl. 12 | * Assumes that you want to use Emacs for editing text and code and not much more. No email, IRC, web browsing, Org mode craziness, etc. 13 | 14 | ## Supported Syntaxes 15 | 16 | Beyond what Emacs supports out of the box: 17 | 18 | * Clojure 19 | * Go 20 | * Scala 21 | * Haskell 22 | * CoffeeScript 23 | * Markdown 24 | * YAML 25 | 26 | ...and some others. See the `Caskfile` for the whole gamut. 27 | 28 | ## Additional Modes and Tweaks 29 | 30 | * Magit – integration with the Git VCS 31 | * ag – a nice interface to The Silver Searcher, which supercedes grep and ack 32 | * defaults to the [Solarized](http://ethanschoonover.com/solarized) dark theme 33 | 34 | ## Inspiration 35 | 36 | * [technomancy](http://github.com/technomancy/emacs-starter-kit) 37 | * [whilp](https://github.com/whilp/dotfiles/tree/master/.emacs.d) 38 | -------------------------------------------------------------------------------- /mac-customizations/my-mac-keys.el: -------------------------------------------------------------------------------- 1 | (setq default-input-method "MacOSX") 2 | 3 | ; don't use Lion press-and-hold 4 | (ns-set-resource nil "ApplePressAndHoldEnabled" "NO") 5 | 6 | ; option/alt is meta key 7 | (setq mac-command-key-is-meta nil) 8 | 9 | ; switch to shell 10 | (global-set-key (kbd "s-0") 'visit-ansi-term) 11 | 12 | ; open file 13 | (global-set-key [(super o)] 'find-file) 14 | 15 | ; buffer switching 16 | (global-set-key [(super {)] 'previous-buffer) 17 | (global-set-key [(super })] 'next-buffer) 18 | 19 | ; frame switching 20 | (global-set-key (kbd "s-`") 'other-window) 21 | 22 | ; indenting and outdenting 23 | (defun textmate-shift-right (&optional arg) 24 | "Shift the line or region to the ARG places to the right. 25 | A place is considered `tab-width' character columns." 26 | (interactive) 27 | (let ((deactivate-mark nil) 28 | (beg (or (and mark-active (region-beginning)) 29 | (line-beginning-position))) 30 | (end (or (and mark-active (region-end)) (line-end-position)))) 31 | (indent-rigidly beg end (* (or arg 1) tab-width)))) 32 | 33 | (defun textmate-shift-left (&optional arg) 34 | "Shift the line or region to the ARG places to the left." 35 | (interactive) 36 | (textmate-shift-right (* -1 (or arg 1)))) 37 | 38 | (global-set-key (kbd "s-[") 'textmate-shift-left) 39 | (global-set-key (kbd "s-]") 'textmate-shift-right) 40 | 41 | ; close window 42 | (global-set-key [(super w)] (lambda () 43 | (interactive) 44 | (kill-buffer (current-buffer) 45 | ))) 46 | 47 | ; navigating through errors 48 | (global-set-key [(meta n)] 'next-error) 49 | (global-set-key [(meta p)] 'previous-error) 50 | -------------------------------------------------------------------------------- /mode-inits/init-webmode.el: -------------------------------------------------------------------------------- 1 | (add-to-list 'auto-mode-alist '("\\.phtml\\'" . web-mode)) 2 | (add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode)) 3 | (add-to-list 'auto-mode-alist '("\\.[gj]sp\\'" . web-mode)) 4 | (add-to-list 'auto-mode-alist '("\\.as[cp]x\\'" . web-mode)) 5 | (add-to-list 'auto-mode-alist '("\\.erb\\'" . web-mode)) 6 | (add-to-list 'auto-mode-alist '("\\.mustache\\'" . web-mode)) 7 | (add-to-list 'auto-mode-alist '("\\.djhtml\\'" . web-mode)) 8 | (add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode)) 9 | (add-to-list 'auto-mode-alist '("\\.jsx?\\'" . web-mode)) 10 | 11 | (defadvice web-mode-highlight-part (around tweak-jsx activate) 12 | (if (equal web-mode-content-type "jsx") 13 | (let ((web-mode-enable-part-face nil)) 14 | ad-do-it) 15 | ad-do-it)) 16 | 17 | (defun my-web-mode-hook () 18 | "Hooks for Web mode." 19 | (setq web-mode-markup-indent-offset 2) 20 | (setq web-mode-css-indent-offset 2) 21 | (setq web-mode-code-indent-offset 2) 22 | (setq web-mode-ac-sources-alist 23 | '(("css" . (ac-source-words-in-buffer ac-source-css-property)) 24 | ("html" . (ac-source-words-in-buffer ac-source-abbrev)) 25 | ("jsx" . (ac-source-words-in-buffer ac-source-words-in-same-mode-buffers)))) 26 | (auto-complete-mode 1) 27 | (lambda () 28 | (when (equal web-mode-content-type "jsx") 29 | (flycheck-select-checker 'javascript-eslint) 30 | (setq-default flycheck-disabled-checkers 31 | (append flycheck-disabled-checkers 32 | '(json-jsonlist))) 33 | (flycheck-mode))) 34 | (add-hook 'web-mode-hook 'my-web-mode-hook)) 35 | 36 | 37 | (autoload 'web-mode "web-mode" "web mode" t) 38 | -------------------------------------------------------------------------------- /Cask: -------------------------------------------------------------------------------- 1 | (source gnu) 2 | (source marmalade) 3 | (source melpa) 4 | (source org) 5 | 6 | (depends-on "ag") 7 | (depends-on "apache-mode") 8 | (depends-on "cask") 9 | (depends-on "cider") 10 | (depends-on "coffee-mode") 11 | (depends-on "company") 12 | (depends-on "company-ghc") 13 | (depends-on "company-go") 14 | (depends-on "csv-mode") 15 | (depends-on "dash") 16 | (depends-on "dash-at-point") 17 | (depends-on "dired+") 18 | (depends-on "dired-details+") 19 | (depends-on "dired-single") 20 | (depends-on "dockerfile-mode") 21 | (depends-on "find-file-in-project") 22 | (depends-on "flx-ido") 23 | (depends-on "flycheck") 24 | (depends-on "flycheck-rust") 25 | (depends-on "ghc") 26 | (depends-on "gist") 27 | (depends-on "git-gutter") 28 | (depends-on "go-eldoc") 29 | (depends-on "go-mode") 30 | (depends-on "go-projectile") 31 | (depends-on "haskell-mode") 32 | (depends-on "inf-ruby") 33 | (depends-on "json-mode") 34 | (depends-on "json-reformat") 35 | (depends-on "json-snatcher") 36 | (depends-on "magit") 37 | (depends-on "markdown-mode") 38 | (depends-on "mo-git-blame") 39 | (depends-on "nginx-mode") 40 | (depends-on "org-plus-contrib") 41 | (depends-on "pallet") 42 | (depends-on "pbcopy") 43 | (depends-on "popup") 44 | (depends-on "projectile") 45 | (depends-on "rainbow-delimiters") 46 | (depends-on "request") 47 | (depends-on "robe") 48 | (depends-on "rubocop") 49 | (depends-on "ruby-mode") 50 | (depends-on "rust-mode") 51 | (depends-on "scala-mode2") 52 | (depends-on "shut-up") 53 | (depends-on "smart-mode-line") 54 | (depends-on "smartparens") 55 | (depends-on "smex") 56 | (depends-on "solarized-theme") 57 | (depends-on "sourcemap") 58 | (depends-on "tern") 59 | (depends-on "textile-mode") 60 | (depends-on "toml-mode") 61 | (depends-on "web-mode") 62 | (depends-on "yaml-mode") -------------------------------------------------------------------------------- /customizations/my-buffers.el: -------------------------------------------------------------------------------- 1 | ; use ibuffer instead of the built in buffer list 2 | (global-set-key (kbd "C-x C-b") 'ibuffer) 3 | 4 | ; dynamic expansion tweaks 5 | (eval-after-load "hippie-exp" 6 | '(setq hippie-expand-try-functions-list 7 | (remove 'try-expand-line hippie-expand-try-functions-list))) 8 | 9 | ; autosave files in tmp dir 10 | (setq auto-save-file-name-transforms `((".*" ,temporary-file-directory t))) 11 | 12 | ; disable backup files (foo~) 13 | (setq backup-inhibited t) 14 | 15 | ; save cursor position within files 16 | (require 'saveplace) 17 | (setq save-place-file "~/.emacs.d/.saveplace") 18 | (setq-default save-place t) 19 | 20 | ; save minibuffer history across sessions 21 | (setq savehist-file "~/.emacs.d/.savehist") 22 | (savehist-mode 1) 23 | 24 | ; nicer naming of buffers with identical names 25 | (require 'uniquify) 26 | (setq uniquify-buffer-name-style 'reverse) 27 | (setq uniquify-separator " • ") 28 | (setq uniquify-after-kill-buffer-p t) 29 | (setq uniquify-ignore-buffers-re "^\\*") 30 | 31 | ; Interactively Do Things 32 | (require 'ido) 33 | (ido-mode t) 34 | (icomplete-mode t) 35 | (ido-init-completion-maps) 36 | (setq ido-enable-flex-matching t) ; case insensitive matching 37 | (add-to-list 'ido-ignore-files "\\.DS_Store") 38 | (setq ido-create-new-buffer 'always) ; always create a new buffer with Ido 39 | (setq ido-use-virtual-buffers t) 40 | (setq confirm-nonexistent-file-or-buffer nil) 41 | 42 | ; automatically clean up old buffers 43 | (require 'midnight) 44 | 45 | ; pick up changes to files on disk automatically (ie, after git pull) 46 | (global-auto-revert-mode 1) 47 | 48 | ; don't confirm opening non-existant files/buffers 49 | (setq confirm-nonexistent-file-or-buffer nil) 50 | 51 | ; yes, I want to kill buffers with processes attached 52 | (setq kill-buffer-query-functions 53 | (remq 'process-kill-buffer-query-function 54 | kill-buffer-query-functions)) 55 | -------------------------------------------------------------------------------- /init.el: -------------------------------------------------------------------------------- 1 | ; env 2 | (setq explicit-shell-file-name "/bin/bash") 3 | (setq exec-path (append '( 4 | "~/bin" 5 | "/usr/local/sbin" 6 | "/usr/local/bin" 7 | "~/.rbenv/shims/" 8 | "/sbin" 9 | "/opt/local/bin" 10 | "/usr/local/share/npm/bin" 11 | "~/.cabal/bin" 12 | "/usr/local/MacGPG2/bin" 13 | "~/src/mygo/bin" 14 | ) 15 | exec-path)) 16 | (setenv "PATH" 17 | (mapconcat 'identity exec-path path-separator)) 18 | (setenv "PAGER" "cat") 19 | (setenv "EDITOR" "emacsclient") 20 | (setenv "ALTERNATE_EDITOR" "emacs") 21 | (setenv "PROMPT_COMMAND" "") 22 | (setenv "PS1" "${debian_chroot:+($debian_chroot)}\\u@\\h:\\w \\$ ") 23 | 24 | (setenv "GIT_EDITOR" "emacsclient") 25 | (setenv "GIT_COMMITTER_NAME" "Alex Payne") 26 | (setenv "GIT_COMMITTER_EMAIL" "al3x@al3x.net") 27 | (setenv "GIT_AUTHOR_NAME" "Alex Payne") 28 | (setenv "GIT_AUTHOR_EMAIL" "al3x@al3x.net") 29 | 30 | (setq default-directory "~/src") 31 | 32 | ; load custom themeing 33 | (setq custom-file "~/.emacs.d/custom.el") 34 | (load custom-file) 35 | 36 | ; add directories to the load path 37 | (add-to-list 'load-path "~/.emacs.d/customizations") 38 | (add-to-list 'load-path "~/.emacs.d/utilities") 39 | (add-to-list 'load-path "~/.emacs.d/vendor") 40 | 41 | ; handy function to load all elisp files in a directory 42 | (load-file "~/.emacs.d/utilities/load-directory.el") 43 | 44 | ; load all utility functions 45 | (mapc 'load-directory '("~/.emacs.d/utilities")) 46 | 47 | ; load personal customizations (keybindings, colors, etc.) 48 | (mapc 'load-directory '("~/.emacs.d/customizations")) 49 | 50 | ; per-OS customizations 51 | (if (string-equal system-type "gnu/linux") 52 | (mapcar 'load-directory '("~/.emacs.d/linux-customizations")) 53 | (mapcar 'load-directory '("~/.emacs.d/mac-customizations"))) 54 | 55 | ; load packages via Pallet and Cask 56 | (require 'cask "/usr/local/Cellar/cask/0.7.3/cask.el") 57 | (cask-initialize) 58 | (require 'pallet) 59 | 60 | ; initialize modes 61 | (mapc 'load-directory '("~/.emacs.d/mode-inits")) 62 | -------------------------------------------------------------------------------- /utilities/jekyll.el: -------------------------------------------------------------------------------- 1 | ;; jekyll.el 2 | ;; 3 | ;; Emacs support for Jekyll blogs. 4 | ;; 5 | ;; To use, just put this file somewhere in the load path and 6 | ;; (require 'jekyll) 7 | ;; 8 | ;; Here are my key bindings: 9 | ;; C-c b d - Show all drafts 10 | ;; C-c b p - Show all posts 11 | ;; C-c b n - Create new draft 12 | ;; C-c b P - Publish current draft 13 | ;; 14 | ;; (global-set-key (kbd "C-c b n") 'jekyll-draft-post) 15 | ;; (global-set-key (kbd "C-c b P") 'jekyll-publish-post) 16 | ;; (global-set-key (kbd "C-c b p") (lambda () 17 | ;; (interactive) 18 | ;; (find-file "~/Sources/blog/_posts/"))) 19 | ;; (global-set-key (kbd "C-c b d") (lambda () 20 | ;; (interactive) 21 | ;; (find-file "~/Sources/blog/_drafts/"))) 22 | 23 | 24 | (provide 'jekyll) 25 | 26 | (defvar jekyll-directory nil 27 | "Path to Jekyll blog.") 28 | (defvar jekyll-drafts-dir "_drafts/" 29 | "Relative path to drafts directory.") 30 | (defvar jekyll-posts-dir "_posts/" 31 | "Relative path to posts directory.") 32 | (defvar jekyll-post-ext ".markdown" 33 | "File extension of Jekyll posts.") 34 | (defvar jekyll-post-template 35 | "---\ntitle: %s\n---\n\n" 36 | "Default template for Jekyll posts. %s will be replace by the post title.") 37 | 38 | (defun jekyll-make-slug (s) 39 | "Turn a string into a slug." 40 | (replace-regexp-in-string 41 | " " "-" (downcase 42 | (replace-regexp-in-string 43 | "[^A-Za-z0-9 ]" "" s)))) 44 | 45 | (defun jekyll-yaml-escape (s) 46 | "Escape a string for YAML." 47 | (if (or (string-match ":" s) 48 | (string-match "\"" s)) 49 | (concat "\"" (replace-regexp-in-string "\"" "\\\\\"" s) "\"") 50 | s)) 51 | 52 | (defun jekyll-draft-post (title) 53 | "Create a new Jekyll blog post." 54 | (interactive "sPost Title: ") 55 | (let ((draft-file (concat jekyll-directory jekyll-drafts-dir 56 | (jekyll-make-slug title) 57 | jekyll-post-ext))) 58 | (if (file-exists-p draft-file) 59 | (find-file draft-file) 60 | (find-file draft-file) 61 | (insert (format jekyll-post-template (jekyll-yaml-escape title)))))) 62 | 63 | (defun jekyll-publish-post () 64 | "Move a draft post to the posts directory, and rename it so that it 65 | contains the date." 66 | (interactive) 67 | (cond 68 | ((not (equal 69 | (file-name-directory (buffer-file-name (current-buffer))) 70 | (concat jekyll-directory jekyll-drafts-dir))) 71 | (message "This is not a draft post.") 72 | (insert (file-name-directory (buffer-file-name (current-buffer))) "\n" 73 | (concat jekyll-directory jekyll-drafts-dir))) 74 | ((buffer-modified-p) 75 | (message "Can't publish post; buffer has modifications.")) 76 | (t 77 | (let ((filename 78 | (concat jekyll-directory jekyll-posts-dir 79 | (format-time-string "%Y-%m-%d-") 80 | (file-name-nondirectory 81 | (buffer-file-name (current-buffer))))) 82 | (old-point (point))) 83 | (rename-file (buffer-file-name (current-buffer)) 84 | filename) 85 | (kill-buffer nil) 86 | (find-file filename) 87 | (set-window-point (selected-window) old-point))))) 88 | -------------------------------------------------------------------------------- /utilities/load-directory.el: -------------------------------------------------------------------------------- 1 | (defvar file-loadable-regexp 2 | (replace-regexp-in-string 3 | "\\." "\\\\." 4 | (let (string 5 | (suffix-list (get-load-suffixes))) 6 | (concat (car suffix-list) "$" 7 | (dolist (extension (cdr suffix-list) string) 8 | (setq string (concat "\\|" extension "$" string)))))) 9 | "Regular expression that matches any file name with a file 10 | extension returned by `get-load-suffixes'.") 11 | 12 | (defun file-loadable-p (file) 13 | "Return t if FILE is an Emacs lisp file. 14 | More precisely, return t if the file name extension matches 15 | `file-loadable-regexp'" 16 | (string-match file-loadable-regexp file)) 17 | 18 | (defun load-directory (&optional directory recurse) 19 | "Load all Emacs Lisp files in DIRECTORY. 20 | 21 | Load files whose file name satisfies predicate `file-loadable-p'. 22 | Non-interactively, DIRECTORY must be specified. If both compiled 23 | and uncompiled versions of the same file exist, only load the 24 | compiled file. If optional argument RECURSE is non-nil, (or, 25 | interactively, with prefix argument) recursively load 26 | subdirectories." 27 | (interactive "P") 28 | ;; The idea here is to allow a prefix arg to specify recursion, but 29 | ;; also to read from the minibuffer the directory name; yet in 30 | ;; non-interactive use to only need the one directory-name argument, 31 | ;; as in: (load-directory "~/foo") 32 | (let* ((recurse (if recurse recurse (when current-prefix-arg t))) 33 | (directory (if (stringp directory) directory 34 | (when (called-interactively-p 'any) 35 | (read-directory-name 36 | (concat (if recurse "Recursively l" "L") 37 | "oad all Emacs lisp files from directory: ") 38 | default-directory default-directory t))))) 39 | ;; For non-interactive use 40 | (when (not (called-interactively-p 'any)) 41 | (unless directory 42 | (error "Must specify a directory to when called non-interactively"))) 43 | (unless (file-directory-p directory) 44 | (error "%s is not a directory" directory)) 45 | (let ((file-list 46 | (directory-files (expand-file-name directory) 47 | t directory-files-no-dot-files-regexp))) 48 | (dolist (file file-list) 49 | (cond 50 | ((and 51 | ;; This will include gzipped elisp files 52 | (file-loadable-p file) 53 | ;; Ignore symlinks to nonexistent targets. 54 | (file-exists-p file) 55 | ;; Don't try to load directies whose names end in ".el" 56 | ;; etc., as if they were files. Note that we do not 57 | ;; predicate on "permission denied" problems, instead 58 | ;; letting things fail in that case so the user knows. 59 | (not (file-directory-p file)) 60 | ;; If there exist both compiled and uncompiled versions of 61 | ;; the same library, only load the compiled one. (This is 62 | ;; why we let-bind the `file-list'.) This could perhaps be 63 | ;; factored out, and currently still double-loads gzipped 64 | ;; libraries. 65 | (not (and (string= (file-name-extension file t) ".el") 66 | (member 67 | (concat (file-name-sans-extension file) ".elc") 68 | file-list)))) 69 | (load file)) 70 | ((and (file-directory-p file) 71 | recurse) 72 | (load-directory file t))))))) --------------------------------------------------------------------------------