[Emacs] Add new Rust snippets, common-lisp layer
This commit adds two new snippets for Rust, one for an easier way to write a `println' macro than the default one, and another one for writing more easily new `new' functions for Rust structs. It also adds the `common-lisp' layer in Emacs so I can test StumpWM.
This commit is contained in:
parent
7345a3deae
commit
2a19478995
10
.config/emacs/private/snippets/rust-mode/new
Normal file
10
.config/emacs/private/snippets/rust-mode/new
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# -*- mode: snippet -*-
|
||||||
|
# name: new
|
||||||
|
# key: _new
|
||||||
|
# --
|
||||||
|
fn new(${1:args}) -> Self {
|
||||||
|
$0
|
||||||
|
Self {
|
||||||
|
${1:$(phundrak/yas-rust-new-assignments yas-text)}
|
||||||
|
}
|
||||||
|
}
|
5
.config/emacs/private/snippets/rust-mode/println
Normal file
5
.config/emacs/private/snippets/rust-mode/println
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# -*- mode: snippet -*-
|
||||||
|
# name: println!("{}", value);
|
||||||
|
# key: pln
|
||||||
|
# --
|
||||||
|
println!("${1:{}}", $2);
|
@ -473,6 +473,12 @@
|
|||||||
lua-lsp-emmy-enable-file-watchers t)
|
lua-lsp-emmy-enable-file-watchers t)
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
|
But that won’t stop me trying to use other window managers. I am currently
|
||||||
|
testing StumpWM, which requires the Common Lisp layer.
|
||||||
|
#+BEGIN_SRC emacs-lisp
|
||||||
|
common-lisp
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
*** Readers
|
*** Readers
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:CUSTOM_ID: Spacemacs_layers_and_packages-Layers-Readers-65e8e4ae
|
:CUSTOM_ID: Spacemacs_layers_and_packages-Layers-Readers-65e8e4ae
|
||||||
@ -1264,6 +1270,38 @@
|
|||||||
Almost all of my code snippets will be prefixed by either my name or the name
|
Almost all of my code snippets will be prefixed by either my name or the name
|
||||||
of the package or layer they are part of, unless they are an explicit
|
of the package or layer they are part of, unless they are an explicit
|
||||||
overwrite of a function that already exists.
|
overwrite of a function that already exists.
|
||||||
|
*** ~phundrak/yas-rust-new-assignments~
|
||||||
|
:PROPERTIES:
|
||||||
|
:CUSTOM_ID: User_Configuration-Custom_functions-phundrakyas-rust-new-assignments-10f73456
|
||||||
|
:END:
|
||||||
|
The following function is a function that will allow me to easily create
|
||||||
|
~new~ functions for Rust structs. Inspired from [[https://github.com/jorgenschaefer/elpy][elpy]]’s
|
||||||
|
~elpy-snippet-init-assignments~ function, it will automatically write
|
||||||
|
assignments to my new struct as I write new parameters in the ~new~
|
||||||
|
function. It also comes with a helper function that parses the arguments
|
||||||
|
given to the ~new~ function.
|
||||||
|
#+BEGIN_SRC emacs-lisp
|
||||||
|
(defun phundrak//yas-snippet-split-args (arg-string)
|
||||||
|
"Split a Rust argument string into ((name, default)...) tuples"
|
||||||
|
(mapcar (lambda (x)
|
||||||
|
(split-string x "[[:blank:]]*:[[:blank:]]*" t))
|
||||||
|
(split-string arg-string "[[:blank:]]*,[[:blank:]]*" t)))
|
||||||
|
|
||||||
|
(defun phundrak/yas-rust-new-assignments (arg-string)
|
||||||
|
"Return a typical new assignment for arguments.
|
||||||
|
|
||||||
|
Inspired from elpy’s functions https://github.com/jorgenschaefer/elpy"
|
||||||
|
(let ((identation (make-string (save-excursion
|
||||||
|
(goto-char start-point)
|
||||||
|
(current-indentation))
|
||||||
|
?\s)))
|
||||||
|
(mapconcat (lambda (arg)
|
||||||
|
(if (string-match "^\\*" (car arg))
|
||||||
|
""
|
||||||
|
(format "%s,\n%s" (car arg) identation)))
|
||||||
|
(phundrak//yas-snippet-split-args arg-string)
|
||||||
|
"")))
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
*** ~phundrak/add-all-to-list~
|
*** ~phundrak/add-all-to-list~
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
|
Loading…
Reference in New Issue
Block a user