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.

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