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.

366 lines
12 KiB

13 years ago
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: 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-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. ;; diminish keeps the modeline tidy
  84. (require 'diminish)
  85. ;; meaningful names for buffers with the same name
  86. (require 'uniquify)
  87. (setq uniquify-buffer-name-style 'forward)
  88. (setq uniquify-separator "/")
  89. (setq uniquify-after-kill-buffer-p t) ; rename after killing uniquified
  90. (setq uniquify-ignore-buffers-re "^\\*") ; don't muck with special buffers
  91. ;; saveplace remembers your location in a file when saving files
  92. (require 'saveplace)
  93. (setq save-place-file (expand-file-name "saveplace" prelude-savefile-dir))
  94. ;; activate it for all buffers
  95. (setq-default save-place t)
  96. ;; savehist keeps track of some history
  97. (require 'savehist)
  98. (setq savehist-additional-variables
  99. ;; search entries
  100. '(search ring regexp-search-ring)
  101. ;; save every minute
  102. savehist-autosave-interval 60
  103. ;; keep the home clean
  104. savehist-file (expand-file-name "savehist" prelude-savefile-dir))
  105. (savehist-mode +1)
  106. ;; save recent files
  107. (require 'recentf)
  108. (setq recentf-save-file (expand-file-name "recentf" prelude-savefile-dir)
  109. recentf-max-saved-items 200
  110. recentf-max-menu-items 15)
  111. (recentf-mode +1)
  112. ;; use shift + arrow keys to switch between visible buffers
  113. (require 'windmove)
  114. (windmove-default-keybindings)
  115. ;; automatically save buffers associated with files on buffer switch
  116. ;; and on windows switch
  117. (defun prelude-auto-save-command ()
  118. (when (and prelude-auto-save
  119. buffer-file-name
  120. (buffer-modified-p (current-buffer)))
  121. (save-buffer)))
  122. (defadvice switch-to-buffer (before save-buffer-now activate)
  123. (prelude-auto-save-command))
  124. (defadvice other-window (before other-window-now activate)
  125. (prelude-auto-save-command))
  126. (defadvice windmove-up (before other-window-now activate)
  127. (prelude-auto-save-command))
  128. (defadvice windmove-down (before other-window-now activate)
  129. (prelude-auto-save-command))
  130. (defadvice windmove-left (before other-window-now activate)
  131. (prelude-auto-save-command))
  132. (defadvice windmove-right (before other-window-now activate)
  133. (prelude-auto-save-command))
  134. (add-hook 'mouse-leave-buffer-hook 'prelude-auto-save-command)
  135. ;; show-paren-mode: subtle highlighting of matching parens (global-mode)
  136. (require 'paren)
  137. (setq show-paren-style 'parenthesis)
  138. (show-paren-mode +1)
  139. ;; highlight the current line
  140. (global-hl-line-mode +1)
  141. (require 'volatile-highlights)
  142. (volatile-highlights-mode t)
  143. (diminish 'volatile-highlights-mode)
  144. ;; note - this should be after volatile-highlights is required
  145. ;; add the ability to copy and cut the current line, without marking it
  146. (defadvice kill-ring-save (before slick-copy activate compile)
  147. "When called interactively with no active region, copy a single line instead."
  148. (interactive
  149. (if mark-active (list (region-beginning) (region-end))
  150. (message "Copied line")
  151. (list (line-beginning-position)
  152. (line-beginning-position 2)))))
  153. (defadvice kill-region (before slick-cut activate compile)
  154. "When called interactively with no active region, kill a single line instead."
  155. (interactive
  156. (if mark-active (list (region-beginning) (region-end))
  157. (list (line-beginning-position)
  158. (line-beginning-position 2)))))
  159. ;; tramp, for sudo access
  160. (require 'tramp)
  161. ;; keep in mind known issues with zsh - see emacs wiki
  162. (setq tramp-default-method "ssh")
  163. ;; ido-mode
  164. (require 'ido)
  165. (setq ido-enable-prefix nil
  166. ido-enable-flex-matching t
  167. ido-create-new-buffer 'always
  168. ido-use-filename-at-point 'guess
  169. ido-max-prospects 10
  170. ido-save-directory-list-file (expand-file-name "ido.hist" prelude-savefile-dir)
  171. ido-default-file-method 'selected-window)
  172. (ido-mode +1)
  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. (require 'flyspell)
  178. (setq ispell-program-name "aspell" ; use aspell instead of ispell
  179. ispell-extra-args '("--sug-mode=ultra"))
  180. (defun prelude-enable-flyspell ()
  181. (when (and prelude-flyspell (executable-find ispell-program-name))
  182. (flyspell-mode +1)))
  183. (defun prelude-enable-whitespace ()
  184. (when prelude-whitespace
  185. ;; keep the whitespace decent all the time (in this buffer)
  186. (add-hook 'before-save-hook 'whitespace-cleanup nil t)
  187. (whitespace-mode +1)))
  188. (add-hook 'text-mode-hook 'prelude-enable-flyspell)
  189. (add-hook 'text-mode-hook 'prelude-enable-whitespace)
  190. ;; enable narrowing commands
  191. (put 'narrow-to-region 'disabled nil)
  192. (put 'narrow-to-page 'disabled nil)
  193. (put 'narrow-to-defun 'disabled nil)
  194. ;; enabled change region case commands
  195. (put 'upcase-region 'disabled nil)
  196. (put 'downcase-region 'disabled nil)
  197. (require 'expand-region)
  198. ;; bookmarks
  199. (require 'bookmark)
  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. (require 'ediff)
  239. (setq ediff-window-setup-function 'ediff-setup-windows-plain)
  240. ;; clean up obsolete buffers automatically
  241. (require 'midnight)
  242. ;; automatically indenting yanked text if in programming-modes
  243. (defvar yank-indent-modes
  244. '(LaTeX-mode TeX-mode)
  245. "Modes in which to indent regions that are yanked (or yank-popped).
  246. Only modes that don't derive from `prog-mode' should be listed here.")
  247. (defvar yank-indent-blacklisted-modes
  248. '(python-mode slim-mode haml-mode)
  249. "Modes for which auto-indenting is suppressed.")
  250. (defvar yank-advised-indent-threshold 1000
  251. "Threshold (# chars) over which indentation does not automatically occur.")
  252. (defun yank-advised-indent-function (beg end)
  253. "Do indentation, as long as the region isn't too large."
  254. (if (<= (- end beg) yank-advised-indent-threshold)
  255. (indent-region beg end nil)))
  256. (defadvice yank (after yank-indent activate)
  257. "If current mode is one of 'yank-indent-modes,
  258. indent yanked text (with prefix arg don't indent)."
  259. (if (and (not (ad-get-arg 0))
  260. (not (member major-mode yank-indent-blacklisted-modes))
  261. (or (derived-mode-p 'prog-mode)
  262. (member major-mode yank-indent-modes)))
  263. (let ((transient-mark-mode nil))
  264. (yank-advised-indent-function (region-beginning) (region-end)))))
  265. (defadvice yank-pop (after yank-pop-indent activate)
  266. "If current mode is one of 'yank-indent-modes,
  267. indent yanked text (with prefix arg don't indent)."
  268. (if (and (not (ad-get-arg 0))
  269. (not (member major-mode yank-indent-blacklisted-modes))
  270. (or (derived-mode-p 'prog-mode)
  271. (member major-mode yank-indent-modes)))
  272. (let ((transient-mark-mode nil))
  273. (yank-advised-indent-function (region-beginning) (region-end)))))
  274. ;; abbrev config
  275. (add-hook 'text-mode-hook 'abbrev-mode)
  276. ;; make a shell script executable automatically on save
  277. (add-hook 'after-save-hook
  278. 'executable-make-buffer-file-executable-if-script-p)
  279. ;; whitespace-mode config
  280. (require 'whitespace)
  281. (setq whitespace-line-column 80) ;; limit line length
  282. (setq whitespace-style '(face tabs empty trailing lines-tail))
  283. ;; saner regex syntax
  284. (require 're-builder)
  285. (setq reb-re-syntax 'string)
  286. (require 'eshell)
  287. (setq eshell-directory-name (expand-file-name "eshell" prelude-savefile-dir))
  288. (setq semanticdb-default-save-directory
  289. (expand-file-name "semanticdb" prelude-savefile-dir))
  290. ;; enable Prelude's keybindings
  291. (prelude-global-mode t)
  292. ;; sensible undo
  293. (global-undo-tree-mode)
  294. (diminish 'undo-tree-mode)
  295. ;; enable winner-mode to manage window configurations
  296. (winner-mode +1)
  297. (provide 'prelude-editor)
  298. ;;; prelude-editor.el ends here