Created
June 19, 2013 12:44
-
-
Save rlb3/5814016 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| (require 's) | |
| (defun rlb3/toggle-file () | |
| (interactive) | |
| (let* ((full-path (buffer-file-name)) | |
| (path (rlb3/remove-ulc full-path)) | |
| (file-type (rlb3/determine-file-type path))) | |
| (if (eq file-type 'test) | |
| (rlb3/jump-to-related-test path) | |
| (rlb3/jump-to-related-module path)))) | |
| (defun rlb3/remove-ulc (path) | |
| (let ((new-path (s-chop-prefix "/usr/local/cpanel/" path ))) | |
| new-path)) | |
| (defun rlb3/determine-file-type (full-path) | |
| (cond ((s-ends-with? ".pm" full-path) 'test) | |
| ((s-ends-with? ".t" full-path) 'module))) | |
| (defun rlb3/jump-to-related-module (path) | |
| (let ((module (rlb3/convert-to-module path))) | |
| (if (file-exists-p module) | |
| (switch-to-buffer (find-file-noselect module)) | |
| (message "%s doesn't exist." module)))) | |
| (defun rlb3/jump-to-related-test (path) | |
| (let ((test (rlb3/convert-to-test path))) | |
| (if (file-exists-p test) | |
| (switch-to-buffer (find-file-noselect test)) | |
| (message "%s doesn't exist." test)))) | |
| (defun rlb3/convert-to-module (path) | |
| (let ((path (concat (car (s-split "_" path)) ".pm"))) | |
| (s-with path | |
| (s-replace ".t" "") | |
| (s-chop-prefix "t/") | |
| (s-prepend "/usr/local/cpanel/") | |
| (s-replace "-" "/")))) | |
| (defun rlb3/convert-to-test (path) | |
| (s-with path | |
| (s-replace ".pm" ".t") | |
| (s-replace "/" "-") | |
| (s-prepend "/usr/local/cpanel/t/"))) | |
| (global-set-key (kbd "<f9>") 'rlb3/toggle-file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment