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.

300 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
  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. ;; note - this should be after volatile-highlights is required
  123. ;; add the ability to copy and cut the current line, without marking it
  124. (defadvice kill-ring-save (before slick-copy activate compile)
  125. "When called interactively with no active region, copy a single line instead."
  126. (interactive
  127. (if mark-active (list (region-beginning) (region-end))
  128. (message "Copied line")
  129. (list (line-beginning-position)
  130. (line-beginning-position 2)))))
  131. (defadvice kill-region (before slick-cut activate compile)
  132. "When called interactively with no active region, kill a single line instead."
  133. (interactive
  134. (if mark-active (list (region-beginning) (region-end))
  135. (list (line-beginning-position)
  136. (line-beginning-position 2)))))
  137. ;; tramp, for sudo access
  138. (require 'tramp)
  139. ;; keep in mind known issues with zsh - see emacs wiki
  140. (setq tramp-default-method "ssh")
  141. ;; ido-mode
  142. (ido-mode t)
  143. (setq ido-enable-prefix nil
  144. ido-enable-flex-matching t
  145. ido-create-new-buffer 'always
  146. ido-use-filename-at-point 'guess
  147. ido-max-prospects 10
  148. ido-save-directory-list-file (concat prelude-savefile-dir "ido.hist")
  149. ido-default-file-method 'selected-window)
  150. ;; auto-completion in minibuffer
  151. (icomplete-mode +1)
  152. (set-default 'imenu-auto-rescan t)
  153. ;; flyspell-mode does spell-checking on the fly as you type
  154. (setq ispell-program-name "aspell" ; use aspell instead of ispell
  155. ispell-extra-args '("--sug-mode=ultra"))
  156. (autoload 'flyspell-mode "flyspell" "On-the-fly spelling checker." t)
  157. (add-hook 'message-mode-hook 'flyspell-mode)
  158. (add-hook 'text-mode-hook 'flyspell-mode)
  159. ;; enable narrowing commands
  160. (put 'narrow-to-region 'disabled nil)
  161. (put 'narrow-to-page 'disabled nil)
  162. (put 'narrow-to-defun 'disabled nil)
  163. ;; enabled change region case commands
  164. (put 'upcase-region 'disabled nil)
  165. (put 'downcase-region 'disabled nil)
  166. (require 'expand-region)
  167. ;; bookmarks
  168. (setq bookmark-default-file (concat prelude-savefile-dir "bookmarks")
  169. bookmark-save-flag 1)
  170. ;; load yasnippet
  171. (require 'yasnippet)
  172. (add-to-list 'yas-snippet-dirs prelude-snippets-dir)
  173. (yas-global-mode 1)
  174. ;; projectile is a project management mode
  175. (require 'projectile)
  176. (projectile-global-mode t)
  177. (require 'helm-misc)
  178. (require 'helm-projectile)
  179. (defun helm-prelude ()
  180. "Preconfigured `helm'."
  181. (interactive)
  182. (if (projectile-project-root)
  183. ;; add project files and buffers when in project
  184. (helm-other-buffer '(helm-c-source-projectile-files-list
  185. helm-c-source-projectile-buffers-list
  186. helm-c-source-buffers-list
  187. helm-c-source-recentf
  188. helm-c-source-buffer-not-found)
  189. "*helm prelude*")
  190. ;; otherwise fallback to helm-mini
  191. (helm-mini)))
  192. ;; shorter aliases for ack-and-a-half commands
  193. (defalias 'ack 'ack-and-a-half)
  194. (defalias 'ack-same 'ack-and-a-half-same)
  195. (defalias 'ack-find-file 'ack-and-a-half-find-file)
  196. (defalias 'ack-find-file-same 'ack-and-a-half-find-file-same)
  197. ;; dired - reuse current buffer by pressing 'a'
  198. (put 'dired-find-alternate-file 'disabled nil)
  199. ;; ediff - don't start another frame
  200. (setq ediff-window-setup-function 'ediff-setup-windows-plain)
  201. ;; clean up obsolete buffers automatically
  202. (require 'midnight)
  203. ;; automatically indenting yanked text if in programming-modes
  204. (defvar yank-indent-modes '(python-mode LaTeX-mode TeX-mode)
  205. "Modes in which to indent regions that are yanked (or yank-popped). Only
  206. modes that don't derive from `prog-mode' should be listed here.")
  207. (defvar yank-advised-indent-threshold 1000
  208. "Threshold (# chars) over which indentation does not automatically occur.")
  209. (defun yank-advised-indent-function (beg end)
  210. "Do indentation, as long as the region isn't too large."
  211. (if (<= (- end beg) yank-advised-indent-threshold)
  212. (indent-region beg end nil)))
  213. (defadvice yank (after yank-indent activate)
  214. "If current mode is one of 'yank-indent-modes,
  215. indent yanked text (with prefix arg don't indent)."
  216. (if (and (not (ad-get-arg 0))
  217. (or (derived-mode-p 'prog-mode)
  218. (member major-mode yank-indent-modes)))
  219. (let ((transient-mark-mode nil))
  220. (yank-advised-indent-function (region-beginning) (region-end)))))
  221. (defadvice yank-pop (after yank-pop-indent activate)
  222. "If current mode is one of 'yank-indent-modes,
  223. indent yanked text (with prefix arg don't indent)."
  224. (if (and (not (ad-get-arg 0))
  225. (or (derived-mode-p 'prog-mode)
  226. (member major-mode yank-indent-modes)))
  227. (let ((transient-mark-mode nil))
  228. (yank-advised-indent-function (region-beginning) (region-end)))))
  229. ;; abbrev config
  230. (add-hook 'text-mode-hook 'abbrev-mode)
  231. ;; make a shell script executable automatically on save
  232. (add-hook 'after-save-hook
  233. 'executable-make-buffer-file-executable-if-script-p)
  234. ;; saner regex syntax
  235. (require 're-builder)
  236. (setq reb-re-syntax 'string)
  237. (require 'eshell)
  238. (setq eshell-directory-name (concat prelude-savefile-dir "/eshell/"))
  239. (setq semanticdb-default-save-directory
  240. (concat prelude-savefile-dir "semanticdb"))
  241. ;; enable Prelude's keybindings
  242. (prelude-global-mode t)
  243. (provide 'prelude-editor)
  244. ;;; prelude-editor.el ends here