branch: elpa/jinja2-mode
commit a99762e050e6ff75f9e6ec226b06b2b1ca7d2d10
Author: Florian Mounier <[email protected]>
Commit: Florian Mounier <[email protected]>
Add end tag command
---
jinja2.el | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/jinja2.el b/jinja2.el
index ec8e20dfe6..793f6613e9 100644
--- a/jinja2.el
+++ b/jinja2.el
@@ -75,6 +75,38 @@
"json" "percent_format" "person_title"
"mail_format" "sort_by" "split"))
+(defun jinja2-html-find-open-tag ()
+ "Return open tag for closed template tag.
+
+If tags are unbalanced, raise error."
+ (if (search-backward-regexp
+ (rx "{%"
+ (* whitespace)
+ (? (group
+ "end"))
+ (group
+ (* word))
+ (group
+ (*? anything))
+ (* whitespace)
+ "%}") nil t)
+ (if (match-string 1)
+ (if (not (string= (match-string 2) (jinja2-html-find-open-tag)))
+ (error "Unmatched Jinja tag")
+ (jinja2-html-find-open-tag))
+ (match-string 2))
+ nil))
+
+(defun jinja2-html-close-tag ()
+ "Close the previously opened template tag."
+ (interactive)
+ (let ((open-tag (save-excursion (jinja2-html-find-open-tag))))
+ (if open-tag
+ (insert
+ (format "{%% end%s %%}"
+ open-tag))
+ (error "Nothing to close"))))
+
(defconst jinja2-font-lock-comments
`(
(,(rx "{#"