Skip to content

Instantly share code, notes, and snippets.

@jcsalterego
Created May 11, 2011 19:04
Show Gist options
  • Select an option

  • Save jcsalterego/967078 to your computer and use it in GitHub Desktop.

Select an option

Save jcsalterego/967078 to your computer and use it in GitHub Desktop.
(defun jump-to-other ()
"jumps from lib/ to test/ and vice-versa"
(interactive)
(defconst test-root "/driver/test/driver/")
(defconst lib-root "/driver/lib/project/")
(defun jump-to-lib (path)
"jump to lib from test"
(and (when (string-match test-root path)
(setq path (replace-match lib-root nil nil path)))
(message "jump to lib")
(when (string-match "_test\.rb$" path)
(setq path (replace-match ".rb" nil nil path)))
(find-file path nil)))
(defun jump-to-test (path)
"jump to test from lib"
(and (when (string-match lib-root path)
(setq path (replace-match test-root nil nil path)))
(when (string-match "\.rb$" path)
(setq path (replace-match "_test.rb" nil nil path)))
(find-file path nil)))
(setq path (buffer-file-name))
(if (cond ((string-match test-root path) (jump-to-lib path))
((string-match lib-root path) (jump-to-test path)))
nil
(progn (message "sorry bub"))))
(global-set-key (kbd "C-x j") 'jump-to-other)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment