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.

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