init-web-mode.el 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. ;;; init-web-mode.el --- .Emacs Configuration -*- lexical-binding: t -*-
  2. ;;; Commentary:
  3. ;;
  4. ;;; Code:
  5. (use-package web-mode
  6. :pin "MELPA"
  7. :mode (("\\.html?\\'" . web-mode)
  8. ("\\.djhtml\\'" . web-mode)
  9. ("\\.blade.php\\'" . web-mode)
  10. ("\\.tpl\\'" . web-mode)
  11. ("\\.twig\\'" . web-mode)
  12. ("\\.jsp\\'" . web-mode)
  13. ("\\.gsp\\'" . web-mode)
  14. ("\\.scss\\'" . web-mode)
  15. ("\\.tsx\\'" . web-mode)
  16. ("\\.ctp\\'" . web-mode))
  17. :config
  18. ;; web-modeの設定
  19. (setq web-mode-enable-current-element-highlight t)
  20. (set-face-background 'web-mode-current-element-highlight-face "#616161")
  21. ;; Fix smarty
  22. (setq web-mode-engines-alist
  23. '(("smarty" . "\\.tpl\\'")))
  24. ;; Django hook
  25. ;; require projectile
  26. (defun my-django-mode ()
  27. (when (and (require 'web-mode nil t)
  28. (fboundp 'web-mode-set-engine))
  29. (if (projectile-project-p)
  30. (when (file-exists-p (concat (projectile-project-root) "manage.py"))
  31. (web-mode-set-engine "django")
  32. ;; HTML auto functions
  33. (setq web-mode-enable-auto-opening t)
  34. (setq web-mode-enable-auto-closing t)
  35. (setq web-mode-enable-auto-quoting t)
  36. (setq web-mode-enable-auto-expanding t)
  37. ;; Auto-pairing
  38. (require 'smartparens)
  39. (sp-pair "{% " " %}")
  40. (sp-pair "{{ " " }}")
  41. (sp-pair "{# " " #}")
  42. (sp-pair "{" nil :actions :rem)
  43. (sp-pair "<" ">")
  44. (setq web-mode-enable-auto-pairing nil)))))
  45. ;; Pelican hook
  46. (defun my-pelican-mode ()
  47. (when (and (require 'web-mode nil t)
  48. (fboundp 'web-mode-set-engine))
  49. (if (projectile-project-p)
  50. (when (file-exists-p (concat (projectile-project-root) "pelicanconf.py"))
  51. (web-mode-set-engine "django")
  52. ;; HTML auto functions
  53. (setq web-mode-enable-auto-opening t)
  54. (setq web-mode-enable-auto-closing t)
  55. (setq web-mode-enable-auto-quoting t)
  56. (setq web-mode-enable-auto-expanding t)
  57. ;; Auto-pairing
  58. (require 'smartparens)
  59. (sp-pair "{% " " %}")
  60. (sp-pair "{" nil :actions :rem)
  61. (sp-pair "<" ">")
  62. (setq web-mode-enable-auto-pairing nil)))))
  63. :hook
  64. (web-mode . my-django-mode)
  65. (web-mode . my-pelican-mode))
  66. (provide 'init-web-mode)
  67. ;;; init-web-mode.el ends here