From 09c2f6381bb6313d0472cbc77724964e2b554c24 Mon Sep 17 00:00:00 2001 From: Dave Mayo Date: Tue, 5 Aug 2014 20:37:07 -0400 Subject: Replace mark-active with (use-region-p) --- emmet-mode.el | 6 +++--- src/mode-def.el | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/emmet-mode.el b/emmet-mode.el index 5ff158a..462adf2 100644 --- a/emmet-mode.el +++ b/emmet-mode.el @@ -3535,13 +3535,13 @@ For more information see `emmet-mode'." (beginning-of-line) (skip-chars-forward " \t") (point)) - (when mark-active (region-beginning)))) + (when (use-region-p) (region-beginning)))) (end (if preview (progn (end-of-line) (skip-chars-backward " \t") (point)) - (when mark-active (region-end))))) + (when (use-region-p) (region-end))))) (if (and preview beg) (progn (goto-char here) @@ -3759,7 +3759,7 @@ cursor position will be moved to after the first quote." "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 mark-active + (interactive (if (use-region-p) (list (region-beginning) (region-end)) (list nil nil))) (emmet-preview-abort) diff --git a/src/mode-def.el b/src/mode-def.el index e84bf96..e8060a6 100644 --- a/src/mode-def.el +++ b/src/mode-def.el @@ -70,13 +70,13 @@ For more information see `emmet-mode'." (beginning-of-line) (skip-chars-forward " \t") (point)) - (when mark-active (region-beginning)))) + (when (use-region-p) (region-beginning)))) (end (if preview (progn (end-of-line) (skip-chars-backward " \t") (point)) - (when mark-active (region-end))))) + (when (use-region-p) (region-end))))) (if (and preview beg) (progn (goto-char here) @@ -294,7 +294,7 @@ cursor position will be moved to after the first quote." "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 mark-active + (interactive (if (use-region-p) (list (region-beginning) (region-end)) (list nil nil))) (emmet-preview-abort) -- cgit v1.2.3 From bee781f7e31c2f6591239fbb0271c4a96b48ecd6 Mon Sep 17 00:00:00 2001 From: Dave Mayo Date: Fri, 8 Aug 2014 17:38:20 -0400 Subject: Changes to come closer to Emmet support, to allow for better consistency of behavior. Major changes include: * Parser is changed to use Emmet's bracket syntax for properties * now uses point as the right bound of the expression * searches for left bound from right bound. This is poorly executed as of now --- README.md | 52 ++++++++++++++++++++++++++-------------------------- emmet-mode.el | 51 ++++++++++++++++++++++++++------------------------- src/html-abbrev.el | 12 +++++++++--- src/mode-def.el | 39 +++++++++++++++++---------------------- src/test.el | 52 ++++++++++++++++++++++++++-------------------------- 5 files changed, 104 insertions(+), 102 deletions(-) diff --git a/README.md b/README.md index 69211b3..dea9958 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ you'll transform your snippet into the appropriate tag structure. #### Self-closing tags - input type=text + input[type=text] img img>metadata/*2 @@ -137,7 +137,7 @@ you'll transform your snippet into the appropriate tag structure.
- ul#q.x.y m=l+
    + ul#q.x.y[m=l]
    @@ -267,27 +267,27 @@ you'll transform your snippet into the appropriate tag structure. #### Properties - b x - b x= - b x="" - b x=y - b x="y" - b x="()" - b x m - b x= m="" - b x=y m=l - b/ x=y m=l - b#foo x=y m=l - b.foo x=y m=l - b#foo.bar.mu x=y m=l - b/#foo.bar.mu x=y m=l - b x=y+b + b[x] + b[x=] + b[x=""] + b[x=y] + b[x="y"] + b[x="()"] + b[x m] + b[x= m=""] + b[x=y m=l] + b/[x=y m=l] + b#foo[x=y m=l] + b.foo[x=y m=l] + b#foo.bar.mu[x=y m=l] + b/#foo.bar.mu[x=y m=l] + b[x=y]+b - b x=y+b x=y + b[x=y]+b[x=y] - b x=y>b - b x=y>b x=y - b x=y>b x=y+c x=y + b[x=y]>b + b[x=y]>b[x=y] + b[x=y]>b[x=y]+c[x=y] @@ -387,11 +387,11 @@ you'll transform your snippet into the appropriate tag structure. a|haml %a a#q.x.y.z|haml %a#q.x.y.z - a#q.x x=y m=l|haml %a#q.x{:x => "y", :m => "l"} + a#q.x[x=y m=l]|haml %a#q.x{:x => "y", :m => "l"} div|haml %div div.footer|haml .footer .footer|haml .footer - p>{txt}+a href=#+br|haml %p + p>{txt}+a[href=#]+br|haml %p txt %a{:href => "#"} %br @@ -400,9 +400,9 @@ you'll transform your snippet into the appropriate tag structure. a|hic [:a] a#q.x.y.z|hic [:a#q.x.y.z] - a#q.x x=y m=l|hic [:a#q.x {:x "y", :m "l"}] + a#q.x[x=y m=l]|hic [:a#q.x {:x "y", :m "l"}] .footer|hic [:div.footer] - p>a href=#+br|hic [:p + p>a[href=#]+br|hic [:p [:a {:href "#"}] [:br]] #q>(a*2>b{x})+p>b|hic [:div#q @@ -413,7 +413,7 @@ you'll transform your snippet into the appropriate tag structure. #### Filter: escape - script src="|e <script src="&quot;"> + script[src="]|e <script src="&quot;"> </script> #### Aliases diff --git a/emmet-mode.el b/emmet-mode.el index 462adf2..c1f5d80 100644 --- a/emmet-mode.el +++ b/emmet-mode.el @@ -2538,7 +2538,7 @@ tbl)) `(tag (,tagname ,has-body? nil)) input)) (let ((tag-data (cadar it)) (input (cdr it))) (emmet-pif (emmet-run - emmet-props + emmet-properties (let ((props (cdr expr))) `((tag ,(append tag-data (list props))) . ,input)) `((tag ,(append tag-data '(nil))) . ,input)) @@ -2617,7 +2617,7 @@ tbl)) (defun emmet-tag-props (tag input) (let ((tag-data (cadr tag))) - (emmet-run emmet-props + (emmet-run emmet-properties (let ((props (cdr expr))) `((tag ,(append tag-data (list props))) . ,input)) `((tag ,(append tag-data '(nil))) . ,input)))) @@ -2631,7 +2631,7 @@ tbl)) (defun emmet-prop (input) (emmet-parse - " " 1 "space" + " *" 1 "space" (emmet-run emmet-name (let ((name (cdr expr))) @@ -2675,6 +2675,12 @@ tbl)) (let ((txt (emmet-split-numbering-expressions (elt it 1)))) `((text ,txt) . ,input)))) +(defun emmet-properties (input) + "A bracketed emmet property expression." + (emmet-parse "\\[\\(.*?\\)\\]" 2 "properties" + `(,(car (emmet-props (elt it 1))) . ,input))) + + (defun emmet-pexpr (input) "A zen coding expression with parentheses around it." (emmet-parse "(" 1 "(" @@ -3473,24 +3479,25 @@ tbl)) (defun emmet-expr-on-line () "Extract a emmet expression and the corresponding bounds for the current line." - (let* ((start (line-beginning-position)) - (end (line-end-position)) + (let* ((end (point)) + (start (emmet-find-left-bound)) (line (buffer-substring-no-properties start end))) - (save-excursion - (save-match-data - (let ((bound (point))) - (goto-char start) - (if (re-search-forward "\\(\\([ \t]+\\)?<[^>]*?>\\)+" bound t) - (progn - (setq start (match-end 0)) - (setq end bound) - (setq line (buffer-substring-no-properties start end)) - ) - )))) (let ((expr (emmet-regex "\\([ \t]*\\)\\([^\n]+\\)" line 2))) (if (first expr) (list (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))) + (while char + (cond ((member char '(?\} ?\] ?\))) (backward-sexp) (setq char (char-before))) + ((member char '(?\/ ?\<)) (search-forward ">") (setq char nil)) + ((not (string-match-p "[[:space:]\"';\n]" (string char))) + (backward-word) (setq char (char-before))) + (t (setq char nil)))) + (point))))) + (defcustom emmet-indentation 4 "Number of spaces used for indentation." :type '(number :tag "Spaces") @@ -3531,16 +3538,10 @@ For more information see `emmet-mode'." (let* ((here (point)) (preview (if emmet-preview-default (not arg) arg)) (beg (if preview - (progn - (beginning-of-line) - (skip-chars-forward " \t") - (point)) + (emmet-find-left-bound) (when (use-region-p) (region-beginning)))) (end (if preview - (progn - (end-of-line) - (skip-chars-backward " \t") - (point)) + here (when (use-region-p) (region-end))))) (if (and preview beg) (progn @@ -3666,7 +3667,7 @@ See also `emmet-expand-line'." (let* ((indent (current-indentation)) (markup (emmet-preview-transformed indent))) (when markup - (delete-region (line-beginning-position) (overlay-end ovli)) + (delete-region (overlay-start ovli) (overlay-end ovli)) (emmet-insert-and-flash markup) (let ((output-markup (buffer-substring-no-properties (line-beginning-position) (point)))) (when (and emmet-move-cursor-after-expanding (emmet-html-text-p markup)) diff --git a/src/html-abbrev.el b/src/html-abbrev.el index 7dbf842..0c5411c 100644 --- a/src/html-abbrev.el +++ b/src/html-abbrev.el @@ -154,7 +154,7 @@ `(tag (,tagname ,has-body? nil)) input)) (let ((tag-data (cadar it)) (input (cdr it))) (emmet-pif (emmet-run - emmet-props + emmet-properties (let ((props (cdr expr))) `((tag ,(append tag-data (list props))) . ,input)) `((tag ,(append tag-data '(nil))) . ,input)) @@ -233,7 +233,7 @@ (defun emmet-tag-props (tag input) (let ((tag-data (cadr tag))) - (emmet-run emmet-props + (emmet-run emmet-properties (let ((props (cdr expr))) `((tag ,(append tag-data (list props))) . ,input)) `((tag ,(append tag-data '(nil))) . ,input)))) @@ -247,7 +247,7 @@ (defun emmet-prop (input) (emmet-parse - " " 1 "space" + " *" 1 "space" (emmet-run emmet-name (let ((name (cdr expr))) @@ -291,6 +291,12 @@ (let ((txt (emmet-split-numbering-expressions (elt it 1)))) `((text ,txt) . ,input)))) +(defun emmet-properties (input) + "A bracketed emmet property expression." + (emmet-parse "\\[\\(.*?\\)\\]" 2 "properties" + `(,(car (emmet-props (elt it 1))) . ,input))) + + (defun emmet-pexpr (input) "A zen coding expression with parentheses around it." (emmet-parse "(" 1 "(" diff --git a/src/mode-def.el b/src/mode-def.el index e8060a6..cef6151 100644 --- a/src/mode-def.el +++ b/src/mode-def.el @@ -8,24 +8,25 @@ (defun emmet-expr-on-line () "Extract a emmet expression and the corresponding bounds for the current line." - (let* ((start (line-beginning-position)) - (end (line-end-position)) + (let* ((end (point)) + (start (emmet-find-left-bound)) (line (buffer-substring-no-properties start end))) - (save-excursion - (save-match-data - (let ((bound (point))) - (goto-char start) - (if (re-search-forward "\\(\\([ \t]+\\)?<[^>]*?>\\)+" bound t) - (progn - (setq start (match-end 0)) - (setq end bound) - (setq line (buffer-substring-no-properties start end)) - ) - )))) (let ((expr (emmet-regex "\\([ \t]*\\)\\([^\n]+\\)" line 2))) (if (first expr) (list (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))) + (while char + (cond ((member char '(?\} ?\] ?\))) (backward-sexp) (setq char (char-before))) + ((member char '(?\/ ?\<)) (search-forward ">") (setq char nil)) + ((not (string-match-p "[[:space:]\"';\n]" (string char))) + (backward-word) (setq char (char-before))) + (t (setq char nil)))) + (point))))) + (defcustom emmet-indentation 4 "Number of spaces used for indentation." :type '(number :tag "Spaces") @@ -66,16 +67,10 @@ For more information see `emmet-mode'." (let* ((here (point)) (preview (if emmet-preview-default (not arg) arg)) (beg (if preview - (progn - (beginning-of-line) - (skip-chars-forward " \t") - (point)) + (emmet-find-left-bound) (when (use-region-p) (region-beginning)))) (end (if preview - (progn - (end-of-line) - (skip-chars-backward " \t") - (point)) + here (when (use-region-p) (region-end))))) (if (and preview beg) (progn @@ -201,7 +196,7 @@ See also `emmet-expand-line'." (let* ((indent (current-indentation)) (markup (emmet-preview-transformed indent))) (when markup - (delete-region (line-beginning-position) (overlay-end ovli)) + (delete-region (overlay-start ovli) (overlay-end ovli)) (emmet-insert-and-flash markup) (let ((output-markup (buffer-substring-no-properties (line-beginning-position) (point)))) (when (and emmet-move-cursor-after-expanding (emmet-html-text-p markup)) diff --git a/src/test.el b/src/test.el index 055be6c..69c5a3c 100644 --- a/src/test.el +++ b/src/test.el @@ -118,7 +118,7 @@ "
      " "
    1. " "
    ") - "ul#q.x.y m=l+" ("
      " + "ul#q.x.y[m=l]+" ("
        " "
      • " "
      ")) @@ -270,27 +270,27 @@ "
    ")) (define-emmet-transform-html-test-case Properties - "a x" ("") - "a x=" ("") - "a x=\"\"" ("") - "a x=y" ("") - "a x=\"y\"" ("") - "a x=\"()\"" ("") - "a x m" ("") - "a x= m=\"\"" ("") - "a x=y m=l" ("") - "a/ x=y m=l" ("") - "a#foo x=y m=l" ("") - "a.foo x=y m=l" ("") - "a#foo.bar.mu x=y m=l" ("") - "a/#foo.bar.mu x=y m=l" ("") - "a x=y+b" ("" + "a[x]" ("") + "a[x=]" ("") + "a[x=\"\"]" ("") + "a[x=y]" ("") + "a[x=\"y\"]" ("") + "a[x=\"()\"]" ("") + "a[x m]" ("") + "a[x= m=\"\"]" ("") + "a[x=y m=l]" ("") + "a/[x=y m=l]" ("") + "a#foo[x=y m=l]" ("") + "a.foo[x=y m=l]" ("") + "a#foo.bar.mu[x=y m=l]" ("") + "a/#foo.bar.mu[x=y m=l]" ("") + "a[x=y]+b" ("" "") - "a x=y+b x=y" ("" + "a[x=y]+b[x=y]" ("" "") - "a x=y>b" ("") - "a x=y>b x=y" ("") - "a x=y>b x=y+c x=y" ("" + "a[x=y]>b" ("") + "a[x=y]>b[x=y]" ("") + "a[x=y]>b[x=y]+c[x=y]" ("" " " " " "")) @@ -346,7 +346,7 @@ "here" " to continue") - "xxx#id.cls p=1{txt}" + "xxx#id.cls[p=1]{txt}" ("txt")) (define-emmet-unit-test-case Lorem-ipsum @@ -403,12 +403,12 @@ (define-emmet-transform-html-test-case Filter-HAML "a|haml" ("%a") "a#q.x.y.z|haml" ("%a#q.x.y.z") - "a#q.x x=y m=l|haml" ("%a#q.x{:x => \"y\", :m => \"l\"}") + "a#q.x[x=y m=l]|haml" ("%a#q.x{:x => \"y\", :m => \"l\"}") "div|haml" ("%div") "div.footer|haml" (".footer") ".footer|haml" (".footer") - "p>{This is haml}*2+a href=#+br|haml" + "p>{This is haml}*2+a[href=#]+br|haml" ("%p" " This is haml" " This is haml" @@ -418,9 +418,9 @@ (define-emmet-transform-html-test-case Filter-Hiccup "a|hic" ("[:a]") "a#q.x.y.z|hic" ("[:a#q.x.y.z]") - "a#q.x x=y m=l|hic" ("[:a#q.x {:x \"y\", :m \"l\"}]") + "a#q.x[x=y m=l]|hic" ("[:a#q.x {:x \"y\", :m \"l\"}]") ".footer|hic" ("[:div.footer]") - "p>a href=#+br|hic" ("[:p" + "p>a[href=#]+br|hic" ("[:p" " [:a {:href \"#\"}]" " [:br]]") @@ -433,7 +433,7 @@ " [:b]]]")) (define-emmet-transform-html-test-case Filter-escape - "script src="|e" ("<script src=\"&quot;\"></script>")) + "script[src="]|e" ("<script src=\"&quot;\"></script>")) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; CSS-abbrev tests -- cgit v1.2.3 From e47b30a56de5fee21a029c5e9d168be744949d92 Mon Sep 17 00:00:00 2001 From: Dave Mayo Date: Sun, 10 Aug 2014 18:18:51 -0400 Subject: Uses backward-char and less selective stop-words. Seems to basically work in all cases I have managed to test. --- emmet-mode.el | 21 ++++++++++++--------- src/mode-def.el | 21 ++++++++++++--------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/emmet-mode.el b/emmet-mode.el index c1f5d80..46c6c0d 100644 --- a/emmet-mode.el +++ b/emmet-mode.el @@ -3491,11 +3491,14 @@ tbl)) (save-excursion (save-match-data (let ((char (char-before))) (while char - (cond ((member char '(?\} ?\] ?\))) (backward-sexp) (setq char (char-before))) - ((member char '(?\/ ?\<)) (search-forward ">") (setq char nil)) - ((not (string-match-p "[[:space:]\"';\n]" (string char))) - (backward-word) (setq char (char-before))) - (t (setq char nil)))) + (cond ((member char '(?\} ?\] ?\))) + (backward-sexp) (setq char (char-before))) + ((member char '(?\<)) + (search-forward ">") (setq char nil)) + ((not (string-match-p "[[:space:]\n]" (string char))) + (backward-char) (setq char (char-before))) + (t + (setq char nil)))) (point))))) (defcustom emmet-indentation 4 @@ -3560,7 +3563,7 @@ For more information see `emmet-mode'." (+ (- p (length output-markup)) (emmet-html-next-insert-point output-markup))))))))))))) -(defvar emmet-mode-keymap +(defvar emmet-mode-keymap (let ((map (make-sparse-keymap))) (define-key map (kbd "C-j") 'emmet-expand-line) @@ -3847,7 +3850,7 @@ accept it or skip it." ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun emmet-go-to-edit-point (count) - (let + (let ((buf (buffer-string)) (point (point)) (edit-point "\\(\\(><\\)\\|\\(^[[:blank:]]+$\\)\\|\\(=\\(\"\\|'\\)\\{2\\}\\)\\)")) @@ -3865,8 +3868,8 @@ accept it or skip it." (backward-char)))) (progn (backward-char) - (let - ((search-result (re-search-backward edit-point nil t (- count)))) + (let + ((search-result (re-search-backward edit-point nil t (- count)))) (if search-result (progn (cond diff --git a/src/mode-def.el b/src/mode-def.el index cef6151..6d7aebc 100644 --- a/src/mode-def.el +++ b/src/mode-def.el @@ -20,11 +20,14 @@ (save-excursion (save-match-data (let ((char (char-before))) (while char - (cond ((member char '(?\} ?\] ?\))) (backward-sexp) (setq char (char-before))) - ((member char '(?\/ ?\<)) (search-forward ">") (setq char nil)) - ((not (string-match-p "[[:space:]\"';\n]" (string char))) - (backward-word) (setq char (char-before))) - (t (setq char nil)))) + (cond ((member char '(?\} ?\] ?\))) + (backward-sexp) (setq char (char-before))) + ((member char '(?\<)) + (search-forward ">") (setq char nil)) + ((not (string-match-p "[[:space:]\n]" (string char))) + (backward-char) (setq char (char-before))) + (t + (setq char nil)))) (point))))) (defcustom emmet-indentation 4 @@ -89,7 +92,7 @@ For more information see `emmet-mode'." (+ (- p (length output-markup)) (emmet-html-next-insert-point output-markup))))))))))))) -(defvar emmet-mode-keymap +(defvar emmet-mode-keymap (let ((map (make-sparse-keymap))) (define-key map (kbd "C-j") 'emmet-expand-line) @@ -376,7 +379,7 @@ accept it or skip it." ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun emmet-go-to-edit-point (count) - (let + (let ((buf (buffer-string)) (point (point)) (edit-point "\\(\\(><\\)\\|\\(^[[:blank:]]+$\\)\\|\\(=\\(\"\\|'\\)\\{2\\}\\)\\)")) @@ -394,8 +397,8 @@ accept it or skip it." (backward-char)))) (progn (backward-char) - (let - ((search-result (re-search-backward edit-point nil t (- count)))) + (let + ((search-result (re-search-backward edit-point nil t (- count)))) (if search-result (progn (cond -- cgit v1.2.3