aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--emmet-mode.el61
-rw-r--r--src/mode-def.el61
2 files changed, 42 insertions, 80 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
diff --git a/src/mode-def.el b/src/mode-def.el
index b9b1f94..3094498 100644
--- a/src/mode-def.el
+++ b/src/mode-def.el
@@ -220,36 +220,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)
@@ -388,11 +365,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)
@@ -401,9 +381,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)
@@ -412,10 +393,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