-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
emmet-mode.el
4272 lines (4076 loc) · 148 KB
/
emmet-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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; emmet-mode.el --- Unofficial Emmet's support for emacs -*- lexical-binding: t; -*-
;; Copyright (C) 2014- Dmitry Mukhutdinov (@flyingleafe https://github.com/flyingleafe)
;; Copyright (C) 2014- William David Mayo (@pbocks https://github.com/pobocks)
;; Copyright (C) 2013- Shin Aoyama (@smihica https://github.com/smihica)
;; Copyright (C) 2009-2012 Chris Done
;; Version: 1.0.10
;; Author: Shin Aoyama <[email protected]>
;; URL: https://github.com/smihica/emmet-mode
;; Last-Updated: 2014-08-11 Mon
;; Keywords: convenience
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;;
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:
;;
;; Unfold CSS-selector-like expressions to markup. Intended to be used
;; with sgml-like languages; xml, html, xhtml, xsl, etc.
;;
;; See `emmet-mode' for more information.
;;
;; Copy emmet-mode.el to your load-path and add to your .emacs:
;;
;; (require 'emmet-mode)
;;
;; Example setup:
;;
;; (add-to-list 'load-path "~/Emacs/emmet/")
;; (require 'emmet-mode)
;; (add-hook 'sgml-mode-hook 'emmet-mode) ;; Auto-start on any markup modes
;; (add-hook 'html-mode-hook 'emmet-mode)
;; (add-hook 'css-mode-hook 'emmet-mode)
;;
;; Enable the minor mode with M-x emmet-mode.
;;
;; See ``Test cases'' section for a complete set of expression types.
;;
;; If you are hacking on this project, eval (emmet-test-cases) to
;; ensure that your changes have not broken anything. Feel free to add
;; new test cases if you add new features.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; History:
;;
;; This is a fork of zencoding-mode to support Emmet's feature.
;; zencoding-mode (https://github.com/rooney/zencoding)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Code:
(defconst emmet-mode:version "1.0.10")
(with-no-warnings
(require 'cl-lib))
;; for portability with < 24.3 EMACS
(unless (fboundp 'cl-labels) (fset 'cl-labels 'labels))
(unless (fboundp 'cl-flet) (fset 'cl-flet 'flet))
;; < 22.1
(unless (fboundp 'string-to-number) (fset 'string-to-number 'string-to-int))
(defmacro emmet-defparameter (symbol &optional initvalue docstring)
`(progn
(defvar ,symbol nil ,docstring)
(setq ,symbol ,initvalue)))
(defun emmet-join-string (lis joiner)
(mapconcat 'identity lis joiner))
(defun emmet-get-keys-of-hash (hash)
(let ((ks nil))
(maphash #'(lambda (k v) (setq ks (cons k ks))) hash)
ks))
(defun emmet-get-vals-of-hash (hash)
(let ((vs nil))
(maphash #'(lambda (k v) (setq vs (cons v vs))) hash)
vs))
(defun emmet-jsx-prop-value-var? (prop-value)
(string-match "{.+}" prop-value))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Generic parsing macros and utilities
(defmacro emmet-aif (test-form then-form &rest else-forms)
"Anaphoric if. Temporary variable `it' is the result of test-form."
`(let ((it ,test-form))
(if it ,then-form ,@(or else-forms '(it)))))
(defmacro emmet-pif (test-form then-form &rest else-forms)
"Parser anaphoric if. Temporary variable `it' is the result of test-form."
`(let ((it ,test-form))
(if (not (eq 'error (car it))) ,then-form ,@(or else-forms '(it)))))
(defmacro emmet-parse (regex nums label &rest body)
"Parse according to a regex and update the `input' variable."
`(emmet-aif (emmet-regex ,regex input ',(number-sequence 0 nums))
(let ((input (elt it ,nums)))
,@body)
`,`(error ,(concat "expected " ,label))))
(defmacro emmet-run (parser then-form &rest else-forms)
"Run a parser and update the input properly, extract the parsed
expression."
`(emmet-pif (,parser input)
(let ((input (cdr it))
(expr (car it)))
,then-form)
,@(or else-forms '(it))))
(defmacro emmet-por (parser1 parser2 then-form &rest else-forms)
"OR two parsers. Try one parser, if it fails try the next."
`(emmet-pif (,parser1 input)
(let ((input (cdr it))
(expr (car it)))
,then-form)
(emmet-pif (,parser2 input)
(let ((input (cdr it))
(expr (car it)))
,then-form)
,@else-forms)))
(defmacro emmet-find (direction regexp &optional limit-of-search repeat-count)
"Regexp-search in given direction, returning the position (or nil)
and leaving the point in place."
`(save-excursion
(if (,(intern (concat "re-search-" direction))
,regexp ,limit-of-search t ,repeat-count)
(match-beginning 0))))
(defun emmet-regex (regexp string refs)
"Return a list of (`ref') matches for a `regex' on a `string' or nil."
(if (string-match (concat "^" regexp "\\([^\n]*\\)$") string)
(mapcar (lambda (ref) (match-string ref string))
(if (sequencep refs) refs (list refs)))
nil))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Emmet minor mode
(defgroup emmet nil
"Customization group for emmet-mode."
:group 'convenience)
(defun emmet-expr-on-line ()
"Extract a emmet expression and the corresponding bounds
for the current line."
(let* ((end (point))
(start (emmet-find-left-bound))
(line (buffer-substring-no-properties start end))
(expr (emmet-regex "\\([ \t]*\\)\\([^\n]+\\)" line 2)))
(if (cl-first expr)
(list (cl-first expr) start end))))
(defun emmet-find-left-bound ()
"Find the left bound of an emmet expr"
(save-excursion (save-match-data
(let ((char (char-before))
(in-style-attr (looking-back "style=[\"'][^\"']*" nil))
(syn-tab (make-syntax-table)))
(modify-syntax-entry ?\\ "\\")
(while char
(cond ((and in-style-attr (member char '(?\" ?\')))
(setq char nil))
((member char '(?\} ?\] ?\)))
(with-syntax-table syn-tab
(backward-sexp) (setq char (char-before))))
((eq char ?\>)
(if (looking-back "<[^>]+>" (line-beginning-position))
(setq char nil)
(progn (backward-char) (setq char (char-before)))))
((not (string-match-p "[[:space:]\n;]" (string char)))
(backward-char) (setq char (char-before)))
(t
(setq char nil))))
(point)))))
(defcustom emmet-indentation 4
"Number of spaces used for indentation."
:type '(number :tag "Spaces")
:group 'emmet)
(defcustom emmet-indent-after-insert t
"Indent region after insert?"
:type 'boolean
:group 'emmet)
(defcustom emmet-use-style-tag-and-attr-detection t
"When true, enables detection of style tags and attributes in HTML
to provide proper CSS abbreviations completion."
:type 'boolean
:group 'emmet)
(defcustom emmet-self-closing-tag-style "/"
"Self-closing tags style.
This determines how Emmet expands self-closing tags.
E.g., FOO is a self-closing tag. When expanding \"FOO\":
When \" /\", the expansion is \"<FOO />\".
When \"/\", the expansion is \"<FOO/>\".
When \"\", the expansion is \"<FOO>\".
Default value is \"/\".
NOTE: only \" /\", \"/\" and \"\" are valid."
:type '(choice (const :tag " />" " /")
(const :tag "/>" "/")
(const :tag ">" ""))
:group 'emmet)
(defvar emmet-use-css-transform nil
"When true, transform Emmet snippets into CSS, instead of the usual HTML.")
(make-variable-buffer-local 'emmet-use-css-transform)
(defvar emmet-use-sass-syntax nil
"When true, uses Sass syntax for CSS abbreviations expanding,
e. g. without semicolons")
(make-variable-buffer-local 'emmet-use-sass-syntax)
(defvar emmet-css-major-modes
'(css-mode
scss-mode
sass-mode
less-mode
less-css-mode)
"Major modes that use emmet for CSS, rather than HTML.")
(defvar emmet-fallback-filter '("html")
"Fallback filter for `emmet-default-filter', if none is found.")
(defvar emmet-file-filter nil
"File local filter used by `emmet-default-filter'.")
(make-variable-buffer-local 'emmet-file-filter)
(defvar emmet-jsx-major-modes
'(rjsx-mode
typescript-tsx-mode
js-jsx-mode
js2-jsx-mode
jsx-mode
js-mode)
"Which modes to check before using jsx class expansion")
(defun emmet-transform (input)
(if (or (emmet-detect-style-tag-and-attr) emmet-use-css-transform)
(emmet-css-transform input)
(emmet-html-transform input)))
(defun emmet-detect-style-tag-and-attr ()
(let* ((style-attr-end "[^=][\"']")
(style-attr-begin "style=[\"']")
(style-tag-end "</style>")
(style-tag-begin "<style.*>"))
(and emmet-use-style-tag-and-attr-detection
(or
(emmet-check-if-between style-attr-begin style-attr-end) ; style attr
(emmet-check-if-between style-tag-begin style-tag-end))))) ; style tag
(defun emmet-check-if-between (begin end)
(let ((begin-back (emmet-find "backward" begin))
(end-back (emmet-find "backward" end))
(begin-front (emmet-find "forward" begin))
(end-front (emmet-find "forward" end)))
(and begin-back end-front
(or (not end-back) (> begin-back end-back))
(or (not begin-front) (< end-front begin-front)))))
(defcustom emmet-preview-default nil
"If non-nil then preview is the default action.
This determines how `emmet-expand-line' works by default."
:type 'boolean
:group 'emmet)
;;;###autoload
(defun emmet-expand-line (arg)
"Replace the current line's emmet expression with the corresponding expansion.
If prefix ARG is given or region is visible call `emmet-preview' to start an
interactive preview.
Otherwise expand line directly.
For more information see `emmet-mode'."
(interactive "P")
(let* ((here (point))
(preview (if emmet-preview-default (not arg) arg))
(beg (if preview
(emmet-find-left-bound)
(when (use-region-p) (region-beginning))))
(end (if preview
here
(when (use-region-p) (region-end)))))
(if (and preview beg)
(progn
(goto-char here)
(emmet-preview beg end))
(let ((expr (emmet-expr-on-line)))
(if expr
(let ((markup (emmet-transform (cl-first expr))))
(when markup
(delete-region (cl-second expr) (cl-third expr))
(emmet-insert-and-flash markup)
(emmet-reposition-cursor expr))))))))
(defvar emmet-mode-keymap
(let
((map (make-sparse-keymap)))
(define-key map (kbd "C-j") 'emmet-expand-line)
(define-key map (kbd "<C-return>") 'emmet-expand-line)
(define-key map (kbd "<C-M-right>") 'emmet-next-edit-point)
(define-key map (kbd "<C-M-left>") 'emmet-prev-edit-point)
(define-key map (kbd "C-c C-c w") 'emmet-wrap-with-markup)
map)
"Keymap for emmet minor mode.")
(defun emmet-after-hook ()
"Initialize Emmet's buffer-local variables."
(if (memq major-mode emmet-css-major-modes)
(setq emmet-use-css-transform t))
(if (eq major-mode 'sass-mode)
(setq emmet-use-sass-syntax t)))
;;;###autoload
(define-minor-mode emmet-mode
"Minor mode for writing HTML and CSS markup.
With emmet for HTML and CSS you can write a line like
ul#name>li.item*2
and have it expanded to
<ul id=\"name\">
<li class=\"item\"></li>
<li class=\"item\"></li>
</ul>
This minor mode defines keys for quick access:
\\{emmet-mode-keymap}
Home page URL `http://www.emacswiki.org/emacs/Emmet'.
See also `emmet-expand-line'."
:lighter (" Emmet" (:eval (if emmet-preview-mode "[P]" "")))
:keymap emmet-mode-keymap
:after-hook (emmet-after-hook))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Emmet yasnippet integration
(defun emmet-transform-yas (input)
(let* ((leaf-count 0)
(emmet-leaf-function
(lambda ()
(format "$%d" (cl-incf leaf-count)))))
(emmet-transform input)))
;;;###autoload
(defun emmet-expand-yas ()
(interactive)
(let ((expr (emmet-expr-on-line)))
(if expr
(let* ((markup (emmet-transform-yas (cl-first expr)))
(filled (replace-regexp-in-string "><" ">\n<" markup)))
(delete-region (cl-second expr) (cl-third expr))
(insert filled)
(indent-region (cl-second expr) (point))
(if (fboundp 'yas/expand-snippet)
(yas/expand-snippet
(buffer-substring (cl-second expr) (point))
(cl-second expr) (point)))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Real-time preview
;;
;;;;;;;;;;
;; Lennart's version
(defvar emmet-preview-input nil)
(make-local-variable 'emmet-preview-input)
(defvar emmet-preview-output nil)
(make-local-variable 'emmet-preview-output)
(defvar emmet-old-show-paren nil)
(make-local-variable 'emmet-old-show-paren)
(defface emmet-preview-input
'((default :box t :inherit secondary-selection))
"Face for preview input field."
:group 'emmet)
(defface emmet-preview-output
'((default :inherit highlight))
"Face for preview output field."
:group 'emmet)
(defvar emmet-preview-keymap
(let ((map (make-sparse-keymap)))
(define-key map (kbd "RET") 'emmet-preview-accept)
(define-key map (kbd "<return>") 'emmet-preview-accept)
(define-key map [(control ?g)] 'emmet-preview-abort)
map))
(defun emmet-html-text-p (markup)
(string-match "^[\s|\t|\n|\r]*<.*$" markup))
(defun emmet-preview-accept ()
(interactive)
(let ((ovli emmet-preview-input)
(expr (emmet-expr-on-line)))
(if (not (and (overlayp ovli)
(bufferp (overlay-buffer ovli))))
(message "Preview is not active")
(let* ((indent (current-indentation))
(markup (emmet-preview-transformed indent)))
(when markup
(delete-region (overlay-start ovli) (overlay-end ovli))
(emmet-insert-and-flash markup)
(emmet-reposition-cursor expr)))))
(emmet-preview-abort))
(defun emmet-html-next-insert-point (str)
(with-temp-buffer
(insert str)
(goto-char (point-min))
(or
(emmet-aif (emmet-go-to-edit-point 1 t) (- it 1)) ; try to find an edit point
(emmet-aif (re-search-forward ".+</" nil t) (- it 3)) ; try to place cursor after tag contents
(length str)))) ; ok, just go to the end
(defun emmet-css-next-insert-point (str)
(let ((regexp (if emmet-use-sass-syntax ": *\\($\\)" ": *\\(;\\)$")))
(save-match-data
(set-match-data nil t)
(string-match regexp str)
(or (match-beginning 1) (length str)))))
(defvar emmet-flash-ovl nil)
(make-variable-buffer-local 'emmet-flash-ovl)
(defun emmet-remove-flash-ovl (buf)
(with-current-buffer buf
(when (overlayp emmet-flash-ovl)
(delete-overlay emmet-flash-ovl))
(setq emmet-flash-ovl nil)))
(defcustom emmet-insert-flash-time 0.5
"Time to flash insertion.
Set this to a negative number if you do not want flashing the
expansion after insertion."
:type '(number :tag "Seconds")
:group 'emmet)
(defcustom emmet-move-cursor-after-expanding t
"If non-nil the the cursor position is
moved to before the first closing tag when the exp was expanded."
:type 'boolean
:group 'emmet)
(defcustom emmet-move-cursor-between-quotes nil
"If emmet-move-cursor-after-expands is non-nil and this is non-nil then
cursor position will be moved to after the first quote."
:type 'boolean
:group 'emmet)
(defun emmet-reposition-cursor (expr)
(let ((output-markup (buffer-substring-no-properties (cl-second expr) (point))))
(when emmet-move-cursor-after-expanding
(let ((p (point))
(new-pos (if (emmet-html-text-p output-markup)
(emmet-html-next-insert-point output-markup)
(emmet-css-next-insert-point output-markup))))
(goto-char
(+ (- p (length output-markup))
new-pos))))))
(defun emmet-insert-and-flash (markup)
(emmet-remove-flash-ovl (current-buffer))
(let ((here (point)))
(insert markup)
(when emmet-indent-after-insert
(indent-region here (point))
(setq here
(save-excursion
(goto-char here)
(skip-chars-forward "[:space:]")
(point))))
(setq emmet-flash-ovl (make-overlay here (point)))
(overlay-put emmet-flash-ovl 'face 'emmet-preview-output)
(when (< 0 emmet-insert-flash-time)
(run-with-idle-timer emmet-insert-flash-time
nil 'emmet-remove-flash-ovl (current-buffer)))))
;;;###autoload
(defun emmet-preview (beg end)
"Expand emmet between BEG and END interactively.
This will show a preview of the expanded emmet code and you can
accept it or skip it."
(interactive (if (use-region-p)
(list (region-beginning) (region-end))
(list nil nil)))
(emmet-preview-abort)
(if (not beg)
(message "Region not active")
(setq emmet-old-show-paren show-paren-mode)
(show-paren-mode -1)
(let ((here (point)))
(goto-char beg)
(forward-line 1)
(unless (= 0 (current-column))
(insert "\n"))
(let* ((opos (point))
(ovli (make-overlay beg end nil nil t))
(ovlo (make-overlay opos opos))
(info (propertize " Emmet preview. Choose with RET. Cancel by stepping out. \n"
'face 'tooltip)))
(overlay-put ovli 'face 'emmet-preview-input)
(overlay-put ovli 'keymap emmet-preview-keymap)
(overlay-put ovlo 'face 'emmet-preview-output)
(overlay-put ovlo 'before-string info)
(setq emmet-preview-input ovli)
(setq emmet-preview-output ovlo)
(add-hook 'before-change-functions 'emmet-preview-before-change t t)
(goto-char here)
(add-hook 'post-command-hook 'emmet-preview-post-command t t)))))
(defun emmet-preview-online ()
"Display `emmet-preview' on the fly as the user types.
To use this, add the function as a local hook:
(add-hook 'post-self-insert-hook 'emmet-preview-online t t)
or enable `emmet-preview-mode'."
(ignore-errors
(let* ((expr (emmet-expr-on-line))
(text (nth 0 expr))
(beg (nth 1 expr))
(end (nth 2 expr)))
(let ((wap (thing-at-point 'word 'no-properties)))
(when (and (not (equal wap text))
(emmet-transform text))
(emmet-preview beg end))))))
(define-minor-mode emmet-preview-mode
"When enabled, automatically show `emmet-preview' as the user types.
See `emmet-preview-online'."
:init-value nil
:group 'emmet
(if emmet-preview-mode
(add-hook 'post-self-insert-hook 'emmet-preview-online :append :local)
(remove-hook 'post-self-insert-hook 'emmet-preview-online :local)))
(defvar emmet-preview-pending-abort nil)
(make-variable-buffer-local 'emmet-preview-pending-abort)
(defun emmet-preview-before-change (beg end)
(when
(or (> beg (overlay-end emmet-preview-input))
(< beg (overlay-start emmet-preview-input))
(> end (overlay-end emmet-preview-input))
(< end (overlay-start emmet-preview-input)))
(setq emmet-preview-pending-abort t)))
(defun emmet-preview-abort ()
"Abort emmet code preview."
(interactive)
(setq emmet-preview-pending-abort nil)
(remove-hook 'before-change-functions 'emmet-preview-before-change t)
(when (overlayp emmet-preview-input)
(delete-overlay emmet-preview-input))
(setq emmet-preview-input nil)
(when (overlayp emmet-preview-output)
(delete-overlay emmet-preview-output))
(setq emmet-preview-output nil)
(remove-hook 'post-command-hook 'emmet-preview-post-command t)
(when emmet-old-show-paren (show-paren-mode 1)))
(defun emmet-preview-post-command ()
(condition-case err
(emmet-preview-post-command-1)
(error (message "emmet-preview-post: %s" err))))
(defun emmet-preview-post-command-1 ()
(if (and (not emmet-preview-pending-abort)
(<= (point) (overlay-end emmet-preview-input))
(>= (point) (overlay-start emmet-preview-input)))
(emmet-update-preview (current-indentation))
(emmet-preview-abort)))
(defun emmet-preview-transformed (indent)
(let* ((string (buffer-substring-no-properties
(overlay-start emmet-preview-input)
(overlay-end emmet-preview-input))))
(let ((output (emmet-transform string)))
(when output
output))))
(defun emmet-update-preview (indent)
(let* ((pretty (emmet-preview-transformed indent))
(show (when pretty
(propertize pretty 'face 'highlight))))
(when show
(overlay-put emmet-preview-output 'after-string
(concat show "\n")))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Implementation of "Go to Edit Point" functionality ;;
;; http://docs.emmet.io/actions/go-to-edit-point/ ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun emmet-go-to-edit-point (count &optional only-before-closed-tag)
(let*
((between-tags
(if only-before-closed-tag "\\(><\\)/" "\\(><\\)"))
(indented-line "\\(^[[:blank:]]+$\\)")
(between-quotes
(if emmet-move-cursor-between-quotes "\\(=\\(\"\\|'\\)\\{2\\}\\)" nil))
(whole-regex
(mapconcat 'identity
(delq nil
(list between-tags indented-line between-quotes))
"\\|"))
(edit-point (format "\\(%s\\)" whole-regex)))
(if (> count 0)
(progn
(forward-char)
(let
((search-result (re-search-forward edit-point nil t count)))
(if search-result
(progn
(cond
((match-string 2) (goto-char (- (match-end 2) 1)))
((match-string 3) (end-of-line))
((match-string 4) (backward-char)))
(point))
(backward-char))))
(progn
(backward-char)
(let
((search-result (re-search-backward edit-point nil t (- count))))
(if search-result
(progn
(cond
((match-string 2) (goto-char (- (match-end 2) 1)))
((match-string 3) (end-of-line))
((match-string 4) (forward-char 2)))
(point))
(forward-char)))))))
(defcustom emmet-postwrap-goto-edit-point nil
"Goto first edit point after wrapping markup?"
:type 'boolean
:group 'emmet)
;;;###autoload
(defun emmet-wrap-with-markup (wrap-with)
"Wrap region with markup."
(interactive "sExpression to wrap with: ")
(let* ((multi (string-match "\\*$" wrap-with))
(txt (buffer-substring-no-properties (region-beginning) (region-end)))
(to-wrap (if multi
(split-string txt "\n")
(list txt)))
(initial-elements (replace-regexp-in-string
"\\(.*\\(\\+\\|>\\)\\)?[^>*]+\\*?[[:digit:]]*$"
"\\1" wrap-with t))
(terminal-element (replace-regexp-in-string
"\\(.*>\\)?\\([^>*]+\\)\\(\\*[[:digit:]]+$\\)?\\*?$"
"\\2" wrap-with t))
(multiplier-expr (replace-regexp-in-string
"\\(.*>\\)?\\([^>*]+\\)\\(\\*[[:digit:]]+$\\)?\\*?$"
"\\3" wrap-with t))
(expr (concat
initial-elements
(mapconcat (lambda (el)
(concat terminal-element
"{!!!"
(secure-hash 'sha1 el)
"!!!}"
multiplier-expr))
to-wrap
"+")))
(markup
(cl-reduce
(lambda (result text)
(replace-regexp-in-string
(concat "!!!" (secure-hash 'sha1 text) "!!!")
text
result t t))
to-wrap
:initial-value (emmet-transform expr))))
(when markup
(delete-region (region-beginning) (region-end))
(insert markup)
(indent-region (region-beginning) (region-end))
(if emmet-postwrap-goto-edit-point
(let ((end (region-end)))
(goto-char (region-beginning))
(unless (ignore-errors (progn (emmet-next-edit-point 1) t))
(goto-char end)))
))))
;;;###autoload
(defun emmet-next-edit-point (count)
(interactive "^p")
(unless (or emmet-use-css-transform (emmet-go-to-edit-point count))
(error "Last edit point reached.")))
;;;###autoload
(defun emmet-prev-edit-point (count)
(interactive "^p")
(unless (or emmet-use-css-transform (emmet-go-to-edit-point (- count)))
(error "First edit point reached.")))
(provide 'emmet-mode)
;; src/snippets.el
;; This file is generated from conf/snippets.json
;; Don't edit.
(emmet-defparameter emmet-snippets
(let ((tbl (make-hash-table :test 'equal)))
(puthash "css" (let ((tbl (make-hash-table :test 'equal)))
(puthash "snippets" (let ((tbl (make-hash-table :test 'equal)))
(puthash "!" "!important" tbl)
(puthash "@f" "@font-face {\n\tfont-family:|;\n\tsrc:url(|);\n}" tbl)
(puthash "@f+" "@font-face {\n\tfont-family: '${1:FontName}';\n\tsrc: url('${2:FileName}.eot');\n\tsrc: url('${2:FileName}.eot?#iefix') format('embedded-opentype'),\n\t\t url('${2:FileName}.woff') format('woff'),\n\t\t url('${2:FileName}.ttf') format('truetype'),\n\t\t url('${2:FileName}.svg#${1:FontName}') format('svg');\n\tfont-style: ${3:normal};\n\tfont-weight: ${4:normal};\n}" tbl)
(puthash "@i" "@import url(|);" tbl)
(puthash "@import" "@import url(|);" tbl)
(puthash "@kf" "@-webkit-keyframes ${1:identifier} {\n\t${2:from} { ${3} }${6}\n\t${4:to} { ${5} }\n}\n@-o-keyframes ${1:identifier} {\n\t${2:from} { ${3} }${6}\n\t${4:to} { ${5} }\n}\n@-moz-keyframes ${1:identifier} {\n\t${2:from} { ${3} }${6}\n\t${4:to} { ${5} }\n}\n@keyframes ${1:identifier} {\n\t${2:from} { ${3} }${6}\n\t${4:to} { ${5} }\n}" tbl)
(puthash "@m" "@media ${1:screen} {\n\t|\n}" tbl)
(puthash "@media" "@media ${1:screen} {\n\t|\n}" tbl)
(puthash "ac" "align-content:|;" tbl)
(puthash "ac:c" "align-content:center;" tbl)
(puthash "ac:fe" "align-content:flex-end;" tbl)
(puthash "ac:fs" "align-content:flex-start;" tbl)
(puthash "ac:s" "align-content:stretch;" tbl)
(puthash "ac:sa" "align-content:space-around;" tbl)
(puthash "ac:sb" "align-content:space-between;" tbl)
(puthash "ai" "align-items:|;" tbl)
(puthash "ai:b" "align-items:baseline;" tbl)
(puthash "ai:c" "align-items:center;" tbl)
(puthash "ai:fe" "align-items:flex-end;" tbl)
(puthash "ai:fs" "align-items:flex-start;" tbl)
(puthash "ai:s" "align-items:stretch;" tbl)
(puthash "anim" "animation:|;" tbl)
(puthash "anim-" "animation:${1:name} ${2:duration} ${3:timing-function} ${4:delay} ${5:iteration-count} ${6:direction} ${7:fill-mode};" tbl)
(puthash "animdel" "animation-delay:${1:time};" tbl)
(puthash "animdir" "animation-direction:${1:normal};" tbl)
(puthash "animdir:a" "animation-direction:alternate;" tbl)
(puthash "animdir:ar" "animation-direction:alternate-reverse;" tbl)
(puthash "animdir:n" "animation-direction:normal;" tbl)
(puthash "animdir:r" "animation-direction:reverse;" tbl)
(puthash "animdur" "animation-duration:${1:0}s;" tbl)
(puthash "animfm" "animation-fill-mode:${1:both};" tbl)
(puthash "animfm:b" "animation-fill-mode:backwards;" tbl)
(puthash "animfm:bh" "animation-fill-mode:both;" tbl)
(puthash "animfm:bt" "animation-fill-mode:both;" tbl)
(puthash "animfm:f" "animation-fill-mode:forwards;" tbl)
(puthash "animic" "animation-iteration-count:${1:1};" tbl)
(puthash "animic:i" "animation-iteration-count:infinite;" tbl)
(puthash "animn" "animation-name:${1:none};" tbl)
(puthash "animps" "animation-play-state:${1:running};" tbl)
(puthash "animps:p" "animation-play-state:paused;" tbl)
(puthash "animps:r" "animation-play-state:running;" tbl)
(puthash "animtf" "animation-timing-function:${1:linear};" tbl)
(puthash "animtf:cb" "animation-timing-function:cubic-bezier(${1:0.1}, ${2:0.7}, ${3:1.0}, ${3:0.1});" tbl)
(puthash "animtf:e" "animation-timing-function:ease;" tbl)
(puthash "animtf:ei" "animation-timing-function:ease-in;" tbl)
(puthash "animtf:eio" "animation-timing-function:ease-in-out;" tbl)
(puthash "animtf:eo" "animation-timing-function:ease-out;" tbl)
(puthash "animtf:l" "animation-timing-function:linear;" tbl)
(puthash "ap" "appearance:${none};" tbl)
(puthash "as" "align-self:|;" tbl)
(puthash "as:a" "align-self:auto;" tbl)
(puthash "as:b" "align-self:baseline;" tbl)
(puthash "as:c" "align-self:center;" tbl)
(puthash "as:fe" "align-self:flex-end;" tbl)
(puthash "as:fs" "align-self:flex-start;" tbl)
(puthash "as:s" "align-self:stretch;" tbl)
(puthash "b" "bottom:|;" tbl)
(puthash "b:a" "bottom:auto;" tbl)
(puthash "bb" "border-bottom:|;" tbl)
(puthash "bd" "border:|;" tbl)
(puthash "bd+" "border:${1:1px} ${2:solid} ${3:#000};" tbl)
(puthash "bd:n" "border:none;" tbl)
(puthash "bdb" "border-bottom:|;" tbl)
(puthash "bdb+" "border-bottom:${1:1px} ${2:solid} ${3:#000};" tbl)
(puthash "bdb:n" "border-bottom:none;" tbl)
(puthash "bdbc" "border-bottom-color:${1:#000};" tbl)
(puthash "bdbc:t" "border-bottom-color:transparent;" tbl)
(puthash "bdbi" "border-bottom-image:url(|);" tbl)
(puthash "bdbi:n" "border-bottom-image:none;" tbl)
(puthash "bdbk" "border-break:${1:close};" tbl)
(puthash "bdbk:c" "border-break:close;" tbl)
(puthash "bdbli" "border-bottom-left-image:url(|);" tbl)
(puthash "bdbli:c" "border-bottom-left-image:continue;" tbl)
(puthash "bdbli:n" "border-bottom-left-image:none;" tbl)
(puthash "bdblrs" "border-bottom-left-radius:|;" tbl)
(puthash "bdbri" "border-bottom-right-image:url(|);" tbl)
(puthash "bdbri:c" "border-bottom-right-image:continue;" tbl)
(puthash "bdbri:n" "border-bottom-right-image:none;" tbl)
(puthash "bdbrrs" "border-bottom-right-radius:|;" tbl)
(puthash "bdbs" "border-bottom-style:|;" tbl)
(puthash "bdbs:n" "border-bottom-style:none;" tbl)
(puthash "bdbw" "border-bottom-width:|;" tbl)
(puthash "bdc" "border-color:${1:#000};" tbl)
(puthash "bdc:t" "border-color:transparent;" tbl)
(puthash "bdci" "border-corner-image:url(|);" tbl)
(puthash "bdci:c" "border-corner-image:continue;" tbl)
(puthash "bdci:n" "border-corner-image:none;" tbl)
(puthash "bdcl" "border-collapse:|;" tbl)
(puthash "bdcl:c" "border-collapse:collapse;" tbl)
(puthash "bdcl:s" "border-collapse:separate;" tbl)
(puthash "bdf" "border-fit:${1:repeat};" tbl)
(puthash "bdf:c" "border-fit:clip;" tbl)
(puthash "bdf:of" "border-fit:overflow;" tbl)
(puthash "bdf:ow" "border-fit:overwrite;" tbl)
(puthash "bdf:r" "border-fit:repeat;" tbl)
(puthash "bdf:sc" "border-fit:scale;" tbl)
(puthash "bdf:sp" "border-fit:space;" tbl)
(puthash "bdf:st" "border-fit:stretch;" tbl)
(puthash "bdi" "border-image:url(|);" tbl)
(puthash "bdi:n" "border-image:none;" tbl)
(puthash "bdl" "border-left:|;" tbl)
(puthash "bdl+" "border-left:${1:1px} ${2:solid} ${3:#000};" tbl)
(puthash "bdl:n" "border-left:none;" tbl)
(puthash "bdlc" "border-left-color:${1:#000};" tbl)
(puthash "bdlc:t" "border-left-color:transparent;" tbl)
(puthash "bdlen" "border-length:|;" tbl)
(puthash "bdlen:a" "border-length:auto;" tbl)
(puthash "bdli" "border-left-image:url(|);" tbl)
(puthash "bdli:n" "border-left-image:none;" tbl)
(puthash "bdls" "border-left-style:|;" tbl)
(puthash "bdls:n" "border-left-style:none;" tbl)
(puthash "bdlw" "border-left-width:|;" tbl)
(puthash "bdr" "border-right:|;" tbl)
(puthash "bdr+" "border-right:${1:1px} ${2:solid} ${3:#000};" tbl)
(puthash "bdr:n" "border-right:none;" tbl)
(puthash "bdrc" "border-right-color:${1:#000};" tbl)
(puthash "bdrc:t" "border-right-color:transparent;" tbl)
(puthash "bdri" "border-right-image:url(|);" tbl)
(puthash "bdri:n" "border-right-image:none;" tbl)
(puthash "bdrs" "border-radius:|;" tbl)
(puthash "bdrst" "border-right-style:|;" tbl)
(puthash "bdrst:n" "border-right-style:none;" tbl)
(puthash "bdrw" "border-right-width:|;" tbl)
(puthash "bds" "border-style:|;" tbl)
(puthash "bds:db" "border-style:double;" tbl)
(puthash "bds:ds" "border-style:dashed;" tbl)
(puthash "bds:dt" "border-style:dotted;" tbl)
(puthash "bds:dtds" "border-style:dot-dash;" tbl)
(puthash "bds:dtdtds" "border-style:dot-dot-dash;" tbl)
(puthash "bds:g" "border-style:groove;" tbl)
(puthash "bds:h" "border-style:hidden;" tbl)
(puthash "bds:i" "border-style:inset;" tbl)
(puthash "bds:n" "border-style:none;" tbl)
(puthash "bds:o" "border-style:outset;" tbl)
(puthash "bds:r" "border-style:ridge;" tbl)
(puthash "bds:s" "border-style:solid;" tbl)
(puthash "bds:w" "border-style:wave;" tbl)
(puthash "bdsp" "border-spacing:|;" tbl)
(puthash "bdt" "border-top:|;" tbl)
(puthash "bdt+" "border-top:${1:1px} ${2:solid} ${3:#000};" tbl)
(puthash "bdt:n" "border-top:none;" tbl)
(puthash "bdtc" "border-top-color:${1:#000};" tbl)
(puthash "bdtc:t" "border-top-color:transparent;" tbl)
(puthash "bdti" "border-top-image:url(|);" tbl)
(puthash "bdti:n" "border-top-image:none;" tbl)
(puthash "bdtli" "border-top-left-image:url(|);" tbl)
(puthash "bdtli:c" "border-top-left-image:continue;" tbl)
(puthash "bdtli:n" "border-top-left-image:none;" tbl)
(puthash "bdtlrs" "border-top-left-radius:|;" tbl)
(puthash "bdtri" "border-top-right-image:url(|);" tbl)
(puthash "bdtri:c" "border-top-right-image:continue;" tbl)
(puthash "bdtri:n" "border-top-right-image:none;" tbl)
(puthash "bdtrrs" "border-top-right-radius:|;" tbl)
(puthash "bdts" "border-top-style:|;" tbl)
(puthash "bdts:n" "border-top-style:none;" tbl)
(puthash "bdtw" "border-top-width:|;" tbl)
(puthash "bdw" "border-width:|;" tbl)
(puthash "bfv" "backface-visibility:|;" tbl)
(puthash "bfv:h" "backface-visibility:hidden;" tbl)
(puthash "bfv:v" "backface-visibility:visible;" tbl)
(puthash "bg" "background:#${1:000};" tbl)
(puthash "bg+" "background:${1:#fff} url(${2}) ${3:0} ${4:0} ${5:no-repeat};" tbl)
(puthash "bg:ie" "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='${1:x}.png',sizingMethod='${2:crop}');" tbl)
(puthash "bg:n" "background:none;" tbl)
(puthash "bga" "background-attachment:|;" tbl)
(puthash "bga:f" "background-attachment:fixed;" tbl)
(puthash "bga:s" "background-attachment:scroll;" tbl)
(puthash "bgbk" "background-break:|;" tbl)
(puthash "bgbk:bb" "background-break:bounding-box;" tbl)
(puthash "bgbk:c" "background-break:continuous;" tbl)
(puthash "bgbk:eb" "background-break:each-box;" tbl)
(puthash "bgc" "background-color:${1:fff};" tbl)
(puthash "bgc:t" "background-color:transparent;" tbl)
(puthash "bgcp" "background-clip:${1:padding-box};" tbl)
(puthash "bgcp:bb" "background-clip:border-box;" tbl)
(puthash "bgcp:cb" "background-clip:content-box;" tbl)
(puthash "bgcp:nc" "background-clip:no-clip;" tbl)
(puthash "bgcp:pb" "background-clip:padding-box;" tbl)
(puthash "bgi" "background-image:url(|);" tbl)
(puthash "bgi:n" "background-image:none;" tbl)
(puthash "bgo" "background-origin:|;" tbl)
(puthash "bgo:bb" "background-origin:border-box;" tbl)
(puthash "bgo:cb" "background-origin:content-box;" tbl)
(puthash "bgo:pb" "background-origin:padding-box;" tbl)
(puthash "bgp" "background-position:${1:0} ${2:0};" tbl)
(puthash "bgpx" "background-position-x:|;" tbl)
(puthash "bgpy" "background-position-y:|;" tbl)
(puthash "bgr" "background-repeat:|;" tbl)
(puthash "bgr:n" "background-repeat:no-repeat;" tbl)
(puthash "bgr:rd" "background-repeat:round;" tbl)
(puthash "bgr:sp" "background-repeat:space;" tbl)
(puthash "bgr:x" "background-repeat:repeat-x;" tbl)
(puthash "bgr:y" "background-repeat:repeat-y;" tbl)
(puthash "bgsz" "background-size:|;" tbl)
(puthash "bgsz:a" "background-size:auto;" tbl)
(puthash "bgsz:ct" "background-size:contain;" tbl)
(puthash "bgsz:cv" "background-size:cover;" tbl)
(puthash "bl" "border-left:|;" tbl)
(puthash "br" "border-right:|;" tbl)
(puthash "bt" "border-top:|;" tbl)
(puthash "bxsh" "box-shadow:${1:inset }${2:hoff} ${3:voff} ${4:blur} ${5:color};" tbl)
(puthash "bxsh:n" "box-shadow:none;" tbl)
(puthash "bxsh:r" "box-shadow:${1:inset }${2:hoff} ${3:voff} ${4:blur} ${5:spread }rgb(${6:0}, ${7:0}, ${8:0});" tbl)
(puthash "bxsh:ra" "box-shadow:${1:inset }${2:h} ${3:v} ${4:blur} ${5:spread }rgba(${6:0}, ${7:0}, ${8:0}, .${9:5});" tbl)
(puthash "bxz" "box-sizing:${1:border-box};" tbl)
(puthash "bxz:bb" "box-sizing:border-box;" tbl)
(puthash "bxz:cb" "box-sizing:content-box;" tbl)
(puthash "c" "color:${1:#000};" tbl)
(puthash "c:r" "color:rgb(${1:0}, ${2:0}, ${3:0});" tbl)
(puthash "c:ra" "color:rgba(${1:0}, ${2:0}, ${3:0}, .${4:5});" tbl)
(puthash "cl" "clear:${1:both};" tbl)
(puthash "cl:b" "clear:both;" tbl)
(puthash "cl:l" "clear:left;" tbl)
(puthash "cl:n" "clear:none;" tbl)
(puthash "cl:r" "clear:right;" tbl)
(puthash "cm" "/* |${child} */" tbl)
(puthash "cnt" "content:'|';" tbl)
(puthash "cnt:a" "content:attr(|);" tbl)
(puthash "cnt:c" "content:counter(|);" tbl)
(puthash "cnt:cq" "content:close-quote;" tbl)
(puthash "cnt:cs" "content:counters(|);" tbl)
(puthash "cnt:n" "content:normal;" tbl)
(puthash "cnt:ncq" "content:no-close-quote;" tbl)
(puthash "cnt:noq" "content:no-open-quote;" tbl)
(puthash "cnt:oq" "content:open-quote;" tbl)
(puthash "coi" "counter-increment:|;" tbl)
(puthash "colm" "columns:|;" tbl)
(puthash "colmc" "column-count:|;" tbl)
(puthash "colmf" "column-fill:|;" tbl)
(puthash "colmg" "column-gap:|;" tbl)
(puthash "colmr" "column-rule:|;" tbl)
(puthash "colmrc" "column-rule-color:|;" tbl)
(puthash "colmrs" "column-rule-style:|;" tbl)
(puthash "colmrw" "column-rule-width:|;" tbl)
(puthash "colms" "column-span:|;" tbl)
(puthash "colmw" "column-width:|;" tbl)
(puthash "cor" "counter-reset:|;" tbl)
(puthash "cp" "clip:|;" tbl)
(puthash "cp:a" "clip:auto;" tbl)
(puthash "cp:r" "clip:rect(${1:top} ${2:right} ${3:bottom} ${4:left});" tbl)
(puthash "cps" "caption-side:|;" tbl)
(puthash "cps:b" "caption-side:bottom;" tbl)
(puthash "cps:t" "caption-side:top;" tbl)
(puthash "ct" "content:|;" tbl)
(puthash "ct:a" "content:attr(|);" tbl)
(puthash "ct:c" "content:counter(|);" tbl)
(puthash "ct:cq" "content:close-quote;" tbl)
(puthash "ct:cs" "content:counters(|);" tbl)
(puthash "ct:n" "content:normal;" tbl)
(puthash "ct:ncq" "content:no-close-quote;" tbl)
(puthash "ct:noq" "content:no-open-quote;" tbl)
(puthash "ct:oq" "content:open-quote;" tbl)
(puthash "cur" "cursor:${pointer};" tbl)
(puthash "cur:a" "cursor:auto;" tbl)
(puthash "cur:c" "cursor:crosshair;" tbl)