-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit-web.el
More file actions
165 lines (141 loc) · 5.17 KB
/
Copy pathinit-web.el
File metadata and controls
165 lines (141 loc) · 5.17 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
;;; elisp/init-web.el
(use-package web-mode
:ensure t)
(use-package mustache-mode
:ensure t)
;; emmet
(use-package emmet-mode
:ensure t
:commands emmet-mode
:init
(setq emmet-indentation 2)
(setq emmet-move-cursor-between-quotes t)
:config
(add-hook 'sgml-mode-hook 'emmet-mode) ;; Auto-start on any markup modes
(add-hook 'css-mode-hook 'emmet-mode)) ;; enable Emmet's css abbreviation.
;; skewer
(use-package skewer-mode
:ensure t
:commands skewer-mode run-skewer
:config (skewer-setup))
;; color ident minor mode
(use-package color-identifiers-mode
:ensure t
:init
(add-hook 'emacs-lisp-mode-hook 'color-identifiers-mode)
:diminish color-identifiers-mode)
;; insert comment with eval
(use-package lisp-mode
:config (defun eval-and-comment-output ()
"Add the output of the sexp as a comment after the sexp"
(interactive)
(save-excursion
(end-of-line)
(condition-case nil
(princ (concat " ; -> " (pp-to-string (eval (preceding-sexp))))
(current-buffer))
(error (message "Invalid expression")))))
:bind ("C-x e" . eval-and-comment-output))
;; block wrappers
(global-set-key (kbd "M-[") 'insert-pair)
(global-set-key (kbd "M-{") 'insert-pair)
(global-set-key (kbd "M-<") 'insert-pair)
(global-set-key (kbd "M-'") 'insert-pair)
(global-set-key (kbd "M-`") 'insert-pair)
(global-set-key (kbd "M-\"") 'insert-pair)
;; wrap regions
;; https://github.com/rejeep/wrap-region.el
(use-package wrap-region
:ensure t
:config
(wrap-region-global-mode t)
(wrap-region-add-wrappers
'(("(" ")")
("[" "]")
("{" "}")
("<" ">")
("'" "'")
("\"" "\"")
("‘" "’" "q")
("“" "”" "Q")
("*" "*" "b" org-mode) ; bolden
("*" "*" "*" org-mode) ; bolden
("/" "/" "i" org-mode) ; italics
("/" "/" "/" org-mode) ; italics
("~" "~" "c" org-mode) ; code
("~" "~" "~" org-mode) ; code
("=" "=" "v" org-mode) ; verbatim
("=" "=" "=" org-mode) ; verbatim
("_" "_" "u" '(org-mode markdown-mode)) ; underline
("**" "**" "b" markdown-mode) ; bolden
("*" "*" "i" markdown-mode) ; italics
("`" "`" "c" '(markdown-mode ruby-mode)) ; code
("`" "'" "c" lisp-mode) ; code
))
:diminish wrap-region-mode)
;; surround text
(defun surround (start end txt)
"Wraps the specified region (or the current 'symbol / word'
with some textual markers that this function requests from the
user. Opening-type text, like parens and angle-brackets will
insert the matching closing symbol.
This function also supports some org-mode wrappers:
- `#s` wraps the region in a source code block
- `#e` wraps it in an example block
- `#q` wraps it in an quote block"
(interactive "r\nsEnter text to surround: " start end txt)
;; If the region is not active, we use the 'thing-at-point' function
;; to get a "symbol" (often a variable or a single word in text),
;; and use that as our region.
(if (not (region-active-p))
(let ((new-region (bounds-of-thing-at-point 'symbol)))
(setq start (car new-region))
(setq end (cdr new-region))))
;; We create a table of "odd balls" where the front and the end are
;; not the same string.
(let* ((s-table '(("#e" . ("#+BEGIN_EXAMPLE\n" "\n#+END_EXAMPLE") )
("#s" . ("#+BEGIN_SRC \n" "\n#+END_SRC") )
("#q" . ("#+BEGIN_QUOTE\n" "\n#+END_QUOTE"))
("<" . ("<" ">"))
("(" . ("(" ")"))
("{" . ("{" "}"))
("[" . ("[" "]")))) ; Why yes, we'll add more
(s-pair (assoc-default txt s-table)))
;; If txt doesn't match a table entry, then the pair will just be
;; the text for both the front and the back...
(unless s-pair
(setq s-pair (list txt txt)))
(save-excursion
(narrow-to-region start end)
(goto-char (point-min))
(insert (car s-pair))
(goto-char (point-max))
(insert (cadr s-pair))
(widen))))
(global-set-key (kbd "C-+") 'surround)
;; wrap wrapper ..?
(defun surround-text (txt)
(if (region-active-p)
(surround (region-beginning) (region-end) txt)
(surround nil nil txt)))
;; interactive lambda expr to keybind
(defun surround-text-with (surr-str)
"Returns an interactive function that when called, will surround the region (or word) with the SURR-STR string."
(lexical-let ((text surr-str))
(lambda ()
(interactive)
(surround-text text))))
(defun surround-html (start end tag)
"Wraps the specified region (or the current 'symbol / word'
with a properly formatted HTML tag."
(interactive "r\nsTag: " start end tag)
(save-excursion
(narrow-to-region start end)
(goto-char (point-min))
(insert (format "<%s>" tag))
(goto-char (point-max))
(insert (format "</%s>" tag))
(widen)))
;;(define-key html-mode-map (kbd "C-c C-w") 'surround-html)
(provide 'init-web)
;; init-web.el ends here