emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/rust-mode bfe24d2 237/486: Merge pull request #132 from to


From: ELPA Syncer
Subject: [nongnu] elpa/rust-mode bfe24d2 237/486: Merge pull request #132 from tomjakubowski/move-module
Date: Sat, 7 Aug 2021 09:25:27 -0400 (EDT)

branch: elpa/rust-mode
commit bfe24d25d29992216eba3cbe627f5da2fc3b400e
Merge: bc0df03 2f42da8
Author: Niko Matsakis <niko@alum.mit.edu>
Commit: Niko Matsakis <niko@alum.mit.edu>

    Merge pull request #132 from tomjakubowski/move-module
    
    Add rust-promote-module-into-dir
---
 rust-mode.el | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]