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.

400 lines
14 KiB

13 years ago
13 years ago
13 years ago
13 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
13 years ago
13 years ago
14 years ago
13 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-clean-whitespace-on-save t
  46. "Cleanup whitespace from file before it's saved.
  47. Will only occur if prelude-whitespace is also enabled."
  48. :type 'boolean
  49. :group 'prelude)
  50. (defcustom prelude-flyspell t
  51. "Non-nil values enable Prelude's flyspell support."
  52. :type 'boolean
  53. :group 'prelude)
  54. ;; Death to the tabs! However, tabs historically indent to the next
  55. ;; 8-character offset; specifying anything else will cause *mass*
  56. ;; confusion, as it will change the appearance of every existing file.
  57. ;; In some cases (python), even worse -- it will change the semantics
  58. ;; (meaning) of the program.
  59. ;;
  60. ;; Emacs modes typically provide a standard means to change the
  61. ;; indentation width -- eg. c-basic-offset: use that to adjust your
  62. ;; personal indentation width, while maintaining the style (and
  63. ;; meaning) of any files you load.
  64. (setq-default indent-tabs-mode nil) ;; don't use tabs to indent
  65. (setq-default tab-width 8) ;; but maintain correct appearance
  66. ;; delete the selection with a keypress
  67. (delete-selection-mode t)
  68. ;; store all backup and autosave files in the tmp dir
  69. (setq backup-directory-alist
  70. `((".*" . ,temporary-file-directory)))
  71. (setq auto-save-file-name-transforms
  72. `((".*" ,temporary-file-directory t)))
  73. ;; revert buffers automatically when underlying files are changed externally
  74. (global-auto-revert-mode t)
  75. ;; hippie expand is dabbrev expand on steroids
  76. (setq hippie-expand-try-functions-list '(try-expand-dabbrev
  77. try-expand-dabbrev-all-buffers
  78. try-expand-dabbrev-from-kill
  79. try-complete-file-name-partially
  80. try-complete-file-name
  81. try-expand-all-abbrevs
  82. try-expand-list
  83. try-expand-line
  84. try-complete-lisp-symbol-partially
  85. try-complete-lisp-symbol))
  86. ;; smart pairing for all
  87. (setq sp-base-key-bindings 'paredit)
  88. (require 'smartparens-config)
  89. (smartparens-global-mode +1)
  90. ;; diminish keeps the modeline tidy
  91. (require 'diminish)
  92. ;; meaningful names for buffers with the same name
  93. (require 'uniquify)
  94. (setq uniquify-buffer-name-style 'forward)
  95. (setq uniquify-separator "/")
  96. (setq uniquify-after-kill-buffer-p t) ; rename after killing uniquified
  97. (setq uniquify-ignore-buffers-re "^\\*") ; don't muck with special buffers
  98. ;; saveplace remembers your location in a file when saving files
  99. (require 'saveplace)
  100. (setq save-place-file (expand-file-name "saveplace" prelude-savefile-dir))
  101. ;; activate it for all buffers
  102. (setq-default save-place t)
  103. ;; savehist keeps track of some history
  104. (require 'savehist)
  105. (setq savehist-additional-variables
  106. ;; search entries
  107. '(search ring regexp-search-ring)
  108. ;; save every minute
  109. savehist-autosave-interval 60
  110. ;; keep the home clean
  111. savehist-file (expand-file-name "savehist" prelude-savefile-dir))
  112. (savehist-mode +1)
  113. ;; save recent files
  114. (require 'recentf)
  115. (setq recentf-save-file (expand-file-name "recentf" prelude-savefile-dir)
  116. recentf-max-saved-items 200
  117. recentf-max-menu-items 15)
  118. (recentf-mode +1)
  119. ;; use shift + arrow keys to switch between visible buffers
  120. (require 'windmove)
  121. (windmove-default-keybindings)
  122. ;; automatically save buffers associated with files on buffer switch
  123. ;; and on windows switch
  124. (defun prelude-auto-save-command ()
  125. "Save the current buffer if `prelude-auto-save' is not nil."
  126. (when (and prelude-auto-save
  127. buffer-file-name
  128. (buffer-modified-p (current-buffer))
  129. (file-writable-p buffer-file-name))
  130. (save-buffer)))
  131. (defadvice switch-to-buffer (before save-buffer-now activate)
  132. "Invoke `prelude-auto-save-command' before `switch-to-window'."
  133. (prelude-auto-save-command))
  134. (defadvice other-window (before other-window-now activate)
  135. "Invoke `prelude-auto-save-command' before `other-window'."
  136. (prelude-auto-save-command))
  137. (defadvice windmove-up (before other-window-now activate)
  138. "Invoke `prelude-auto-save-command' before `windmove-up'."
  139. (prelude-auto-save-command))
  140. (defadvice windmove-down (before other-window-now activate)
  141. "Invoke `prelude-auto-save-command' before `windmove-down'."
  142. (prelude-auto-save-command))
  143. (defadvice windmove-left (before other-window-now activate)
  144. "Invoke `prelude-auto-save-command' before `windmove-left'."
  145. (prelude-auto-save-command))
  146. (defadvice windmove-right (before other-window-now activate)
  147. "Invoke `prelude-auto-save-command' before `windmove-right'."
  148. (prelude-auto-save-command))
  149. (add-hook 'mouse-leave-buffer-hook 'prelude-auto-save-command)
  150. ;; show-paren-mode: subtle highlighting of matching parens (global-mode)
  151. (require 'paren)
  152. (setq show-paren-style 'parenthesis)
  153. (show-paren-mode +1)
  154. ;; highlight the current line
  155. (global-hl-line-mode +1)
  156. (require 'volatile-highlights)
  157. (volatile-highlights-mode t)
  158. (diminish 'volatile-highlights-mode)
  159. ;; note - this should be after volatile-highlights is required
  160. ;; add the ability to copy and cut the current line, without marking it
  161. (defadvice kill-ring-save (before smart-copy activate compile)
  162. "When called interactively with no active region, copy a single line instead."
  163. (interactive
  164. (if mark-active (list (region-beginning) (region-end))
  165. (message "Copied line")
  166. (list (line-beginning-position)
  167. (line-end-position)))))
  168. (defadvice kill-region (before smart-cut activate compile)
  169. "When called interactively with no active region, kill a single line instead."
  170. (interactive
  171. (if mark-active (list (region-beginning) (region-end))
  172. (list (line-beginning-position)
  173. (line-beginning-position 2)))))
  174. ;; tramp, for sudo access
  175. (require 'tramp)
  176. ;; keep in mind known issues with zsh - see emacs wiki
  177. (setq tramp-default-method "ssh")
  178. ;; ido-mode
  179. (require 'ido)
  180. (require 'ido-ubiquitous)
  181. (setq ido-enable-prefix nil
  182. ido-enable-flex-matching t
  183. ido-create-new-buffer 'always
  184. ido-use-filename-at-point 'guess
  185. ido-max-prospects 10
  186. ido-save-directory-list-file (expand-file-name "ido.hist" prelude-savefile-dir)
  187. ido-default-file-method 'selected-window)
  188. (ido-mode +1)
  189. (ido-ubiquitous +1)
  190. ;; smex, remember recently and most frequently used commands
  191. (require 'smex)
  192. (setq smex-save-file (expand-file-name ".smex-items" prelude-savefile-dir))
  193. (smex-initialize)
  194. (global-set-key (kbd "M-x") 'smex)
  195. (global-set-key (kbd "M-X") 'smex-major-mode-commands)
  196. (set-default 'imenu-auto-rescan t)
  197. ;; flyspell-mode does spell-checking on the fly as you type
  198. (require 'flyspell)
  199. (setq ispell-program-name "aspell" ; use aspell instead of ispell
  200. ispell-extra-args '("--sug-mode=ultra"))
  201. (defun prelude-enable-flyspell ()
  202. "Enable command `flyspell-mode' if `prelude-flyspell' is not nil."
  203. (when (and prelude-flyspell (executable-find ispell-program-name))
  204. (flyspell-mode +1)))
  205. (defun prelude-cleanup-maybe ()
  206. "Invoke `whitespace-cleanup' if `prelude-clean-whitespace-on-save' is not nil."
  207. (when prelude-clean-whitespace-on-save
  208. (whitespace-cleanup)))
  209. (defun prelude-enable-whitespace ()
  210. "Enable `whitespace-mode' if `prelude-whitespace' is not nil."
  211. (when prelude-whitespace
  212. ;; keep the whitespace decent all the time (in this buffer)
  213. (add-hook 'before-save-hook 'prelude-cleanup-maybe nil t)
  214. (whitespace-mode +1)))
  215. (add-hook 'text-mode-hook 'prelude-enable-flyspell)
  216. (add-hook 'text-mode-hook 'prelude-enable-whitespace)
  217. ;; enable narrowing commands
  218. (put 'narrow-to-region 'disabled nil)
  219. (put 'narrow-to-page 'disabled nil)
  220. (put 'narrow-to-defun 'disabled nil)
  221. ;; enabled change region case commands
  222. (put 'upcase-region 'disabled nil)
  223. (put 'downcase-region 'disabled nil)
  224. ;; enable erase-buffer command
  225. (put 'erase-buffer 'disabled nil)
  226. (require 'expand-region)
  227. ;; bookmarks
  228. (require 'bookmark)
  229. (setq bookmark-default-file (expand-file-name "bookmarks" prelude-savefile-dir)
  230. bookmark-save-flag 1)
  231. ;; projectile is a project management mode
  232. (require 'projectile)
  233. (setq projectile-cache-file (expand-file-name "projectile.cache" prelude-savefile-dir))
  234. (projectile-global-mode t)
  235. (diminish 'projectile-mode "Prjl")
  236. (require 'helm-misc)
  237. (require 'helm-projectile)
  238. (defun helm-prelude ()
  239. "Preconfigured `helm'."
  240. (interactive)
  241. (condition-case nil
  242. (if (projectile-project-root)
  243. (helm-projectile)
  244. ;; otherwise fallback to helm-mini
  245. (helm-mini))
  246. ;; fall back to helm mini if an error occurs (usually in projectile-project-root)
  247. (error (helm-mini))))
  248. ;; shorter aliases for ack-and-a-half commands
  249. (defalias 'ack 'ack-and-a-half)
  250. (defalias 'ack-same 'ack-and-a-half-same)
  251. (defalias 'ack-find-file 'ack-and-a-half-find-file)
  252. (defalias 'ack-find-file-same 'ack-and-a-half-find-file-same)
  253. ;; dired - reuse current buffer by pressing 'a'
  254. (put 'dired-find-alternate-file 'disabled nil)
  255. ;; always delete and copy recursively
  256. (setq dired-recursive-deletes 'always)
  257. (setq dired-recursive-copies 'always)
  258. ;; if there is a dired buffer displayed in the next window, use its
  259. ;; current subdir, instead of the current subdir of this dired buffer
  260. (setq dired-dwim-target t)
  261. ;; enable some really cool extensions like C-x C-j(dired-jump)
  262. (require 'dired-x)
  263. ;; ediff - don't start another frame
  264. (require 'ediff)
  265. (setq ediff-window-setup-function 'ediff-setup-windows-plain)
  266. ;; clean up obsolete buffers automatically
  267. (require 'midnight)
  268. ;; automatically indenting yanked text if in programming-modes
  269. (defvar yank-indent-modes
  270. '(LaTeX-mode TeX-mode)
  271. "Modes in which to indent regions that are yanked (or yank-popped).
  272. Only modes that don't derive from `prog-mode' should be listed here.")
  273. (defvar yank-indent-blacklisted-modes
  274. '(python-mode slim-mode haml-mode)
  275. "Modes for which auto-indenting is suppressed.")
  276. (defvar yank-advised-indent-threshold 1000
  277. "Threshold (# chars) over which indentation does not automatically occur.")
  278. (defun yank-advised-indent-function (beg end)
  279. "Do indentation, as long as the region isn't too large."
  280. (if (<= (- end beg) yank-advised-indent-threshold)
  281. (indent-region beg end nil)))
  282. (defadvice yank (after yank-indent activate)
  283. "If current mode is one of 'yank-indent-modes,
  284. indent yanked text (with prefix arg don't indent)."
  285. (if (and (not (ad-get-arg 0))
  286. (not (member major-mode yank-indent-blacklisted-modes))
  287. (or (derived-mode-p 'prog-mode)
  288. (member major-mode yank-indent-modes)))
  289. (let ((transient-mark-mode nil))
  290. (yank-advised-indent-function (region-beginning) (region-end)))))
  291. (defadvice yank-pop (after yank-pop-indent activate)
  292. "If current mode is one of 'yank-indent-modes,
  293. indent yanked text (with prefix arg don't indent)."
  294. (if (and (not (ad-get-arg 0))
  295. (not (member major-mode yank-indent-blacklisted-modes))
  296. (or (derived-mode-p 'prog-mode)
  297. (member major-mode yank-indent-modes)))
  298. (let ((transient-mark-mode nil))
  299. (yank-advised-indent-function (region-beginning) (region-end)))))
  300. ;; abbrev config
  301. (add-hook 'text-mode-hook 'abbrev-mode)
  302. ;; make a shell script executable automatically on save
  303. (add-hook 'after-save-hook
  304. 'executable-make-buffer-file-executable-if-script-p)
  305. ;; .zsh file is shell script too
  306. (add-to-list 'auto-mode-alist '("\\.zsh\\'" . shell-script-mode))
  307. ;; whitespace-mode config
  308. (require 'whitespace)
  309. (setq whitespace-line-column 80) ;; limit line length
  310. (setq whitespace-style '(face tabs empty trailing lines-tail))
  311. ;; saner regex syntax
  312. (require 're-builder)
  313. (setq reb-re-syntax 'string)
  314. (require 'eshell)
  315. (setq eshell-directory-name (expand-file-name "eshell" prelude-savefile-dir))
  316. (setq semanticdb-default-save-directory
  317. (expand-file-name "semanticdb" prelude-savefile-dir))
  318. ;; enable Prelude's keybindings
  319. (prelude-global-mode t)
  320. ;; sensible undo
  321. (global-undo-tree-mode)
  322. (diminish 'undo-tree-mode)
  323. ;; enable winner-mode to manage window configurations
  324. (winner-mode +1)
  325. (provide 'prelude-editor)
  326. ;;; prelude-editor.el ends here