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

267 lines
8.4 KiB
EmacsLisp
Raw Normal View History

;;; packages.el --- HTML Layer packages File for Spacemacs
;;
;; Copyright (c) 2012-2016 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(setq html-packages
'(
company
(company-web :toggle (configuration-layer/package-usedp 'company))
css-mode
emmet-mode
evil-matchit
flycheck
haml-mode
(helm-css-scss :toggle (configuration-layer/package-usedp 'helm))
less-css-mode
pug-mode
2015-03-17 22:15:58 +00:00
sass-mode
scss-mode
slim-mode
smartparens
tagedit
web-mode
yasnippet
))
(defun html/post-init-company ()
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-css
:modes css-mode))
(defun html/init-company-web ()
2016-12-14 05:55:04 +00:00
(use-package company-web
:defer t
: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
:variables
;; see https://github.com/osv/company-web/issues/4
company-minimum-prefix-length 0)
(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)
;; Explicitly run prog-mode hooks since css-mode does not derive from
;; prog-mode major-mode in Emacs 24 and below.
(when (version< emacs-version "25")
(add-hook 'css-mode-hook 'spacemacs/run-prog-mode-hooks))
2015-08-28 06:07:17 +00:00
(defun css-expand-statement ()
"Expand CSS block"
(interactive)
(save-excursion
(end-of-line)
(search-backward "{")
(forward-char 1)
(while (or (eobp) (not (looking-at "}")))
(let ((beg (point)))
(newline)
(search-forward ";")
(indent-region beg (point))
))
(newline)))
(defun css-contract-statement ()
"Contract CSS block"
(interactive)
(end-of-line)
(search-backward "{")
(while (not (looking-at "}"))
(join-line -1)))
(spacemacs/set-leader-keys-for-major-mode 'css-mode
"zc" 'css-contract-statement
"zo" '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
(evil-define-key 'insert emmet-mode-keymap (kbd "TAB") 'spacemacs/emmet-expand)
(evil-define-key 'insert emmet-mode-keymap (kbd "<tab>") 'spacemacs/emmet-expand)
(evil-define-key 'emacs emmet-mode-keymap (kbd "TAB") 'spacemacs/emmet-expand)
(evil-define-key 'emacs emmet-mode-keymap (kbd "<tab>") 'spacemacs/emmet-expand)
(evil-define-key 'hybrid emmet-mode-keymap (kbd "TAB") 'spacemacs/emmet-expand)
(evil-define-key 'hybrid emmet-mode-keymap (kbd "<tab>") 'spacemacs/emmet-expand)
(spacemacs|hide-lighter emmet-mode))))
(defun html/post-init-evil-matchit ()
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/add-flycheck-hook mode)))
(defun html/init-haml-mode ()
(use-package haml-mode
:defer t))
(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-less-css-mode ()
(use-package less-css-mode
:defer t
:mode ("\\.less\\'" . less-css-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
:mode ("\\.scss\\'" . scss-mode)))
(defun html/init-slim-mode ()
(use-package slim-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
:defer t))
(defun html/post-init-smartparens ()
(spacemacs/add-to-hooks
(if dotspacemacs-smartparens-strict-mode
'smartparens-strict-mode
'smartparens-mode)
'(css-mode-hook scss-mode-hook sass-mode-hook less-css-mode-hook))
2016-01-21 15:49:08 +00:00
(add-hook 'web-mode-hook 'spacemacs/toggle-smartparens-off))
(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
2015-03-02 20:52:30 +00:00
:config
(progn
2016-08-12 14:57:34 +00:00
(spacemacs/declare-prefix-for-mode 'web-mode "me" "errors")
(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
"eh" '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
2015-03-02 20:52:30 +00:00
;; TODO element close would be nice but broken with evil.
)
;; (defvar spacemacs--web-mode-ms-doc-toggle 0
;; "Display a short doc when nil, full doc otherwise.")
;; (defun spacemacs//web-mode-ms-doc ()
;; (if (equal 0 spacemacs--web-mode-ms-doc-toggle)
;; "[_?_] for help"
;; "
;; [_?_] display this help
;; [_k_] previous [_j_] next [_K_] previous sibling [_J_] next sibling
;; [_h_] parent [_l_] child [_c_] clone [_d_] delete [_D_] kill [_r_] rename
;; [_w_] wrap [_p_] xpath
;; [_q_] quit"))
;; (defun spacemacs//web-mode-ms-toggle-doc ()
;; (interactive)
;; (setq spacemacs--web-mode-ms-doc-toggle
;; (logxor spacemacs--web-mode-ms-doc-toggle 1)))
2016-01-20 02:55:38 +00:00
(spacemacs|define-transient-state web-mode
:title "Web-mode Transient State"
:columns 4
:foreign-keys run
:evil-leader-for-mode (web-mode . ".")
2015-03-02 20:52:30 +00:00
:bindings
("j" web-mode-element-next "next")
("J" web-mode-element-sibling-next "next sibling")
("gj" web-mode-element-sibling-next)
("k" web-mode-element-previous "previous")
("K" web-mode-element-sibling-previous "previous sibling")
("gk" web-mode-element-sibling-previous)
("h" web-mode-element-parent "parent")
("l" web-mode-element-child "child")
("c" web-mode-element-clone "clone")
("d" web-mode-element-vanish "delete")
("D" web-mode-element-kill "kill")
("r" web-mode-element-rename "rename" :exit t)
("w" web-mode-element-wrap "wrap")
("p" web-mode-dom-xpath "xpath")
("q" nil "quit" :exit t)
("<escape>" nil nil :exit t)))
:mode
(("\\.phtml\\'" . web-mode)
("\\.tpl\\.php\\'" . web-mode)
2015-08-18 16:13:32 +00:00
("\\.twig\\'" . 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)
("\\.djhtml\\'" . web-mode))))
(defun html/post-init-yasnippet ()
(spacemacs/add-to-hooks 'spacemacs/load-yasnippet '(css-mode-hook
jade-mode
slim-mode)))