File tree 1 file changed +22
-0
lines changed
1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -1402,6 +1402,28 @@ See `compilation-error-regexp-alist' for help on their format.")
1402
1402
(interactive )
1403
1403
(rust-playpen-region (point-min ) (point-max )))
1404
1404
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
+
1405
1427
(provide 'rust-mode )
1406
1428
1407
1429
; ;; rust-mode.el ends here
You can’t perform that action at this time.
0 commit comments