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.

375 lines
12 KiB

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