web.el 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. ;; --- web configuration file.---
  2. ;; Provides basic utility for web programming such as:
  3. ;; * Tag auto-pairing
  4. ;; * Switching major modes when entering different tags
  5. ;; Requires:
  6. (require 'package-loader)
  7. (defun my-sgml-insert-gt ()
  8. "Inserts a `>' character and calls
  9. `my-sgml-close-tag-if-necessary', leaving point where it is."
  10. (interactive)
  11. (insert ">")
  12. (save-excursion (my-sgml-close-tag-if-necessary)))
  13. (defun my-sgml-close-tag-if-necessary ()
  14. "Calls sgml-close-tag if the tag immediately before point is
  15. an opening tag that is not followed by a matching closing tag."
  16. (when (looking-back "<\\s-*\\([^</> \t\r\n]+\\)[^</>]*>")
  17. (let ((tag (match-string 1)))
  18. (unless (and (not (sgml-unclosed-tag-p tag))
  19. (looking-at (concat "\\s-*<\\s-*/\\s-*" tag "\\s-*>")))
  20. (sgml-close-tag)))))
  21. ;; TODO: Disable autopair in HTML. Interferes with autoclose tab.
  22. (use-package multi-web-mode
  23. :init
  24. (setq mweb-default-major-mode 'html-mode
  25. mweb-tags '((php-mode "<\\?php\\|<\\? \\|<\\?=" "\\?>")
  26. (js-mode "<script[^>]*>" "</script>")
  27. (css-mode "<style[^>]*>" "</style>"))
  28. mweb-filename-extensions '("php" "htm" "html" "ctp" "phtml" "php4" "php5"))
  29. :config
  30. (multi-web-global-mode 1)
  31. (eval-after-load "sgml-mode"
  32. '(define-key sgml-mode-map ">" 'my-sgml-insert-gt)))
  33. (provide 'web)