lang/web: fix +css/toggle-inline-or-block
This commit is contained in:
parent
18b48cc841
commit
399f3538ce
1 changed files with 27 additions and 12 deletions
|
@ -6,24 +6,39 @@
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
;; TODO (defun +css/sass-build ())
|
;; TODO (defun +css/sass-build ())
|
||||||
|
|
||||||
|
(defun +css--toggle-inline-or-block (beg end)
|
||||||
|
(skip-chars-forward " \t")
|
||||||
|
(let ((orig (point-marker)))
|
||||||
|
(with-no-warnings
|
||||||
|
(quiet!
|
||||||
|
(if (= (line-number-at-pos beg) (line-number-at-pos end))
|
||||||
|
(progn
|
||||||
|
(goto-char (1+ beg)) (insert "\n")
|
||||||
|
(replace-regexp ";\\s-+" ";\n" nil beg end)
|
||||||
|
(indent-region beg end))
|
||||||
|
(replace-regexp "\n" " " nil beg end)
|
||||||
|
(replace-regexp " +" " " nil beg end))))
|
||||||
|
(if orig (goto-char orig))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +css/toggle-inline-or-block ()
|
(defun +css/toggle-inline-or-block ()
|
||||||
"Toggles between a bracketed block and inline block."
|
"Toggles between a bracketed block and inline block."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((inhibit-modification-hooks t))
|
(let ((inhibit-modification-hooks t))
|
||||||
(cl-destructuring-bind (&key beg end op cl &allow-other-keys)
|
(cl-destructuring-bind (&key beg end op cl &allow-other-keys)
|
||||||
(sp-get-thing)
|
(save-excursion
|
||||||
(when (or (string-empty-p op) (string-empty-p cl))
|
(when (and (eq (char-after) ?{)
|
||||||
(user-error "No block found"))
|
(not (eq (char-before) ?{)))
|
||||||
(with-no-warnings
|
(forward-char))
|
||||||
(if (= (line-number-at-pos beg) (line-number-at-pos end))
|
(sp-get-sexp))
|
||||||
(progn
|
(when (or (not (and beg end op cl))
|
||||||
(goto-char end) (insert "\n")
|
(string-empty-p op) (string-empty-p cl))
|
||||||
(goto-char (1+ beg)) (insert "\n")
|
(user-error "No block found %s" (list beg end op cl)))
|
||||||
(replace-regexp ";\\s-+" ";\n" nil beg end)
|
(unless (string= op "{")
|
||||||
(indent-region beg end))
|
(user-error "Incorrect block found"))
|
||||||
(replace-regexp "\n" " " nil beg end)
|
(if (featurep 'evil)
|
||||||
(replace-regexp " +" " " nil beg end))))))
|
(evil-with-single-undo (+css--toggle-inline-or-block beg end))
|
||||||
|
(+css--toggle-inline-or-block beg end)))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +css/comment-indent-new-line ()
|
(defun +css/comment-indent-new-line ()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue