From ec7dc0b32e3b7e09a40a7488e784d2c6a17d70f2 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Fri, 23 Aug 2019 23:39:07 -0700 Subject: Add snippets to ‘oni-css’ --- .gitlab-ci.yml | 14 ++++ GNUmakefile | 18 ++++- oni-css.el | 147 ----------------------------------- oni-css/Cask | 13 ++++ oni-css/oni-css.el | 147 +++++++++++++++++++++++++++++++++++ oni-css/snippets/css-mode/box-shadow | 5 ++ 6 files changed, 195 insertions(+), 149 deletions(-) delete mode 100644 oni-css.el create mode 100644 oni-css/Cask create mode 100644 oni-css/oni-css.el create mode 100644 oni-css/snippets/css-mode/box-shadow diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f7e76bd..692bfd4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,6 +16,16 @@ package-oni-conf: paths: - oni-conf/dist/ +package-oni-css: + stage: pre-package-multifile + before_script: + - rm -rf oni-css/dist + script: + - cask --path oni-css package + artifacts: + paths: + - oni-css/dist/ + test-oni-alert: stage: test script: make test-oni-alert @@ -33,6 +43,9 @@ test-oni-conf: test-oni-css: stage: test + dependencies: + - package-oni-css + needs: [package-oni-css] script: make test-oni-css test-oni-grep: @@ -51,6 +64,7 @@ package: stage: package dependencies: - package-oni-conf + - package-oni-css before_script: - rm -rf bin/ - mkdir bin/ diff --git a/GNUmakefile b/GNUmakefile index 79a833c..e6d2dc3 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -16,6 +16,12 @@ package-oni-conf: --funcall package-initialize \ --eval "(package-upload-file (car (sort (file-expand-wildcards \"oni-conf/dist/*.tar\") #'string>)))" +package-oni-css: + emacs --batch \ + --load oni-package.el \ + --funcall package-initialize \ + --eval "(package-upload-file (car (sort (file-expand-wildcards \"oni-css/dist/*.tar\") #'string>)))" + install-%: emacs --batch \ --load oni-package.el \ @@ -32,6 +38,14 @@ install-oni-conf: $(foreach DEP,$(DEPS),--eval "(package-install-file \"$(DEP).el\")") \ --eval "(package-install-file (car (sort (file-expand-wildcards \"oni-conf/dist/*.tar\") #'string>)))" \ +install-oni-css: + emacs --batch \ + --load oni-package.el \ + --funcall package-initialize \ + --eval '(package-refresh-contents)' \ + $(foreach DEP,$(DEPS),--eval "(package-install-file \"$(DEP).el\")") \ + --eval "(package-install-file (car (sort (file-expand-wildcards \"oni-css/dist/*.tar\") #'string>)))" \ + test-%: install-% emacs --batch \ --load oni-package.el \ @@ -41,10 +55,10 @@ test-%: install-% --eval "(setq ert-batch-backtrace-right-margin nil)" \ --funcall ert-run-tests-batch-and-exit -test-oni-css: DEPS := oni-company oni-fci test-oni-bookmark: DEPS := oni-data-dir -test-oni-php: DEPS := oni-flycheck oni-company oni-fci test-oni-conf: DEPS := oni-yasnippet +test-oni-css: DEPS := oni-company oni-fci +test-oni-php: DEPS := oni-flycheck oni-company oni-fci clean: rm -fv $(FILES) diff --git a/oni-css.el b/oni-css.el deleted file mode 100644 index 6669f3c..0000000 --- a/oni-css.el +++ /dev/null @@ -1,147 +0,0 @@ -;;; oni-css.el --- CSS configuration -*- lexical-binding: t; -*- - -;; Copyright (C) 2019 Tom Willemse - -;; Author: Tom Willemse -;; Keywords: local -;; Version: 20190822234329 -;; Package-Requires: (oni-company oni-fci hydra rainbow-mode) - -;; This program is free software; you can redistribute it and/or modify -;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation, either version 3 of the License, or -;; (at your option) any later version. - -;; This program is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . - -;;; Commentary: - -;; Configuration for `css-mode' and `scss-mode'. - -;;; Code: - -(require 'align) -(require 'css-mode) -(require 'hydra) - -(eval-when-compile - (require 'compile) - (require 'grep)) - -(defun oni-css-property-important-p () - "Return whether or not the current property is important." - (save-excursion - (beginning-of-line) - (re-search-forward "!important" (line-end-position) :noerror))) - -(defun oni-css-add-important () - "Add an important flag to the property on the current line." - (interactive) - (unless (oni-css-property-important-p) - (save-excursion - (end-of-line) - (when (re-search-backward ";" (line-beginning-position) :noerror) - (insert " !important"))))) - -(defun oni-css-remove-important () - "Remove the important flag from the property on the current line." - (interactive) - (when (oni-css-property-important-p) - (save-excursion - (end-of-line) - (when (re-search-backward " !important" (line-beginning-position) :noerror) - (replace-match ""))))) - -(defun oni-css-mode-init--toggle-important () - "Toggle the important flag on the property on the current line." - (interactive) - (if (oni-css-property-important-p) - (oni-css-remove-important) - (oni-css-add-important))) - -(defhydra css-mode-hydra (:color blue) - ("!" oni-css-mode-init--toggle-important)) - -(setq css-indent-offset 2) - -(add-hook 'css-mode-hook 'company-mode) -(add-hook 'css-mode-hook 'electric-indent-local-mode) -(add-hook 'css-mode-hook 'electric-pair-local-mode) -(add-hook 'css-mode-hook 'fci-mode) -(add-hook 'css-mode-hook 'rainbow-mode) - -(with-eval-after-load 'compile - (let ((scss-error-regexp - (rx (and bol - (zero-or-more space) "on line " - (group (one-or-more digit)) " of " - (group (one-or-more (or word punct (syntax symbol)))) - eol)))) - - (add-to-list 'compilation-error-regexp-alist - (list scss-error-regexp 2 1 nil 2 2)))) - -(define-key css-mode-map (kbd "C-c m") #'css-mode-hydra/body) - -;; Align CSS files like so: - -;; body { color: #ffffff; } -;; .some-class { background-color: #ffffff; } -;; #some-id { width: 200px; } - -;; .some-more-class { -;; color: #ffffff; -;; background-color: #ffffff; -;; width: 200px; -;; } - -;; Keep these in order. They are each added to the _front_ of the -;; list and are applied in order. Changing their order will change -;; the results. -(add-to-list 'align-rules-list - `(css-closing-brace - (regexp . ,(rx (group (0+ whitespace)) "}" eol)) - (group . (1)) - (modes . '(scss-mode css-mode)))) - -(add-to-list 'align-rules-list - `(css-colons - (regexp . ,(rx bol - (0+ whitespace) - (1+ (any (?a . ?z) ?- ?$)) - ":" - (group (0+ whitespace)) - (0+ nonl) - ";" - eol)) - (group . (1)) - (modes . '(scss-mode css-mode)) - (repeat . t))) - -(add-to-list 'align-rules-list - `(css-opening-brace - (regexp . ,(rx bol - (0+ whitespace) - (0+ (any ?# ?. ?, ?\s ?& ?: ?- - (?a . ?z) (?A . ?Z) (?0 . ?9))) - (any (?a . ?z) (?A . ?Z) (?0 . ?9)) - (group (0+ whitespace)) - "{" - (0+ nonl))) - (group . (1)) - (modes . '(scss-mode css-mode)))) - -;;;###autoload -(with-eval-after-load 'grep - (add-to-list 'grep-files-aliases '("css" . "*.css *.less *.sass *.scss"))) - -;;;###autoload(with-eval-after-load 'css-mode (require 'oni-css)) - -(provide 'oni-css) -;;; oni-css.el ends here diff --git a/oni-css/Cask b/oni-css/Cask new file mode 100644 index 0000000..b22146e --- /dev/null +++ b/oni-css/Cask @@ -0,0 +1,13 @@ +(source gnu) +(source melpa) + +(package-file "./oni-css.el") + +(depends-on "oni-company" :git "../" :files ("oni-company.el")) +(depends-on "oni-fci" :git "../" :files ("oni-fci.el")) +(depends-on "hydra") +(depends-on "rainbow-mode") + +(files + "*.el" + ("snippets" "./snippets/*")) diff --git a/oni-css/oni-css.el b/oni-css/oni-css.el new file mode 100644 index 0000000..6669f3c --- /dev/null +++ b/oni-css/oni-css.el @@ -0,0 +1,147 @@ +;;; oni-css.el --- CSS configuration -*- lexical-binding: t; -*- + +;; Copyright (C) 2019 Tom Willemse + +;; Author: Tom Willemse +;; Keywords: local +;; Version: 20190822234329 +;; Package-Requires: (oni-company oni-fci hydra rainbow-mode) + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; Configuration for `css-mode' and `scss-mode'. + +;;; Code: + +(require 'align) +(require 'css-mode) +(require 'hydra) + +(eval-when-compile + (require 'compile) + (require 'grep)) + +(defun oni-css-property-important-p () + "Return whether or not the current property is important." + (save-excursion + (beginning-of-line) + (re-search-forward "!important" (line-end-position) :noerror))) + +(defun oni-css-add-important () + "Add an important flag to the property on the current line." + (interactive) + (unless (oni-css-property-important-p) + (save-excursion + (end-of-line) + (when (re-search-backward ";" (line-beginning-position) :noerror) + (insert " !important"))))) + +(defun oni-css-remove-important () + "Remove the important flag from the property on the current line." + (interactive) + (when (oni-css-property-important-p) + (save-excursion + (end-of-line) + (when (re-search-backward " !important" (line-beginning-position) :noerror) + (replace-match ""))))) + +(defun oni-css-mode-init--toggle-important () + "Toggle the important flag on the property on the current line." + (interactive) + (if (oni-css-property-important-p) + (oni-css-remove-important) + (oni-css-add-important))) + +(defhydra css-mode-hydra (:color blue) + ("!" oni-css-mode-init--toggle-important)) + +(setq css-indent-offset 2) + +(add-hook 'css-mode-hook 'company-mode) +(add-hook 'css-mode-hook 'electric-indent-local-mode) +(add-hook 'css-mode-hook 'electric-pair-local-mode) +(add-hook 'css-mode-hook 'fci-mode) +(add-hook 'css-mode-hook 'rainbow-mode) + +(with-eval-after-load 'compile + (let ((scss-error-regexp + (rx (and bol + (zero-or-more space) "on line " + (group (one-or-more digit)) " of " + (group (one-or-more (or word punct (syntax symbol)))) + eol)))) + + (add-to-list 'compilation-error-regexp-alist + (list scss-error-regexp 2 1 nil 2 2)))) + +(define-key css-mode-map (kbd "C-c m") #'css-mode-hydra/body) + +;; Align CSS files like so: + +;; body { color: #ffffff; } +;; .some-class { background-color: #ffffff; } +;; #some-id { width: 200px; } + +;; .some-more-class { +;; color: #ffffff; +;; background-color: #ffffff; +;; width: 200px; +;; } + +;; Keep these in order. They are each added to the _front_ of the +;; list and are applied in order. Changing their order will change +;; the results. +(add-to-list 'align-rules-list + `(css-closing-brace + (regexp . ,(rx (group (0+ whitespace)) "}" eol)) + (group . (1)) + (modes . '(scss-mode css-mode)))) + +(add-to-list 'align-rules-list + `(css-colons + (regexp . ,(rx bol + (0+ whitespace) + (1+ (any (?a . ?z) ?- ?$)) + ":" + (group (0+ whitespace)) + (0+ nonl) + ";" + eol)) + (group . (1)) + (modes . '(scss-mode css-mode)) + (repeat . t))) + +(add-to-list 'align-rules-list + `(css-opening-brace + (regexp . ,(rx bol + (0+ whitespace) + (0+ (any ?# ?. ?, ?\s ?& ?: ?- + (?a . ?z) (?A . ?Z) (?0 . ?9))) + (any (?a . ?z) (?A . ?Z) (?0 . ?9)) + (group (0+ whitespace)) + "{" + (0+ nonl))) + (group . (1)) + (modes . '(scss-mode css-mode)))) + +;;;###autoload +(with-eval-after-load 'grep + (add-to-list 'grep-files-aliases '("css" . "*.css *.less *.sass *.scss"))) + +;;;###autoload(with-eval-after-load 'css-mode (require 'oni-css)) + +(provide 'oni-css) +;;; oni-css.el ends here diff --git a/oni-css/snippets/css-mode/box-shadow b/oni-css/snippets/css-mode/box-shadow new file mode 100644 index 0000000..82fe9d5 --- /dev/null +++ b/oni-css/snippets/css-mode/box-shadow @@ -0,0 +1,5 @@ +# -*- mode: snippet; require-final-newline: nil -*- +# name: box-shadow +# key: boxshadow +# -- +box-shadow: ${1:offset-x} ${2:offset-y}${3: [blur-radius]}${4: [spread-radius]}${5: [color]}; \ No newline at end of file -- cgit v1.3-2-g0d8e