commit | author | age
|
5cb5f7
|
1 |
;;; smartparens-html.el --- Additional configuration for HTML based modes. -*- lexical-binding: t; -*- |
C |
2 |
|
|
3 |
;; Copyright (C) 2013-2014 Matus Goljer |
|
4 |
|
|
5 |
;; Author: Matus Goljer <matus.goljer@gmail.com> |
|
6 |
;; Maintainer: Matus Goljer <matus.goljer@gmail.com> |
|
7 |
;; Created: 14 Sep 2013 |
|
8 |
;; Keywords: abbrev convenience editing |
|
9 |
;; URL: https://github.com/Fuco1/smartparens |
|
10 |
|
|
11 |
;; This file is not part of GNU Emacs. |
|
12 |
|
|
13 |
;;; License: |
|
14 |
|
|
15 |
;; This file is part of Smartparens. |
|
16 |
|
|
17 |
;; Smartparens is free software; you can redistribute it and/or modify |
|
18 |
;; it under the terms of the GNU General Public License as published by |
|
19 |
;; the Free Software Foundation, either version 3 of the License, or |
|
20 |
;; (at your option) any later version. |
|
21 |
|
|
22 |
;; Smartparens is distributed in the hope that it will be useful, |
|
23 |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
24 |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
25 |
;; GNU General Public License for more details. |
|
26 |
|
|
27 |
;; You should have received a copy of the GNU General Public License |
|
28 |
;; along with Smartparens. If not, see <http://www.gnu.org/licenses/>. |
|
29 |
|
|
30 |
;;; Commentary: |
|
31 |
|
|
32 |
;; This file provides some additional configuration for HTML based |
|
33 |
;; modes. To use it, simply add: |
|
34 |
;; |
|
35 |
;; (require 'smartparens-html) |
|
36 |
;; |
|
37 |
;; into your configuration. You can use this in conjunction with the |
|
38 |
;; default config or your own configuration. |
|
39 |
|
|
40 |
;; This file provides these interactive functions: |
|
41 |
|
|
42 |
;; `sp-html-next-tag' - Recommended binding: C-c C-f |
|
43 |
;; `sp-html-previous-tag' - Recommended binding: C-c C-b |
|
44 |
;; |
|
45 |
;; (These two bindings are used for navigation by tags forward or |
|
46 |
;; backward, but `sp-forward-sexp' already does that.) |
|
47 |
|
|
48 |
;; If you have good ideas about what should be added please file an |
|
49 |
;; issue on the github tracker. |
|
50 |
|
|
51 |
;; For more info, see github readme at |
|
52 |
;; https://github.com/Fuco1/smartparens |
|
53 |
|
|
54 |
;;; Code: |
|
55 |
|
|
56 |
(require 'smartparens) |
|
57 |
|
|
58 |
(defun sp-html-next-tag (arg) |
|
59 |
"Move point to the beginning of next SGML tag. |
|
60 |
|
|
61 |
With ARG positive N > 1, move N tags forward. |
|
62 |
|
|
63 |
With ARG raw prefix argument \\[universal-argument] move out of |
|
64 |
the current tag and to the beginning of enclosing tag. |
|
65 |
|
|
66 |
Note: this function is based on `sp-beginning-of-sexp' but |
|
67 |
specialized to only work with SGML tags and to always move |
|
68 |
forward." |
|
69 |
(interactive "P") |
|
70 |
(let ((sp-prefix-tag-object t)) |
|
71 |
(if (sp--raw-argument-p arg) |
|
72 |
(sp-beginning-of-sexp arg) |
|
73 |
(sp-beginning-of-sexp (1+ (prefix-numeric-value arg)))))) |
|
74 |
|
|
75 |
(defun sp-html-previous-tag (arg) |
|
76 |
"Move point to the beginning of previous SGML tag. |
|
77 |
|
|
78 |
With ARG positive N > 1, move N tags backward. |
|
79 |
|
|
80 |
With ARG raw prefix argument \\[universal-argument] move out of |
|
81 |
the current tag and to the beginning of enclosing tag. |
|
82 |
|
|
83 |
Note: this function is based on `sp-beginning-of-sexp' but |
|
84 |
specialized to only work with SGML tags and to always move |
|
85 |
backward." |
|
86 |
(interactive "P") |
|
87 |
(let ((sp-prefix-tag-object t)) |
|
88 |
(if (sp--raw-argument-p arg) |
|
89 |
(sp-beginning-of-sexp arg) |
|
90 |
(sp-beginning-of-sexp (1- (- (prefix-numeric-value arg))))))) |
|
91 |
|
|
92 |
(defun sp-html-post-handler (&optional _id action _context) |
|
93 |
"Post-action hooks for `html-mode'. |
|
94 |
|
|
95 |
ID is the tag being processed, ACTION is the action and CONTEXT |
|
96 |
specifies if we are inside a string or code." |
|
97 |
(cl-case action |
|
98 |
(slurp-forward |
|
99 |
(save-excursion |
|
100 |
(let ((sp-prefix-pair-object t)) |
|
101 |
(sp-backward-sexp)) |
|
102 |
(-when-let (enc (sp-get-enclosing-sexp)) |
|
103 |
(sp-get enc |
|
104 |
(goto-char :beg-in) |
|
105 |
(when (looking-at-p "[ \t]*$") |
|
106 |
(goto-char :end-in) |
|
107 |
(save-excursion |
|
108 |
(sp-backward-sexp) |
|
109 |
(forward-line -1) |
|
110 |
(when (sp-point-in-blank-line) |
|
111 |
(delete-region (line-beginning-position) (1+ (line-end-position))))) |
|
112 |
(newline-and-indent)))))) |
|
113 |
(slurp-backward |
|
114 |
(save-excursion |
|
115 |
(-when-let (enc (sp-get-enclosing-sexp)) |
|
116 |
(sp-get enc |
|
117 |
(goto-char :end-in) |
|
118 |
(when (sp--looking-back-p "^[ \t]*") |
|
119 |
(save-excursion |
|
120 |
(goto-char :beg-in) |
|
121 |
(newline-and-indent) |
|
122 |
(sp-forward-sexp) |
|
123 |
(forward-line) |
|
124 |
(when (sp-point-in-blank-line) |
|
125 |
(delete-region (line-beginning-position) (1+ (line-end-position)))))))))) |
|
126 |
(barf-forward |
|
127 |
(save-excursion |
|
128 |
(let ((sp-prefix-pair-object t)) |
|
129 |
(sp-backward-sexp)) |
|
130 |
(-when-let (enc (sp-get-enclosing-sexp)) |
|
131 |
(sp-get enc |
|
132 |
(goto-char :beg-in) |
|
133 |
(when (looking-at-p "[ \t]*$") |
|
134 |
(goto-char :end-in) |
|
135 |
(newline-and-indent))))) |
|
136 |
(save-excursion |
|
137 |
(sp-forward-sexp) |
|
138 |
(forward-line) |
|
139 |
(when (sp-point-in-blank-line) |
|
140 |
(delete-region (line-beginning-position) (1+ (line-end-position)))))) |
|
141 |
(barf-backward |
|
142 |
(save-excursion |
|
143 |
(-when-let (enc (sp-get-enclosing-sexp)) |
|
144 |
(sp-get enc |
|
145 |
(goto-char :end-in) |
|
146 |
(when (sp--looking-back-p "^[ \t]*") |
|
147 |
(goto-char :beg-in) |
|
148 |
(newline-and-indent) |
|
149 |
(sp-backward-up-sexp) |
|
150 |
(sp-backward-sexp) |
|
151 |
(forward-line -1) |
|
152 |
(when (sp-point-in-blank-line) |
|
153 |
(delete-region (line-beginning-position) (1+ (line-end-position))))))))) |
|
154 |
(beginning-of-sexp |
|
155 |
(when (looking-at-p "[ \t]*$") |
|
156 |
(sp-next-sexp))) |
|
157 |
(end-of-sexp |
|
158 |
(when (sp--looking-back-p "^[ \t]*" nil t) |
|
159 |
(sp-previous-sexp))))) |
|
160 |
|
|
161 |
(sp-with-modes sp--html-modes |
|
162 |
(sp-local-pair "<" ">") |
|
163 |
(sp-local-tag "<" "<_>" "</_>" :transform 'sp-match-sgml-tags :post-handlers '(sp-html-post-handler))) |
|
164 |
|
|
165 |
(--each sp--html-modes |
|
166 |
(add-to-list 'sp-navigate-consider-sgml-tags it)) |
|
167 |
|
|
168 |
(--each '(web-mode) |
|
169 |
(add-to-list 'sp-sexp-suffix (list it 'regexp ""))) |
|
170 |
|
|
171 |
(provide 'smartparens-html) |
|
172 |
|
|
173 |
;;; smartparens-html.el ends here |