diff options
author | William David Mayo ("Dave") <pobocks@gmail.com> | 2014-08-21 21:06:45 -0400 |
---|---|---|
committer | William David Mayo ("Dave") <pobocks@gmail.com> | 2014-08-21 21:06:45 -0400 |
commit | 5a41445c8c00defc3f7f1ff79f747b56691ba897 (patch) | |
tree | c13ac89cda0242c61de8cd69d2e4ad3d6adbf2ed /emmet-mode.el | |
parent | 31ea096b2e8e3d16f1984b29b2155cdc09706150 (diff) | |
parent | 7722c7703404b36fb9d931246ca2a9106ad004a9 (diff) | |
download | emmet-mode-5a41445c8c00defc3f7f1ff79f747b56691ba897.tar.lz emmet-mode-5a41445c8c00defc3f7f1ff79f747b56691ba897.tar.xz emmet-mode-5a41445c8c00defc3f7f1ff79f747b56691ba897.zip |
Merge pull request #37 from flyingleafe/master
Adapted emmet-html-next-insert-point to use emmet-go-to-edit-point
Diffstat (limited to 'emmet-mode.el')
-rw-r--r-- | emmet-mode.el | 61 |
1 files changed, 21 insertions, 40 deletions
diff --git a/emmet-mode.el b/emmet-mode.el index 4108948..e49c9e2 100644 --- a/emmet-mode.el +++ b/emmet-mode.el @@ -3709,36 +3709,13 @@ See also `emmet-expand-line'." (emmet-preview-abort)) (defun emmet-html-next-insert-point (str) - (let ((intag t) (instring nil) - (last-c nil) (c nil) - (rti 0)) - (loop for i to (1- (length str)) do - (setq last-c c) - (setq c (elt str i)) - (case c - (?\" (if (not (= last-c ?\\)) - (progn (setq instring (not instring)) - (when (and emmet-move-cursor-between-quotes - (not instring) - (= last-c ?\")) - (return i))))) - (?> (if (not instring) - (if intag - (if (= last-c ?/) (return (1+ i)) - (progn (setq intag nil) - (setq rti (1+ i)))) - (return i)))) ;; error? - (?< (if (and (not instring) (not intag)) - (setq intag t))) - (?/ (if (and intag - (not instring) - (= last-c ?<)) - (return rti))) - (t - (if (memq c '(?\t ?\n ?\r ?\s)) - (progn (setq c last-c)) - (if (and (not intag) (not instring)) - (return rti)))))))) + (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 (defvar emmet-flash-ovl nil) (make-variable-buffer-local 'emmet-flash-ovl) @@ -3877,11 +3854,14 @@ accept it or skip it." ;; http://docs.emmet.io/actions/go-to-edit-point/ ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(defun emmet-go-to-edit-point (count) - (let - ((buf (buffer-string)) - (point (point)) - (edit-point "\\(\\(><\\)\\|\\(^[[:blank:]]+$\\)\\|\\(=\\(\"\\|'\\)\\{2\\}\\)\\)")) +(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 "\\(=\\(\"\\|'\\)\\{2\\}\\)") + (edit-point (format "\\(%s\\|%s\\|%s\\)" + between-tags indented-line between-quotes))) (if (> count 0) (progn (forward-char) @@ -3890,9 +3870,10 @@ accept it or skip it." (if search-result (progn (cond - ((or (match-string 2) (match-string 4)) (backward-char)) - ((match-string 3) (end-of-line))) - search-result) + ((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) @@ -3901,10 +3882,10 @@ accept it or skip it." (if search-result (progn (cond - ((match-string 2) (forward-char)) + ((match-string 2) (goto-char (- (match-end 2) 1))) ((match-string 3) (end-of-line)) ((match-string 4) (forward-char 2))) - search-result) + (point)) (forward-char))))))) ;;;###autoload |