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

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

[nongnu] elpa/rust-mode 3eb6d2f 485/486: Create rust-utils.el from exist


From: ELPA Syncer
Subject: [nongnu] elpa/rust-mode 3eb6d2f 485/486: Create rust-utils.el from existing code
Date: Sat, 7 Aug 2021 09:26:19 -0400 (EDT)

branch: elpa/rust-mode
commit 3eb6d2fc2dcdf117e0570fa1891ccf63720f27ca
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: brotzeit <brotzeitmacher@gmail.com>

    Create rust-utils.el from existing code
---
 Makefile      |  1 +
 rust-mode.el  | 69 ++-----------------------------------------------
 rust-utils.el | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 85 insertions(+), 67 deletions(-)

diff --git a/Makefile b/Makefile
index aaa652c..64bb106 100644
--- a/Makefile
+++ b/Makefile
@@ -14,6 +14,7 @@ ELS  += rust-cargo.el
 ELS  += rust-compile.el
 ELS  += rust-playpen.el
 ELS  += rust-rustfmt.el
+ELS  += rust-utils.el
 ELCS  = $(ELS:.el=.elc)
 
 DEPS  =
diff --git a/rust-mode.el b/rust-mode.el
index d4d61d7..94604e1 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -17,8 +17,6 @@
 
 (eval-when-compile (require 'rx))
 
-(require 'thingatpt)
-
 (defvar electric-pair-inhibit-predicate)
 (defvar electric-pair-skip-self)
 (defvar electric-indent-chars)
@@ -1551,71 +1549,6 @@ This is written mainly to be used as 
`end-of-defun-function' for Rust."
     ;; There is no opening brace, so consider the whole buffer to be one 
"defun"
     (goto-char (point-max))))
 
-;;; Secondary Commands
-
-(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))))))
-
-(defun rust-insert-dbg ()
-  "Insert the dbg! macro."
-  (cond ((region-active-p)
-         (when (< (mark) (point))
-           (exchange-point-and-mark))
-         (let ((old-point (point)))
-           (insert-parentheses)
-           (goto-char old-point)))
-        (t
-         (when (rust-in-str)
-           (up-list -1 t t))
-         (insert "(")
-         (forward-sexp)
-         (insert ")")
-         (backward-sexp)))
-  (insert "dbg!"))
-
-;;;###autoload
-(defun rust-dbg-wrap-or-unwrap ()
-  "Either remove or add the dbg! macro."
-  (interactive)
-  (save-excursion
-    (if (region-active-p)
-        (rust-insert-dbg)
-
-      (let ((beginning-of-symbol (ignore-errors (beginning-of-thing 'symbol))))
-        (when beginning-of-symbol
-          (goto-char beginning-of-symbol)))
-
-      (let ((dbg-point (save-excursion
-                         (or (and (looking-at-p "dbg!") (+ 4 (point)))
-                             (ignore-errors
-                               (while (not (rust-looking-back-str "dbg!"))
-                                 (backward-up-list))
-                               (point))))))
-        (cond (dbg-point
-               (goto-char dbg-point)
-               (delete-char -4)
-               (delete-pair))
-              (t (rust-insert-dbg)))))))
-
 ;;; _
 
 (defun rust-mode-reload ()
@@ -1625,4 +1558,6 @@ visit the new file."
   (rust-mode))
 
 (provide 'rust-mode)
+(require 'rust-utils)
+
 ;;; rust-mode.el ends here
diff --git a/rust-utils.el b/rust-utils.el
new file mode 100644
index 0000000..022973b
--- /dev/null
+++ b/rust-utils.el
@@ -0,0 +1,82 @@
+;;; rust-utils.el --- Various Rust utilities        -*- lexical-binding:t -*-
+;;; Commentary:
+
+;; This library implements various utilities for dealing with Rust
+;; code.
+
+;;; Code:
+
+(require 'thingatpt)
+
+(require 'rust-mode) ; for `rust-in-str' and `rust-looking-back-str'
+
+;;; Promote module
+
+(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))))))
+
+;;; dbg! macro
+
+(defun rust-insert-dbg ()
+  "Insert the dbg! macro."
+  (cond ((region-active-p)
+         (when (< (mark) (point))
+           (exchange-point-and-mark))
+         (let ((old-point (point)))
+           (insert-parentheses)
+           (goto-char old-point)))
+        (t
+         (when (rust-in-str)
+           (up-list -1 t t))
+         (insert "(")
+         (forward-sexp)
+         (insert ")")
+         (backward-sexp)))
+  (insert "dbg!"))
+
+;;;###autoload
+(defun rust-dbg-wrap-or-unwrap ()
+  "Either remove or add the dbg! macro."
+  (interactive)
+  (save-excursion
+    (if (region-active-p)
+        (rust-insert-dbg)
+
+      (let ((beginning-of-symbol (ignore-errors (beginning-of-thing 'symbol))))
+        (when beginning-of-symbol
+          (goto-char beginning-of-symbol)))
+
+      (let ((dbg-point (save-excursion
+                         (or (and (looking-at-p "dbg!") (+ 4 (point)))
+                             (ignore-errors
+                               (while (not (rust-looking-back-str "dbg!"))
+                                 (backward-up-list))
+                               (point))))))
+        (cond (dbg-point
+               (goto-char dbg-point)
+               (delete-char -4)
+               (delete-pair))
+              (t (rust-insert-dbg)))))))
+
+;;; _
+(provide 'rust-utils)
+;;; rust-utils.el ends here



reply via email to

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