2017-06-08 11:47:56 +02:00
|
|
|
|
;;; lang/web/autoload/html.el -*- lexical-binding: t; -*-
|
2017-02-19 18:57:16 -05:00
|
|
|
|
|
|
|
|
|
(defvar +web-entities-list
|
2017-10-17 23:56:55 +02:00
|
|
|
|
[["&" "&"] [" " " "] [" " " "] [" " " "] [" " " "]
|
2020-01-28 12:17:51 +08:00
|
|
|
|
["<" "<"] [">" ">"]
|
2017-02-19 18:57:16 -05:00
|
|
|
|
["‏" ""] ["‎" ""] ["‍" ""] ["‌" ""]
|
2017-07-04 13:09:25 +02:00
|
|
|
|
["¡" "¡"] ["¢" "¢"] ["£" "£"] ["¤" "¤"] ["¥" "¥"]
|
|
|
|
|
["¦" "¦"] ["§" "§"] ["¨" "¨"] ["©" "©"] ["ª" "ª"]
|
|
|
|
|
["«" "«"] ["¬" "¬"] ["­" ""] ["®" "®"] ["¯" "¯"]
|
|
|
|
|
["°" "°"] ["±" "±"] ["²" "²"] ["³" "³"] ["´" "´"]
|
|
|
|
|
["µ" "µ"] ["¶" "¶"] ["·" "·"] ["¸" "¸"] ["¹" "¹"]
|
|
|
|
|
["º" "º"] ["»" "»"] ["¼" "¼"] ["½" "½"]
|
|
|
|
|
["¾" "¾"] ["¿" "¿"] ["À" "À"] ["Á" "Á"]
|
|
|
|
|
["Â" "Â"] ["Ã" "Ã"] ["Ä" "Ä"] ["Å" "Å"] ["Æ" "Æ"]
|
|
|
|
|
["Ç" "Ç"] ["È" "È"] ["É" "É"] ["Ê" "Ê"]
|
|
|
|
|
["Ë" "Ë"] ["Ì" "Ì"] ["Í" "Í"] ["Î" "Î"] ["Ï" "Ï"]
|
|
|
|
|
["Ð" "Ð"] ["Ñ" "Ñ"] ["Ò" "Ò"] ["Ó" "Ó"]
|
|
|
|
|
["Ô" "Ô"] ["Õ" "Õ"] ["Ö" "Ö"] ["×" "×"] ["Ø" "Ø"]
|
|
|
|
|
["Ù" "Ù"] ["Ú" "Ú"] ["Û" "Û"] ["Ü" "Ü"]
|
|
|
|
|
["Ý" "Ý"] ["Þ" "Þ"] ["ß" "ß"] ["à" "à"] ["á" "á"]
|
|
|
|
|
["â" "â"] ["ã" "ã"] ["ä" "ä"] ["å" "å"]
|
|
|
|
|
["æ" "æ"] ["ç" "ç"] ["è" "è"] ["é" "é"] ["ê" "ê"]
|
|
|
|
|
["ë" "ë"] ["ì" "ì"] ["í" "í"] ["î" "î"]
|
|
|
|
|
["ï" "ï"] ["ð" "ð"] ["ñ" "ñ"] ["ò" "ò"] ["ó" "ó"]
|
|
|
|
|
["ô" "ô"] ["õ" "õ"] ["ö" "ö"] ["÷" "÷"] ["ø" "ø"]
|
|
|
|
|
["ù" "ù"] ["ú" "ú"] ["û" "û"] ["ü" "ü"] ["ý" "ý"]
|
|
|
|
|
["þ" "þ"] ["ÿ" "ÿ"] ["ƒ" "ƒ"] ["Α" "Α"] ["Β" "Β"]
|
|
|
|
|
["Γ" "Γ"] ["Δ" "Δ"] ["Ε" "Ε"] ["Ζ" "Ζ"] ["Η" "Η"]
|
|
|
|
|
["Θ" "Θ"] ["Ι" "Ι"] ["Κ" "Κ"] ["Λ" "Λ"] ["Μ" "Μ"]
|
|
|
|
|
["Ν" "Ν"] ["Ξ" "Ξ"] ["Ο" "Ο"] ["Π" "Π"] ["Ρ" "Ρ"]
|
|
|
|
|
["Σ" "Σ"] ["Τ" "Τ"] ["Υ" "Υ"] ["Φ" "Φ"] ["Χ" "Χ"]
|
|
|
|
|
["Ψ" "Ψ"] ["Ω" "Ω"] ["α" "α"] ["β" "β"] ["γ" "γ"]
|
|
|
|
|
["δ" "δ"] ["ε" "ε"] ["ζ" "ζ"] ["η" "η"] ["θ" "θ"]
|
|
|
|
|
["ι" "ι"] ["κ" "κ"] ["λ" "λ"] ["μ" "μ"] ["ν" "ν"]
|
|
|
|
|
["ξ" "ξ"] ["ο" "ο"] ["π" "π"] ["ρ" "ρ"] ["ς" "ς"]
|
|
|
|
|
["σ" "σ"] ["τ" "τ"] ["υ" "υ"] ["φ" "φ"] ["χ" "χ"]
|
|
|
|
|
["ψ" "ψ"] ["ω" "ω"] ["ϑ" "ϑ"] ["ϒ" "ϒ"] ["ϖ" "ϖ"]
|
|
|
|
|
["•" "•"] ["…" "…"] ["′" "′"] ["″" "″"] ["‾" "‾"]
|
|
|
|
|
["⁄" "⁄"] ["℘" "℘"] ["ℑ" "ℑ"] ["ℜ" "ℜ"] ["™" "™"]
|
|
|
|
|
["ℵ" "ℵ"] ["←" "←"] ["↑" "↑"] ["→" "→"] ["↓" "↓"]
|
|
|
|
|
["↔" "↔"] ["↵" "↵"] ["⇐" "⇐"] ["⇑" "⇑"] ["⇒" "⇒"]
|
|
|
|
|
["⇓" "⇓"] ["⇔" "⇔"] ["∀" "∀"] ["∂" "∂"] ["∃" "∃"]
|
|
|
|
|
["∅" "∅"] ["∇" "∇"] ["∈" "∈"] ["∉" "∉"] ["∋" "∋"]
|
|
|
|
|
["∏" "∏"] ["∑" "∑"] ["−" "−"] ["∗" "∗"] ["√" "√"]
|
|
|
|
|
["∝" "∝"] ["∞" "∞"] ["∠" "∠"] ["∧" "∧"] ["∨" "∨"]
|
|
|
|
|
["∩" "∩"] ["∪" "∪"] ["∫" "∫"] ["∴" "∴"] ["∼" "∼"]
|
|
|
|
|
["≅" "≅"] ["≈" "≈"] ["≠" "≠"] ["≡" "≡"] ["≤" "≤"]
|
|
|
|
|
["≥" "≥"] ["⊂" "⊂"] ["⊃" "⊃"] ["⊄" "⊄"] ["⊆" "⊆"]
|
|
|
|
|
["⊇" "⊇"] ["⊕" "⊕"] ["⊗" "⊗"] ["⊥" "⊥"] ["⋅" "⋅"]
|
|
|
|
|
["⌈" "⌈"] ["⌉" "⌉"] ["⌊" "⌊"] ["⌋" "⌋"] ["⟨" "〈"]
|
|
|
|
|
["⟩" "〉"] ["◊" "◊"] ["♠" "♠"] ["♣" "♣"]
|
|
|
|
|
["♥" "♥"] ["♦" "♦"] [""" "\""] ["Œ" "Œ"] ["œ" "œ"]
|
|
|
|
|
["Š" "Š"] ["š" "š"] ["Ÿ" "Ÿ"] ["ˆ" "ˆ"]
|
|
|
|
|
["˜" "˜"] ["–" "–"] ["—" "—"] ["‘" "‘"] ["’" "’"]
|
|
|
|
|
["‚" "‚"] ["“" "“"] ["”" "”"] ["„" "„"]
|
|
|
|
|
["†" "†"] ["‡" "‡"] ["‰" "‰"] ["‹" "‹"] ["›" "›"]
|
|
|
|
|
["€" "€"]]
|
2017-02-19 18:57:16 -05:00
|
|
|
|
"A list of sequence string pairs, representing an html entity and its decoded
|
|
|
|
|
character.")
|
|
|
|
|
|
|
|
|
|
(defun +web--entities-string (text &optional decode-p)
|
|
|
|
|
"HTML encode/decode TEXT. Based on Xah's replace HTML named entities function
|
|
|
|
|
@ http://ergoemacs.org/emacs/elisp_replace_html_entities_command.html"
|
|
|
|
|
(interactive "<!><r>")
|
2019-07-21 23:31:42 +02:00
|
|
|
|
(mapc (lambda (rep)
|
|
|
|
|
(let ((from (elt rep (if decode-p 0 1)))
|
|
|
|
|
(to (elt rep (if decode-p 1 0)))
|
|
|
|
|
case-fold-search)
|
|
|
|
|
(when (and (not (equal from " "))
|
|
|
|
|
(string-match-p (regexp-quote from) text))
|
|
|
|
|
(setq text (replace-regexp-in-string (regexp-quote from) to text t t)))))
|
|
|
|
|
+web-entities-list)
|
2017-07-03 02:57:31 +02:00
|
|
|
|
text)
|
2017-02-19 18:57:16 -05:00
|
|
|
|
|
|
|
|
|
(defun +web--entities-region (beg end &optional decode-p)
|
|
|
|
|
"HTML encode/decode the selected region. Based on Xah's replace HTML named entities
|
|
|
|
|
function @ http://ergoemacs.org/emacs/elisp_replace_html_entities_command.html"
|
|
|
|
|
(save-restriction
|
|
|
|
|
(narrow-to-region beg end)
|
2019-07-21 23:31:42 +02:00
|
|
|
|
(mapc (lambda (rep)
|
|
|
|
|
(let ((from (elt rep (if decode-p 0 1)))
|
|
|
|
|
(to (elt rep (if decode-p 1 0)))
|
|
|
|
|
case-fold-search)
|
|
|
|
|
(unless (equal from " ")
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(while (search-forward from nil t)
|
|
|
|
|
(replace-match to 'FIXEDCASE 'LITERAL)))))
|
|
|
|
|
+web-entities-list)))
|
2017-02-19 18:57:16 -05:00
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun +web-encode-entities (text)
|
|
|
|
|
"TODO"
|
|
|
|
|
(+web--entities-string text nil))
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun +web-decode-entities (text)
|
|
|
|
|
"TODO"
|
|
|
|
|
(+web--entities-string text t))
|
|
|
|
|
|
2019-05-01 19:12:52 -04:00
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
;;; Commands
|
|
|
|
|
|
2017-02-19 18:57:16 -05:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun +web/encode-entities-region (beg end)
|
|
|
|
|
"Encode HTML entities in region."
|
|
|
|
|
(interactive "r")
|
|
|
|
|
(+web--entities-region beg end))
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun +web/decode-entities-region (beg end)
|
|
|
|
|
"Decode HTML entities in region."
|
|
|
|
|
(interactive "r")
|
|
|
|
|
(+web--entities-region beg end t))
|
2018-08-01 19:25:06 +02:00
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun +web/indent-or-yas-or-emmet-expand ()
|
2019-05-01 19:12:52 -04:00
|
|
|
|
"Do-what-I-mean on TAB.
|
|
|
|
|
|
|
|
|
|
Invokes `indent-for-tab-command' if at or before text bol, `yas-expand' if on a
|
|
|
|
|
snippet, or `emmet-expand-yas'/`emmet-expand-line', depending on whether
|
2018-08-01 19:25:06 +02:00
|
|
|
|
`yas-minor-mode' is enabled or not."
|
|
|
|
|
(interactive)
|
|
|
|
|
(call-interactively
|
2020-09-01 19:35:54 -04:00
|
|
|
|
(cond ((or (<= (current-column) (current-indentation))
|
|
|
|
|
(not (eolp))
|
2020-10-05 15:35:28 -04:00
|
|
|
|
(not (or (memq (char-after) (list ?\n ?\s ?\t))
|
|
|
|
|
(eobp))))
|
2018-08-01 19:25:06 +02:00
|
|
|
|
#'indent-for-tab-command)
|
2022-08-12 20:29:19 +02:00
|
|
|
|
((modulep! :editor snippets)
|
2021-06-05 12:49:40 -04:00
|
|
|
|
(require 'yasnippet)
|
2018-08-01 19:25:06 +02:00
|
|
|
|
(if (yas--templates-for-key-at-point)
|
|
|
|
|
#'yas-expand
|
|
|
|
|
#'emmet-expand-yas))
|
|
|
|
|
(#'emmet-expand-line))))
|