lang/css: refactor +css/toggle-inline-or-block

Replaces instances of replace-regexp (interactive-only functions),
removing the need for with-no-warnings and quiet!.

Improves regexp responsible for compacting whitespace in between
properties, which reduces compaction of whitespace in string arguments.
This commit is contained in:
Henrik Lissner 2018-09-27 22:44:07 -04:00
parent 4bdd6002a4
commit 29ad900c1f
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -1,24 +1,29 @@
;;; lang/web/autoload/css.el -*- lexical-binding: t; -*-
;;;###autoload
;; ;;;###autoload
;; TODO (defun +css/scss-build ())
;;;###autoload
;; ;;;###autoload
;; 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))))
(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 ()
@ -36,9 +41,7 @@
(user-error "No block found %s" (list beg end op cl)))
(unless (string= op "{")
(user-error "Incorrect block found"))
(if (featurep 'evil)
(evil-with-single-undo (+css--toggle-inline-or-block beg end))
(+css--toggle-inline-or-block beg end)))))
(+css--toggle-inline-or-block beg end))))
;;;###autoload
(defun +css/comment-indent-new-line ()