Emacs config utilizing prelude as a base
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

272 lines
9.3 KiB

14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
  1. ;;; prelude-editor.el --- Emacs Prelude: enhanced core editing experience.
  2. ;;
  3. ;; Copyright (c) 2011 Bozhidar Batsov
  4. ;;
  5. ;; Author: Bozhidar Batsov <bozhidar.batsov@gmail.com>
  6. ;; URL: http://www.emacswiki.org/cgi-bin/wiki/Prelude
  7. ;; Version: 1.0.0
  8. ;; Keywords: convenience
  9. ;; This file is not part of GNU Emacs.
  10. ;;; Commentary:
  11. ;; Refinements of the core editing experience in Emacs.
  12. ;;; License:
  13. ;; This program is free software; you can redistribute it and/or
  14. ;; modify it under the terms of the GNU General Public License
  15. ;; as published by the Free Software Foundation; either version 3
  16. ;; of the License, or (at your option) any later version.
  17. ;;
  18. ;; This program is distributed in the hope that it will be useful,
  19. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. ;; GNU General Public License for more details.
  22. ;;
  23. ;; You should have received a copy of the GNU General Public License
  24. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  25. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  26. ;; Boston, MA 02110-1301, USA.
  27. ;;; Code:
  28. ;; customize
  29. (defgroup editor nil
  30. "Emacs Prelude Editor enhancements"
  31. :group 'prelude)
  32. ;; Emacs users obviously have little need for Command and Option keys,
  33. ;; but they do need Meta and Super
  34. (when (eq system-type 'darwin)
  35. (setq mac-command-modifier 'super)
  36. (setq mac-option-modifier 'meta))
  37. ;; Death to the tabs! However, tabs historically indent to the next
  38. ;; 8-character offset; specifying anything else will cause *mass*
  39. ;; confusion, as it will change the appearance of every existing file.
  40. ;; In some cases (python), even worse -- it will change the semantics
  41. ;; (meaning) of the program.
  42. ;;
  43. ;; Emacs modes typically provide a standard means to change the
  44. ;; indentation width -- eg. c-basic-offset: use that to adjust your
  45. ;; personal indentation width, while maintaining the style (and
  46. ;; meaning) of any files you load.
  47. (setq-default indent-tabs-mode nil) ;; don't use tabs to indent
  48. (setq-default tab-width 8) ;; but maintain correct appearance
  49. ;; delete the selection with a keypress
  50. (delete-selection-mode t)
  51. ;; store all backup and autosave files in the tmp dir
  52. (setq backup-directory-alist
  53. `((".*" . ,temporary-file-directory)))
  54. (setq auto-save-file-name-transforms
  55. `((".*" ,temporary-file-directory t)))
  56. ;; revert buffers automatically when underlying files are changed externally
  57. (global-auto-revert-mode t)
  58. ;; hippie expand is dabbrev expand on steroids
  59. (setq hippie-expand-try-functions-list '(try-expand-dabbrev
  60. try-expand-dabbrev-all-buffers
  61. try-expand-dabbrev-from-kill
  62. try-complete-file-name-partially
  63. try-complete-file-name
  64. try-expand-all-abbrevs
  65. try-expand-list
  66. try-expand-line
  67. try-complete-lisp-symbol-partially
  68. try-complete-lisp-symbol))
  69. ;; smart indenting and pairing for all
  70. (electric-pair-mode t)
  71. (electric-indent-mode t)
  72. (electric-layout-mode t)
  73. ;; meaningful names for buffers with the same name
  74. (require 'uniquify)
  75. (setq uniquify-buffer-name-style 'forward)
  76. (setq uniquify-separator "/")
  77. (setq uniquify-after-kill-buffer-p t) ; rename after killing uniquified
  78. (setq uniquify-ignore-buffers-re "^\\*") ; don't muck with special buffers
  79. ;; saveplace remembers your location in a file when saving files
  80. (setq save-place-file (concat user-emacs-directory "saveplace"))
  81. ;; activate it for all buffers
  82. (setq-default save-place t)
  83. (require 'saveplace)
  84. ;; savehist keeps track of some history
  85. (setq savehist-additional-variables
  86. ;; search entries
  87. '(search ring regexp-search-ring)
  88. ;; save every minute
  89. savehist-autosave-interval 60
  90. ;; keep the home clean
  91. savehist-file (concat user-emacs-directory "savehist"))
  92. (savehist-mode t)
  93. ;; save recent files
  94. (setq recentf-save-file (concat user-emacs-directory "recentf")
  95. recentf-max-saved-items 200
  96. recentf-max-menu-items 15)
  97. (recentf-mode t)
  98. ;; time-stamps
  99. ;; when there's "Time-stamp: <>" in the first 10 lines of the file
  100. (setq time-stamp-active t
  101. ;; check first 10 buffer lines for Time-stamp: <>
  102. time-stamp-line-limit 10
  103. time-stamp-format "%04y-%02m-%02d %02H:%02M:%02S (%u)") ; date format
  104. (add-hook 'write-file-hooks 'time-stamp) ; update when saving
  105. ;; use shift + arrow keys to switch between visible buffers
  106. (require 'windmove)
  107. (windmove-default-keybindings 'super)
  108. ;; automatically save buffers associated with files on buffer switch
  109. ;; and on windows switch
  110. (defadvice switch-to-buffer (before save-buffer-now activate)
  111. (when buffer-file-name (save-buffer)))
  112. (defadvice other-window (before other-window-now activate)
  113. (when buffer-file-name (save-buffer)))
  114. (defadvice windmove-up (before other-window-now activate)
  115. (when buffer-file-name (save-buffer)))
  116. (defadvice windmove-down (before other-window-now activate)
  117. (when buffer-file-name (save-buffer)))
  118. (defadvice windmove-left (before other-window-now activate)
  119. (when buffer-file-name (save-buffer)))
  120. (defadvice windmove-right (before other-window-now activate)
  121. (when buffer-file-name (save-buffer)))
  122. ;; show-paren-mode: subtle highlighting of matching parens
  123. (show-paren-mode t)
  124. (setq show-paren-style 'parenthesis)
  125. ;; highlight the current line
  126. (global-hl-line-mode +1)
  127. (require 'volatile-highlights)
  128. (volatile-highlights-mode t)
  129. ;; tramp, for sudo access
  130. (require 'tramp)
  131. ;; keep in mind known issues with zsh - see emacs wiki
  132. (setq tramp-default-method "ssh")
  133. ;; ido-mode
  134. (ido-mode t)
  135. (setq ido-enable-prefix nil
  136. ido-enable-flex-matching t
  137. ido-create-new-buffer 'always
  138. ido-use-filename-at-point 'guess
  139. ido-max-prospects 10
  140. ido-default-file-method 'selected-window)
  141. ;; auto-completion in minibuffer
  142. (icomplete-mode +1)
  143. (set-default 'imenu-auto-rescan t)
  144. ;; flyspell-mode does spell-checking on the fly as you type
  145. (setq ispell-program-name "aspell" ; use aspell instead of ispell
  146. ispell-extra-args '("--sug-mode=ultra"))
  147. (autoload 'flyspell-mode "flyspell" "On-the-fly spelling checker." t)
  148. (defun prelude-turn-on-flyspell ()
  149. "Force flyspell-mode on using a positive argument. For use in hooks."
  150. (interactive)
  151. (flyspell-mode +1))
  152. (add-hook 'message-mode-hook 'prelude-turn-on-flyspell)
  153. (add-hook 'text-mode-hook 'prelude-turn-on-flyspell)
  154. ;; enable narrowing commands
  155. (put 'narrow-to-region 'disabled nil)
  156. (put 'narrow-to-page 'disabled nil)
  157. (put 'narrow-to-defun 'disabled nil)
  158. ;; enabled change region case commands
  159. (put 'upcase-region 'disabled nil)
  160. (put 'downcase-region 'disabled nil)
  161. (require 'expand-region)
  162. ;; bookmarks
  163. (setq bookmark-default-file (concat user-emacs-directory "bookmarks")
  164. bookmark-save-flag 1)
  165. ;; enabled auto-fill mode in text-mode and all related modes
  166. (add-hook 'text-mode-hook 'turn-on-auto-fill)
  167. ;; load yasnippet
  168. (require 'yasnippet)
  169. (setq yas/snippet-dirs prelude-snippets-dir prelude-personal-snippets-dir)
  170. (yas/global-mode 1)
  171. ;; Helm makes finding stuff in Emacs much simpler
  172. (require 'helm-config)
  173. ;; projectile is a project management mode
  174. (require 'projectile)
  175. (projectile-global-mode t)
  176. ;; dired - reuse current buffer by pressing 'a'
  177. (put 'dired-find-alternate-file 'disabled nil)
  178. ;; ediff - don't start another frame
  179. (setq ediff-window-setup-function 'ediff-setup-windows-plain)
  180. ;; clean up obsolete buffers automatically
  181. (require 'midnight)
  182. ;; automatically indenting yanked text if in programming-modes
  183. (defvar yank-indent-modes '(python-mode LaTeX-mode TeX-mode)
  184. "Modes in which to indent regions that are yanked (or yank-popped). Only
  185. modes that don't derive from `prog-mode' should be listed here.")
  186. (defvar yank-advised-indent-threshold 1000
  187. "Threshold (# chars) over which indentation does not automatically occur.")
  188. (defun yank-advised-indent-function (beg end)
  189. "Do indentation, as long as the region isn't too large."
  190. (if (<= (- end beg) yank-advised-indent-threshold)
  191. (indent-region beg end nil)))
  192. (defadvice yank (after yank-indent activate)
  193. "If current mode is one of 'yank-indent-modes,
  194. indent yanked text (with prefix arg don't indent)."
  195. (if (and (not (ad-get-arg 0))
  196. (or (derived-mode-p 'prog-mode)
  197. (member major-mode yank-indent-modes)))
  198. (let ((transient-mark-mode nil))
  199. (yank-advised-indent-function (region-beginning) (region-end)))))
  200. (defadvice yank-pop (after yank-pop-indent activate)
  201. "If current mode is one of 'yank-indent-modes,
  202. indent yanked text (with prefix arg don't indent)."
  203. (if (and (not (ad-get-arg 0))
  204. (or (derived-mode-p 'prog-mode)
  205. (member major-mode yank-indent-modes)))
  206. (let ((transient-mark-mode nil))
  207. (yank-advised-indent-function (region-beginning) (region-end)))))
  208. ;; abbrev config
  209. (add-hook 'text-mode-hook 'prelude-turn-on-abbrev)
  210. ;; make a shell script executable automatically on save
  211. (add-hook 'after-save-hook
  212. 'executable-make-buffer-file-executable-if-script-p)
  213. ;; saner regex syntax
  214. (require 're-builder)
  215. (setq reb-re-syntax 'string)
  216. ;; enable Prelude's keybindings
  217. (prelude-global-mode t)
  218. (provide 'prelude-editor)
  219. ;;; prelude-editor.el ends here