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.

562 lines
19 KiB

13 years ago
14 years ago
14 years ago
12 years ago
  1. Emacs Prelude
  2. =============
  3. Prelude is an Emacs distribution that aims to enhance the default
  4. Emacs experience. Prelude alters a lot of the default settings,
  5. bundles a plethora of additional packages and adds its own core
  6. library to the mix. The final product offers an easy to use Emacs
  7. configuration for Emacs newcomers and lots of additional power for
  8. Emacs power users.
  9. Prelude is compatible **ONLY with GNU Emacs 24.x**. In general you're
  10. advised to always run Prelude with the latest Emacs - currently
  11. **24.3**.
  12. ## Fast Forward
  13. Assuming you're using an Unix-like OS (`*BSD`, `GNU/Linux`, `OS X`, `Solaris`,
  14. etc), you already have Emacs 24 installed, as well as `git` & `curl` you
  15. can skip the whole manual and just type in your favorite shell the
  16. following command:
  17. ```bash
  18. curl -L http://git.io/epre | sh
  19. ```
  20. You can now power up your Emacs, sit back and enjoy Prelude,
  21. forgetting about the rest of this manual.
  22. There are two environment variables you can use to control the
  23. source repository and the installation directory. To change the
  24. installation directory:
  25. ```bash
  26. export PRELUDE_INSTALL_DIR="$HOME/.emacs.d" && curl -L https://github.com/bbatsov/prelude/raw/master/utils/installer.sh | sh
  27. ```
  28. To change the source repository:
  29. ```bash
  30. export PRELUDE_URL="https://github.com/yourname/prelude.git" && curl -L https://github.com/bbatsov/prelude/raw/master/utils/installer.sh | sh
  31. ```
  32. Note that the installer will back up any existing `.emacs` file or
  33. `.emacs.d` since it will unpack Prelude's code in `.emacs.d`. If
  34. you're doing a manual install make sure you don't have a `.emacs` file
  35. or back up your existing `.emacs.d` directory manually.
  36. Don't forget to adjust your `prelude-modules.el` file once the installation is done.
  37. By default most of the modules that ship with Prelude are not loaded.
  38. ## Installing Emacs 24
  39. Obviously to use the Emacs Prelude you have to install Emacs 24
  40. first. Have a look at the [WikEmacs articles on installing Emacs](http://wikemacs.org/wiki/Installing_Emacs).
  41. ## Installation
  42. ### Automated
  43. You can install **Emacs Prelude** via the command line with either `curl` or
  44. `wget`. Naturally `git` is also required.
  45. #### Via Curl
  46. If you're using `curl` type the following command:
  47. ```bash
  48. curl -L https://github.com/bbatsov/prelude/raw/master/utils/installer.sh | sh
  49. ```
  50. #### Via Wget
  51. If you're using `wget` type:
  52. ```bash
  53. wget --no-check-certificate https://github.com/bbatsov/prelude/raw/master/utils/installer.sh -O - | sh
  54. ```
  55. ### Manual
  56. ```bash
  57. git clone git://github.com/bbatsov/prelude.git path/to/local/repo
  58. ln -s path/to/local/repo ~/.emacs.d
  59. cd ~/.emacs.d
  60. ```
  61. You'd do well to replace `~/.emacs.d` with the value of
  62. `user-emacs-directory` for your OS. You can check the value by doing
  63. `C-h v user-emacs-directory` inside Emacs.
  64. ## Updating Prelude
  65. ### Manual update
  66. The update procedure is fairly straightforward and consists of 3 steps:
  67. #### Update all bundled packages
  68. Just run <kbd>M-x package-list-packages RET U x</kbd>.
  69. #### Update Prelude's code
  70. ```bash
  71. cd path/to/prelude/installation
  72. git pull
  73. ```
  74. The `path/to/prelude/installation` is usually `~/.emacs.d` (at least
  75. on Unix systems).
  76. #### Restart Prelude
  77. It's generally a good idea to stop Emacs after you do the update. The
  78. next time Prelude starts it will install any new dependencies (if
  79. there are such).
  80. ### Automatic update
  81. Simply run <kbd>M-x prelude-update</kbd> from Emacs itself and restart Emacs afterwards.
  82. ## Enabling additional modules
  83. By default most of the modules that ship with Prelude are not loaded. For more information on the functionality provided by these modules visit the [docs](modules/doc/README.md).
  84. ```lisp
  85. ;;; Uncomment the modules you'd like to use and restart Prelude afterwards
  86. (require 'prelude-c)
  87. ;; (require 'prelude-clojure)
  88. ;; (require 'prelude-coffee)
  89. ;; (require 'prelude-common-lisp)
  90. ;; (require 'prelude-css)
  91. (require 'prelude-emacs-lisp)
  92. (require 'prelude-erc)
  93. ;; (require 'prelude-erlang)
  94. ;; (require 'prelude-haskell)
  95. (require 'prelude-js)
  96. ;; (require 'prelude-latex)
  97. (require 'prelude-lisp)
  98. ;; (require 'prelude-markdown)
  99. ;; (require 'prelude-mediawiki)
  100. (require 'prelude-org)
  101. (require 'prelude-perl)
  102. ;; (require 'prelude-python)
  103. ;; (require 'prelude-ruby)
  104. ;; (require 'prelude-scala)
  105. (require 'prelude-scheme)
  106. ;; (require 'prelude-scss)
  107. ;; (require 'prelude-web)
  108. (require 'prelude-xml)
  109. ```
  110. You'll need to adjust your `prelude-modules.el` file once the
  111. installation is done. If you are doing a manual install then you first
  112. need to copy the `prelude-modules.el` available in the sample
  113. directory to the root of `path/to/prelude/installation` and then
  114. adjust that one.
  115. After you've uncommented a module you should either restart Emacs or evaluate the module
  116. `require` expression with <kbd>C-x C-e</kbd>.
  117. ## Running
  118. Nothing fancy here. Just start Emacs as usual. Personally I run Emacs
  119. in daemon mode:
  120. ```bash
  121. emacs --daemon
  122. ```
  123. Afterwards I connect to the server with either a terminal or a GUI
  124. client like this:
  125. ```bash
  126. emacsclient -t
  127. emacsclient -c
  128. ```
  129. You'd probably do well to put a few aliases in your `.zshrc` (or
  130. `.bashrc`):
  131. ```bash
  132. alias e=emacsclient -t
  133. alias ec=emacsclient -c
  134. alias vim=emacsclient -t
  135. alias vi=emacsclient -t
  136. ```
  137. The last two aliases are helpful if you're used to editing files from
  138. the command line using `vi(m)`.
  139. ## Getting to know Prelude
  140. Certainly the best way to understand how Prelude enhances the default
  141. Emacs experience is to peruse Prelude's source code (which is
  142. obviously written in Emacs Lisp). Understanding the code is not
  143. necessary of course. Prelude includes a `prelude-mode` minor Emacs mode
  144. which collects some of the additional functionality added by
  145. Prelude. It also adds an additional keymap that binds many of those
  146. extensions to keybindings.
  147. ### Keymap
  148. #### Global
  149. Keybinding | Description
  150. -------------------|------------------------------------------------------------
  151. <kbd>C-M-h</kbd> | Kill the previous word(`backward-kill-word`). (as in Bash/Zsh)
  152. <kbd>C-x \\</kbd> | `align-regexp`
  153. <kbd>C-+</kbd> | Increase font size(`text-scale-increase`).
  154. <kbd>C--</kbd> | Decrease font size(`text-scale-decrease`).
  155. <kbd>C-x O</kbd> | Go back to previous window (the inverse of `other-window` (`C-x o`)).
  156. <kbd>C-^</kbd> | Join two lines into one(`prelude-top-join-line`).
  157. <kbd>C-x p</kbd> | Start `proced` (manage processes from Emacs; works only in Linux).
  158. <kbd>C-x m</kbd> | Start `eshell`.
  159. <kbd>C-x M-m</kbd> | Start your default shell.
  160. <kbd>C-x C-m</kbd> | Alias for `M-x`.
  161. <kbd>C-h A</kbd> | Run `apropos` (search in all Emacs symbols).
  162. <kbd>M-/</kbd> | Run `hippie-expand` (a replacement for the default `dabbrev-expand`).
  163. <kbd>C-x C-b</kbd> | Open `ibuffer` (a replacement for the default `buffer-list`).
  164. <kbd>F11</kbd> | Make the window full screen.
  165. <kbd>F12</kbd> | Toggle the Emacs menu bar.
  166. <kbd>C-x g</kbd> | Open Magit's status buffer.
  167. <kbd>C-=</kbd> | Run `expand-region` (incremental text selection).
  168. <kbd>C-a</kbd> | Run `prelude-move-beginning-of-line`. Read [this](http://emacsredux.com/blog/2013/05/22/smarter-navigation-to-the-beginning-of-a-line/) for details.
  169. #### Prelude Mode
  170. Keybinding | Description
  171. -------------------|------------------------------------------------------------
  172. <kbd>C-c o</kbd> | Open the currently visited file with an external program.
  173. <kbd>C-c i</kbd> | Search for a symbol, only for buffers that contain code
  174. <kbd>C-c g</kbd> | Search in Google for the thing under point (or an interactive query).
  175. <kbd>C-c G</kbd> | Search in GitHub for the thing under point (or an interactive query).
  176. <kbd>C-c y</kbd> | Search in YouTube for the thing under point (or an interactive query).
  177. <kbd>C-S-RET</kbd> or <kbd>M-O</kbd> or <kbd>Super-o</kbd> | Insert an empty line above the current line and indent it properly.
  178. <kbd>S-RET</kbd> or <kbd>M-o</kbd> | Insert an empty line and indent it properly (as in most IDEs).
  179. <kbd>C-S-up</kbd> or <kbd>M-S-up</kbd> | Move the current line or region up.
  180. <kbd>C-S-down</kbd> or <kbd>M-S-down</kbd>| Move the current line or region down.
  181. <kbd>C-c n</kbd> | Fix indentation in buffer and strip whitespace.
  182. <kbd>C-c f</kbd> | Open recently visited file.
  183. <kbd>C-M-\\</kbd> | Indent region (if selected) or the entire buffer.
  184. <kbd>C-c u</kbd> | Open URL in your default browser.
  185. <kbd>C-c e</kbd> | Eval a bit of Emacs Lisp code and replace it with its result.
  186. <kbd>C-c s</kbd> | Swap two active windows.
  187. <kbd>C-c d</kbd> | Duplicate the current line (or region).
  188. <kbd>C-c M-d</kbd> | Duplicate and comment the current line (or region).
  189. <kbd>C-c r</kbd> | Rename the currently visited file and buffer.
  190. <kbd>C-c t</kbd> | Open a terminal emulator (`ansi-term`).
  191. <kbd>C-c k</kbd> | Kill all open buffers except the one you're currently in.
  192. <kbd>C-c h</kbd> | Open Helm (a useful means of navigating your buffers and project files).
  193. <kbd>C-c +</kbd> | Increment integer at point.
  194. <kbd>C-c -</kbd> | Decrement integer at point.
  195. <kbd>Super-r</kbd> | Recent files
  196. <kbd>Super-x</kbd> | Expand region
  197. <kbd>Super-j</kbd> | Join lines
  198. <kbd>Super-k</kbd> | Kill whole line
  199. <kbd>Super-m m</kbd> | Magit status
  200. <kbd>Super-m l</kbd> | Magit log
  201. <kbd>Super-m f</kbd> | Magit file log
  202. <kbd>Super-m b</kbd> | Magit blame mode
  203. #### OSX modifier keys
  204. Prelude does not mess by default with the standard mapping of `Command` (to `Super`) and `Option` (to `Meta`).
  205. If you want to swap them add this to your personal config:
  206. ```lisp
  207. (setq mac-command-modifier 'meta)
  208. (setq mac-option-modifier 'super)
  209. ```
  210. You can also temporarily swap them with `C-c w` (`M-x prelude-swap-meta-and-super`).
  211. #### Projectile
  212. Here's a list of functionality provided by [Projectile](https://github.com/bbatsov/projectile):
  213. Keybinding | Description
  214. -------------------|------------------------------------------------------------
  215. <kbd>C-c p f</kbd> | Display a list of all files in the project. With a prefix argument it will clear the cache first.
  216. <kbd>C-c p d</kbd> | Display a list of all directories in the project. With a prefix argument it will clear the cache first.
  217. <kbd>C-c p T</kbd> | Display a list of all test files(specs, features, etc) in the project.
  218. <kbd>C-c p g</kbd> | Run grep on the files in the project.
  219. <kbd>C-c p b</kbd> | Display a list of all project buffers currently open.
  220. <kbd>C-c p o</kbd> | Runs `multi-occur` on all project buffers currently open.
  221. <kbd>C-c p r</kbd> | Runs interactive query-replace on all files in the projects.
  222. <kbd>C-c p i</kbd> | Invalidates the project cache (if existing).
  223. <kbd>C-c p R</kbd> | Regenerates the projects `TAGS` file.
  224. <kbd>C-c p k</kbd> | Kills all project buffers.
  225. <kbd>C-c p D</kbd> | Opens the root of the project in `dired`.
  226. <kbd>C-c p e</kbd> | Shows a list of recently visited project files.
  227. <kbd>C-c p a</kbd> | Runs `ack` on the project. Requires the presence of `ack-and-a-half`.
  228. <kbd>C-c p c</kbd> | Runs a standard compilation command for your type of project.
  229. <kbd>C-c p p</kbd> | Runs a standard test command for your type of project.
  230. <kbd>C-c p z</kbd> | Adds the currently visited to the cache.
  231. <kbd>C-c p s</kbd> | Display a list of known projects you can switch to.
  232. Prelude adds some extra keybindings:
  233. Keybinding | Command
  234. -------------------|------------------------------------------------------------
  235. <kbd>Super-f</kbd> | Find file in project
  236. <kbd>Super-d</kbd> | Find directory in project
  237. <kbd>Super-g</kbd> | Run grep on project
  238. <kbd>Super-p</kbd> | Switch projects
  239. If you ever forget any of Projectile's keybindings just do a:
  240. <kbd>C-c p C-h</kbd>
  241. #### Key-chords
  242. Keybinding | Description
  243. -------------------|----------------------------------------------
  244. <kbd>jj</kbd> | Jump to the beginning of a word(`ace-jump-word-mode`)
  245. <kbd>jk</kbd> | Jump to a character(`ace-jump-char-mode`)
  246. <kbd>jl</kbd> | Jump to the beginning of a line(`ace-jump-line-mode`)
  247. <kbd>JJ</kbd> | Jump back to previous buffer(`prelude-switch-to-previous-buffer`)
  248. <kbd>uu</kbd> | View edits as a tree(`undo-tree-visualize`)
  249. ##### Disabling key-chords
  250. In some cases you may not want to have a key-chord that is defined by prelude,
  251. in which case you can disable the binding in your `personal.el` file by setting
  252. its command to `nil`. For example, to disable the `jj` key-chord add the
  253. following line:
  254. ```lisp
  255. (key-chord-define-global "jj" nil)
  256. ```
  257. If you're an `evil-mode` user you'll probably do well to disable `key-chord-mode` altogether:
  258. ```lisp
  259. (key-chord-mode -1)
  260. ```
  261. ## Automatic package installation
  262. The default Prelude installation comes with a bare minimum of
  263. functionality. It will however install add-ons for various programming
  264. languages and frameworks on demand. For instance - if you try to open
  265. a `.clj` file `clojure-mode`, `nrepl.el` and prelude's enhanced Lisp
  266. configuration will be installed automatically for you.
  267. You can, of course, install anything you wish manually as well.
  268. ### Color Themes
  269. Emacs 24 ships with a new theming facility that effectively renders
  270. the old color-theme package obsolete. Emacs 24 provides a dozen of
  271. built-in themes you can use out-of-the-box by invoking the `M-x
  272. load-theme` command.
  273. [Zenburn](https://github.com/bbatsov/zenburn-emacs) is the default color theme in Prelude, but you can change it
  274. at your discretion. Why Zenburn? I (and lots of hackers around the
  275. world) find it pretty neat for some reason. Personally I find the
  276. default theme pretty tiresome for the eyes, that's why I took that
  277. "controversial" decision to replace it. You can, of course, easily go
  278. back to the default (or select another theme entirely).
  279. To disable Zenburn just put in your personal config the following
  280. line:
  281. ```lisp
  282. (disable-theme 'zenburn)
  283. ```
  284. Or you can use another theme altogether by adding something like:
  285. ```lisp
  286. (load-theme 'solarized-dark t)
  287. ```
  288. **P.S.** Solarized is not available by default - you'll have to
  289. install it from MELPA first (`M-x package-install RET
  290. solarized-theme`).
  291. ### Personalizing
  292. Fork the official Prelude repo and add your own touch to it. You're advised to avoid changing stuff outside of the
  293. personal folder to avoid having to deal with git merge conflicts in the future.
  294. If you'd like to add some auto installation of packages in your
  295. personal config use the following code:
  296. ```lisp
  297. (prelude-require-packages '(some-package some-other-package))
  298. ```
  299. If you require just a single package you can also use:
  300. ```lisp
  301. (prelude-require-package 'some-package)
  302. ```
  303. #### Disabling whitespace-mode
  304. Although `whitespace-mode` is awesome some people might find it too
  305. intrusive. You can disable it in your
  306. personal config with the following bit of code:
  307. ```lisp
  308. (setq prelude-whitespace nil)
  309. ```
  310. If you like `whitespace-mode` but prefer it to not automatically
  311. cleanup your file on save, you can disable that behavior by setting
  312. prelude-clean-whitespace-on-save to nil in your config file with:
  313. ```lisp
  314. (setq prelude-clean-whitespace-on-save nil)
  315. ```
  316. The prelude-clean-whitespace-on-save setting can also be set on a
  317. per-file or directory basis by using a file variable or a
  318. .dir-locals.el file.
  319. #### Disable flyspell-mode
  320. If you're not fond of spellchecking on the fly:
  321. ```lisp
  322. (setq prelude-flyspell nil)
  323. ```
  324. ## Caveats & Pitfalls
  325. ### Updating bundled packages
  326. Generally it's a good idea to do a package update before running
  327. updating Prelude, since the latest Prelude code might depend on newer
  328. versions of the bundled packages than you would currently have
  329. installed.
  330. If you're doing manual Prelude updates you should always do a package update first.
  331. `M-x package-list-packages RET U x`
  332. That's not necessary if you're using `M-x prelude-update`, since it
  333. will automatically update the installed packages.
  334. ### Problems with flyspell-mode
  335. Prelude makes heavy use of the flyspell-mode package for spell
  336. checking of various things. The proper operation of flyspell depends
  337. on the presence of the `aspell` program and an `en` dictionary on your
  338. system. You can install `aspell` and the dictionary on OS X with
  339. `homebrew` like this:
  340. ```bash
  341. brew install aspell --with-lang=en
  342. ```
  343. On Linux distros - just use your distro's package manager.
  344. ### Ugly colors in the terminal Emacs version
  345. If your Emacs looks considerably uglier in a terminal (compared to the
  346. GUI version) try adding this to your `.bashrc` or `.zshrc`:
  347. ```bash
  348. export TERM=xterm-256color
  349. ```
  350. Source the `.bashrc` file and start Emacs again.
  351. ### MELPA error on initial startup
  352. If you get some http connection error related to the MELPA repo
  353. just do a manual `M-x package-refresh-contents` and restart Emacs
  354. afterwards.
  355. ### No arrow navigation in editor buffers
  356. This is not a bug - it's a feature! I firmly believe that the one true
  357. way to use Emacs is by using it the way it was intended to be used (as
  358. far as navigation is concerned at least). That's why I've disabled all
  359. movement commands with arrows (and keys like page up, page down, etc) - to prevent you from being tempted to
  360. use them.
  361. If you'd still like to use the arrow keys just invoke `M-x
  362. guru-mode` to enable them for the duration of your
  363. current Emacs session or add the following snippet to your
  364. personal Emacs customization to enable them permanently:
  365. ```lisp
  366. (setq prelude-guru nil)
  367. ```
  368. ### Customized C-a behavior
  369. Prelude overrides `C-a` to behave as described
  370. [here](http://emacsredux.com/blog/2013/05/22/smarter-navigation-to-the-beginning-of-a-line/). If
  371. you don't like that simply add this to your personal config:
  372. ```lisp
  373. (global-set-key [remap move-beginning-of-line]
  374. 'move-beginning-of-line)
  375. ```
  376. ### Poor ido matching performance on large datasets
  377. Prelude swaps the default `ido` flex matching with the more powerful
  378. [ido-flx](https://github.com/lewang/flx).
  379. The sorting algorithm `flx` uses is more complex, but yields better results.
  380. On slower machines, it may be necessary to lower `flx-ido-threshhold` to
  381. ensure a smooth experience.
  382. ```lisp
  383. (setq flx-ido-threshhold 1000)
  384. ```
  385. You can always disable the improved sorting algorithm all together like this:
  386. ```lisp
  387. (flx-ido-mode -1)
  388. ```
  389. ### Windows compatibility
  390. While everything in Prelude should work fine in Windows, I test it only
  391. with Linux & OSX, so there are Windows related problems from time to
  392. time. This situation will probably improve over time.
  393. ## Share the knowledge
  394. [WikEmacs](http://wikemacs.org) collects useful resources for working
  395. with GNU Emacs. Please, take the time to peruse and improve them as
  396. you accumulate knowledge about Emacs. Prelude makes this especially
  397. easy, since it bundles
  398. [MediaWiki support](http://wikemacs.org/wiki/Mediawiki.el) + the
  399. settings required to access WikEmacs right away.
  400. ## Known issues
  401. Check out the project's
  402. [issue list](https://github.com/bbatsov/prelude/issues?sort=created&direction=desc&state=open)
  403. a list of unresolved issues. By the way - feel free to fix any of them
  404. and send me a pull request. :-)
  405. ## Support
  406. Support is available via the Prelude Google Group <emacs-prelude@googlegroups.com>.
  407. ## Contributors
  408. Here's a [list](https://github.com/bbatsov/prelude/contributors) of all the people who have contributed to the
  409. development of Emacs Prelude.
  410. ## Bugs & Improvements
  411. Bug reports and suggestions for improvements are always
  412. welcome. GitHub pull requests are even better! :-)
  413. Cheers,<br/>
  414. [Bozhidar](https://twitter.com/bbatsov)