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 @@ -1409,6 +1409,28 @@ See `compilation-error-regexp-alist' for help on their format.")
1409
1409
(interactive )
1410
1410
(rust-playpen-region (point-min ) (point-max )))
1411
1411
1412
+ (defun rust-promote-module-into-dir ()
1413
+ " Promote the module file visited by the current buffer into its own directory.
1414
+
1415
+ For example, if the current buffer is visiting the file `foo.rs' ,
1416
+ then this function creates the directory `foo' and renames the
1417
+ file to `foo/mod.rs' . The current buffer will be updated to
1418
+ visit the new file."
1419
+ (interactive )
1420
+ (let ((filename (buffer-file-name )))
1421
+ (if (not filename)
1422
+ (message " Buffer is not visiting a file. " )
1423
+ (if (string-equal (file-name-nondirectory filename) " mod.rs" )
1424
+ (message " Won't promote a module file already named mod.rs. " )
1425
+ (let* ((basename (file-name-sans-extension
1426
+ (file-name-nondirectory filename)))
1427
+ (mod-dir (file-name-as-directory
1428
+ (concat (file-name-directory filename) basename)))
1429
+ (new-name (concat mod-dir " mod.rs" )))
1430
+ (mkdir mod-dir t )
1431
+ (rename-file filename new-name 1 )
1432
+ (set-visited-file-name new-name))))))
1433
+
1412
1434
(provide 'rust-mode )
1413
1435
1414
1436
; ;; rust-mode.el ends here
You can’t perform that action at this time.
0 commit comments