summaryrefslogtreecommitdiff
path: root/rust-mode.el
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2016-03-09 05:01:23 -0500
committerNiko Matsakis <niko@alum.mit.edu>2016-03-09 05:01:23 -0500
commitbfe24d25d29992216eba3cbe627f5da2fc3b400e (patch)
tree55f2efacbe77dbbb7c9d8e5dc84a392927c0c3ef /rust-mode.el
parentbc0df03bec8b92e8aded61cce364a0386e8c04b2 (diff)
parent2f42da89c773b9eaf439d23553a02c4de39829d7 (diff)
downloadrust-mode-bfe24d25d29992216eba3cbe627f5da2fc3b400e.tar.gz
Merge pull request #132 from tomjakubowski/move-module
Add rust-promote-module-into-dir
Diffstat (limited to 'rust-mode.el')
-rw-r--r--rust-mode.el22
1 files changed, 22 insertions, 0 deletions
diff --git a/rust-mode.el b/rust-mode.el
index 43245e4..d141a0c 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -1409,6 +1409,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