diff options
| author | Tom Jakubowski <tom@crystae.net> | 2016-03-05 14:54:53 -0800 |
|---|---|---|
| committer | Tom Jakubowski <tom@crystae.net> | 2016-03-05 15:17:00 -0800 |
| commit | 2f42da89c773b9eaf439d23553a02c4de39829d7 (patch) | |
| tree | 06378499e190df460841f3d36e3c7e19aaba1405 | |
| parent | 6739dd9d6312f231a9a9ed550939994adca271d6 (diff) | |
| download | rust-mode-2f42da89c773b9eaf439d23553a02c4de39829d7.tar.gz | |
Add rust-promote-module-into-dir
Lacking tests and completely untested on Windows!
closes #128
| -rw-r--r-- | rust-mode.el | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/rust-mode.el b/rust-mode.el index 56b356d..2ce102a 100644 --- a/rust-mode.el +++ b/rust-mode.el @@ -1402,6 +1402,28 @@ See `compilation-error-regexp-alist' for help on their format.") (interactive) (rust-playpen-region (point-min) (point-max))) +(defun rust-promote-module-into-dir () + "Promote the module file visited by the current buffer into its own directory. + +For example, if the current buffer is visiting the file `foo.rs', +then this function creates the directory `foo' and renames the +file to `foo/mod.rs'. The current buffer will be updated to +visit the new file." + (interactive) + (let ((filename (buffer-file-name))) + (if (not filename) + (message "Buffer is not visiting a file.") + (if (string-equal (file-name-nondirectory filename) "mod.rs") + (message "Won't promote a module file already named mod.rs.") + (let* ((basename (file-name-sans-extension + (file-name-nondirectory filename))) + (mod-dir (file-name-as-directory + (concat (file-name-directory filename) basename))) + (new-name (concat mod-dir "mod.rs"))) + (mkdir mod-dir t) + (rename-file filename new-name 1) + (set-visited-file-name new-name)))))) + (provide 'rust-mode) ;;; rust-mode.el ends here |
