Skip to content

Instantly share code, notes, and snippets.

@mgallego
Created January 6, 2013 22:49
Show Gist options
  • Save mgallego/4470840 to your computer and use it in GitHub Desktop.
Save mgallego/4470840 to your computer and use it in GitHub Desktop.
A few functions in emacs lisp to play with twig templates.
(defun twig-trans-text (text)
"print-a-text-in-a-twig-trans-label"
(interactive "sText:")
(insert (concat "{% trans %}" text "{% endtrans %}"))
)
(defun twig-trans-region ()
"include-a-region-between-trans-labels"
(interactive)
"print-a-text-in-a-twig-trans-label"
(goto-char (region-end))
(insert "{% endtrans %}")
(goto-char (region-beginning))
(insert "{% trans %}")
)
(defun twig-create-block (block-name)
"create-an-empty-block"
(interactive "sBlock-Name:")
(insert (concat "{% block " block-name " %}"))
(newline)
(newline)
(insert (concat "{% endblock " block-name " %}"))
(previous-line)
)
(defun twig-for (variable in-variable)
"create-a-for-block"
(interactive
(list
(read-string "Variable:")
(read-string "In variable:")
))
(insert (concat "{% for " variable " in " in-variable " %}"))
(newline)
(setq point-to-insert (point))
(newline)
(insert "{% else %}")
(newline)
(insert (concat "{% endfor %}"))
(goto-char point-to-insert)
)
(defun twig-insert-variable (var-name)
"insert-a-variable"
(interactive
(list
(read-string "Variable:")
))
(insert (concat "{{ " var-name " }}"))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment