2017-06-08 11:47:56 +02:00
|
|
|
;;; lang/web/autoload/css.el -*- lexical-binding: t; -*-
|
2017-02-19 18:57:16 -05:00
|
|
|
|
2018-09-27 22:44:07 -04:00
|
|
|
;; ;;;###autoload
|
2017-04-07 01:45:57 -04:00
|
|
|
;; TODO (defun +css/scss-build ())
|
2017-02-19 18:57:16 -05:00
|
|
|
|
2018-09-27 22:44:07 -04:00
|
|
|
;; ;;;###autoload
|
2017-04-07 01:45:57 -04:00
|
|
|
;; TODO (defun +css/sass-build ())
|
2017-04-03 13:18:02 -04:00
|
|
|
|
2018-05-08 15:19:09 +02:00
|
|
|
(defun +css--toggle-inline-or-block (beg end)
|
|
|
|
(skip-chars-forward " \t")
|
|
|
|
(let ((orig (point-marker)))
|
2018-09-27 22:44:07 -04:00
|
|
|
(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")))
|
2018-05-08 15:19:09 +02:00
|
|
|
|
2017-04-03 13:18:02 -04:00
|
|
|
;;;###autoload
|
|
|
|
(defun +css/toggle-inline-or-block ()
|
|
|
|
"Toggles between a bracketed block and inline block."
|
|
|
|
(interactive)
|
2018-02-08 16:08:04 -05:00
|
|
|
(let ((inhibit-modification-hooks t))
|
2018-02-14 20:55:29 -05:00
|
|
|
(cl-destructuring-bind (&key beg end op cl &allow-other-keys)
|
2018-05-08 15:19:09 +02:00
|
|
|
(save-excursion
|
2018-08-31 02:40:15 +02:00
|
|
|
(when (and (eq (char-after) ?\{)
|
|
|
|
(not (eq (char-before) ?\{)))
|
2018-05-08 15:19:09 +02:00
|
|
|
(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"))
|
2018-09-27 22:44:07 -04:00
|
|
|
(+css--toggle-inline-or-block beg end))))
|
2018-02-14 20:58:36 -05:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +css/comment-indent-new-line ()
|
2019-05-01 19:12:52 -04:00
|
|
|
"Continues the comment in an indented new line.
|
|
|
|
|
|
|
|
Meant for `comment-line-break-function' in `css-mode' and `scss-mode'."
|
2018-02-14 20:58:36 -05:00
|
|
|
(interactive)
|
|
|
|
(when (sp-point-in-comment)
|
|
|
|
(let ((at-end (looking-at-p ".+\\*/"))
|
|
|
|
type pre-indent post-indent)
|
|
|
|
(save-excursion
|
|
|
|
(let ((bol (line-beginning-position))
|
|
|
|
(eol (line-end-position)))
|
|
|
|
(if (not comment-use-syntax)
|
|
|
|
(progn
|
|
|
|
(goto-char bol)
|
|
|
|
(when (re-search-forward comment-start-skip eol t)
|
|
|
|
(goto-char (or (match-end 1) (match-beginning 0)))))
|
|
|
|
(goto-char (comment-beginning))))
|
|
|
|
(save-match-data
|
|
|
|
(looking-at "\\(//\\|/?\\*\\)")
|
|
|
|
(setq type (match-string 0)
|
|
|
|
pre-indent (- (match-beginning 0) (line-beginning-position))
|
|
|
|
post-indent
|
|
|
|
(progn
|
|
|
|
(goto-char (match-end 0))
|
|
|
|
(max 1 (skip-chars-forward " " (line-end-position)))))
|
|
|
|
(if (eolp) (setq post-indent 1))))
|
|
|
|
(insert "\n"
|
|
|
|
(make-string pre-indent 32)
|
|
|
|
(if (string= "/*" type)
|
|
|
|
" *"
|
|
|
|
type)
|
|
|
|
(make-string post-indent 32))
|
|
|
|
(when at-end
|
|
|
|
(save-excursion
|
|
|
|
(insert "\n" (make-string pre-indent 32))
|
|
|
|
(delete-char -1))))))
|