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.

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