diff options
| author | Simeon Simeonov | 2026-07-22 11:10:34 +0200 |
|---|---|---|
| committer | Simeon Simeonov | 2026-07-22 11:10:34 +0200 |
| commit | 85601f50f236686da662b1b00e01df0a0abe761b (patch) | |
| tree | ab188e994e2bc569e0f4291c8428e13721245ebe /.emacs.d/lisp/rust-utils.el | |
| parent | 5ae7014a54984c194f103d406f9fbdbafb277885 (diff) | |
Update markdown-mode, rust-mode and yaml-mode. Remove unused snippets
Diffstat (limited to '.emacs.d/lisp/rust-utils.el')
| -rw-r--r-- | .emacs.d/lisp/rust-utils.el | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/.emacs.d/lisp/rust-utils.el b/.emacs.d/lisp/rust-utils.el index d93bd0a..b0b0ae1 100644 --- a/.emacs.d/lisp/rust-utils.el +++ b/.emacs.d/lisp/rust-utils.el | |||
| @@ -108,15 +108,38 @@ if not. Move cursor to the end of macro." | |||
| 108 | ) | 108 | ) |
| 109 | ) | 109 | ) |
| 110 | 110 | ||
| 111 | ;;;###autoload | ||
| 111 | (defun rust-toggle-mutability () | 112 | (defun rust-toggle-mutability () |
| 112 | "Toggles the mutability of the variable defined on the current line" | 113 | "Toggle the mutability of the binding or reference near point. |
| 114 | Handles `let' <-> `let mut' and `&' <-> `&mut' (including `&self')." | ||
| 113 | (interactive) | 115 | (interactive) |
| 114 | (save-excursion | 116 | (save-excursion |
| 115 | (back-to-indentation) | 117 | (let ((line-start (line-beginning-position)) |
| 116 | (forward-word) | 118 | (line-end (line-end-position))) |
| 117 | (if (string= " mut" (buffer-substring (point) (+ (point) 4))) | 119 | (cond |
| 118 | (delete-region (point) (+ (point) 4)) | 120 | ;; Remove: &mut -> & |
| 119 | (insert " mut")))) | 121 | ((search-backward "&mut " line-start t) |
| 122 | (forward-char 1) | ||
| 123 | (delete-region (point) (+ (point) 4))) | ||
| 124 | ;; Remove: let mut -> let | ||
| 125 | ((progn (goto-char (line-beginning-position)) | ||
| 126 | (re-search-forward "\\_<let mut\\_>" line-end t)) | ||
| 127 | (replace-match "let")) | ||
| 128 | ;; Add: & -> &mut | ||
| 129 | ((progn (goto-char (line-end-position)) | ||
| 130 | (search-backward "& " line-start t)) | ||
| 131 | (forward-char 1) | ||
| 132 | (insert "mut ")) | ||
| 133 | ;; Add: &self -> &mut self | ||
| 134 | ((progn (goto-char (line-end-position)) | ||
| 135 | (search-backward "&self" line-start t)) | ||
| 136 | (forward-char 1) | ||
| 137 | (insert "mut ")) | ||
| 138 | ;; Add: let -> let mut | ||
| 139 | ((progn (goto-char (line-beginning-position)) | ||
| 140 | (re-search-forward "\\_<let\\_>" line-end t)) | ||
| 141 | (insert " mut")) | ||
| 142 | (t (message "No mutable/immutable binding or reference found on this line")))))) | ||
| 120 | ;;; _ | 143 | ;;; _ |
| 121 | (provide 'rust-utils) | 144 | (provide 'rust-utils) |
| 122 | ;;; rust-utils.el ends here | 145 | ;;; rust-utils.el ends here |
