-
-
Save davidsm/f1a0711171ed0ed609fb to your computer and use it in GitHub Desktop.
yasnippet for variable number of key-value pairs (concept shamefully stolen from https://github.com/capitaomorte/yasnippet/issues/348)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: snippet -*- | |
# name: keyvalue | |
# key: kv | |
# type: command | |
# -- | |
(let ((yas-good-grace nil) | |
(count (* 2 (read-number "Number of elements: ")))) | |
(yas-expand-snippet | |
(concat "{\n" | |
"\t" | |
(mapconcat | |
#'identity | |
(mapcar (lambda (num) | |
(format "${%d:key}: ${%d:value}" num (1+ num))) | |
(number-sequence 1 count 2)) | |
",\n") | |
"\n" | |
"}\n"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment