Emacs 24 includes many improvements over 23, but there is one particular addition that makes me run around and go crazy with joy: a built-in package management system, ELPA (Emacs 24 is still in development, Bozhidar Batsov has a good guide on how to get it set up). I switched over to Emacs almost a year ago, searching for something that would give me an IDE with the following attributes:
Functionality (context-based completion, on the fly syntax checking)
Customization (key bindings, easily extensible)
Portability (minimal setup on new environments)
There are a lot of nice extensions that do well for the first two. However, Portability was always tricky. To get some of the more power coding features in Emacs, one needed to install large packages, and there was no way to move these around short of zipping the whole thing up or finding and installing all these packages again.
ELPA completes the trifecta I have been looking for. It was now easy to have a list of packages to install. I have a GitHub repository to contain all of my .emacs setup, so I can just clone a repository with every new environment. To make the setup completely automatic, I needed a method to automatically install packages that did not exist. After a little research, I was able to figure it out:
;; Packages to install first (check if emacs is 24 or higher)
(if (>= emacs-major-version 24)
(progn
;; Add a larger package list
(setq package-archives '(("ELPA" . "http://tromey.com/elpa/")
("gnu" . "http://elpa.gnu.org/packages/")
("marmalade" . "http://marmalade-repo.org/packages/")))
(package-refresh-contents)
;; Install flymake mode if it doesn't exist, then configure
(when (not (require 'flymake nil t))
(package-install 'flymake))
(global-set-key (kbd "C-; C-f") 'flymake-mode)
;; flymake-cursor
(when (not (require 'flymake-cursor nil t))
(package-install 'flymake-cursor))
;; Install rainbow mode if it doesn't exist, then configure
(when (not (require 'rainbow-mode nil t))
(package-install 'rainbow-mode))
(defun all-css-modes() (css-mode)
(rainbow-mode))
(add-to-list 'auto-mode-alist '("\.css$" . all-css-modes))
)
)
NOTE!!! This must be run after ALL OTHER INITIALIZATIONS are run! You can do this by placing it within a hook:
(add-hook 'after-init-hook '(lambda ()
(load "~/.emacs.loadpackages"))) ;; anything within the lambda will run after everything has initialized.
As you can see, I've put the above logic into a file called ".emacs.loadpackages". This is so I can remove it at easy if I want a more bare environment.
I'd like to talk about this a little bit in detail. The first line ensures that emacs is version 24 or higher:
And then onto the logic to see if a package exists! You can use require to see if a package exists, nullifying the error message it usually return by adding the true statement at the end. For example, this will return true when the package fly-make cursor is not installed:
There a couple of things I'm still working on regarding this setup. Although I haven't gotten any environment breaking errors so far, there's not a lot of error checking, so I'm sure it can break if things are not completely right. In addition, this does not work very well for portable programmers, as Emacs will try to initialize ELPA, resulting in an exception due to not being able to contact the server.
Please leave comments and suggestions!
It\'s too bad ido doesn\'t learn like Quicksilver did. You could type qrr then select query-replace-regexp and after 2-3 times of doing that it would learn that\'s what you want to come up when you type qrr.Btw I use ido-hacks.el which I think gives me the beefints of smex on M-x but last time I compared smex was slower.
It's too bad ido doesn't learn like Quicksilver did. You could type qrr then select query-replace-regexp and after 2-3 times of doing that it would learn that's what you want to come up when you type qrr.Btw I use ido-hacks.el which I think gives me the beefints of smex on M-x but last time I compared smex was slower.
Comments
toumorokoshi | 05/19/2012 02:17pm
vvhhwzvtvlfutvutvnj, <a href="http://www.xxaxordjne.com" rel="nofollow">kjxyqxynvr</a> , [url=http://www.zpxewfjwdh.com]tphdrwqgtk[/url], http://www.abgpjwcuhx.com kjxyqxynvrtoumorokoshi | 05/19/2012 11:12am
mjzcezvtvlfutvutvnj, <a href="http://www.pbjkrvqfcv.com" rel="nofollow">ncsmcztaep</a> , [url=http://www.gnesqnxton.com]fhloencjla[/url], http://www.mroaejcdjz.com ncsmcztaeptoumorokoshi | 05/17/2012 05:37pm
6URRxy , [url=http://maguxjfylvqy.com/]maguxjfylvqy[/url], [link=http://edbbjaceygvj.com/]edbbjaceygvj[/link], http://pivnpjicdeqo.com/toumorokoshi | 05/16/2012 04:44pm
Lz8ZJI <a href="http://gqruybalrpgb.com/" rel="nofollow">gqruybalrpgb</a>toumorokoshi | 05/16/2012 09:44am
30xCbe , [url=http://oyhrogrkuzhc.com/]oyhrogrkuzhc[/url], [link=http://hhauqrtmpvmx.com/]hhauqrtmpvmx[/link], http://pjwddhneicth.com/toumorokoshi | 05/15/2012 06:52am
jRMneq <a href="http://zppprtxbntgr.com/" rel="nofollow">zppprtxbntgr</a>toumorokoshi | 05/14/2012 02:00pm
It\'s too bad ido doesn\'t learn like Quicksilver did. You could type qrr then select query-replace-regexp and after 2-3 times of doing that it would learn that\'s what you want to come up when you type qrr.Btw I use ido-hacks.el which I think gives me the beefints of smex on M-x but last time I compared smex was slower.toumorokoshi | 05/14/2012 02:00pm
It's too bad ido doesn't learn like Quicksilver did. You could type qrr then select query-replace-regexp and after 2-3 times of doing that it would learn that's what you want to come up when you type qrr.Btw I use ido-hacks.el which I think gives me the beefints of smex on M-x but last time I compared smex was slower.