45 lines
5.6 KiB
EmacsLisp
45 lines
5.6 KiB
EmacsLisp
;;; defuns-web.el
|
||
|
||
;;;###autoload
|
||
(defun doom/web-html-email2mailto (beg end)
|
||
(interactive "r")
|
||
(replace-regexp "\\b\\([a-zA-Z0-9._+-%]+@[a-zA-Z0-9-.]+\\.[a-zA-Z]+\\)\\b"
|
||
"<a href=\"mailto:\\1\">\\1</a>"
|
||
nil beg end))
|
||
|
||
;;;###autoload
|
||
(defun doom/web-html-url2anchor (beg end)
|
||
(interactive "r")
|
||
(replace-regexp "\\bhttps?://.+?\\b"
|
||
"<a href=\"\\1\">\\1</a>"
|
||
nil beg end))
|
||
|
||
;;;###autoload
|
||
(defun doom/web-refresh-browser ()
|
||
(interactive)
|
||
(call-process-shell-command "osascript -e 'tell application \"Google Chrome\" to tell the active tab of its first window to reload' &" nil 0))
|
||
|
||
;;;###autoload (autoload 'doom/html-entities "defuns-web" nil t)
|
||
(evil-define-operator doom/html-entities (bang beg end)
|
||
"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"
|
||
(interactive "<!><r>")
|
||
(let ((reps [[" " " "] [" " " "] [" " " "] [" " " "]
|
||
["‏" ""] ["‎" ""] ["‍" ""] ["‌" ""]
|
||
["¡" "¡"] ["¢" "¢"] ["£" "£"] ["¤" "¤"] ["¥" "¥"] ["¦" "¦"] ["§" "§"] ["¨" "¨"] ["©" "©"] ["ª" "ª"] ["«" "«"] ["¬" "¬"] ["­" ""] ["®" "®"] ["¯" "¯"] ["°" "°"] ["±" "±"] ["²" "²"] ["³" "³"] ["´" "´"] ["µ" "µ"] ["¶" "¶"] ["·" "·"] ["¸" "¸"] ["¹" "¹"] ["º" "º"] ["»" "»"] ["¼" "¼"] ["½" "½"] ["¾" "¾"] ["¿" "¿"]
|
||
["À" "À"] ["Á" "Á"] ["Â" "Â"] ["Ã" "Ã"] ["Ä" "Ä"] ["Å" "Å"] ["Æ" "Æ"] ["Ç" "Ç"] ["È" "È"] ["É" "É"] ["Ê" "Ê"] ["Ë" "Ë"] ["Ì" "Ì"] ["Í" "Í"] ["Î" "Î"] ["Ï" "Ï"] ["Ð" "Ð"] ["Ñ" "Ñ"] ["Ò" "Ò"] ["Ó" "Ó"] ["Ô" "Ô"] ["Õ" "Õ"] ["Ö" "Ö"] ["×" "×"] ["Ø" "Ø"] ["Ù" "Ù"] ["Ú" "Ú"] ["Û" "Û"] ["Ü" "Ü"] ["Ý" "Ý"] ["Þ" "Þ"] ["ß" "ß"] ["à" "à"] ["á" "á"] ["â" "â"] ["ã" "ã"] ["ä" "ä"] ["å" "å"] ["æ" "æ"] ["ç" "ç"] ["è" "è"] ["é" "é"] ["ê" "ê"] ["ë" "ë"] ["ì" "ì"] ["í" "í"] ["î" "î"] ["ï" "ï"] ["ð" "ð"] ["ñ" "ñ"] ["ò" "ò"] ["ó" "ó"] ["ô" "ô"] ["õ" "õ"] ["ö" "ö"]
|
||
["÷" "÷"] ["ø" "ø"] ["ù" "ù"] ["ú" "ú"] ["û" "û"] ["ü" "ü"] ["ý" "ý"] ["þ" "þ"] ["ÿ" "ÿ"] ["ƒ" "ƒ"]
|
||
["Α" "Α"] ["Β" "Β"] ["Γ" "Γ"] ["Δ" "Δ"] ["Ε" "Ε"] ["Ζ" "Ζ"] ["Η" "Η"] ["Θ" "Θ"] ["Ι" "Ι"] ["Κ" "Κ"] ["Λ" "Λ"] ["Μ" "Μ"] ["Ν" "Ν"] ["Ξ" "Ξ"] ["Ο" "Ο"] ["Π" "Π"] ["Ρ" "Ρ"] ["Σ" "Σ"] ["Τ" "Τ"] ["Υ" "Υ"] ["Φ" "Φ"] ["Χ" "Χ"] ["Ψ" "Ψ"] ["Ω" "Ω"] ["α" "α"] ["β" "β"] ["γ" "γ"] ["δ" "δ"] ["ε" "ε"] ["ζ" "ζ"] ["η" "η"] ["θ" "θ"] ["ι" "ι"] ["κ" "κ"] ["λ" "λ"] ["μ" "μ"] ["ν" "ν"] ["ξ" "ξ"] ["ο" "ο"] ["π" "π"] ["ρ" "ρ"] ["ς" "ς"] ["σ" "σ"] ["τ" "τ"] ["υ" "υ"] ["φ" "φ"] ["χ" "χ"] ["ψ" "ψ"] ["ω" "ω"] ["ϑ" "ϑ"] ["ϒ" "ϒ"] ["ϖ" "ϖ"]
|
||
["•" "•"] ["…" "…"] ["′" "′"] ["″" "″"] ["‾" "‾"] ["⁄" "⁄"] ["℘" "℘"] ["ℑ" "ℑ"] ["ℜ" "ℜ"] ["™" "™"] ["ℵ" "ℵ"] ["←" "←"] ["↑" "↑"] ["→" "→"] ["↓" "↓"] ["↔" "↔"] ["↵" "↵"] ["⇐" "⇐"] ["⇑" "⇑"] ["⇒" "⇒"] ["⇓" "⇓"] ["⇔" "⇔"] ["∀" "∀"] ["∂" "∂"] ["∃" "∃"] ["∅" "∅"] ["∇" "∇"] ["∈" "∈"] ["∉" "∉"] ["∋" "∋"] ["∏" "∏"] ["∑" "∑"] ["−" "−"] ["∗" "∗"] ["√" "√"] ["∝" "∝"] ["∞" "∞"] ["∠" "∠"] ["∧" "∧"] ["∨" "∨"] ["∩" "∩"] ["∪" "∪"] ["∫" "∫"] ["∴" "∴"] ["∼" "∼"] ["≅" "≅"] ["≈" "≈"] ["≠" "≠"] ["≡" "≡"] ["≤" "≤"] ["≥" "≥"] ["⊂" "⊂"] ["⊃" "⊃"] ["⊄" "⊄"] ["⊆" "⊆"] ["⊇" "⊇"] ["⊕" "⊕"] ["⊗" "⊗"] ["⊥" "⊥"] ["⋅" "⋅"] ["⌈" "⌈"] ["⌉" "⌉"] ["⌊" "⌊"] ["⌋" "⌋"] ["⟨" "〈"] ["⟩" "〉"] ["◊" "◊"] ["♠" "♠"] ["♣" "♣"] ["♥" "♥"] ["♦" "♦"] [""" "\""] ["Œ" "Œ"] ["œ" "œ"] ["Š" "Š"] ["š" "š"] ["Ÿ" "Ÿ"] ["ˆ" "ˆ"] ["˜" "˜"] ["–" "–"] ["—" "—"] ["‘" "‘"] ["’" "’"] ["‚" "‚"] ["“" "“"] ["”" "”"] ["„" "„"] ["†" "†"] ["‡" "‡"] ["‰" "‰"] ["‹" "‹"] ["›" "›"] ["€" "€"]
|
||
]))
|
||
(save-restriction
|
||
(narrow-to-region beg end)
|
||
(let (case-fold-search)
|
||
(mapc (lambda (rep)
|
||
(goto-char (point-min))
|
||
(while (search-forward (elt rep (if bang 0 1)) nil t)
|
||
(replace-match (elt rep (if bang 1 0)) 'FIXEDCASE 'LITERAL)))
|
||
reps)))))
|
||
|
||
(provide 'defuns-web)
|
||
;;; defuns-web.el ends here
|