forked from magnars/.emacs.d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-html-mode.el
51 lines (43 loc) · 1.84 KB
/
setup-html-mode.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(defun skip-to-next-blank-line ()
(interactive)
(let ((inhibit-changing-match-data t))
(skip-syntax-forward " >")
(unless (search-forward-regexp "^\\s *$" nil t)
(goto-char (point-max)))))
(defun skip-to-previous-blank-line ()
(interactive)
(let ((inhibit-changing-match-data t))
(skip-syntax-backward " >")
(unless (search-backward-regexp "^\\s *$" nil t)
(goto-char (point-min)))))
(defun html-wrap-in-tag (beg end)
(interactive "r")
(let ((oneline? (= (line-number-at-pos beg) (line-number-at-pos end))))
(deactivate-mark)
(goto-char end)
(unless oneline? (newline-and-indent))
(insert "</div>")
(goto-char beg)
(insert "<div>")
(unless oneline? (newline-and-indent))
(indent-region beg (+ end 11))
(goto-char (+ beg 4))))
(eval-after-load "sgml-mode"
'(progn
(define-key html-mode-map [remap forward-paragraph] 'skip-to-next-blank-line)
(define-key html-mode-map [remap backward-paragraph] 'skip-to-previous-blank-line)
(define-key html-mode-map (kbd "C-c C-w") 'html-wrap-in-tag)
(define-key html-mode-map (kbd "/") nil) ;; no buggy matching of slashes
(require 'tagedit)
;; paredit lookalikes
(define-key html-mode-map (kbd "s-<right>") 'tagedit-forward-slurp-tag)
(define-key html-mode-map (kbd "C-)") 'tagedit-forward-slurp-tag)
(define-key html-mode-map (kbd "s-<left>") 'tagedit-forward-barf-tag)
(define-key html-mode-map (kbd "C-}") 'tagedit-forward-barf-tag)
(define-key html-mode-map (kbd "M-r") 'tagedit-raise-tag)
(tagedit-add-experimental-features)
(add-hook 'html-mode-hook (lambda () (tagedit-mode 1)))
;; no paredit equivalents
(define-key html-mode-map (kbd "s-k") 'tagedit-kill-attribute)
(define-key html-mode-map (kbd "s-<return>") 'tagedit-toggle-multiline-tag)))
(provide 'setup-html-mode)