This commit is contained in:
ry
2022-01-11 18:05:13 -08:00
parent 2046befee2
commit 8e7b654716
846 changed files with 71287 additions and 4 deletions

View File

@@ -0,0 +1,105 @@
;;; lang/web/autoload/css.el -*- lexical-binding: t; -*-
;; ;;;###autoload
;; TODO (defun +css/scss-build ())
;; ;;;###autoload
;; TODO (defun +css/sass-build ())
(defun +css--toggle-inline-or-block (beg end)
(skip-chars-forward " \t")
(let ((orig (point-marker)))
(goto-char beg)
(if (= (line-number-at-pos beg) (line-number-at-pos end))
(progn
(forward-char)
(insert "\n")
(while (re-search-forward ";\\s-+" end t)
(replace-match ";\n" nil t))
(indent-region beg end))
(save-excursion
(while (re-search-forward "\n+" end t)
(replace-match " " nil t)))
(while (re-search-forward "\\([{;]\\) +" end t)
(replace-match (concat (match-string 1) " ") nil t)))
(if orig (goto-char orig))
(skip-chars-forward " \t")))
;;;###autoload
(defun +css/toggle-inline-or-block ()
"Toggles between a bracketed block and inline block."
(interactive)
(let ((inhibit-modification-hooks t))
(cl-destructuring-bind (&key beg end op cl &allow-other-keys)
(save-excursion
(when (and (eq (char-after) ?\{)
(not (eq (char-before) ?\{)))
(forward-char))
(sp-get-sexp))
(when (or (not (and beg end op cl))
(string-empty-p op) (string-empty-p cl))
(user-error "No block found %s" (list beg end op cl)))
(unless (string= op "{")
(user-error "Incorrect block found"))
(+css--toggle-inline-or-block beg end))))
;;;###autoload
(defun +css/comment-indent-new-line (&optional _)
"Continues the comment in an indented new line.
Meant for `comment-line-break-function' in `css-mode' and `scss-mode'."
(interactive)
(cond ((or (not (doom-point-in-comment-p))
(and comment-use-syntax
(not (save-excursion (comment-beginning)))))
(let (comment-line-break-function)
(newline-and-indent)))
((save-match-data
(let ((at-end (looking-at-p ".+\\*/"))
(indent-char (if indent-tabs-mode ?\t ?\s))
(post-indent (save-excursion
(move-to-column (1+ (current-indentation)))
(skip-chars-forward " \t" (line-end-position))))
(pre-indent (current-indentation))
opener)
(save-excursion
(if comment-use-syntax
(goto-char (comment-beginning))
(goto-char (line-beginning-position))
(when (re-search-forward comment-start-skip (line-end-position) t)
(goto-char (or (match-end 1)
(match-beginning 0)))))
(buffer-substring-no-properties (point) (line-end-position))
(when (looking-at "\\(//\\|/?\\*\\**/?\\)\\(?:[^/]\\)")
(list (match-string-no-properties 1)
(- (match-beginning 1) (line-beginning-position))))
(if (looking-at "\\(//\\|/?\\*\\**/?\\)\\(?:[^/]\\)")
(setq opener (match-string-no-properties 1)
pre-indent (- (match-beginning 1) (line-beginning-position)))
(setq opener ""
pre-indent 0)))
(insert-and-inherit
"\n" (make-string pre-indent indent-char)
(if (string-prefix-p "/*" opener)
(if (or (eq +web-continue-block-comments t)
(string= "/**" opener))
" *"
"")
opener)
(make-string post-indent indent-char))
(when at-end
(save-excursion
(just-one-space)
(insert "\n" (make-string pre-indent indent-char)))))))))
;;;###autoload
(defun +css-adaptive-fill-fn ()
"An `adaptive-fill-function' that conjoins SCSS line comments correctly."
(when (looking-at "[ \t]*/[/*][ \t]*")
(let ((str (match-string 0)))
(when (string-match "/[/*]" str)
(replace-match (if (string= (match-string 0 str) "/*")
" *"
"//")
t t str)))))

View File

@@ -0,0 +1,26 @@
;;; lang/html/autoload/evil.el -*- lexical-binding: t; -*-
;;;###if (featurep! :editor evil)
;;;###autoload (autoload '+web:encode-html-entities "lang/web/autoload/evil" nil t)
(evil-define-operator +web:encode-html-entities (beg end &optional bang input)
"Encodes HTML entities in INPUT or the selected region."
(interactive "<r><!><a>")
(cond (input
(let ((result (+web-encode-entities input)))
(if bang
(kill-new result)
(insert result))))
((and beg end)
(+web/encode-entities-region beg end))))
;;;###autoload (autoload '+web:decode-html-entities "lang/web/autoload/evil" nil t)
(evil-define-operator +web:decode-html-entities (beg end &optional bang input)
"Decodes HTML entities in INPUT or the selected region."
(interactive "<r><!><a>")
(cond (input
(let ((result (+web-decode-entities input)))
(if bang
(kill-new result)
(insert result))))
((and beg end)
(+web/decode-entities-region beg end))))

View File

@@ -0,0 +1,135 @@
;;; lang/web/autoload/html.el -*- lexical-binding: t; -*-
(defvar +web-entities-list
[["&amp;" "&"] ["&nbsp;" " "] ["&ensp;" ""] ["&emsp;" ""] ["&thinsp;" ""]
["&lt;" "<"] ["&gt;" ">"]
["&rlm;" ""] ["&lrm;" ""] ["&zwj;" ""] ["&zwnj;" ""]
["&iexcl;" "¡"] ["&cent;" "¢"] ["&pound;" "£"] ["&curren;" "¤"] ["&yen;" "¥"]
["&brvbar;" "¦"] ["&sect;" "§"] ["&uml;" "¨"] ["&copy;" "©"] ["&ordf;" "ª"]
["&laquo;" "«"] ["&not;" "¬"] ["&shy;" "­"] ["&reg;" "®"] ["&macr;" "¯"]
["&deg;" "°"] ["&plusmn;" "±"] ["&sup2;" "²"] ["&sup3;" "³"] ["&acute;" "´"]
["&micro;" "µ"] ["&para;" ""] ["&middot;" "·"] ["&cedil;" "¸"] ["&sup1;" "¹"]
["&ordm;" "º"] ["&raquo;" "»"] ["&frac14;" "¼"] ["&frac12;" "½"]
["&frac34;" "¾"] ["&iquest;" "¿"] ["&Agrave;" "À"] ["&Aacute;" "Á"]
["&Acirc;" "Â"] ["&Atilde;" "Ã"] ["&Auml;" "Ä"] ["&Aring;" "Å"] ["&AElig;" "Æ"]
["&Ccedil;" "Ç"] ["&Egrave;" "È"] ["&Eacute;" "É"] ["&Ecirc;" "Ê"]
["&Euml;" "Ë"] ["&Igrave;" "Ì"] ["&Iacute;" "Í"] ["&Icirc;" "Î"] ["&Iuml;" "Ï"]
["&ETH;" "Ð"] ["&Ntilde;" "Ñ"] ["&Ograve;" "Ò"] ["&Oacute;" "Ó"]
["&Ocirc;" "Ô"] ["&Otilde;" "Õ"] ["&Ouml;" "Ö"] ["&times;" "×"] ["&Oslash;" "Ø"]
["&Ugrave;" "Ù"] ["&Uacute;" "Ú"] ["&Ucirc;" "Û"] ["&Uuml;" "Ü"]
["&Yacute;" "Ý"] ["&THORN;" "Þ"] ["&szlig;" "ß"] ["&agrave;" "à"] ["&aacute;" "á"]
["&acirc;" "â"] ["&atilde;" "ã"] ["&auml;" "ä"] ["&aring;" "å"]
["&aelig;" "æ"] ["&ccedil;" "ç"] ["&egrave;" "è"] ["&eacute;" "é"] ["&ecirc;" "ê"]
["&euml;" "ë"] ["&igrave;" "ì"] ["&iacute;" "í"] ["&icirc;" "î"]
["&iuml;" "ï"] ["&eth;" "ð"] ["&ntilde;" "ñ"] ["&ograve;" "ò"] ["&oacute;" "ó"]
["&ocirc;" "ô"] ["&otilde;" "õ"] ["&ouml;" "ö"] ["&divide;" "÷"] ["&oslash;" "ø"]
["&ugrave;" "ù"] ["&uacute;" "ú"] ["&ucirc;" "û"] ["&uuml;" "ü"] ["&yacute;" "ý"]
["&thorn;" "þ"] ["&yuml;" "ÿ"] ["&fnof;" "ƒ"] ["&Alpha;" "Α"] ["&Beta;" "Β"]
["&Gamma;" "Γ"] ["&Delta;" "Δ"] ["&Epsilon;" "Ε"] ["&Zeta;" "Ζ"] ["&Eta;" "Η"]
["&Theta;" "Θ"] ["&Iota;" "Ι"] ["&Kappa;" "Κ"] ["&Lambda;" "Λ"] ["&Mu;" "Μ"]
["&Nu;" "Ν"] ["&Xi;" "Ξ"] ["&Omicron;" "Ο"] ["&Pi;" "Π"] ["&Rho;" "Ρ"]
["&Sigma;" "Σ"] ["&Tau;" "Τ"] ["&Upsilon;" "Υ"] ["&Phi;" "Φ"] ["&Chi;" "Χ"]
["&Psi;" "Ψ"] ["&Omega;" "Ω"] ["&alpha;" "α"] ["&beta;" "β"] ["&gamma;" "γ"]
["&delta;" "δ"] ["&epsilon;" "ε"] ["&zeta;" "ζ"] ["&eta;" "η"] ["&theta;" "θ"]
["&iota;" "ι"] ["&kappa;" "κ"] ["&lambda;" "λ"] ["&mu;" "μ"] ["&nu;" "ν"]
["&xi;" "ξ"] ["&omicron;" "ο"] ["&pi;" "π"] ["&rho;" "ρ"] ["&sigmaf;" "ς"]
["&sigma;" "σ"] ["&tau;" "τ"] ["&upsilon;" "υ"] ["&phi;" "φ"] ["&chi;" "χ"]
["&psi;" "ψ"] ["&omega;" "ω"] ["&thetasym;" "ϑ"] ["&upsih;" "ϒ"] ["&piv;" "ϖ"]
["&bull;" ""] ["&hellip;" ""] ["&prime;" ""] ["&Prime;" ""] ["&oline;" ""]
["&frasl;" ""] ["&weierp;" ""] ["&image;" ""] ["&real;" ""] ["&trade;" ""]
["&alefsym;" ""] ["&larr;" ""] ["&uarr;" ""] ["&rarr;" ""] ["&darr;" ""]
["&harr;" ""] ["&crarr;" ""] ["&lArr;" ""] ["&uArr;" ""] ["&rArr;" ""]
["&dArr;" ""] ["&hArr;" ""] ["&forall;" ""] ["&part;" ""] ["&exist;" ""]
["&empty;" ""] ["&nabla;" ""] ["&isin;" ""] ["&notin;" ""] ["&ni;" ""]
["&prod;" ""] ["&sum;" ""] ["&minus;" ""] ["&lowast;" ""] ["&radic;" ""]
["&prop;" ""] ["&infin;" ""] ["&ang;" ""] ["&and;" ""] ["&or;" ""]
["&cap;" ""] ["&cup;" ""] ["&int;" ""] ["&there4;" ""] ["&sim;" ""]
["&cong;" ""] ["&asymp;" ""] ["&ne;" ""] ["&equiv;" ""] ["&le;" ""]
["&ge;" ""] ["&sub;" ""] ["&sup;" ""] ["&nsub;" ""] ["&sube;" ""]
["&supe;" ""] ["&oplus;" ""] ["&otimes;" ""] ["&perp;" ""] ["&sdot;" ""]
["&lceil;" ""] ["&rceil;" ""] ["&lfloor;" ""] ["&rfloor;" ""] ["&lang;" ""]
["&rang;" ""] ["&loz;" ""] ["&spades;" ""] ["&clubs;" ""]
["&hearts;" ""] ["&diams;" ""] ["&quot;" "\""] ["&OElig;" "Œ"] ["&oelig;" "œ"]
["&Scaron;" "Š"] ["&scaron;" "š"] ["&Yuml;" "Ÿ"] ["&circ;" "ˆ"]
["&tilde;" "˜"] ["&ndash;" ""] ["&mdash;" ""] ["&lsquo;" ""] ["&rsquo;" ""]
["&sbquo;" ""] ["&ldquo;" ""] ["&rdquo;" ""] ["&bdquo;" ""]
["&dagger;" ""] ["&Dagger;" ""] ["&permil;" ""] ["&lsaquo;" ""] ["&rsaquo;" ""]
["&euro;" ""]]
"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>")
(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)
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)
(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)))
;;;###autoload
(defun +web-encode-entities (text)
"TODO"
(+web--entities-string text nil))
;;;###autoload
(defun +web-decode-entities (text)
"TODO"
(+web--entities-string text t))
;;
;;; Commands
;;;###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))
;;;###autoload
(defun +web/indent-or-yas-or-emmet-expand ()
"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
`yas-minor-mode' is enabled or not."
(interactive)
(call-interactively
(cond ((or (<= (current-column) (current-indentation))
(not (eolp))
(not (or (memq (char-after) (list ?\n ?\s ?\t))
(eobp))))
#'indent-for-tab-command)
((featurep! :editor snippets)
(require 'yasnippet)
(if (yas--templates-for-key-at-point)
#'yas-expand
#'emmet-expand-yas))
(#'emmet-expand-line))))