Skip to content

Commit

Permalink
Resolved issue rooney#4 "cursor position after expanding".
Browse files Browse the repository at this point in the history
  • Loading branch information
smihica committed Aug 6, 2013
1 parent de0eb83 commit 57b7cf6
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 4 deletions.
36 changes: 34 additions & 2 deletions emmet-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -3337,7 +3337,6 @@ tbl))
(replace-regexp-in-string "\n" (concat "\n" first-col)
(replace-regexp-in-string " " tab markup)))))


(defun emmet-transform (input)
(if (memq major-mode '(css-mode scss-mode sass-mode))
(emmet-css-transform input)
Expand Down Expand Up @@ -3481,9 +3480,42 @@ See also `emmet-expand-line'."
(markup (emmet-preview-transformed indent)))
(when markup
(delete-region (line-beginning-position) (overlay-end ovli))
(emmet-insert-and-flash markup)))))
(emmet-insert-and-flash markup)
(when (= (elt markup 0) ?<)
(let ((p (point)))
(goto-char
(+ (- p (length markup))
(emmet-html-next-insert-point markup)))))))))
(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 ?\\))
(setq instring (not instring))))
(?> (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))))))))

(defvar emmet-flash-ovl nil)
(make-variable-buffer-local 'emmet-flash-ovl)

Expand Down
37 changes: 35 additions & 2 deletions src/mode-def.el
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
(replace-regexp-in-string " " tab markup)))))

(defun emmet-transform (input)
(if (eql major-mode 'css-mode)
(if (memq major-mode '(css-mode scss-mode sass-mode))
(emmet-css-transform input)
(emmet-html-transform input)))

Expand Down Expand Up @@ -170,9 +170,42 @@ See also `emmet-expand-line'."
(markup (emmet-preview-transformed indent)))
(when markup
(delete-region (line-beginning-position) (overlay-end ovli))
(emmet-insert-and-flash markup)))))
(emmet-insert-and-flash markup)
(when (= (elt markup 0) ?<)
(let ((p (point)))
(goto-char
(+ (- p (length markup))
(emmet-html-next-insert-point markup)))))))))
(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 ?\\))
(setq instring (not instring))))
(?> (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))))))))

(defvar emmet-flash-ovl nil)
(make-variable-buffer-local 'emmet-flash-ovl)

Expand Down

0 comments on commit 57b7cf6

Please sign in to comment.