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.

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