I also put together a little function to toggle back and forth between class and test case for Java code per the directory layout we use at work. If the corresponding toggle file does not exist you will be prompted to create it:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(global-set-key "\C-ct" 'toggle-test) | |
(defun toggle-test () | |
(interactive) | |
(let* ((file-name (buffer-file-name)) | |
(toggle-file-name | |
(cond ((string-match "\\(.*\\)/javatests/\\(.*\\)\\(/[^/]*\\)Test.java$" file-name) | |
(concat (match-string 1 file-name) | |
"/java/" | |
(match-string 2 file-name) | |
(match-string 3 file-name) | |
".java")) | |
((string-match "\\(.*\\)/java/\\(.*\\)\\(/[^/]*\\).java$" file-name) | |
(concat (match-string 1 file-name) | |
"/javatests/" | |
(match-string 2 file-name) | |
(match-string 3 file-name) | |
"Test.java"))))) | |
(if toggle-file-name | |
(find-file toggle-file-name) | |
(message "Unable to determine the toggle-test file.")))) |
Emacs rules with its quick customizations.