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.

364 lines
12 KiB

13 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
14 years ago
  1. ;;; prelude-editor.el --- Emacs Prelude: enhanced core editing experience.
  2. ;;
  3. ;; Copyright © 2011-2013 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 t
  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. (diminish 'volatile-highlights-mode)
  146. ;; note - this should be after volatile-highlights is required
  147. ;; add the ability to copy and cut the current line, without marking it
  148. (defadvice kill-ring-save (before slick-copy activate compile)
  149. "When called interactively with no active region, copy a single line instead."
  150. (interactive
  151. (if mark-active (list (region-beginning) (region-end))
  152. (message "Copied line")
  153. (list (line-beginning-position)
  154. (line-beginning-position 2)))))
  155. (defadvice kill-region (before slick-cut activate compile)
  156. "When called interactively with no active region, kill a single line instead."
  157. (interactive
  158. (if mark-active (list (region-beginning) (region-end))
  159. (list (line-beginning-position)
  160. (line-beginning-position 2)))))
  161. ;; tramp, for sudo access
  162. (require 'tramp)
  163. ;; keep in mind known issues with zsh - see emacs wiki
  164. (setq tramp-default-method "ssh")
  165. ;; ido-mode
  166. (ido-mode t)
  167. (setq ido-enable-prefix nil
  168. ido-enable-flex-matching t
  169. ido-create-new-buffer 'always
  170. ido-use-filename-at-point 'guess
  171. ido-max-prospects 10
  172. ido-save-directory-list-file (expand-file-name "ido.hist" prelude-savefile-dir)
  173. ido-default-file-method 'selected-window)
  174. ;; auto-completion in minibuffer
  175. (icomplete-mode +1)
  176. (set-default 'imenu-auto-rescan t)
  177. ;; flyspell-mode does spell-checking on the fly as you type
  178. (setq ispell-program-name "aspell" ; use aspell instead of ispell
  179. ispell-extra-args '("--sug-mode=ultra"))
  180. (autoload 'flyspell-mode "flyspell" "On-the-fly spelling checker." t)
  181. (defun prelude-enable-flyspell ()
  182. (when (and prelude-flyspell (executable-find ispell-program-name))
  183. (flyspell-mode +1)))
  184. (defun prelude-enable-whitespace ()
  185. (when prelude-whitespace
  186. ;; keep the whitespace decent all the time (in this buffer)
  187. (add-hook 'before-save-hook 'whitespace-cleanup nil t)
  188. (whitespace-mode +1)))
  189. (add-hook 'text-mode-hook 'prelude-enable-flyspell)
  190. (add-hook 'text-mode-hook 'prelude-enable-whitespace)
  191. ;; enable narrowing commands
  192. (put 'narrow-to-region 'disabled nil)
  193. (put 'narrow-to-page 'disabled nil)
  194. (put 'narrow-to-defun 'disabled nil)
  195. ;; enabled change region case commands
  196. (put 'upcase-region 'disabled nil)
  197. (put 'downcase-region 'disabled nil)
  198. (require 'expand-region)
  199. ;; bookmarks
  200. (setq bookmark-default-file (expand-file-name "bookmarks" prelude-savefile-dir)
  201. bookmark-save-flag 1)
  202. ;; load yasnippet
  203. (require 'yasnippet)
  204. (add-to-list 'yas-snippet-dirs prelude-snippets-dir)
  205. (add-to-list 'yas-snippet-dirs prelude-personal-snippets-dir)
  206. (yas-global-mode 1)
  207. ;; projectile is a project management mode
  208. (require 'projectile)
  209. (setq projectile-cache-file (expand-file-name "projectile.cache" prelude-savefile-dir))
  210. (projectile-global-mode t)
  211. (diminish 'projectile-mode "Prjl")
  212. (require 'helm-misc)
  213. (require 'helm-projectile)
  214. (defun helm-prelude ()
  215. "Preconfigured `helm'."
  216. (interactive)
  217. (condition-case nil
  218. (if (projectile-project-root)
  219. ;; add project files and buffers when in project
  220. (helm-other-buffer '(helm-c-source-projectile-files-list
  221. helm-c-source-projectile-buffers-list
  222. helm-c-source-buffers-list
  223. helm-c-source-recentf
  224. helm-c-source-buffer-not-found)
  225. "*helm prelude*")
  226. ;; otherwise fallback to helm-mini
  227. (helm-mini))
  228. ;; fall back to helm mini if an error occurs (usually in projectile-project-root)
  229. (error (helm-mini))))
  230. ;; shorter aliases for ack-and-a-half commands
  231. (defalias 'ack 'ack-and-a-half)
  232. (defalias 'ack-same 'ack-and-a-half-same)
  233. (defalias 'ack-find-file 'ack-and-a-half-find-file)
  234. (defalias 'ack-find-file-same 'ack-and-a-half-find-file-same)
  235. ;; dired - reuse current buffer by pressing 'a'
  236. (put 'dired-find-alternate-file 'disabled nil)
  237. ;; ediff - don't start another frame
  238. (setq ediff-window-setup-function 'ediff-setup-windows-plain)
  239. ;; clean up obsolete buffers automatically
  240. (require 'midnight)
  241. ;; automatically indenting yanked text if in programming-modes
  242. (defvar yank-indent-modes
  243. '(LaTeX-mode TeX-mode)
  244. "Modes in which to indent regions that are yanked (or yank-popped).
  245. Only modes that don't derive from `prog-mode' should be listed here.")
  246. (defvar yank-indent-blacklisted-modes
  247. '(python-mode slim-mode haml-mode)
  248. "Modes for which auto-indenting is suppressed.")
  249. (defvar yank-advised-indent-threshold 1000
  250. "Threshold (# chars) over which indentation does not automatically occur.")
  251. (defun yank-advised-indent-function (beg end)
  252. "Do indentation, as long as the region isn't too large."
  253. (if (<= (- end beg) yank-advised-indent-threshold)
  254. (indent-region beg end nil)))
  255. (defadvice yank (after yank-indent activate)
  256. "If current mode is one of 'yank-indent-modes,
  257. indent yanked text (with prefix arg don't indent)."
  258. (if (and (not (ad-get-arg 0))
  259. (not (member major-mode yank-indent-blacklisted-modes))
  260. (or (derived-mode-p 'prog-mode)
  261. (member major-mode yank-indent-modes)))
  262. (let ((transient-mark-mode nil))
  263. (yank-advised-indent-function (region-beginning) (region-end)))))
  264. (defadvice yank-pop (after yank-pop-indent activate)
  265. "If current mode is one of 'yank-indent-modes,
  266. indent yanked text (with prefix arg don't indent)."
  267. (if (and (not (ad-get-arg 0))
  268. (not (member major-mode yank-indent-blacklisted-modes))
  269. (or (derived-mode-p 'prog-mode)
  270. (member major-mode yank-indent-modes)))
  271. (let ((transient-mark-mode nil))
  272. (yank-advised-indent-function (region-beginning) (region-end)))))
  273. ;; abbrev config
  274. (add-hook 'text-mode-hook 'abbrev-mode)
  275. ;; make a shell script executable automatically on save
  276. (add-hook 'after-save-hook
  277. 'executable-make-buffer-file-executable-if-script-p)
  278. ;; whitespace-mode config
  279. (setq whitespace-line-column 80) ;; limit line length
  280. (setq whitespace-style '(face tabs empty trailing lines-tail))
  281. ;; saner regex syntax
  282. (require 're-builder)
  283. (setq reb-re-syntax 'string)
  284. (require 'eshell)
  285. (setq eshell-directory-name (expand-file-name "eshell" prelude-savefile-dir))
  286. (setq semanticdb-default-save-directory
  287. (expand-file-name "semanticdb" prelude-savefile-dir))
  288. ;; enable Prelude's keybindings
  289. (prelude-global-mode t)
  290. ;; sensible undo
  291. (global-undo-tree-mode)
  292. (diminish 'undo-tree-mode)
  293. ;; enable winner-mode to manage window configurations
  294. (winner-mode +1)
  295. (provide 'prelude-editor)
  296. ;;; prelude-editor.el ends here