Skip to content

Instantly share code, notes, and snippets.

@davidsm
Created Jul 9, 2014
Embed
What would you like to do?
yasnippet for variable number of key-value pairs (concept shamefully stolen from https://github.com/capitaomorte/yasnippet/issues/348)
# -*- 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