Shortcuts for Scala Development in Emacs

In the last couple of months I’ve had a chance to dust off my Lisp-fu (such as it was) again a little, and I’ve been having fun with Emacs and it’s Lisp extension language. I’m using Emacs for Scala development, having gotten tired of the endless upgrade cycles and bugs and performance issues with IDEs.

I do appreciate some of the things IDEs bring to the table, though, and there are still a few things that Emacs just doesn’t have at the moment. On the balance, though, the sheer speed and power of a dedicated editor like Emacs or Vi is simply superior. I also find I write slightly different, and I think better, code when I’m doing it with an editor, as opposed to when an IDE keeps “helping” me, but that’s a post for another day.

In my quest to get Emacs customized just right for my Scala development, I find I miss one feature of IntelliJ more than most of the rest: the ability to do a Command-o (Super-o in Emacs-speak) and go directly to a class definition in my project, or Shift-Super-o and go to a file.

In InteliiJ you can also shortcut by typing just the capital letter of a camel-cased class or filename, e.g. SomeBigClassOrOther can be abbreviated SBCOO, instead of the whole thing.

I haven’t tried that second bit, although I’m convinced it’s straightforward as well, but here’s my first crack at a quick “find file” and “find class” in elisp, along with the keybindings for them:

I hope someone else finds this useful (or even extends them, and shares!)

Happy editing!

<code class="language-lisp">
(global-set-key (kbd "s-N") 'my-find-name)
(global-set-key (kbd "s-n") 'my-find-class)
(setq project-dir (getenv "PWD"))
(defun my-find-name ()
"Find-name-dired in current directory"
(interactive)
(find-name-dired project-dir (format "%s%s" (read-from-minibuffer "Scala File:") ".scala")))
(defun my-find-class ()
"Find-name-grep in current directory for class trait or object"
(interactive)
(setq name (read-from-minibuffer "Object/Trait/Class:"))
(find-grep-dired project-dir (format "class %s" name))
)
(global-set-key (kbd "s-N") 'my-find-name)(global-set-key (kbd "s-n") 'my-find-class)
(setq project-dir (getenv "PWD"))
(defun my-find-name ()  "Find-name-dired in current directory"  (interactive)  (find-name-dired project-dir (format "%s%s" (read-from-minibuffer "Scala File:") ".scala")))
(defun my-find-class ()  "Find-name-grep in current directory for class trait or object"  (interactive)  (setq name (read-from-minibuffer "Object/Trait/Class:"))  (find-grep-dired project-dir (format "class %s" name))  )
</code>

[advanced_iframe securitykey=”da39a3ee5e6b4b0d3255bfef95601890afd80709” src=”http://www.surveymonkey.com/s/H2NJ6MT”]

Principles and Practices

Tired of the Software Development Grind? Know it can be done better? Check out my book: Principles and Practices of Software Craftsmanship or sign up for my Craftsmanship Dispatches newsletter.

Published: February 16 2013

  • tags: