Smarter scss toggle block/inline defun

This commit is contained in:
Henrik Lissner 2015-07-27 15:11:47 +02:00
parent 6e4cadd261
commit 7d2163c6b2

View file

@ -6,16 +6,26 @@
(interactive) (interactive)
(save-excursion (save-excursion
(let* ((bounds (ignore-errors (evil-a-curly))) (let* ((bounds (ignore-errors (evil-a-curly)))
(beg (car bounds)) beg end)
(end (cadr bounds)))
(goto-char beg)
(unless bounds (unless bounds
(user-error "No block found")) (user-error "No block found"))
(setq beg (car bounds))
(setq end (cadr bounds))
(if (= (line-number-at-pos beg) (line-number-at-pos end)) (if (= (line-number-at-pos beg) (line-number-at-pos end))
(progn (replace-regexp ";[\s\t]*" ";\n" nil beg end) (save-excursion
(save-excursion (goto-char (1+ beg)) (insert "\n") (goto-char (1+ beg)) (insert "\n")
(evil-indent beg (+ 2 end)))) (unless (string-match ";[\s\t]*}$" (buffer-substring-no-properties beg (1+ end)))
(evil-join beg end))))) (goto-char end) (insert "\n"))
(replace-regexp ";[\s\t]*" ";\n" nil beg (1+ end))
(setq end (cadr (evil-a-curly)))
(evil-indent beg end)
(delete-trailing-whitespace beg end))
(goto-char beg)
(evil-join beg end)
(goto-char (1+ beg))
(just-one-space)
(goto-char (cadr (evil-inner-curly)))
(just-one-space)))))
(provide 'defuns-scss) (provide 'defuns-scss)
;;; defuns-scss.el ends here ;;; defuns-scss.el ends here