Emacs: Format CSS Code 📜
put this in your Emacs Init File:
(defun xah-css-format-buffer () "Format CSS code of current buffer. This command requires external command deno. if buffer is a file, it is save first. URL `http://xahlee.info/emacs/emacs/emacs_format_css_code.html' Created: 2025-01-05 Version: 2025-10-23_083844" (interactive) (when buffer-file-name (when (buffer-modified-p) (save-buffer)) (let ((xbackupName (concat buffer-file-name "." (format-time-string "%Y%m%d_%H%M%S") "~"))) (write-region (point-min) (point-max) xbackupName) (message (concat "\nBackup saved at: " xbackupName)))) (let ((xpos (point)) (xoutbuf (get-buffer-create "*xah-css-format output*")) xexitstatus) (with-current-buffer xoutbuf (erase-buffer)) (setq xexitstatus (call-process-region (point-min) (point-max) "deno" nil xoutbuf nil "fmt" "-" "-q" "--ext" "css" "--indent-width" "1" "--line-width" "10000")) (if (eq 0 xexitstatus) (progn (erase-buffer) (insert-buffer-substring xoutbuf) (goto-char xpos) (kill-buffer xoutbuf)) (progn (display-buffer xoutbuf) (error "error xah-css-format-buffer")))))
part of Emacs: Xah CSS Mode 📦