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.

281 lines
9.6 KiB

14 years ago
14 years ago
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-2012 Bozhidar Batsov
  4. ;;
  5. ;; Author: Bozhidar Batsov <bozhidar@batsov.com>
  6. ;; URL: http://batsov.com/emacs-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. ;; Death to the tabs! However, tabs historically indent to the next
  33. ;; 8-character offset; specifying anything else will cause *mass*
  34. ;; confusion, as it will change the appearance of every existing file.
  35. ;; In some cases (python), even worse -- it will change the semantics
  36. ;; (meaning) of the program.
  37. ;;
  38. ;; Emacs modes typically provide a standard means to change the
  39. ;; indentation width -- eg. c-basic-offset: use that to adjust your
  40. ;; personal indentation width, while maintaining the style (and
  41. ;; meaning) of any files you load.
  42. (setq-default indent-tabs-mode nil) ;; don't use tabs to indent
  43. (setq-default tab-width 8) ;; but maintain correct appearance
  44. ;; delete the selection with a keypress
  45. (delete-selection-mode t)
  46. ;; store all backup and autosave files in the tmp dir
  47. (setq backup-directory-alist
  48. `((".*" . ,temporary-file-directory)))
  49. (setq auto-save-file-name-transforms
  50. `((".*" ,temporary-file-directory t)))
  51. ;; revert buffers automatically when underlying files are changed externally
  52. (global-auto-revert-mode t)
  53. ;; hippie expand is dabbrev expand on steroids
  54. (setq hippie-expand-try-functions-list '(try-expand-dabbrev
  55. try-expand-dabbrev-all-buffers
  56. try-expand-dabbrev-from-kill
  57. try-complete-file-name-partially
  58. try-complete-file-name
  59. try-expand-all-abbrevs
  60. try-expand-list
  61. try-expand-line
  62. try-complete-lisp-symbol-partially
  63. try-complete-lisp-symbol))
  64. ;; smart indenting and pairing for all
  65. (electric-pair-mode t)
  66. (electric-indent-mode t)
  67. (electric-layout-mode t)
  68. ;; meaningful names for buffers with the same name
  69. (require 'uniquify)
  70. (setq uniquify-buffer-name-style 'forward)
  71. (setq uniquify-separator "/")
  72. (setq uniquify-after-kill-buffer-p t) ; rename after killing uniquified
  73. (setq uniquify-ignore-buffers-re "^\\*") ; don't muck with special buffers
  74. ;; saveplace remembers your location in a file when saving files
  75. (setq save-place-file (concat user-emacs-directory "saveplace"))
  76. ;; activate it for all buffers
  77. (setq-default save-place t)
  78. (require 'saveplace)
  79. ;; savehist keeps track of some history
  80. (setq savehist-additional-variables
  81. ;; search entries
  82. '(search ring regexp-search-ring)
  83. ;; save every minute
  84. savehist-autosave-interval 60
  85. ;; keep the home clean
  86. savehist-file (concat user-emacs-directory "savehist"))
  87. (savehist-mode t)
  88. ;; save recent files
  89. (setq recentf-save-file (concat user-emacs-directory "recentf")
  90. recentf-max-saved-items 200
  91. recentf-max-menu-items 15)
  92. (recentf-mode t)
  93. ;; time-stamps
  94. ;; when there's "Time-stamp: <>" in the first 10 lines of the file
  95. (setq time-stamp-active t
  96. ;; check first 10 buffer lines for Time-stamp: <>
  97. time-stamp-line-limit 10
  98. time-stamp-format "%04y-%02m-%02d %02H:%02M:%02S (%u)") ; date format
  99. (add-hook 'write-file-hooks 'time-stamp) ; update when saving
  100. ;; use shift + arrow keys to switch between visible buffers
  101. (require 'windmove)
  102. (windmove-default-keybindings 'super)
  103. ;; automatically save buffers associated with files on buffer switch
  104. ;; and on windows switch
  105. (defadvice switch-to-buffer (before save-buffer-now activate)
  106. (when buffer-file-name (save-buffer)))
  107. (defadvice other-window (before other-window-now activate)
  108. (when buffer-file-name (save-buffer)))
  109. (defadvice windmove-up (before other-window-now activate)
  110. (when buffer-file-name (save-buffer)))
  111. (defadvice windmove-down (before other-window-now activate)
  112. (when buffer-file-name (save-buffer)))
  113. (defadvice windmove-left (before other-window-now activate)
  114. (when buffer-file-name (save-buffer)))
  115. (defadvice windmove-right (before other-window-now activate)
  116. (when buffer-file-name (save-buffer)))
  117. ;; show-paren-mode: subtle highlighting of matching parens
  118. (show-paren-mode t)
  119. (setq show-paren-style 'parenthesis)
  120. ;; highlight the current line
  121. (global-hl-line-mode +1)
  122. (require 'volatile-highlights)
  123. (volatile-highlights-mode t)
  124. ;; tramp, for sudo access
  125. (require 'tramp)
  126. ;; keep in mind known issues with zsh - see emacs wiki
  127. (setq tramp-default-method "ssh")
  128. ;; ido-mode
  129. (ido-mode t)
  130. (setq ido-enable-prefix nil
  131. ido-enable-flex-matching t
  132. ido-create-new-buffer 'always
  133. ido-use-filename-at-point 'guess
  134. ido-max-prospects 10
  135. ido-default-file-method 'selected-window)
  136. ;; auto-completion in minibuffer
  137. (icomplete-mode +1)
  138. (set-default 'imenu-auto-rescan t)
  139. ;; flyspell-mode does spell-checking on the fly as you type
  140. (setq ispell-program-name "aspell" ; use aspell instead of ispell
  141. ispell-extra-args '("--sug-mode=ultra"))
  142. (autoload 'flyspell-mode "flyspell" "On-the-fly spelling checker." t)
  143. (defun prelude-turn-on-flyspell ()
  144. "Force flyspell-mode on using a positive argument. For use in hooks."
  145. (interactive)
  146. (flyspell-mode +1))
  147. (add-hook 'message-mode-hook 'prelude-turn-on-flyspell)
  148. (add-hook 'text-mode-hook 'prelude-turn-on-flyspell)
  149. ;; enable narrowing commands
  150. (put 'narrow-to-region 'disabled nil)
  151. (put 'narrow-to-page 'disabled nil)
  152. (put 'narrow-to-defun 'disabled nil)
  153. ;; enabled change region case commands
  154. (put 'upcase-region 'disabled nil)
  155. (put 'downcase-region 'disabled nil)
  156. (require 'expand-region)
  157. ;; bookmarks
  158. (setq bookmark-default-file (concat user-emacs-directory "bookmarks")
  159. bookmark-save-flag 1)
  160. ;; enabled auto-fill mode in text-mode and all related modes
  161. (add-hook 'text-mode-hook 'turn-on-auto-fill)
  162. ;; load yasnippet
  163. (require 'yasnippet)
  164. (add-to-list 'yas/snippet-dirs prelude-snippets-dir)
  165. (yas/global-mode 1)
  166. ;; projectile is a project management mode
  167. (require 'projectile)
  168. (projectile-global-mode t)
  169. (require 'helm-misc)
  170. (require 'helm-projectile)
  171. (defun helm-prelude ()
  172. "Preconfigured `helm'."
  173. (interactive)
  174. (if (projectile-get-project-root)
  175. ;; add project files and buffers when in project
  176. (helm-other-buffer '(helm-c-source-projectile-files-list
  177. helm-c-source-projectile-buffers-list
  178. helm-c-source-buffers-list
  179. helm-c-source-recentf
  180. helm-c-source-buffer-not-found)
  181. "*helm prelude*")
  182. ;; otherwise fallback to helm-mini
  183. (helm-mini)))
  184. ;; dired - reuse current buffer by pressing 'a'
  185. (put 'dired-find-alternate-file 'disabled nil)
  186. ;; ediff - don't start another frame
  187. (setq ediff-window-setup-function 'ediff-setup-windows-plain)
  188. ;; clean up obsolete buffers automatically
  189. (require 'midnight)
  190. ;; automatically indenting yanked text if in programming-modes
  191. (defvar yank-indent-modes '(python-mode LaTeX-mode TeX-mode)
  192. "Modes in which to indent regions that are yanked (or yank-popped). Only
  193. modes that don't derive from `prog-mode' should be listed here.")
  194. (defvar yank-advised-indent-threshold 1000
  195. "Threshold (# chars) over which indentation does not automatically occur.")
  196. (defun yank-advised-indent-function (beg end)
  197. "Do indentation, as long as the region isn't too large."
  198. (if (<= (- end beg) yank-advised-indent-threshold)
  199. (indent-region beg end nil)))
  200. (defadvice yank (after yank-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. (defadvice yank-pop (after yank-pop-indent activate)
  209. "If current mode is one of 'yank-indent-modes,
  210. indent yanked text (with prefix arg don't indent)."
  211. (if (and (not (ad-get-arg 0))
  212. (or (derived-mode-p 'prog-mode)
  213. (member major-mode yank-indent-modes)))
  214. (let ((transient-mark-mode nil))
  215. (yank-advised-indent-function (region-beginning) (region-end)))))
  216. ;; abbrev config
  217. (add-hook 'text-mode-hook 'prelude-turn-on-abbrev)
  218. ;; make a shell script executable automatically on save
  219. (add-hook 'after-save-hook
  220. 'executable-make-buffer-file-executable-if-script-p)
  221. ;; saner regex syntax
  222. (require 're-builder)
  223. (setq reb-re-syntax 'string)
  224. ;; enable Prelude's keybindings
  225. (prelude-global-mode t)
  226. (provide 'prelude-editor)
  227. ;;; prelude-editor.el ends here