Skip to content

Commit 2f42da8

Browse files
committed
Add rust-promote-module-into-dir
Lacking tests and completely untested on Windows! closes #128
1 parent 6739dd9 commit 2f42da8

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

rust-mode.el

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,28 @@ See `compilation-error-regexp-alist' for help on their format.")
14021402
(interactive)
14031403
(rust-playpen-region (point-min) (point-max)))
14041404

1405+
(defun rust-promote-module-into-dir ()
1406+
"Promote the module file visited by the current buffer into its own directory.
1407+
1408+
For example, if the current buffer is visiting the file `foo.rs',
1409+
then this function creates the directory `foo' and renames the
1410+
file to `foo/mod.rs'. The current buffer will be updated to
1411+
visit the new file."
1412+
(interactive)
1413+
(let ((filename (buffer-file-name)))
1414+
(if (not filename)
1415+
(message "Buffer is not visiting a file.")
1416+
(if (string-equal (file-name-nondirectory filename) "mod.rs")
1417+
(message "Won't promote a module file already named mod.rs.")
1418+
(let* ((basename (file-name-sans-extension
1419+
(file-name-nondirectory filename)))
1420+
(mod-dir (file-name-as-directory
1421+
(concat (file-name-directory filename) basename)))
1422+
(new-name (concat mod-dir "mod.rs")))
1423+
(mkdir mod-dir t)
1424+
(rename-file filename new-name 1)
1425+
(set-visited-file-name new-name))))))
1426+
14051427
(provide 'rust-mode)
14061428

14071429
;;; rust-mode.el ends here

0 commit comments

Comments
 (0)