[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:
Lucien Cartier-Tilet 2020-08-24 14:41:09 +02:00
parent 7345a3deae
commit 2a19478995
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA
3 changed files with 53 additions and 0 deletions

View 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)}
}
}

View File

@ -0,0 +1,5 @@
# -*- mode: snippet -*-
# name: println!("{}", value);
# key: pln
# --
println!("${1:{}}", $2);

View File

@ -473,6 +473,12 @@
lua-lsp-emmy-enable-file-watchers t)
#+END_SRC
But that wont 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
:PROPERTIES:
: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
of the package or layer they are part of, unless they are an explicit
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 elpys 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~
:PROPERTIES: