emacs - Replacing yasnippet fields by entries from a list -
recently stumbled across question "a quick way repeatedly enter variable name in emacs?" asks way create , expand snippets "on-the-fly". found package auto-yasnippet created author of question , result of question. package much, expanded functionality. package allows following:
you write following snippet:
convert img$1.jpg -monochrome -resize 50% -rotate 180 img$1_mono.pdf
call aya-create
, enter new line , call aya-expand
: above code pasted , can replace placeholders ($1
, $2
, ...) ordinary yasnippet.
this great feature, however, if have create many copies of snippet , enter expansion string becomes not fun. nice pass list (or list of lists if have multiple placeholders) used expand placeholders. lets have call above thing files img_1.jpg
img_9.jpg
, results should called img_a_mono.jpg
img_k_mono.jpg
, 1 create list:
(setq foo-list '( '( 1 2 3 4 5 6 7 8 9 ) '( b c d e f g h j k ) )
write snippet
convert img$1.jpg -monochrome -resize 50% -rotate 180 img$2_mono.pdf
and call expansion function specifying foo-list
argument. [of course 1 might create these lists on fly function number-sequence
]
i afraid i'm not proficient enough elips code myself, however, maybe has skills , sees use of feature.
i've written package job describe. relevant snippet is:
m1\n10&convert img&s.jpg -monochrome -resize 50% -rotate 180 img&s_mono.pdf
it expands to
convert img1.jpg -monochrome -resize 50% -rotate 180 img1_mono.pdf convert img2.jpg -monochrome -resize 50% -rotate 180 img2_mono.pdf convert img3.jpg -monochrome -resize 50% -rotate 180 img3_mono.pdf convert img4.jpg -monochrome -resize 50% -rotate 180 img4_mono.pdf convert img5.jpg -monochrome -resize 50% -rotate 180 img5_mono.pdf convert img6.jpg -monochrome -resize 50% -rotate 180 img6_mono.pdf convert img7.jpg -monochrome -resize 50% -rotate 180 img7_mono.pdf convert img8.jpg -monochrome -resize 50% -rotate 180 img8_mono.pdf convert img9.jpg -monochrome -resize 50% -rotate 180 img9_mono.pdf convert img10.jpg -monochrome -resize 50% -rotate 180 img10_mono.pdf
the syntax follows:
m[<range start:=0>][<separator:= >]<range end>[lisp expr][&][format expr]
x
default var in elisp expression. take 1 one value of numbers in range.
&
means elisp expr has ended , format expr has begun. can used part of format expr if there's one. keys same format
: translate & %.
you can find more snippets in comment section of tiny.el
.
upd: expr can return list
following suggestions, here's next improvement. 1 without auxiliary var(96 value of (- ?a 1)
):
m1\n10listx+x96&convert img&s.jpg -monochrome -resize 50% -rotate 180 img&c_mono.pdf
this 1 auxiliary var. first define (using tiny
, of course:):
(setq foo-list '(m 10+x97&?&c))
expand to
(setq foo-list '(?a ?b ?c ?d ?e ?f ?g ?h ?i ?j ?k))
and here's how use it:
m1\n10listxnthxfoo-list&convert img&s.jpg -monochrome -resize 50% -rotate 180 img&c_mono.pdf
the expansion be
convert img1.jpg -monochrome -resize 50% -rotate 180 imga_mono.pdf convert img2.jpg -monochrome -resize 50% -rotate 180 imgb_mono.pdf convert img3.jpg -monochrome -resize 50% -rotate 180 imgc_mono.pdf convert img4.jpg -monochrome -resize 50% -rotate 180 imgd_mono.pdf convert img5.jpg -monochrome -resize 50% -rotate 180 imge_mono.pdf convert img6.jpg -monochrome -resize 50% -rotate 180 imgf_mono.pdf convert img7.jpg -monochrome -resize 50% -rotate 180 imgg_mono.pdf convert img8.jpg -monochrome -resize 50% -rotate 180 imgh_mono.pdf convert img9.jpg -monochrome -resize 50% -rotate 180 imgi_mono.pdf convert img10.jpg -monochrome -resize 50% -rotate 180 imgj_mono.pdf
Comments
Post a Comment