emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/jinja2-mode a99762e050 06/57: Add end tag command


From: ELPA Syncer
Subject: [nongnu] elpa/jinja2-mode a99762e050 06/57: Add end tag command
Date: Mon, 17 Jan 2022 05:58:22 -0500 (EST)

branch: elpa/jinja2-mode
commit a99762e050e6ff75f9e6ec226b06b2b1ca7d2d10
Author: Florian Mounier <florian.mounier@kozea.fr>
Commit: Florian Mounier <florian.mounier@kozea.fr>

    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 "{#"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]