Category Archives: emacs

Syncing Required Packages in Emacs

I use Emacs on several different computers. To keep my configuration
consistent across all of them, I do what many people do and made the
~/.emacs.d directory a git repository. I don’t like to keep
copies of all of the Elisp extensions that I use, such as paredit and
geiser, in this repository. Instead, I prefer to use package.el
(introduced in Emacs 24) with the MELPA repository. This saves me
from having to manually keep all of the extensions I use up-to-date,
but requires another method to keep useful packages in sync between
computers.

There’s a project called Pallet that solves this problem, but it was
too heavy for my liking. Instead, I wrote a short function that
simply iterates over a list of required packages and installs those
that are not currently installed.

;; Additional packages that I use.
 (setq required-packages
       '(better-defaults
         elfeed
         geiser
         ido-ubiquitous
         js2-mode
         magit
         paredit
         rainbow-delimiters
         smex))

 (defun install-missing-packages ()
   "Install all required packages that haven't been installed."
   (interactive)
   (mapc (lambda (package)
           (unless (package-installed-p package)
             (package-install package)))
         required-packages)
   (message "Installed all missing packages!"))

Now, it’s as easy as typing M-x install-missing-packages RET when
starting Emacs for the first time on a new computer to download all of
the extensions that I need. Note that before calling
install-missing-packages you must have already initialized the
package manager via the package-initialize function. This
approach does require some manual bookkeeping in order to keep the
required-packages list up-to-date with your workflow, but I
haven’t found it to be problematic.

Update: If this solution is too simplistic for you, you should check
out use-package, which reddit user lunayorn pointed out to
me. Thanks!

Check out the comments on reddit.

From the blog dthompson by David Thompson and used with permission of the author. All other rights reserved by the author.

Jump to Jasmine Specs with Rinari

I use the rinari Emacs mode to assist me when working on rails
projects. One of rinari’s most useful features is the ability to
quickly jump from one file to another related file. I use this
feature almost exclusively for jumping between a ruby class file and
its associated rspec file, but lately I’ve been spending most of my
time writing javascript. At VHL, we use jasmine for our unit testing
framework and the jasmine ruby gem to integrate it with our rails
projects. Rinari doesn’t have any built-in jump settings for jasmine
test files, so I wrote this quick hack to make it work:

;; Make rinari jump to/from javascript source files and specs.
(setcdr (assoc 'javascript rinari-jump-schema)
        '("j"
          (("app/assets/javascripts/\\1.js" . "spec/javascripts/\\1_spec.js")
           ("spec/javascripts/\\1_spec.js"  . "app/assets/javascripts/\\1.js")
           (t . "spec/javascripts/.*")
           (t . "app/javascripts/.*"))
          t))
(rinari-apply-jump-schema rinari-jump-schema)

Now I can press C-c ; f j to jump between a javascript file in
app/assets/javascripts/ and its jasmine test file in
spec/javascripts/. Perhaps I shouldn’t be overwriting the
predefined (but not very useful) javascript jump settings, but I
really wanted to use the j key.

From the blog dthompson by David Thompson and used with permission of the author. All other rights reserved by the author.