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.

395 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. (electric-pair-mode t)
  88. ;; diminish keeps the modeline tidy
  89. (require 'diminish)
  90. ;; meaningful names for buffers with the same name
  91. (require 'uniquify)
  92. (setq uniquify-buffer-name-style 'forward)
  93. (setq uniquify-separator "/")
  94. (setq uniquify-after-kill-buffer-p t) ; rename after killing uniquified
  95. (setq uniquify-ignore-buffers-re "^\\*") ; don't muck with special buffers
  96. ;; saveplace remembers your location in a file when saving files
  97. (require 'saveplace)
  98. (setq save-place-file (expand-file-name "saveplace" prelude-savefile-dir))
  99. ;; activate it for all buffers
  100. (setq-default save-place t)
  101. ;; savehist keeps track of some history
  102. (require 'savehist)
  103. (setq savehist-additional-variables
  104. ;; search entries
  105. '(search ring regexp-search-ring)
  106. ;; save every minute
  107. savehist-autosave-interval 60
  108. ;; keep the home clean
  109. savehist-file (expand-file-name "savehist" prelude-savefile-dir))
  110. (savehist-mode +1)
  111. ;; save recent files
  112. (require 'recentf)
  113. (setq recentf-save-file (expand-file-name "recentf" prelude-savefile-dir)
  114. recentf-max-saved-items 200
  115. recentf-max-menu-items 15)
  116. (recentf-mode +1)
  117. ;; use shift + arrow keys to switch between visible buffers
  118. (require 'windmove)
  119. (windmove-default-keybindings)
  120. ;; automatically save buffers associated with files on buffer switch
  121. ;; and on windows switch
  122. (defun prelude-auto-save-command ()
  123. "Save the current buffer if `prelude-auto-save' is not nil."
  124. (when (and prelude-auto-save
  125. buffer-file-name
  126. (buffer-modified-p (current-buffer)))
  127. (save-buffer)))
  128. (defadvice switch-to-buffer (before save-buffer-now activate)
  129. "Invoke `prelude-auto-save-command' before `switch-to-window'."
  130. (prelude-auto-save-command))
  131. (defadvice other-window (before other-window-now activate)
  132. "Invoke `prelude-auto-save-command' before `other-window'."
  133. (prelude-auto-save-command))
  134. (defadvice windmove-up (before other-window-now activate)
  135. "Invoke `prelude-auto-save-command' before `windmove-up'."
  136. (prelude-auto-save-command))
  137. (defadvice windmove-down (before other-window-now activate)
  138. "Invoke `prelude-auto-save-command' before `windmove-down'."
  139. (prelude-auto-save-command))
  140. (defadvice windmove-left (before other-window-now activate)
  141. "Invoke `prelude-auto-save-command' before `windmove-left'."
  142. (prelude-auto-save-command))
  143. (defadvice windmove-right (before other-window-now activate)
  144. "Invoke `prelude-auto-save-command' before `windmove-right'."
  145. (prelude-auto-save-command))
  146. (add-hook 'mouse-leave-buffer-hook 'prelude-auto-save-command)
  147. ;; show-paren-mode: subtle highlighting of matching parens (global-mode)
  148. (require 'paren)
  149. (setq show-paren-style 'parenthesis)
  150. (show-paren-mode +1)
  151. ;; highlight the current line
  152. (global-hl-line-mode +1)
  153. (require 'volatile-highlights)
  154. (volatile-highlights-mode t)
  155. (diminish 'volatile-highlights-mode)
  156. ;; note - this should be after volatile-highlights is required
  157. ;; add the ability to copy and cut the current line, without marking it
  158. (defadvice kill-ring-save (before smart-copy activate compile)
  159. "When called interactively with no active region, copy a single line instead."
  160. (interactive
  161. (if mark-active (list (region-beginning) (region-end))
  162. (message "Copied line")
  163. (list (line-beginning-position)
  164. (line-beginning-position 2)))))
  165. (defadvice kill-region (before smart-cut activate compile)
  166. "When called interactively with no active region, kill a single line instead."
  167. (interactive
  168. (if mark-active (list (region-beginning) (region-end))
  169. (list (line-beginning-position)
  170. (line-beginning-position 2)))))
  171. ;; tramp, for sudo access
  172. (require 'tramp)
  173. ;; keep in mind known issues with zsh - see emacs wiki
  174. (setq tramp-default-method "ssh")
  175. ;; ido-mode
  176. (require 'ido)
  177. (require 'ido-ubiquitous)
  178. (setq ido-enable-prefix nil
  179. ido-enable-flex-matching t
  180. ido-create-new-buffer 'always
  181. ido-use-filename-at-point 'guess
  182. ido-max-prospects 10
  183. ido-save-directory-list-file (expand-file-name "ido.hist" prelude-savefile-dir)
  184. ido-default-file-method 'selected-window)
  185. (ido-mode +1)
  186. (ido-ubiquitous +1)
  187. ;; smex, remember recently and most frequently used commands
  188. (require 'smex)
  189. (setq smex-save-file (expand-file-name ".smex-items" prelude-savefile-dir))
  190. (smex-initialize)
  191. (global-set-key (kbd "M-x") 'smex)
  192. (global-set-key (kbd "M-X") 'smex-major-mode-commands)
  193. (set-default 'imenu-auto-rescan t)
  194. ;; flyspell-mode does spell-checking on the fly as you type
  195. (require 'flyspell)
  196. (setq ispell-program-name "aspell" ; use aspell instead of ispell
  197. ispell-extra-args '("--sug-mode=ultra"))
  198. (defun prelude-enable-flyspell ()
  199. "Enable command `flyspell-mode' if `prelude-flyspell' is not nil."
  200. (when (and prelude-flyspell (executable-find ispell-program-name))
  201. (flyspell-mode +1)))
  202. (defun prelude-cleanup-maybe ()
  203. "Invoke `whitespace-cleanup' if `prelude-clean-whitespace-on-save' is not nil."
  204. (when prelude-clean-whitespace-on-save
  205. (whitespace-cleanup)))
  206. (defun prelude-enable-whitespace ()
  207. "Enable `whitespace-mode' if `prelude-whitespace' is not nil."
  208. (when prelude-whitespace
  209. ;; keep the whitespace decent all the time (in this buffer)
  210. (add-hook 'before-save-hook 'prelude-cleanup-maybe nil t)
  211. (whitespace-mode +1)))
  212. (add-hook 'text-mode-hook 'prelude-enable-flyspell)
  213. (add-hook 'text-mode-hook 'prelude-enable-whitespace)
  214. ;; enable narrowing commands
  215. (put 'narrow-to-region 'disabled nil)
  216. (put 'narrow-to-page 'disabled nil)
  217. (put 'narrow-to-defun 'disabled nil)
  218. ;; enabled change region case commands
  219. (put 'upcase-region 'disabled nil)
  220. (put 'downcase-region 'disabled nil)
  221. (require 'expand-region)
  222. ;; bookmarks
  223. (require 'bookmark)
  224. (setq bookmark-default-file (expand-file-name "bookmarks" prelude-savefile-dir)
  225. bookmark-save-flag 1)
  226. ;; load yasnippet
  227. (require 'yasnippet)
  228. (add-to-list 'yas-snippet-dirs prelude-snippets-dir)
  229. (add-to-list 'yas-snippet-dirs prelude-personal-snippets-dir)
  230. (yas-global-mode 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. ;; add project files and buffers when in project
  244. (helm-other-buffer '(helm-c-source-projectile-files-list
  245. helm-c-source-projectile-buffers-list
  246. helm-c-source-buffers-list
  247. helm-c-source-recentf
  248. helm-c-source-buffer-not-found)
  249. "*helm prelude*")
  250. ;; otherwise fallback to helm-mini
  251. (helm-mini))
  252. ;; fall back to helm mini if an error occurs (usually in projectile-project-root)
  253. (error (helm-mini))))
  254. ;; shorter aliases for ack-and-a-half commands
  255. (defalias 'ack 'ack-and-a-half)
  256. (defalias 'ack-same 'ack-and-a-half-same)
  257. (defalias 'ack-find-file 'ack-and-a-half-find-file)
  258. (defalias 'ack-find-file-same 'ack-and-a-half-find-file-same)
  259. ;; dired - reuse current buffer by pressing 'a'
  260. (put 'dired-find-alternate-file 'disabled nil)
  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. ;; whitespace-mode config
  306. (require 'whitespace)
  307. (setq whitespace-line-column 80) ;; limit line length
  308. (setq whitespace-style '(face tabs empty trailing lines-tail))
  309. ;; saner regex syntax
  310. (require 're-builder)
  311. (setq reb-re-syntax 'string)
  312. (require 'eshell)
  313. (setq eshell-directory-name (expand-file-name "eshell" prelude-savefile-dir))
  314. (setq semanticdb-default-save-directory
  315. (expand-file-name "semanticdb" prelude-savefile-dir))
  316. ;; enable Prelude's keybindings
  317. (prelude-global-mode t)
  318. ;; sensible undo
  319. (global-undo-tree-mode)
  320. (diminish 'undo-tree-mode)
  321. ;; enable winner-mode to manage window configurations
  322. (winner-mode +1)
  323. (provide 'prelude-editor)
  324. ;;; prelude-editor.el ends here