doomemacs/modules/lang/web/autoload/html.el
Henrik Lissner c7254e7bdc
Major optimization refactor, across the board
+ enable lexical-scope everywhere (lexical-binding = t): ~5-10% faster
  startup; ~5-20% general boost
+ reduce consing, function calls & garbage collection by preferring
  cl-loop & dolist over lambda closures (for mapc[ar], add-hook, and
  various cl-lib filter/map/reduce functions) -- where possible
+ prefer functions with dedicated opcodes, like assq (see byte-defop's
  in bytecomp.el for more)
+ prefer pcase & cond (faster) over cl-case
+ general refactor for code readability
+ ensure naming & style conventions are adhered to
+ appease byte-compiler by marking unused variables with underscore
+ defer minor mode activation to after-init, emacs-startup or
  window-setup hooks; a customization opportunity for users + ensures
  custom functionality won't interfere with startup.
2017-06-09 00:47:45 +02:00

57 lines
5.8 KiB
EmacsLisp
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

;;; lang/web/autoload/html.el -*- lexical-binding: t; -*-
;;;###autoload
(defvar +web-entities-list
[[" " " "] [" " ""] [" " ""] [" " ""]
["‏" ""] ["‎" ""] ["‍" ""] ["‌" ""]
["¡" "¡"] ["¢" "¢"] ["£" "£"] ["¤" "¤"] ["¥" "¥"] ["¦" "¦"] ["§" "§"] ["¨" "¨"] ["©" "©"] ["ª" "ª"] ["«" "«"] ["¬" "¬"] ["­" "­"] ["®" "®"] ["¯" "¯"] ["°" "°"] ["±" "±"] ["²" "²"] ["³" "³"] ["´" "´"] ["µ" "µ"] ["¶" ""] ["·" "·"] ["¸" "¸"] ["¹" "¹"] ["º" "º"] ["»" "»"] ["¼" "¼"] ["½" "½"] ["¾" "¾"] ["¿" "¿"]
["À" "À"] ["Á" "Á"] ["Â" "Â"] ["Ã" "Ã"] ["Ä" "Ä"] ["Å" "Å"] ["Æ" "Æ"] ["Ç" "Ç"] ["È" "È"] ["É" "É"] ["Ê" "Ê"] ["Ë" "Ë"] ["Ì" "Ì"] ["Í" "Í"] ["Î" "Î"] ["Ï" "Ï"] ["Ð" "Ð"] ["Ñ" "Ñ"] ["Ò" "Ò"] ["Ó" "Ó"] ["Ô" "Ô"] ["Õ" "Õ"] ["Ö" "Ö"] ["×" "×"] ["Ø" "Ø"] ["Ù" "Ù"] ["Ú" "Ú"] ["Û" "Û"] ["Ü" "Ü"] ["Ý" "Ý"] ["Þ" "Þ"] ["ß" "ß"] ["à" "à"] ["á" "á"] ["â" "â"] ["ã" "ã"] ["ä" "ä"] ["å" "å"] ["æ" "æ"] ["ç" "ç"] ["è" "è"] ["é" "é"] ["ê" "ê"] ["ë" "ë"] ["ì" "ì"] ["í" "í"] ["î" "î"] ["ï" "ï"] ["ð" "ð"] ["ñ" "ñ"] ["ò" "ò"] ["ó" "ó"] ["ô" "ô"] ["õ" "õ"] ["ö" "ö"]
["÷" "÷"] ["ø" "ø"] ["ù" "ù"] ["ú" "ú"] ["û" "û"] ["ü" "ü"] ["ý" "ý"] ["þ" "þ"] ["ÿ" "ÿ"] ["ƒ" "ƒ"]
["Α" "Α"] ["Β" "Β"] ["Γ" "Γ"] ["Δ" "Δ"] ["Ε" "Ε"] ["Ζ" "Ζ"] ["Η" "Η"] ["Θ" "Θ"] ["Ι" "Ι"] ["Κ" "Κ"] ["Λ" "Λ"] ["Μ" "Μ"] ["Ν" "Ν"] ["Ξ" "Ξ"] ["Ο" "Ο"] ["Π" "Π"] ["Ρ" "Ρ"] ["Σ" "Σ"] ["Τ" "Τ"] ["Υ" "Υ"] ["Φ" "Φ"] ["Χ" "Χ"] ["Ψ" "Ψ"] ["Ω" "Ω"] ["α" "α"] ["β" "β"] ["γ" "γ"] ["δ" "δ"] ["ε" "ε"] ["ζ" "ζ"] ["η" "η"] ["θ" "θ"] ["ι" "ι"] ["κ" "κ"] ["λ" "λ"] ["μ" "μ"] ["ν" "ν"] ["ξ" "ξ"] ["ο" "ο"] ["π" "π"] ["ρ" "ρ"] ["ς" "ς"] ["σ" "σ"] ["τ" "τ"] ["υ" "υ"] ["φ" "φ"] ["χ" "χ"] ["ψ" "ψ"] ["ω" "ω"] ["ϑ" "ϑ"] ["ϒ" "ϒ"] ["ϖ" "ϖ"]
["•" ""] ["…" ""] ["′" ""] ["″" ""] ["‾" ""] ["⁄" ""] ["℘" ""] ["ℑ" ""] ["ℜ" ""] ["™" ""] ["ℵ" ""] ["←" ""] ["↑" ""] ["→" ""] ["↓" ""] ["↔" ""] ["↵" ""] ["⇐" ""] ["⇑" ""] ["⇒" ""] ["⇓" ""] ["⇔" ""] ["∀" ""] ["∂" ""] ["∃" ""] ["∅" ""] ["∇" ""] ["∈" ""] ["∉" ""] ["∋" ""] ["∏" ""] ["∑" ""] ["−" ""] ["∗" ""] ["√" ""] ["∝" ""] ["∞" ""] ["∠" ""] ["∧" ""] ["∨" ""] ["∩" ""] ["∪" ""] ["∫" ""] ["∴" ""] ["∼" ""] ["≅" ""] ["≈" ""] ["≠" ""] ["≡" ""] ["≤" ""] ["≥" ""] ["⊂" ""] ["⊃" ""] ["⊄" ""] ["⊆" ""] ["⊇" ""] ["⊕" ""] ["⊗" ""] ["⊥" ""] ["⋅" ""] ["⌈" ""] ["⌉" ""] ["⌊" ""] ["⌋" ""] ["⟨" ""] ["⟩" ""] ["◊" ""] ["♠" ""] ["♣" ""] ["♥" ""] ["♦" ""] [""" "\""] ["Œ" "Œ"] ["œ" "œ"] ["Š" "Š"] ["š" "š"] ["Ÿ" "Ÿ"] ["ˆ" "ˆ"] ["˜" "˜"] ["–" ""] ["—" ""] ["‘" ""] ["’" ""] ["‚" ""] ["“" ""] ["”" ""] ["„" ""] ["†" ""] ["‡" ""] ["‰" ""] ["‹" ""] ["›" ""] ["€" ""]]
"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>")
(dolist (rep +web-entities-list text)
(let ((from (elt rep (if decode-p 0 1)))
(to (elt rep (if decode-p 1 0)))
(case-fold-search t))
(when (string-match-p (regexp-quote from) text)
(setq text (s-replace from to text))))))
(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)
(let (case-fold-search)
(dolist (rep reps)
(goto-char (point-min))
(while (search-forward (elt rep (if decode-p 0 1)) nil t)
(replace-match (elt rep (if decode-p 1 0)) 'FIXEDCASE 'LITERAL))))))
;;;###autoload
(defun +web-encode-entities (text)
"TODO"
(+web--entities-string text nil))
;;;###autoload
(defun +web-decode-entities (text)
"TODO"
(+web--entities-string text t))
;;;###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))