This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/layers/+lang/html/packages.el

263 lines
8.5 KiB
EmacsLisp
Raw Normal View History

;;; packages.el --- HTML Layer packages File for Spacemacs
;;
2021-03-22 20:11:29 +00:00
;; Copyright (c) 2012-2021 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;; 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 <http://www.gnu.org/licenses/>.
(setq html-packages
'(
add-node-modules-path
company
2017-07-03 07:52:54 +00:00
(company-web :requires company)
css-mode
emmet-mode
evil-matchit
flycheck
haml-mode
(counsel-css :requires ivy)
2017-07-03 07:52:54 +00:00
(helm-css-scss :requires helm)
impatient-mode
less-css-mode
prettier-js
pug-mode
sass-mode
scss-mode
slim-mode
smartparens
tagedit
web-mode
yasnippet
web-beautify))
(defun html/post-init-add-node-modules-path ()
(add-hook 'css-mode-hook #'add-node-modules-path)
(add-hook 'less-css-mode-hook #'add-node-modules-path)
(add-hook 'pug-mode-hook #'add-node-modules-path)
(add-hook 'sass-mode-hook #'add-node-modules-path)
(add-hook 'scss-mode-hook #'add-node-modules-path)
(add-hook 'slim-mode-hook #'add-node-modules-path)
(add-hook 'web-mode-hook #'add-node-modules-path))
(defun html/post-init-company ()
2019-05-08 13:06:17 +00:00
(unless css-enable-lsp
(spacemacs|add-company-backends
:backends company-css
:modes css-mode)))
(defun html/init-company-web ()
2016-12-14 05:55:04 +00:00
(use-package company-web
:defer t
2016-12-14 05:55:04 +00:00
:init
(progn
Refactor and simplify company backends declaration Enabling a company backend for a specific mode was a tedious tasks with code scattered at different locations, one for local variable definitions, one for company hook function definitions and another where the backends were pushed to the local variables (which was problematic, since we ended up pushing the same backends over and over again with `SPC f e R`, pushes have been replaced by add-to-list calls in the new macro). All these steps are now put together at one place with the new macro spacemacs|add-company-backends, check its docstring for more info on its arguments. This macro also allows to define arbitrary buffer local variables to tune company for specific modes (similar to layer variables via a keyword :variables) The code related to company backends management has been moved to the auto-completion layer in the funcs.el file. A nice side effect of this move is that it enforces correct encapsulation of company backends related code. We can now easily detect if there is some configuration leakage when the auto-completion layer is not used. But we loose macro expansion at file loading time (not sue it is a big concern though). The function spacemacs|enable-auto-complete was never used so it has been deleted which led to the deletion of the now empty file core-auto-completion.el. The example in LAYERS.org regarding auto-completion is now out of date and has been deleted. An example to setup auto-completion is provided in the README.org file of the auto-completion layer.
2017-01-02 05:39:04 +00:00
(spacemacs|add-company-backends
:backends (company-web-html company-css)
:modes web-mode)
Refactor and simplify company backends declaration Enabling a company backend for a specific mode was a tedious tasks with code scattered at different locations, one for local variable definitions, one for company hook function definitions and another where the backends were pushed to the local variables (which was problematic, since we ended up pushing the same backends over and over again with `SPC f e R`, pushes have been replaced by add-to-list calls in the new macro). All these steps are now put together at one place with the new macro spacemacs|add-company-backends, check its docstring for more info on its arguments. This macro also allows to define arbitrary buffer local variables to tune company for specific modes (similar to layer variables via a keyword :variables) The code related to company backends management has been moved to the auto-completion layer in the funcs.el file. A nice side effect of this move is that it enforces correct encapsulation of company backends related code. We can now easily detect if there is some configuration leakage when the auto-completion layer is not used. But we loose macro expansion at file loading time (not sue it is a big concern though). The function spacemacs|enable-auto-complete was never used so it has been deleted which led to the deletion of the now empty file core-auto-completion.el. The example in LAYERS.org regarding auto-completion is now out of date and has been deleted. An example to setup auto-completion is provided in the README.org file of the auto-completion layer.
2017-01-02 05:39:04 +00:00
(spacemacs|add-company-backends
:backends company-web-jade
:modes pug-mode)
(spacemacs|add-company-backends
:backends company-web-slim
:modes slim-mode))))
(defun html/init-css-mode ()
(use-package css-mode
:defer t
:init
2015-08-28 06:07:17 +00:00
(progn
;; Mark `css-indent-offset' as safe-local variable
(put 'css-indent-offset 'safe-local-variable #'integerp)
2019-05-08 13:06:17 +00:00
(when css-enable-lsp
(add-hook 'css-mode-hook
2019-10-06 03:29:43 +00:00
#'spacemacs//setup-lsp-for-web-mode-buffers t))
2019-05-08 13:06:17 +00:00
(spacemacs/declare-prefix-for-mode 'css-mode "m=" "format")
(spacemacs/declare-prefix-for-mode 'css-mode "mg" "goto")
(spacemacs/declare-prefix-for-mode 'css-mode "mz" "foldz")
(spacemacs/set-leader-keys-for-major-mode 'css-mode
2018-05-18 04:46:12 +00:00
"zc" 'spacemacs/css-contract-statement
"zo" 'spacemacs/css-expand-statement))))
(defun html/init-emmet-mode ()
(use-package emmet-mode
:defer t
:init (spacemacs/add-to-hooks 'emmet-mode '(css-mode-hook
html-mode-hook
sass-mode-hook
scss-mode-hook
web-mode-hook))
:config
(progn
(define-key emmet-mode-keymap (kbd "<C-return>") 'spacemacs/emmet-expand)
(spacemacs|hide-lighter emmet-mode))))
(defun html/post-init-evil-matchit ()
(evilmi-load-plugin-rules '(web-mode) '(simple template html))
2015-08-10 19:40:05 +00:00
(add-hook 'web-mode-hook 'turn-on-evil-matchit-mode))
(defun html/post-init-flycheck ()
2016-01-27 20:08:25 +00:00
(dolist (mode '(haml-mode
less-mode
pug-mode
2016-01-27 20:08:25 +00:00
sass-mode
scss-mode
slim-mode
web-mode))
(spacemacs/enable-flycheck mode)))
(defun html/init-haml-mode ()
(use-package haml-mode
:defer t))
(defun html/init-counsel-css ()
(use-package counsel-css
:defer t
2018-01-07 02:38:13 +00:00
:init (cl-loop for (mode . mode-hook) in '((css-mode . css-mode-hook)
2019-10-06 03:29:43 +00:00
(scss-mode . scss-mode-hook))
do (add-hook mode-hook 'counsel-css-imenu-setup)
(spacemacs/set-leader-keys-for-major-mode mode "gh" 'counsel-css))))
(defun html/init-helm-css-scss ()
(use-package helm-css-scss
:defer t
:init
(dolist (mode '(css-mode scss-mode))
(spacemacs/set-leader-keys-for-major-mode mode "gh" 'helm-css-scss))))
(defun html/init-impatient-mode ()
(use-package impatient-mode
:defer t
:init
(progn
(dolist (mode '(web-mode css-mode))
2018-06-05 05:57:25 +00:00
(spacemacs/set-leader-keys-for-major-mode 'web-mode "I" 'spacemacs/impatient-mode)))))
(defun html/init-less-css-mode ()
(use-package less-css-mode
:defer t
2019-05-08 13:06:17 +00:00
:init
(when less-enable-lsp
(add-hook 'less-css-mode-hook
2019-10-06 03:29:43 +00:00
#'spacemacs//setup-lsp-for-web-mode-buffers t))
:mode ("\\.less\\'" . less-css-mode)))
(defun html/pre-init-prettier-js ()
(when (eq web-fmt-tool 'prettier)
(dolist (mode '(css-mode less-css-mode scss-mode web-mode))
(add-to-list 'spacemacs--prettier-modes mode))))
(defun html/init-pug-mode ()
(use-package pug-mode
:defer t
Refactor and simplify company backends declaration Enabling a company backend for a specific mode was a tedious tasks with code scattered at different locations, one for local variable definitions, one for company hook function definitions and another where the backends were pushed to the local variables (which was problematic, since we ended up pushing the same backends over and over again with `SPC f e R`, pushes have been replaced by add-to-list calls in the new macro). All these steps are now put together at one place with the new macro spacemacs|add-company-backends, check its docstring for more info on its arguments. This macro also allows to define arbitrary buffer local variables to tune company for specific modes (similar to layer variables via a keyword :variables) The code related to company backends management has been moved to the auto-completion layer in the funcs.el file. A nice side effect of this move is that it enforces correct encapsulation of company backends related code. We can now easily detect if there is some configuration leakage when the auto-completion layer is not used. But we loose macro expansion at file loading time (not sue it is a big concern though). The function spacemacs|enable-auto-complete was never used so it has been deleted which led to the deletion of the now empty file core-auto-completion.el. The example in LAYERS.org regarding auto-completion is now out of date and has been deleted. An example to setup auto-completion is provided in the README.org file of the auto-completion layer.
2017-01-02 05:39:04 +00:00
:mode ("\\.pug$" . pug-mode)))
(defun html/init-sass-mode ()
(use-package sass-mode
:defer t
:mode ("\\.sass\\'" . sass-mode)))
(defun html/init-scss-mode ()
(use-package scss-mode
:defer t
2019-05-08 13:06:17 +00:00
:init
(when scss-enable-lsp
2019-10-06 03:29:43 +00:00
(add-hook 'scss-mode-hook #'spacemacs//setup-lsp-for-web-mode-buffers t))
:mode ("\\.scss\\'" . scss-mode)))
(defun html/init-slim-mode ()
(use-package slim-mode
:defer t))
(defun html/post-init-smartparens ()
(spacemacs/add-to-hooks
#'spacemacs//activate-smartparens
'(css-mode-hook scss-mode-hook sass-mode-hook less-css-mode-hook))
(add-hook 'web-mode-hook #'spacemacs//deactivate-smartparens))
(defun html/init-tagedit ()
(use-package tagedit
:defer t
:config
(progn
(tagedit-add-experimental-features)
(add-hook 'html-mode-hook (lambda () (tagedit-mode 1)))
(spacemacs|diminish tagedit-mode "" " T"))))
(defun html/init-web-mode ()
(use-package web-mode
:defer t
:init
(progn
(spacemacs//web-setup-transient-state)
(when html-enable-lsp
(add-hook 'web-mode-hook #'spacemacs//setup-lsp-for-html-buffer t)))
2015-03-02 20:52:30 +00:00
:config
(progn
(spacemacs/declare-prefix-for-mode 'web-mode "m=" "format")
(spacemacs/declare-prefix-for-mode 'web-mode "mE" "errors")
2016-08-12 14:57:34 +00:00
(spacemacs/declare-prefix-for-mode 'web-mode "mg" "goto")
(spacemacs/declare-prefix-for-mode 'web-mode "mh" "dom")
(spacemacs/declare-prefix-for-mode 'web-mode "mr" "refactor")
(spacemacs/set-leader-keys-for-major-mode 'web-mode
"El" 'web-mode-dom-errors-show
"gb" 'web-mode-element-beginning
"gc" 'web-mode-element-child
"gp" 'web-mode-element-parent
"gs" 'web-mode-element-sibling-next
"hp" 'web-mode-dom-xpath
"rc" 'web-mode-element-clone
"rd" 'web-mode-element-vanish
"rk" 'web-mode-element-kill
"rr" 'web-mode-element-rename
"rw" 'web-mode-element-wrap
"z" 'web-mode-fold-or-unfold))
;; TODO element close would be nice but broken with evil.
:mode
(("\\.phtml\\'" . web-mode)
("\\.tpl\\.php\\'" . web-mode)
2015-08-18 16:13:32 +00:00
("\\.twig\\'" . web-mode)
("\\.xml\\'" . web-mode)
("\\.html\\'" . web-mode)
("\\.htm\\'" . web-mode)
("\\.[gj]sp\\'" . web-mode)
2015-08-30 11:20:26 +00:00
("\\.as[cp]x?\\'" . web-mode)
2015-07-06 14:27:47 +00:00
("\\.eex\\'" . web-mode)
("\\.erb\\'" . web-mode)
("\\.mustache\\'" . web-mode)
("\\.handlebars\\'" . web-mode)
("\\.hbs\\'" . web-mode)
("\\.eco\\'" . web-mode)
2015-07-05 20:20:07 +00:00
("\\.ejs\\'" . web-mode)
("\\.svelte\\'" . web-mode)
("\\.ctp\\'" . web-mode)
("\\.djhtml\\'" . web-mode))))
(defun html/post-init-yasnippet ()
(spacemacs/add-to-hooks 'spacemacs/load-yasnippet '(css-mode-hook
jade-mode
slim-mode)))
(defun html/pre-init-web-beautify ()
(when (eq web-fmt-tool 'web-beautify)
(add-to-list 'spacemacs--web-beautify-modes (cons 'css-mode 'web-beautify-css))
(add-to-list 'spacemacs--web-beautify-modes (cons 'web-mode 'web-beautify-html))))