└── modern-starter-kit.el /modern-starter-kit.el: -------------------------------------------------------------------------------- 1 | ;;; modern-starter-kit.el --- My updates to esk 2 | ;; 3 | ;; Author: Brandon van Beekum 4 | ;; URL: http://www.emacswiki.org/cgi-bin/wiki/StarterKit 5 | ;; Version: 2.0.2 6 | ;; Keywords: convenience 7 | 8 | ;; This file is not part of GNU Emacs. 9 | 10 | ;;;###autoload 11 | (progn 12 | 13 | (defun msk-local-column-number-mode () 14 | (make-local-variable 'column-number-mode) 15 | (column-number-mode t)) 16 | 17 | (defun msk-local-comment-auto-fill () 18 | (set (make-local-variable 'comment-auto-fill-only-comments) t) 19 | (auto-fill-mode t)) 20 | 21 | (defun msk-turn-on-hl-line-mode () 22 | (when (> (display-color-cells) 8) 23 | (hl-line-mode t))) 24 | 25 | (defun msk-turn-on-save-place-mode () 26 | (require 'saveplace) 27 | (setq save-place t)) 28 | 29 | (defun msk-pretty-lambdas () 30 | (font-lock-add-keywords 31 | nil `(("(?\\(lambda\\>\\)" 32 | (0 (progn (compose-region (match-beginning 1) (match-end 1) 33 | ,(make-char 'greek-iso8859-7 107)) 34 | nil)))))) 35 | 36 | (defun msk-add-watchwords () 37 | (font-lock-add-keywords 38 | nil '(("\\<\\(FIX\\(ME\\)?\\|TODO\\|HACK\\|REFACTOR\\|NOCOMMIT\\)" 39 | 1 font-lock-warning-face t)))) 40 | 41 | (add-hook 'prog-mode-hook 'msk-local-column-number-mode) 42 | (add-hook 'prog-mode-hook 'msk-local-comment-auto-fill) 43 | (add-hook 'prog-mode-hook 'msk-turn-on-hl-line-mode) 44 | (add-hook 'prog-mode-hook 'msk-turn-on-save-place-mode) 45 | (add-hook 'prog-mode-hook 'msk-pretty-lambdas) 46 | (add-hook 'prog-mode-hook 'msk-add-watchwords) 47 | ;; (add-hook 'prog-mode-hook 'idle-highlight-mode) 48 | 49 | (defun msk-prog-mode-hook () 50 | (run-hooks 'prog-mode-hook)) 51 | 52 | (defun msk-turn-off-tool-bar () 53 | (if (functionp 'tool-bar-mode) (tool-bar-mode -1))) 54 | 55 | (defun msk-untabify-buffer () 56 | (interactive) 57 | (untabify (point-min) (point-max))) 58 | 59 | (defun msk-indent-buffer () 60 | (interactive) 61 | (indent-region (point-min) (point-max))) 62 | 63 | (defun msk-cleanup-buffer () 64 | "Perform a bunch of operations on the whitespace content of a buffer." 65 | (interactive) 66 | (msk-indent-buffer) 67 | (msk-untabify-buffer) 68 | (delete-trailing-whitespace)) 69 | 70 | (when window-system 71 | (setq frame-title-format '(buffer-file-name "%f" ("%b"))) 72 | (tooltip-mode -1) 73 | (mouse-wheel-mode t) 74 | (blink-cursor-mode -1)) 75 | 76 | ;; can't do it at launch or emacsclient won't always honor it 77 | (add-hook 'before-make-frame-hook 'msk-turn-off-tool-bar) 78 | 79 | (setq visible-bell t 80 | inhibit-startup-message t 81 | color-theme-is-global t 82 | sentence-end-double-space nil 83 | shift-select-mode nil 84 | mouse-yank-at-point t 85 | uniquify-buffer-name-style 'forward 86 | whitespace-style '(face trailing lines-tail tabs) 87 | whitespace-line-column 80 88 | ediff-window-setup-function 'ediff-setup-windows-plain 89 | oddmuse-directory (concat user-emacs-directory "oddmuse") 90 | save-place-file (concat user-emacs-directory "places") 91 | backup-directory-alist `(("." . ,(concat user-emacs-directory "backups"))) 92 | diff-switches "-u") 93 | 94 | (add-to-list 'safe-local-variable-values '(lexical-binding . t)) 95 | (add-to-list 'safe-local-variable-values '(whitespace-line-column . 80)) 96 | 97 | ;; Set this to whatever browser you use 98 | ;; (setq browse-url-browser-function 'browse-url-firefox) 99 | ;; (setq browse-url-browser-function 'browse-default-macosx-browser) 100 | ;; (setq browse-url-browser-function 'browse-default-windows-browser) 101 | ;; (setq browse-url-browser-function 'browse-default-kde) 102 | ;; (setq browse-url-browser-function 'browse-default-epiphany) 103 | ;; (setq browse-url-browser-function 'browse-default-w3m) 104 | ;; (setq browse-url-browser-function 'browse-url-generic 105 | ;; browse-url-generic-program "~/src/conkeror/conkeror") 106 | 107 | ;; Highlight matching parentheses when the point is on them. 108 | (show-paren-mode 1) 109 | 110 | ;; ido-mode is like magic pixie dust! 111 | (ido-mode t) 112 | ;; (ido-ubiquitous-mode) 113 | (setq ido-enable-prefix nil 114 | ido-enable-flex-matching t 115 | ido-auto-merge-work-directories-length nil 116 | ido-create-new-buffer 'always 117 | ido-use-filename-at-point 'guess 118 | ido-use-virtual-buffers t 119 | ido-handle-duplicate-virtual-buffers 2 120 | ido-max-prospects 10) 121 | 122 | (require 'ffap) 123 | (defvar ffap-c-commment-regexp "^/\\*+" 124 | "Matches an opening C-style comment, like \"/***\".") 125 | 126 | (defadvice ffap-file-at-point (after avoid-c-comments activate) 127 | "Don't return paths like \"/******\" unless they actually exist. 128 | 129 | This fixes the bug where ido would try to suggest a C-style 130 | comment as a filename." 131 | (ignore-errors 132 | (when (and ad-return-value 133 | (string-match-p ffap-c-commment-regexp 134 | ad-return-value) 135 | (not (ffap-file-exists-string ad-return-value))) 136 | (setq ad-return-value nil)))) 137 | 138 | (set-default 'indent-tabs-mode nil) 139 | (set-default 'indicate-empty-lines t) 140 | (set-default 'imenu-auto-rescan t) 141 | 142 | (add-hook 'text-mode-hook 'turn-on-auto-fill) 143 | ;; (when (executable-find ispell-program-name) 144 | ;; (add-hook 'text-mode-hook 'turn-on-flyspell)) 145 | 146 | (eval-after-load "ispell" 147 | '(when (executable-find ispell-program-name) 148 | (add-hook 'text-mode-hook 'turn-on-flyspell))) 149 | 150 | (defalias 'yes-or-no-p 'y-or-n-p) 151 | (defalias 'auto-tail-revert-mode 'tail-mode) 152 | 153 | (random t) ;; Seed the random-number generator 154 | 155 | ;; Hippie expand: at times perhaps too hip 156 | (eval-after-load 'hippie-exp 157 | '(progn 158 | (dolist (f '(try-expand-line try-expand-list try-complete-file-name-partially)) 159 | (delete f hippie-expand-try-functions-list)) 160 | 161 | ;; Add this back in at the end of the list. 162 | (add-to-list 'hippie-expand-try-functions-list 'try-complete-file-name-partially t))) 163 | 164 | (eval-after-load 'grep 165 | '(when (boundp 'grep-find-ignored-files) 166 | (add-to-list 'grep-find-ignored-files "*.class"))) 167 | 168 | ;; Cosmetics 169 | 170 | (eval-after-load 'diff-mode 171 | '(progn 172 | (set-face-foreground 'diff-added "green4") 173 | (set-face-foreground 'diff-removed "red3"))) 174 | 175 | ;; Get around the emacswiki spam protection 176 | (eval-after-load 'oddmuse 177 | (add-hook 'oddmuse-mode-hook 178 | (lambda () 179 | (unless (string-match "question" oddmuse-post) 180 | (setq oddmuse-post (concat "uihnscuskc=1;" oddmuse-post)))))) 181 | 182 | ;; Turn off mouse interface early in startup to avoid momentary display 183 | (dolist (mode '(menu-bar-mode tool-bar-mode scroll-bar-mode)) 184 | (when (fboundp mode) (funcall mode -1))) 185 | 186 | ;; You can keep system- or user-specific customizations here 187 | (setq msk-system-config (concat user-emacs-directory system-name ".el") 188 | msk-user-config (concat user-emacs-directory user-login-name ".el") 189 | msk-user-dir (concat user-emacs-directory user-login-name)) 190 | 191 | (setq smex-save-file (concat user-emacs-directory ".smex-items")) 192 | ;; (smex-initialize) 193 | (global-set-key (kbd "M-x") 'smex) 194 | 195 | (defun msk-eval-after-init (form) 196 | "Add `(lambda () FORM)' to `after-init-hook'. 197 | 198 | If Emacs has already finished initialization, also eval FORM immediately." 199 | (let ((func (list 'lambda nil form))) 200 | (add-hook 'after-init-hook func) 201 | (when after-init-time 202 | (eval form)))) 203 | 204 | (msk-eval-after-init 205 | '(progn 206 | (when (file-exists-p msk-system-config) (load msk-system-config)) 207 | (when (file-exists-p msk-user-config) (load msk-user-config)) 208 | (when (file-exists-p msk-user-dir) 209 | (mapc 'load (directory-files msk-user-dir t "^[^#].*el$"))))) 210 | 211 | ;; It's all about the project. 212 | (global-set-key (kbd "C-c f") 'find-file-in-project) 213 | 214 | ;; You know, like Readline. 215 | (global-set-key (kbd "C-M-h") 'backward-kill-word) 216 | 217 | ;; Completion that uses many different methods to find options. 218 | (global-set-key (kbd "M-/") 'hippie-expand) 219 | 220 | ;; Perform general cleanup. 221 | (global-set-key (kbd "C-c n") 'msk-cleanup-buffer) 222 | 223 | ;; Turn on the menu bar for exploring new modes 224 | (global-set-key (kbd "C-") 'menu-bar-mode) 225 | 226 | ;; Font size 227 | (define-key global-map (kbd "C-+") 'text-scale-increase) 228 | (define-key global-map (kbd "C--") 'text-scale-decrease) 229 | 230 | ;; Use regex searches by default. 231 | (global-set-key (kbd "C-s") 'isearch-forward-regexp) 232 | (global-set-key (kbd "\C-r") 'isearch-backward-regexp) 233 | (global-set-key (kbd "M-%") 'query-replace-regexp) 234 | (global-set-key (kbd "C-M-s") 'isearch-forward) 235 | (global-set-key (kbd "C-M-r") 'isearch-backward) 236 | (global-set-key (kbd "C-M-%") 'query-replace) 237 | 238 | ;; Jump to a definition in the current file. (Protip: this is awesome.) 239 | (global-set-key (kbd "C-x C-i") 'imenu) 240 | 241 | ;; File finding 242 | (global-set-key (kbd "C-x M-f") 'ido-find-file-other-window) 243 | (global-set-key (kbd "C-c y") 'bury-buffer) 244 | (global-set-key (kbd "C-c r") 'revert-buffer) 245 | 246 | ;; Window switching. (C-x o goes to the next window) 247 | (windmove-default-keybindings) ;; Shift+direction 248 | (global-set-key (kbd "C-x O") (lambda () (interactive) (other-window -1))) ;; back one 249 | (global-set-key (kbd "C-x C-o") (lambda () (interactive) (other-window 2))) ;; forward two 250 | 251 | ;; Start eshell or switch to it if it's active. 252 | (global-set-key (kbd "C-x m") 'eshell) 253 | 254 | ;; Start a new eshell even if one is active. 255 | (global-set-key (kbd "C-x M") (lambda () (interactive) (eshell t))) 256 | 257 | ;; Start a regular shell if you prefer that. 258 | (global-set-key (kbd "C-x C-m") 'shell) 259 | 260 | ;; If you want to be able to M-x without meta (phones, etc) 261 | (global-set-key (kbd "C-c x") 'execute-extended-command) 262 | 263 | ;; Help should search more than just commands 264 | (define-key 'help-command "a" 'apropos) 265 | 266 | ;; Should be able to eval-and-replace anywhere. 267 | (global-set-key (kbd "C-c e") 'msk-eval-and-replace) 268 | 269 | ;; M-S-6 is awkward 270 | (global-set-key (kbd "C-c q") 'join-line) 271 | 272 | ;; So good! 273 | (global-set-key (kbd "C-c g") 'magit-status) 274 | 275 | ;; This is a little hacky since VC doesn't support git add internally 276 | (eval-after-load 'vc 277 | (define-key vc-prefix-map "i" 278 | '(lambda () (interactive) 279 | (if (not (eq 'Git (vc-backend buffer-file-name))) 280 | (vc-register) 281 | (shell-command (format "git add %s" buffer-file-name)) 282 | (message "Staged changes."))))) 283 | 284 | ;; Activate occur easily inside isearch 285 | (define-key isearch-mode-map (kbd "C-o") 286 | (lambda () (interactive) 287 | (let ((case-fold-search isearch-case-fold-search)) 288 | (occur (if isearch-regexp isearch-string (regexp-quote isearch-string)))))) 289 | 290 | (add-hook 'emacs-lisp-mode-hook 'eldoc-mode) 291 | (add-hook 'emacs-lisp-mode-hook 'msk-remove-elc-on-save) 292 | (add-hook 'emacs-lisp-mode-hook 'msk-prog-mode-hook) 293 | 294 | (defun msk-remove-elc-on-save () 295 | "If you're saving an elisp file, likely the .elc is no longer valid." 296 | (make-local-variable 'after-save-hook) 297 | (add-hook 'after-save-hook 298 | (lambda () 299 | (if (file-exists-p (concat buffer-file-name "c")) 300 | (delete-file (concat buffer-file-name "c")))))) 301 | 302 | (define-key emacs-lisp-mode-map (kbd "C-c v") 'eval-buffer) 303 | (define-key read-expression-map (kbd "TAB") 'lisp-complete-symbol) 304 | (define-key lisp-mode-shared-map (kbd "RET") 'reindent-then-newline-and-indent) 305 | 306 | ;; TODO: look into parenface package 307 | (defface msk-paren-face 308 | '((((class color) (background dark)) 309 | (:foreground "grey50")) 310 | (((class color) (background light)) 311 | (:foreground "grey55"))) 312 | "Face used to dim parentheses." 313 | :group 'starter-kit-faces) 314 | 315 | (dolist (mode '(scheme emacs-lisp lisp clojure clojurescript racket)) 316 | (when (> (display-color-cells) 8) 317 | (font-lock-add-keywords (intern (concat (symbol-name mode) "-mode")) 318 | '(("(\\|)" . 'msk-paren-face)))) 319 | (add-hook (intern (concat (symbol-name mode) "-mode-hook")) 320 | 'paredit-mode)) 321 | 322 | (defun msk-pretty-fn () 323 | (font-lock-add-keywords nil `(("(\\(\\\\)" 324 | (0 (progn (compose-region (match-beginning 1) 325 | (match-end 1) 326 | "\u0192" 327 | 'decompose-region))))))) 328 | (add-hook 'clojure-mode-hook 'msk-pretty-fn) 329 | (add-hook 'clojurescript-mode-hook 'msk-pretty-fn) 330 | ) 331 | 332 | (provide 'modern-starter-kit.el) 333 | ;;; modern-starter-kit.el ends here 334 | --------------------------------------------------------------------------------