Skip to content

Commit

Permalink
HTML mode changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamzehn committed Apr 29, 2024
1 parent 1263d32 commit f46a42d
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions lisp/init-html.el
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
;;; init-html.el --- Editing HTML -*- lexical-binding: t -*-
;; init-html.el --- Editing HTML -*- lexical-binding: t -*-
;;; Commentary:

;; ERB is configured separately in init-ruby

;;; Code:

(require-package 'tagedit)
(with-eval-after-load 'sgml-mode
(tagedit-add-paredit-like-keybindings)
(define-key tagedit-mode-map (kbd "M-?") nil)
(define-key tagedit-mode-map (kbd "M-s") nil)
(add-hook 'sgml-mode-hook (lambda () (tagedit-mode 1))))
(require 'sgml-mode)

(add-auto-mode 'html-mode "\\.\\(jsp\\|tmpl\\)\\'")
(when (maybe-require-package 'web-mode)
(add-to-list 'auto-mode-alist '("\\.phtml\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.[agj]sp\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.as[cp]x\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.erb\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.mustache\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.djhtml\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode)))


(with-eval-after-load 'web-mode
(setq web-mode-markup-indent-offset 2))

(defun my/enable-minor-mode (my-pair)
"Enable minor mode if filename match the regexp. MY-PAIR is a cons cell (regexp . minor-mode)."
(if (buffer-file-name)
(if (string-match (car my-pair) buffer-file-name)
(funcall (cdr my-pair)))))

(when (maybe-require-package 'prettier-js)
(add-hook 'web-mode-hook #'(lambda ()
(my/enable-minor-mode
'("\\.html?\\'" . prettier-js-mode)))))

(defun my/turn-on-sgml-electric-tag-pair-mode ()
(sgml-electric-tag-pair-mode 1))
(add-hook 'web-mode-hook 'my/turn-on-sgml-electric-tag-pair-mode)

(provide 'init-html)
;;; init-html.el ends here

0 comments on commit f46a42d

Please sign in to comment.