diff options
| author | 2025-06-21 08:51:16 -0700 | |
|---|---|---|
| committer | 2025-06-21 08:51:16 -0700 | |
| commit | ed31162161e26377a75cf601ed8557a509c3079b (patch) | |
| tree | 96db9c37707d878ac14f80c512df90cf175247f5 /oni | |
| parent | 6067689b1f5e255f241b988c00cfe5fab670b273 (diff) | |
| download | new-dotfiles-ed31162161e26377a75cf601ed8557a509c3079b.tar.gz new-dotfiles-ed31162161e26377a75cf601ed8557a509c3079b.zip | |
Emacs: Add temporary fix for web-mode in Vue
This makes it so that some more Vue properties are recognized in web-mode as
executable code rather than HTML attributes.
Diffstat (limited to 'oni')
| -rw-r--r-- | oni/home/config/pop-os/emacs.el | 801 |
1 files changed, 801 insertions, 0 deletions
diff --git a/oni/home/config/pop-os/emacs.el b/oni/home/config/pop-os/emacs.el index d1b98b6..5c67ad1 100644 --- a/oni/home/config/pop-os/emacs.el +++ b/oni/home/config/pop-os/emacs.el @@ -250,4 +250,805 @@ buffers.") (sql-server "localhost") (sql-port 5432)))) +(with-eval-after-load 'web-mode + (defun web-mode-scan-blocks (reg-beg reg-end) + "Identifies blocks (with block-side, block-beg, block-end text properties)." + (save-excursion + + (let ((i 0) open close closing-string sub1 sub2 pos tagopen tmp delim-open delim-close part-beg part-end tagclose) + + (goto-char reg-beg) + + ;;(message "%S: %Sx%S" (point) reg-beg reg-end) + ;;(message "regexp=%S" web-mode-block-regexp) + (while (and (< i 2000) + (> reg-end (point)) + web-mode-block-regexp + (re-search-forward web-mode-block-regexp reg-end t) + (not (eobp))) + + (setq i (1+ i) + closing-string nil + close nil + tagopen (match-string 0) + open (match-beginning 0) + delim-open nil + delim-close nil + pos nil) + + (let ((l (length tagopen))) + (when (member (string-to-char tagopen) '(?\s ?\t)) + (setq tagopen (replace-regexp-in-string "\\`[ \t]*" "" tagopen)) + (setq open (+ open (- l (length tagopen)))) + (setq l (length tagopen)) + ) + (setq sub1 (substring tagopen 0 1) + sub2 (substring tagopen 0 (if (>= l 2) 2 1))) + ) + ;;(message " found block #(%S) at pos=(%S), part-type=(%S)" i open (get-text-property open 'part-side)) + (cond + + ((string= web-mode-engine "php") + (unless (member (char-after) '(?x ?X)) + (setq closing-string '("<\\?". "\\?>"))) + (cond + ((looking-at-p "<?php") + (setq delim-open "<?php") + (setq delim-close "?>")) + ((eq (char-after) ?\=) + (setq delim-open "<?=") + (setq delim-close "?>")) + (t + (setq delim-open "<?") + (setq delim-close "?>")) + ) ;cond + ) ;php + + ((string= web-mode-engine "erb") + (cond + ((string= sub2 "<%") + (setq closing-string '("<%". "%>") + delim-open "<%\\(==\\|[=-]\\)?" + delim-close "[-]?%>")) + (t + (setq closing-string "EOL" + delim-open "%")) + ) + ) ;erb + + ((string= web-mode-engine "django") + (cond + ((string= sub2 "{{") + (setq closing-string "EODQ" + ;;(setq closing-string '("{{" . "}}") + delim-open "{{" + delim-close "}}")) + ((string= sub2 "{%") + (setq closing-string "%}" + delim-open "{%[+-]?" + delim-close "[-]?%}")) + ((string= sub2 "{#") + (setq closing-string "#}")) + (t + (setq closing-string "EOL" + delim-open "#[#]?")) + ) + ) ;django + + ((string= web-mode-engine "anki") + (setq closing-string "}}" + delim-open "{{[#/^]?" + delim-close "}}") + ) ;anki + + ((string= web-mode-engine "ejs") + (setq closing-string "%>" + delim-open "<%[=-]?" + delim-close "[-]?%>") + ) ;ejs + + ((string= web-mode-engine "lsp") + (setq closing-string "%>" + delim-open "<%[%#]?" + delim-close "%>") + ) ;lsp + + ((string= web-mode-engine "mako") + (cond + ((and (string= tagopen "<%") + (member (char-after) '(?\s ?\n ?\!))) + (setq closing-string "%>" + delim-open "<%[!]?" + delim-close "%>")) + ((member sub2 '("<%" "</")) + (setq closing-string ">" + delim-open "</?%" + delim-close "/?>")) + ((string= sub2 "${") + (setq closing-string "}" + delim-open "${" + delim-close "}")) + (t + (setq closing-string "EOL" + delim-open "%")) + ) + ) ;mako + + ((string= web-mode-engine "cl-emb") + (cond + ((string= tagopen "<%#") + (setq closing-string "#%>")) + ((string= sub2 "<%") + (setq closing-string "%>" + delim-open "<%[=%]?" + delim-close "%>")) + ) + ) ;cl-emb + + ((string= web-mode-engine "artanis") + (cond + ((string= tagopen "<%;") + (setq closing-string "%>")) + ((string= tagopen "<%#|") + (setq closing-string "|#%>")) + ((string= sub2 "<@") + (setq closing-string "%>" + delim-open "<@\\(css\\|icon\\|include\\|js\\)" + delim-close "%>")) + ((string= sub2 "<%") + (setq closing-string "%>" + delim-open "<%[=]?" + delim-close "%>")) + ) + ) ;artanis + + ((string= web-mode-engine "elixir") + (cond + ((member (char-after) '(?\#)) + (setq closing-string "%>")) + (t + (setq closing-string "%>" + delim-open "<%[=%]?" + delim-close "%>")) + ) + ) ;elixir + + ((string= web-mode-engine "mojolicious") + (cond + ((string= tagopen "<%#") + (setq closing-string "%>")) + ((string= sub2 "<%") + (setq closing-string "%>" + delim-open "<%\\(==\\|[=%]\\)?" + delim-close "%>")) + ((string= sub2 "%#") + (setq closing-string "EOL")) + (t + (setq closing-string "EOL" + delim-open "%\\(==\\|[=%]\\)?")) + ) + ) ;mojolicious + + ((string= web-mode-engine "ctemplate") + (cond + ((member tagopen '("{{{" "{{~")) + (setq closing-string "}~?}}" + delim-open "{{~?{" + delim-close "}~?}}") + ) + ((string= tagopen "{~{") + (setq closing-string "}~?}" + delim-open "{~{" + delim-close "}~?}") + ) + ((string= tagopen "{{!") + (setq closing-string (if (looking-at-p "--") "--}}" "}}")) + ) + ((string= sub2 "{{") + (setq closing-string "}~?}" + delim-open "{{[>#/%^&]?" + delim-close "}~?}")) + (t + (setq closing-string "}}" + delim-open "${{" + delim-close "}}")) + ) + ) ;ctemplate + + ((string= web-mode-engine "antlers") + (cond + ((string= tagopen "{{$") + (setq closing-string "$}}" + delim-open "{{$" + delim-close "$}}") + ) + ((string= tagopen "{{?") + (setq closing-string "?}}" + delim-open "{{?" + delim-close "?}}") + ) + ((string= tagopen "{{$") + (setq closing-string "$}}" + delim-open "{{$" + delim-close "$}}") + ) + ((string= sub2 "{{") + (setq closing-string "}}" + delim-open "{{" + delim-close "}}")) + ) + ) ;antlers + + ((string= web-mode-engine "astro") + (cond + ((string= tagopen "---") + (setq closing-string "---" + delim-open "---" + delim-close "---") + ) + ) + ) ;astro + + ((string= web-mode-engine "aspx") + (setq closing-string "%>" + delim-open "<%[:=#@$]?" + delim-close "%>") + ) ;aspx + + ((string= web-mode-engine "asp") + (cond + ((string= sub2 "<%") + (setq closing-string "%>" + delim-open "<%[:=#@$]?" + delim-close "%>")) + (t + (setq closing-string ">" + delim-open "</?" + delim-close "/?>")) + ) + ) ;asp + + ((string= web-mode-engine "jsp") + (cond + ((looking-at-p "--") + (setq closing-string "--%>")) + ((string= sub2 "<%") + (setq closing-string "%>" + delim-open "<%\\([!=@]\\|#=\\)?" + delim-close "[-]?%>")) + ((string= sub2 "${") + (setq closing-string "}" + delim-open "${" + delim-close "}")) + ) + ) ;jsp + + ((string= web-mode-engine "clip") + (setq closing-string ">" + delim-open "</?" + delim-close "/?>") + ) ;clip + + ((string= web-mode-engine "perl") + (setq closing-string ">" + delim-open "</?" + delim-close "/?>") + ) ;perl + + ((string= web-mode-engine "blade") + (cond + ((string= tagopen "{{-") + (setq closing-string "--}}")) + ((string= tagopen "{!!") + (setq closing-string "!!}" + delim-open "{!!" + delim-close "!!}")) + ((string= tagopen "@{{") + (setq closing-string nil)) + ((string= tagopen "{{{") + (setq closing-string "}}}" + delim-open "{{{" + delim-close "}}}")) + ((string= sub2 "{{") + (setq closing-string "}}" + delim-open "{{" + delim-close "}}")) + ((looking-at-p "[[:alnum:]]+\\.[[:alpha:]]+") + ) + ((string= sub1 "@") + (setq closing-string "EOB" + delim-open "@")) + ((looking-at-p "[[:alnum:]]+(") + (setq closing-string ")" + delim-open "@")) + ) + ;;(message "closing-string=%S delim-open=%S delim-close=%S" closing-string delim-open delim-close) + ) ;blade + + ((string= web-mode-engine "smarty") + (cond + ((string= tagopen "{*") + (setq closing-string "*}") + ) + ((string= tagopen "{#") + (setq closing-string "#}" + delim-open "{#" + delim-close "#}") + ) + (t + (setq closing-string (cons "{" "}") + delim-open "{/?" + delim-close "}") + ) ;t + ) ;cond + ) ;smarty + + ((string= web-mode-engine "hero") + (setq closing-string "%>" + delim-open "<%==?\\([biufsv]\\|bs\\)?\\|<%[:~@+!]?" + delim-close "%>") + ) ;hero + + ((string= web-mode-engine "xoops") + (cond + ((string= tagopen "<{*") + (setq closing-string "*}>") + ) + ((string= tagopen "<{#") + (setq closing-string "#}>" + delim-open "<{#" + delim-close "#}>") + ) + (t + (setq closing-string (cons "<{" "}>") + delim-open "<{/?" + delim-close "}>") + ) ;t + ) ;cond + ) ;xoops + + ((string= web-mode-engine "web2py") + (setq closing-string "}}" + delim-open "{{[=]?" + delim-close "}}") + ) ;web2py + + ((string= web-mode-engine "expressionengine") + (cond + ((string= sub2 "{!--") + (setq closing-string "--}")) + (t + (setq closing-string '("{". "}") + delim-open "{/?" + delim-close "}") + ) + ) + ) ;expressionengine + + ((string= web-mode-engine "dust") + (cond + ((string= sub2 "{!") + (setq closing-string "!}")) + (t + (setq closing-string '("{". "}") + delim-open "{[#/:?@><+^]?" + delim-close "/?}") + ) + ) + ) ;dust + + ((string= web-mode-engine "svelte") + (cond + ((string= sub2 "{!") + (setq closing-string "!}")) + ((string= sub2 "{}") + (setq closing-string nil + delim-open nil + delim-close nil)) + (t + (setq closing-string '("{". "}") + delim-open "{[#/:?@><+^]?" + delim-close "/?}") + ) + ) + ) ;svelte + + ((string= web-mode-engine "closure") + (cond + ((string= sub2 "//") + (setq closing-string "EOL") + ) + ((string= sub2 "/*") + (setq closing-string "*/") + ) + (t + (setq closing-string "}" + delim-open "{/?" + delim-close "/?}") + ) + ) + ) ;closure + + ((string= web-mode-engine "go") + (setq closing-string "}}" + delim-open "{{-?" + delim-close "-?}}") + ) ;go + + ((string= web-mode-engine "angular") + (setq closing-string "}}" + delim-open "{{" + delim-close "}}") + ) ;angular + + ((string= web-mode-engine "vue") + (message "foo %s" tagopen) + (cond + ((string-match-p "[:@][-[:alpha:].]+=\"" tagopen) + (setq closing-string "\"" + delim-open tagopen + delim-close "\"")) + ((string= tagopen "{{") + (setq closing-string "}}" + delim-open "{{" + delim-close "}}"))) + ) ;vue + + ((string= web-mode-engine "mason") + (cond + ((and (member sub2 '("<%" "</")) + (looking-at "[[:alpha:]]+")) + (if (member (match-string-no-properties 0) '("after" "around" "augment" "before" "def" "filter" "method" "override")) + (setq closing-string ">" + delim-open "<[/]?%" + delim-close ">") + (setq closing-string (concat "</%" (match-string-no-properties 0) ">") + delim-open "<[^>]+>" + delim-close "<[^>]+>") + ) ;if + ) + ((and (string= sub2 "<%") + (eq (char-after) ?\s)) + (setq closing-string "%>" + delim-open "<%" + delim-close "%>")) + ((string= tagopen "</&") + (setq closing-string ">" + delim-open "</&" + delim-close ">") + ) + ((string= sub2 "<&") + (setq closing-string "&>" + delim-open "<&[|]?" + delim-close "&>")) + (t + (setq closing-string "EOL" + delim-open "%")) + ) + ) ;mason + + ((string= web-mode-engine "underscore") + (setq closing-string "%>" + delim-open "<%" + delim-close "%>") + ) ;underscore + + ((string= web-mode-engine "template-toolkit") + (cond + ((string= tagopen "%%#") + (setq closing-string "EOL")) + ((string= tagopen "[%#") + (setq closing-string "%]")) + (t + (setq closing-string "%]" + delim-open "\\[%[-+]?" + delim-close "[-=+]?%\\]")) + ) + ) ;template-toolkit + + ((string= web-mode-engine "freemarker") + (cond + ((and (string= sub2 "<#") (eq (char-after) ?\-)) + (setq closing-string "-->")) + ((string= sub1 "<") + (setq closing-string ">" + delim-open "</?[#@]" + delim-close "/?>")) + ((string= sub1 "[") + (setq closing-string "]" + delim-open "\\[/?[#@]" + delim-close "/?\\]")) + (t + (setq closing-string "}" + delim-open "${" + delim-close "}")) + ) + ) ;freemarker + + ((string= web-mode-engine "velocity") + (cond + ((string= sub2 "##") + (setq closing-string "EOL")) + ((string= sub2 "#*") + (setq closing-string "*#")) + (t + (setq closing-string "EOV" + delim-open "#")) + ) + ) ;velocity + + ((string= web-mode-engine "razor") + (cond + ((string= sub2 "@@") + (forward-char 2) + (setq closing-string nil)) + ((string= sub2 "@*") + (setq closing-string "*@")) + ((string= sub1 "@") + (setq closing-string "EOR" + delim-open "@")) + ((and (string= sub1 "}") + (looking-at-p "[ ]*\n")) + ;;(setq closing-string "EOC") + (save-excursion + (let (paren-pos) + (setq paren-pos (web-mode-part-opening-paren-position (1- (point)))) + (if (and paren-pos (get-text-property paren-pos 'block-side)) + (setq closing-string "EOC") + (setq closing-string nil) + ) ;if + ) ;let + ) ;save-excursion + ;;(message "%s %S %S" sub2 (point) (get-text-property (point) 'part-side)) + ) + ((string= sub1 "}") + ;;(message "%s: %s" (point) sub1) + (save-excursion + (let (paren-pos) + (setq paren-pos (web-mode-part-opening-paren-position (1- (point)))) + (if (and paren-pos (get-text-property paren-pos 'block-side)) + (setq closing-string "EOR") + (setq closing-string nil) + ) ;if + ) ;let + ) ;save-excursion + ) ;case } + ) ;cond + ) ;razor + + ((and (string= web-mode-engine "riot") + (not (get-text-property open 'part-side))) + (setq closing-string (if (string= tagopen "{") "}" "/// end script") + delim-open "{" + delim-close "}") + ) ;riot + + ((string= web-mode-engine "spip") + (cond + ((and (string= sub1 "#") + (looking-at "[A-Z0-9_]+")) + (setq closing-string (match-string-no-properties 0))) + ((string= sub1 "(") + (setq closing-string '("(" . ")"))) + ((string= sub1 "{") + (setq closing-string '("{" . "}"))) + ((string= sub2 "<:") + (setq closing-string ":>")) + (t + (setq closing-string "]")) + )) + + ((string= web-mode-engine "marko") + (setq closing-string "}" + delim-open "${" + delim-close "}") + ) ;marko + + ) ;cond + + (when closing-string + (cond + + ((listp closing-string) + (cond + ((web-mode-rsf-balanced (car closing-string) (cdr closing-string) reg-end t) + (setq close (match-end 0) + pos (point)) + ) + ((and (string= web-mode-engine "php") + (string= "<?" sub2)) + + (if (or (text-property-not-all (1+ open) (point-max) 'tag-beg nil) + (text-property-not-all (1+ open) (point-max) 'block-beg nil) + (looking-at-p "[ \t\n]*<")) + (setq close nil + delim-close nil + pos (point)) + (setq close (point-max) + delim-close nil + pos (point-max)) + ) ;if + ) ;case + ) ;cond + ) ;case listp + + ((and (string= web-mode-engine "smarty") + (string= closing-string "}")) + (goto-char open) + (setq tmp (web-mode-closing-delimiter-position + "}" + (point) + (line-end-position))) + (if tmp + (setq tmp (1+ tmp)) + (setq tmp (line-end-position))) + (goto-char tmp) + (setq close (point) + pos (point)) + ) + + ((and (member web-mode-engine '("closure")) + (string= closing-string "}")) + (when (web-mode-closure-skip reg-beg reg-end) + (setq close (point) + pos (point)) + ;;(message "close=%S pos=%S" close pos) + ) ;when + ) + + ((string= closing-string "EOB") + (web-mode-blade-skip open) + (setq close (point) + pos (point))) + + ((string= closing-string "EOL") + (end-of-line) + (setq close (point) + pos (point))) + + ((string= closing-string "EOC") + (setq close (point) + pos (point))) + + ((string= closing-string "EODQ") + (when (web-mode-django-skip reg-beg reg-end) + (setq close (point) + pos (point)) + )) + + ((string= closing-string "EOR") + (web-mode-razor-skip open) + (setq close (if (> (point) reg-end) reg-end (point)) + pos (if (> (point) reg-end) reg-end (point))) + (goto-char pos)) + + ((string= closing-string "EOV") + (web-mode-velocity-skip open) + (setq close (point) + pos (point))) + + ((and (member web-mode-engine '("ctemplate")) + (re-search-forward closing-string reg-end t)) + (setq close (match-end 0) + pos (point))) + + ((and (member web-mode-engine '("antlers")) + (re-search-forward closing-string reg-end t)) + (setq close (match-end 0) + pos (point))) + + ((and (member web-mode-engine '("astro")) + (re-search-forward closing-string reg-end t)) + (setq close (match-end 0) + pos (point))) + + ((search-forward closing-string reg-end t) + (setq close (match-end 0) + pos (point))) + ) ;cond + + (when (and close (>= reg-end pos)) + ;;(message "pos(%S) : open(%S) close(%S)" pos open close) + (put-text-property open (1+ open) 'block-beg 0) + (put-text-property open (1+ open) 'block-controls 0) + (put-text-property open close 'block-side t) + (put-text-property (1- close) close 'block-end t) + (when delim-open + (web-mode-block-delimiters-set open close delim-open delim-close)) + (web-mode-block-scan open close) + (cond + ((and (string= web-mode-engine "erb") + (looking-at-p "<%= javascript_tag do %>")) + (setq tagopen "<%= javascript_tag do %>")) + ((and (string= web-mode-engine "mojolicious") + (looking-at-p "%= javascript begin")) + (setq tagopen "%= javascript begin")) + ((and (string= web-mode-engine "mako") + (looking-at-p "<%block filter=\"collect_js\">")) + (setq tagopen "<%block filter=\"collect_js\">")) + ((and (string= web-mode-engine "mako") + (looking-at-p "<%block filter=\"collect_css\">")) + (setq tagopen "<%block filter=\"collect_css\">")) + ((and (string= web-mode-engine "django") + (looking-at-p "{% javascript %}")) + (setq tagopen "{% javascript %}")) + ((and (string= web-mode-engine "django") + (looking-at-p "{% schema %}")) + (setq tagopen "{% schema %}")) + ((and (string= web-mode-engine "django") + (looking-at-p "{% stylesheet %}")) + (setq tagopen "{% stylesheet %}")) + ) + ;;(message "%S %s" (point) tagopen) + (when (and (member tagopen '("<r:script" "<r:style" + "<c:js" "<c:css" + "<%= javascript_tag do %>" + "<%block filter=\"collect_js\">" + "<%block filter=\"collect_css\">" + "{% javascript %}" + "{% schema %}" + "{% stylesheet %}" + "%= javascript begin" + "---")) + (setq part-beg close) + (setq tagclose + (cond + ((string= tagopen "<r:script") "</r:script") + ((string= tagopen "<r:style") "</r:style") + ((string= tagopen "<c:js") "</c:js") + ((string= tagopen "<c:css") "</c:css") + ((string= tagopen "{% javascript %}") "{% endjavascript %}") + ((string= tagopen "{% schema %}") "{% endschema %}") + ((string= tagopen "{% stylesheet %}") "{% endstylesheet %}") + ((string= tagopen "%= javascript begin") "% end") + ((string= tagopen "---") "---") + ((string= tagopen "<%= javascript_tag do %>") "<% end %>") + ((member tagopen '("<%block filter=\"collect_js\">" + "<%block filter=\"collect_css\">")) "</%block") + )) + (web-mode-sf tagclose) + (setq part-end (match-beginning 0)) + (> part-end part-beg)) + ;;(message "tagopen=%S tagclose=%S end=%S" tagopen tagclose (point)) + (put-text-property part-beg part-end + 'part-side + (cond + ((member tagopen '("<r:style" "<c:css" "<%block filter=\"collect_css\">" "{% stylesheet %}")) 'css) + (t 'javascript))) + (setq pos part-beg + part-beg nil + part-end nil) + ) ;when + ) ;when close + + (if pos (goto-char pos)) + + ) ;when closing-string + + ) ;while + + (cond + ((>= i 2000) + (message "scan-blocks ** warning (%S) **" i)) + ((string= web-mode-engine "razor") + (web-mode-block-foreach reg-beg reg-end 'web-mode-block-scan)) + ((string= web-mode-engine "django") + (web-mode-scan-engine-comments reg-beg reg-end + "{% comment %}" "{% endcomment %}")) + ((string= web-mode-engine "mako") + (web-mode-scan-engine-comments reg-beg reg-end + "<%doc>" "</%doc>")) + ((string= web-mode-engine "mason") + (web-mode-scan-engine-comments reg-beg reg-end + "<%doc>" "</%doc>")) + ) ;cond + + ))) + + (setf (map-elt web-mode-engine-open-delimiter-regexps "vue") + "{{\\|[:@][-[:alpha:].]+=\"")) + (require 'oni-js) + +(with-eval-after-load 'sh-script + (require 'oni-sh)) |
