Function: web-mode-block-controls-set

web-mode-block-controls-set is a natively compiled function defined in web-mode.el.

Signature

(web-mode-block-controls-set REG-BEG REG-END)

Source Code

;; Defined in /nix/store/2qgnz1rp30nzfz6w0apx4kdm14if1bbs-emacs-packages-deps/share/emacs/site-lisp/elpa/web-mode-20260831.219/web-mode.el
(defun web-mode-block-controls-set (reg-beg reg-end)
  (save-excursion
    (goto-char reg-beg)
    (let (controls pos type control)

      (cond

        ((null web-mode-engine)
         (message "block-controls-set ** unknown engine (%S) **" web-mode-engine)
         )

        ((string= web-mode-engine "php")
         (setq controls (web-mode-set-php-controls reg-beg reg-end))
         (when (web-mode-block-starts-with "}" reg-beg)
           (setq controls (append controls (list (cons 'close "{")))))
         (when (web-mode-block-ends-with (cons "{" "}") reg-beg)
           (setq controls (append controls (list (cons 'open "{")))))
         ) ;php

        ((string= web-mode-engine "ejs")
         (cond
           ((web-mode-block-ends-with "}[ ]*else[ ]*{" reg-beg)
            (setq controls (append controls (list (cons 'inside "{")))))
           ((web-mode-block-starts-with "}" reg-beg)
            (setq controls (append controls (list (cons 'close "{")))))
           ((web-mode-block-ends-with "{" reg-beg)
            (setq controls (append controls (list (cons 'open "{")))))
           )
         ) ;ejs

        ((string= web-mode-engine "erb")
         (cond
           ((web-mode-block-starts-with "else\\|elsif\\|when" reg-beg)
            (setq controls (append controls (list (cons 'inside "ctrl")))))
           ((web-mode-block-starts-with "end" reg-beg)
            (setq controls (append controls (list (cons 'close "ctrl")))))
           ((web-mode-block-ends-with " do\\( |.*|\\)?" reg-beg)
            (setq controls (append controls (list (cons 'open "ctrl")))))
           ((and (web-mode-block-starts-with "\\(for\\|if\\|unless\\|case\\)\\_>" reg-beg)
                 (not (web-mode-block-ends-with "end" reg-end)))
            (setq controls (append controls (list (cons 'open "ctrl")))))
           )
         ) ;erb

        ((string= web-mode-engine "django")
         (cond
           ((and (string= web-mode-minor-engine "jinja") ;#504
                 (web-mode-block-starts-with "else\\_>" reg-beg))
            (let ((continue t)
                  (pos reg-beg)
                  (ctrl nil))
              (while continue
                (cond
                  ((null (setq pos (web-mode-block-control-previous-position 'open pos)))
                   (setq continue nil))
                  ((member (setq ctrl (cdr (car (get-text-property pos 'block-controls)))) '("if" "ifequal" "ifnotequal" "for"))
                   (setq continue nil)
                   )
                  ) ;cond
                )
              (setq controls (append controls (list (cons 'inside (or ctrl "if")))))
              )
            )
           ((web-mode-block-starts-with "form_start[ ]*(" reg-beg)
            (setq controls (append controls (list (cons 'open "form_start")))))
           ((web-mode-block-starts-with "form_end[ ]*(" reg-beg)
            (setq controls (append controls (list (cons 'close "form_start")))))
           ((not (eq (char-after (1+ reg-beg)) ?\%))
            )
           ((web-mode-block-starts-with "\\(else\\|els?if\\)" reg-beg)
            (let ((continue t)
                  (pos reg-beg)
                  (ctrl nil))
              (while continue
                (cond
                  ((null (setq pos (web-mode-block-control-previous-position 'open pos)))
                   (setq continue nil))
                  ((member (setq ctrl (cdr (car (get-text-property pos 'block-controls)))) '("if" "ifequal" "ifnotequal"))
                   (setq continue nil)
                   )
                  ) ;cond
                ) ;while
              (setq controls (append controls (list (cons 'inside (or ctrl "if")))))
              ) ;let
            ) ;case else
           ((web-mode-block-starts-with "\\(empty\\)" reg-beg)
            (setq controls (append controls (list (cons 'inside "for")))))
           ((web-mode-block-starts-with "end\\([[:alpha:]]+\\)" reg-beg)
            (setq controls (append controls (list (cons 'close (match-string-no-properties 1))))))
           ((web-mode-block-starts-with "set [[:alpha:]]+[ ]*%}" reg-beg)
            (setq controls (append controls (list (cons 'open "set")))))
           ((web-mode-block-starts-with (concat web-mode-django-control-blocks-regexp "[ %]") reg-beg)
            (let (control)
              (setq control (match-string-no-properties 1))
              ;;(message "%S %S %S" control (concat "end" control) web-mode-django-control-blocks)
              (when (member (concat "end" control) web-mode-django-control-blocks)
                (setq controls (append controls (list (cons 'open control))))
                ) ;when
              ) ;let
            ) ;case
           ) ;cond
         ) ;django

        ((string= web-mode-engine "smarty")
         (cond
           ((and (eq (char-after (1+ reg-beg)) ?\/)
                 (web-mode-block-starts-with "\\([[:alpha:]]+\\)" reg-beg))
            (setq controls (append controls (list (cons 'close (match-string-no-properties 1))))))
           ((web-mode-block-starts-with "\\(else\\|elseif\\)" reg-beg)
            (setq controls (append controls (list (cons 'inside "if")))))
           ((web-mode-block-starts-with "\\(block\\|foreach\\|for\\|if\\|section\\|while\\)")
            (setq controls (append controls (list (cons 'open (match-string-no-properties 1))))))
           )
         ) ;smarty

        ((string= web-mode-engine "expressionengine")
         (cond
           ((and (eq (char-after (1+ reg-beg)) ?\/)
                 (web-mode-block-starts-with "\\(if\\)" reg-beg))
            (setq controls (append controls (list (cons 'close (match-string-no-properties 1))))))
           ((web-mode-block-starts-with "\\(if:else\\|if:ifelse\\)" reg-beg)
            (setq controls (append controls (list (cons 'inside "if")))))
           ((web-mode-block-starts-with "\\(if\\)")
            (setq controls (append controls (list (cons 'open (match-string-no-properties 1))))))
           )
         ) ;expressionengine

        ((string= web-mode-engine "xoops")
         (cond
           ((and (eq (char-after (+ reg-beg 2)) ?\/)
                 (web-mode-block-starts-with "\\([[:alpha:]]+\\)" reg-beg))
            (setq controls (append controls (list (cons 'close (match-string-no-properties 1))))))
           ((web-mode-block-starts-with "\\(else\\|elseif\\)" reg-beg)
            (setq controls (append controls (list (cons 'inside "if")))))
           ((web-mode-block-starts-with "\\(block\\|foreach\\|for\\|if\\|section\\|while\\)")
            (setq controls (append controls (list (cons 'open (match-string-no-properties 1))))))
           )
         ) ;xoops

        ((string= web-mode-engine "web2py")
         (cond
           ((web-mode-block-starts-with "def" reg-beg)
            (setq controls (append controls (list (cons 'open "def")))))
           ((web-mode-block-starts-with "return" reg-beg)
            (setq controls (append controls (list (cons 'close "def")))))
           ((web-mode-block-starts-with "block" reg-beg)
            (setq controls (append controls (list (cons 'open "block")))))
           ((web-mode-block-starts-with "end" reg-beg)
            (setq controls (append controls (list (cons 'close "block")))))
           ((web-mode-block-starts-with "pass" reg-beg)
            (setq controls (append controls (list (cons 'close "ctrl")))))
           ((web-mode-block-starts-with "\\(except\\|finally\\|els\\)" reg-beg)
            (setq controls (append controls (list (cons 'inside "ctrl")))))
           ((web-mode-block-starts-with "\\(if\\|for\\|try\\|while\\)")
            (setq controls (append controls (list (cons 'open "ctrl")))))
           )
         ) ;web2py

        ((string= web-mode-engine "dust")
         (cond
           ((eq (char-after (1- reg-end)) ?\/)
            )
           ((eq (char-after (1+ reg-beg)) ?\:)
            (setq pos (web-mode-block-control-previous-position 'open reg-beg))
            (when pos
              (setq controls (append controls
                                     (list
                                      (cons 'inside
                                            (cdr (car (web-mode-block-controls-get pos))))))))
            )
           ((looking-at "{/\\([[:alpha:].]+\\)")
            (setq controls (append controls (list (cons 'close (match-string-no-properties 1))))))
           ((looking-at "{[#?@><+^]\\([[:alpha:].]+\\)")
            (setq controls (append controls (list (cons 'open (match-string-no-properties 1))))))
           )
         ) ;dust

        ((string= web-mode-engine "anki")
         (cond
           ((looking-at "{{[#^]\\([[:alpha:].]+\\)")
            (setq controls (append controls (list (cons 'open (match-string-no-properties 1))))))
           ((looking-at "{{/\\([[:alpha:].]+\\)")
            (setq controls (append controls (list (cons 'close (match-string-no-properties 1))))))
           )
         ) ;anki

        ((member web-mode-engine '("mojolicious"))
         (cond
           ((web-mode-block-ends-with "begin" reg-beg)
            (setq controls (append controls (list (cons 'open "begin")))))
           ((web-mode-block-starts-with "end" reg-beg)
            (setq controls (append controls (list (cons 'close "begin")))))
           ((web-mode-block-starts-with "}[ ]*else[ ]*{" reg-beg)
            (setq controls (append controls (list (cons 'inside "{")))))
           ((web-mode-block-starts-with "}" reg-beg)
            (setq controls (append controls (list (cons 'close "{")))))
           ((web-mode-block-ends-with "{" reg-beg)
            (setq controls (append controls (list (cons 'open "{")))))
           )
         ) ;mojolicious

        ((member web-mode-engine '("aspx" "underscore"))
         (cond
           ((and (web-mode-block-starts-with "}" reg-beg)
                 (web-mode-block-ends-with "{" reg-beg))
            (setq controls (append controls (list (cons 'inside "{")))))
           ((web-mode-block-starts-with "}" reg-beg)
            (setq controls (append controls (list (cons 'close "{")))))
           ((web-mode-block-ends-with "{" reg-beg)
            (setq controls (append controls (list (cons 'open "{")))))
           )
         ) ;aspx underscore

        ((member web-mode-engine '("jsp" "asp" "clip" "perl"))
         (cond
           ((eq (char-after (1- reg-end)) ?\/)
            )
           ((looking-at "<TMPL_ELSE")
            (setq controls (append controls (list (cons 'inside "TMPL_IF")))))
           ((looking-at "</?\\([[:alpha:]]+\\(?:[:.][[:alpha:]]+\\)\\|[[:alpha:]]+Template\\|TMPL_[[:alpha:]]+\\)")
            (setq control (match-string-no-properties 1)
                  type (if (eq (aref (match-string-no-properties 0) 1) ?\/) 'close 'open))
            (when (not (member control '("h:inputtext" "jsp:usebean" "jsp:forward" "struts:property")))
              (setq controls (append controls (list (cons type control)))))
            )
           (t
            (when (web-mode-block-starts-with "}" reg-beg)
              (setq controls (append controls (list (cons 'close "{")))))
            (when (web-mode-block-ends-with "{" reg-beg)
              (setq controls (append controls (list (cons 'open "{")))))
            )
           )
         ) ;jsp asp

        ((string= web-mode-engine "mako")
         (cond
           ((looking-at "</?%\\([[:alpha:]]+\\(?:[:][[:alpha:]]+\\)?\\)")
            (cond
              ((eq (char-after (- (web-mode-block-end-position reg-beg) 1)) ?\/)
               )
              (t
               (setq control (match-string-no-properties 1)
                     type (if (eq (aref (match-string-no-properties 0) 1) ?\/) 'close 'open))
               (setq controls (append controls (list (cons type control)))))
              )
            )
           ((web-mode-block-starts-with "\\(else\\|elif\\)" reg-beg)
            (setq controls (append controls (list (cons 'inside "if")))))
           ((web-mode-block-starts-with "end\\(if\\|for\\)" reg-beg)
            (setq controls (append controls (list (cons 'close (match-string-no-properties 1))))))
           ((and (web-mode-block-starts-with "if\\|for" reg-beg)
                 (web-mode-block-ends-with ":" reg-beg))
            (setq controls (append controls (list (cons 'open (match-string-no-properties 0))))))
           )
         ) ;mako

        ((string= web-mode-engine "mason")
         (cond
           ((looking-at "</?%\\(after\\|around\\|augment\\|before\\|def\\|filter\\|method\\|override\\)")
            (setq control (match-string-no-properties 1)
                  type (if (eq (aref (match-string-no-properties 0) 1) ?\/) 'close 'open))
            (setq controls (append controls (list (cons type control))))
            )
           )
         ) ;mason

        ((string= web-mode-engine "ctemplate")
         (cond
           ((looking-at-p "{{else") ;#721
            (let ((continue t)
                  (pos reg-beg)
                  (ctrl nil))
              (while continue
                (cond
                  ((null (setq pos (web-mode-block-control-previous-position 'open pos)))
                   (setq continue nil))
                  ((member (setq ctrl (cdr (car (get-text-property pos 'block-controls)))) '("if" "each"))
                   (setq continue nil)
                   )
                  ) ;cond
                ) ;while
              (setq controls (append controls (list (cons 'inside (or ctrl "if")))))
              )
            )

           ((looking-at "{{[#^/][ ]*\\([[:alpha:]_.-]+\\)")
            (setq control (match-string-no-properties 1)
                  type (if (eq (aref (match-string-no-properties 0) 2) ?\/) 'close 'open))
            (setq controls (append controls (list (cons type control))))
            )
           )
         ) ;ctemplate

        ((string= web-mode-engine "antlers")
         (cond
           ((web-mode-block-starts-with "\\(else\\|elseif\\)" reg-beg)
            (setq controls (append controls (list (cons 'inside "if")))))
           ((looking-at  "{{[ ]*/?\\(if\\|unless\\)")
            (setq control (match-string-no-properties 1)
                  type (if (eq (aref (match-string-no-properties 0) 3) ?\/) 'close 'open))
            (setq controls (append controls (list (cons type control))))
            )
           )
         ) ;antlers

        ((string= web-mode-engine "blade")
         (cond
           ((not (eq (char-after) ?\@))
            )
           ((web-mode-block-starts-with
             "section\(\s*\\(['\"]\\).*\\1\s*,\s*\\(['\"]\\).*\\2\s*\)" reg-beg)
            )
           ((web-mode-block-starts-with "case\\|break" reg-beg)
            (setq type (if (eq (aref (match-string-no-properties 0) 0) ?b) 'close 'open))
            (setq controls (append controls (list (cons type "case"))))
            )
           ((web-mode-block-starts-with
             (concat "\\(?:end\\)?\\(" web-mode-blade-control-blocks-regexp "\\)")
             reg-beg)
            (setq control (match-string-no-properties 1)
                  type (if (eq (aref (match-string-no-properties 0) 0) ?e) 'close 'open))
            (setq controls (append controls (list (cons type control))))
            )
           ((web-mode-block-starts-with "stop\\|show\\|overwrite" reg-beg)
            (setq controls (append controls (list (cons 'close "section")))))
           ((web-mode-block-starts-with "else\\|elseif" reg-beg)
            (setq controls (append controls (list (cons 'inside "if")))))
           ((web-mode-block-starts-with "empty" reg-beg)
            (setq controls (append controls (list (cons 'inside "forelse")))))
           )
         ) ;blade

        ((string= web-mode-engine "closure")
         (cond
           ((eq (char-after (1- reg-end)) ?\/)
            )
           ((looking-at "alias\\|namespace")
            )
           ((web-mode-block-starts-with "ifempty" reg-beg)
            (setq controls (append controls (list (cons 'inside "foreach")))))
           ((web-mode-block-starts-with "else\\|elseif" reg-beg)
            (setq controls (append controls (list (cons 'inside "if")))))
           ((web-mode-block-starts-with "case\\|default" reg-beg)
            (setq controls (append controls (list (cons 'inside "switch")))))
           ((looking-at
             "{/?\\(call\\|deltemplate\\|for\\|foreach\\|if\\|let\\|literal\\|msg\\|param\\|switch\\|template\\)")
            (setq control (match-string-no-properties 1)
                  type (if (eq (aref (match-string-no-properties 0) 1) ?\/) 'close 'open))
            (setq controls (append controls (list (cons type control))))
            )
           )
         ) ;closure

        ((string= web-mode-engine "go")
         (cond
           ((web-mode-block-starts-with "end\\_>" reg-beg)
            (setq controls (append controls (list (cons 'close "ctrl")))))
           ((web-mode-block-starts-with "else\\_>" reg-beg)
            (setq controls (append controls (list (cons 'inside "ctrl")))))
           ((web-mode-block-starts-with "\\(range\\|with\\|if\\|define\\|block\\)\\_>" reg-beg)
            (setq controls (append controls (list (cons 'open "ctrl")))))
           )
         ) ;go

        ((string= web-mode-engine "template-toolkit")
         (cond
           ((web-mode-block-starts-with "end" reg-beg)
            (setq controls (append controls (list (cons 'close "ctrl")))))
           ((web-mode-block-starts-with "els\\|catch\\|final" reg-beg)
            (setq controls (append controls (list (cons 'inside "ctrl")))))
           ((web-mode-block-starts-with "filter\\|foreach\\|if\\|last\\|next\\|perl\\|rawperl\\|try\\|unless\\|while" reg-beg)
            (setq controls (append controls (list (cons 'open "ctrl")))))
           )
         ) ;template-toolkit

        ((string= web-mode-engine "cl-emb")
         (cond
           ((web-mode-block-starts-with "@else" reg-beg)
            (setq controls (append controls (list (cons 'inside "if")))))
           ((web-mode-block-starts-with "@\\(?:end\\)?\\(if\\|unless\\|repeat\\|loop\\|with\\|genloop\\)" reg-beg)
            (setq control (match-string-no-properties 1)
                  type (if (eq (aref (match-string-no-properties 0) 1) ?e) 'close 'open))
            (setq controls (append controls (list (cons type control)))))
           )
         ) ;cl-emb

        ((string= web-mode-engine "elixir")
         (cond
           ((web-mode-block-starts-with "end" reg-beg)
            (setq controls (append controls (list (cons 'close "ctrl")))))
           ((web-mode-block-starts-with "else" reg-beg)
            (setq controls (append controls (list (cons 'inside "ctrl")))))
           ((web-mode-block-ends-with " do" reg-beg)
            (setq controls (append controls (list (cons 'open "ctrl")))))
           ((web-mode-block-ends-with " ->" reg-beg)
            (setq controls (append controls (list (cons 'open "ctrl")))))
           )
         ) ;elixir

        ((string= web-mode-engine "velocity")
         (cond
           ((web-mode-block-starts-with "{?end" reg-beg)
            (setq controls (append controls (list (cons 'close "ctrl")))))
           ((web-mode-block-starts-with "{?els" reg-beg)
            (setq controls (append controls (list (cons 'inside "ctrl")))))
           ((web-mode-block-starts-with "{?\\(def\\|if\\|for\\|foreach\\|macro\\)" reg-beg)
            ;;((web-mode-block-starts-with "{?\\(define\\|\\|if\\|for\\|foreach\\|macro\\)" reg-beg)
            (setq controls (append controls (list (cons 'open "ctrl")))))
           )
         ) ;velocity

        ((string= web-mode-engine "freemarker")
         (cond
           ((looking-at "[<[]#\\(import\\|include\\|assign\\|return\\|local\\)")
            )
           ((eq (char-after (1- reg-end)) ?\/)
            )
           ((looking-at "[<[]#\\(break\\|case\\|default\\)")
            (setq controls (append controls (list (cons 'inside "switch"))))
            )
           ((looking-at "[<[]#els")
            (setq controls (append controls (list (cons 'inside "if"))))
            )
           ((looking-at "</?\\([[:alpha:]]+\\(?:[:][[:alpha:]]+\\)?\\)")
            (setq control (match-string-no-properties 1)
                  type (if (eq (aref (match-string-no-properties 0) 1) ?\/) 'close 'open))
            (setq controls (append controls (list (cons type control))))
            )
           ((looking-at "[<[]/?\\(@\\)")
            (setq control (match-string-no-properties 1)
                  type (if (eq (aref (match-string-no-properties 0) 1) ?\/) 'close 'open))
            (setq controls (append controls (list (cons type control))))
            )
           ((looking-at "[<[]/?#\\([[:alpha:]]+\\(?:[:][[:alpha:]]+\\)?\\)")
            (setq control (match-string-no-properties 1)
                  type (if (eq (aref (match-string-no-properties 0) 1) ?\/) 'close 'open))
            (setq controls (append controls (list (cons type control))))
            )
           (t
            (when (web-mode-block-starts-with "}" reg-beg)
              (setq controls (append controls (list (cons 'close "{")))))
            (when (web-mode-block-ends-with "{" reg-beg)
              (setq controls (append controls (list (cons 'open "{")))))
            )
           )
         ) ;freemarker

        ((string= web-mode-engine "razor")
         (when (web-mode-block-starts-with "}" reg-beg)
           (setq controls (append controls (list (cons 'close "{")))))
         (when (web-mode-block-ends-with "{" reg-beg)
           (setq controls (append controls (list (cons 'open "{")))))
         ) ;razor

        ((string= web-mode-engine "lsp")
         (when (web-mode-block-starts-with ")" reg-beg)
           (setq controls (append controls (list (cons 'close "(")))))
         (when (web-mode-block-is-opened-sexp reg-beg reg-end)
           (setq controls (append controls (list (cons 'open "(")))))
         ) ;lsp

        ((string= web-mode-engine "hero")
         (cond
           ((web-mode-block-ends-with "}[ ]*else[ ]*{" reg-beg)
            (setq controls (append controls (list (cons 'inside "{")))))
           ((web-mode-block-starts-with "}" reg-beg)
            (setq controls (append controls (list (cons 'close "{")))))
           ((web-mode-block-ends-with "{" reg-beg)
            (setq controls (append controls (list (cons 'open "{")))))
           )
         ) ;hero

        ((string= web-mode-engine "svelte")
         (cond
           ((eq (char-after (1- reg-end)) ?\/)
            )
           ((eq (char-after (1+ reg-beg)) ?\:)
            (setq pos (web-mode-block-control-previous-position 'open reg-beg))
            (when pos
              (setq controls (append controls
                                     (list
                                      (cons 'inside
                                            (cdr (car (web-mode-block-controls-get pos))))))))
            )
           ((looking-at "{/\\([[:alpha:].]+\\)")
            (setq controls (append controls (list (cons 'close (match-string-no-properties 1))))))
           ((looking-at "{[#?><+^]\\([[:alpha:].]+\\)")
            (setq controls (append controls (list (cons 'open (match-string-no-properties 1))))))
           )
         ) ;svelte

        ) ;cond engine

      (put-text-property reg-beg (1+ reg-beg) 'block-controls controls)
      ;;(message "(%S) controls=%S" reg-beg controls)

      )))