Skip to content

Instantly share code, notes, and snippets.

@davidsm
Created July 9, 2014 18:15
Show Gist options
  • Save davidsm/f1a0711171ed0ed609fb to your computer and use it in GitHub Desktop.
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)
# -*- 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