* Fixed html auto-indent (redesigned yas/indent slightly to collect

all the snipept markers then restore them.
This commit is contained in:
capitaomorte 2009-07-24 15:06:09 +00:00
parent 5ca14b495e
commit 8dd3a78c01

View File

@ -1626,8 +1626,8 @@ delegate to `yas/next-field'."
(defun yas/place-overlays (snippet field) (defun yas/place-overlays (snippet field)
"Correctly place overlays for SNIPPET's FIELD" "Correctly place overlays for SNIPPET's FIELD"
(yas/make-move-active-field-overlay snippet field) (yas/make-move-field-protection-overlays snippet field)
(yas/make-move-field-protection-overlays snippet field)) (yas/make-move-active-field-overlay snippet field))
(defun yas/move-to-field (snippet field) (defun yas/move-to-field (snippet field)
"Update SNIPPET to move to field FIELD. "Update SNIPPET to move to field FIELD.
@ -1901,7 +1901,7 @@ Move the overlay, or create it if it does not exit."
(yas/field-end field) (yas/field-end field)
nil nil t)) nil nil t))
(overlay-put yas/active-field-overlay 'face 'yas/field-highlight-face) (overlay-put yas/active-field-overlay 'face 'yas/field-highlight-face)
;;(overlay-put yas/active-field-overlay 'evaporate t) (overlay-put yas/active-field-overlay 'yas/snippet snippet)
(overlay-put yas/active-field-overlay 'modification-hooks '(yas/on-field-overlay-modification)) (overlay-put yas/active-field-overlay 'modification-hooks '(yas/on-field-overlay-modification))
(overlay-put yas/active-field-overlay 'insert-in-front-hooks '(yas/on-field-overlay-modification)) (overlay-put yas/active-field-overlay 'insert-in-front-hooks '(yas/on-field-overlay-modification))
(overlay-put yas/active-field-overlay 'insert-behind-hooks '(yas/on-field-overlay-modification)))) (overlay-put yas/active-field-overlay 'insert-behind-hooks '(yas/on-field-overlay-modification))))
@ -1959,7 +1959,7 @@ Move the overlays, or create them if they do not exit."
;; insert a newline. the `(1+ (buffer-size))' should prevent this ;; insert a newline. the `(1+ (buffer-size))' should prevent this
;; when using stacked expansion ;; when using stacked expansion
;; ;;
(when (< (1+ (buffer-size)) (1+ end)) (when (< (buffer-size) end)
(save-excursion (save-excursion
(let ((inhibit-modification-hooks t)) (let ((inhibit-modification-hooks t))
(goto-char (point-max)) (goto-char (point-max))
@ -2181,7 +2181,8 @@ Returns the newly created snippet."
(push mirror (yas/field-back-adjacent-mirrors field)))) (push mirror (yas/field-back-adjacent-mirrors field))))
(when (and (not (eq otherfield field)) (when (and (not (eq otherfield field))
(= (yas/field-end field) (yas/field-start otherfield))) (= (yas/field-end field) (yas/field-start otherfield)))
(push otherfield (yas/field-back-adjacent-fields field)))) (when (not (find field (yas/field-back-adjacent-fields otherfield)))
(push otherfield (yas/field-back-adjacent-fields field)))))
;; Calculate the adjacencies of each one of its mirrors ;; Calculate the adjacencies of each one of its mirrors
;; ;;
;; TODO: Known bug. ;; TODO: Known bug.
@ -2221,12 +2222,20 @@ Meant to be called in a narrowed buffer, does various passes"
;; ;;
(goto-char parse-start) (goto-char parse-start)
(yas/restore-escapes) (yas/restore-escapes)
;; update mirrors for the first time
;;
(yas/update-mirrors snippet)
;; indent the best we can ;; indent the best we can
;; ;;
(goto-char parse-start) (goto-char parse-start)
(yas/indent snippet))) (yas/indent snippet)))
(defun yas/indent (snippet) (defun yas/indent (snippet)
(save-excursion
(while (re-search-forward "$>" nil t)
(delete-region (match-beginning 0) (match-end 0))
(when (not (eq yas/indent-line 'auto))
(indent-according-to-mode))))
(save-excursion (save-excursion
(cond ((eq yas/indent-line 'fixed) (cond ((eq yas/indent-line 'fixed)
(let* ((indent (if indent-tabs-mode (let* ((indent (if indent-tabs-mode
@ -2238,7 +2247,8 @@ Meant to be called in a narrowed buffer, does various passes"
(= (current-column) 0)) (= (current-column) 0))
(insert indent)))) (insert indent))))
((eq yas/indent-line 'auto) ((eq yas/indent-line 'auto)
(let ((end (set-marker (make-marker) (point-max)))) (let ((end (set-marker (make-marker) (point-max)))
(snippet-markers (yas/collect-snippet-markers snippet)))
(save-restriction (save-restriction
(widen) (widen)
;; XXX: Here seems to be the indent problem: ;; XXX: Here seems to be the indent problem:
@ -2258,20 +2268,31 @@ Meant to be called in a narrowed buffer, does various passes"
(not (eobp)) (not (eobp))
(<= (point) end)) (<= (point) end))
(goto-char (yas/real-line-beginning)) (goto-char (yas/real-line-beginning))
(if (buffer-has-markers-at (point)) (let ((trouble-markers (remove-if-not #'(lambda (marker)
(progn (= marker (point)))
(insert-before-markers "Y") snippet-markers)))
(indent-according-to-mode) (indent-according-to-mode)
(backward-delete-char 1)) (mapc #'(lambda (marker)
(set-marker marker (point)))
trouble-markers)
(indent-according-to-mode))) (indent-according-to-mode)))
(set-marker end nil)))) (set-marker end nil))))
(t (t
nil))) nil))))
(save-excursion
(while (re-search-forward "$>" nil t) (defun yas/collect-snippet-markers (snippet)
(delete-region (match-beginning 0) (match-end 0)) "Make a list of all the markers used by SNIPPET."
(when (not (eq yas/indent-line 'auto)) (let (markers)
(indent-according-to-mode))))) (dolist (field (yas/snippet-fields snippet))
(push (yas/field-start field) markers)
(push (yas/field-end field) markers)
(dolist (mirror (yas/field-mirrors field))
(push (yas/mirror-start mirror) markers)
(push (yas/mirror-end mirror) markers)))
(when (and (yas/snippet-exit snippet)
(marker-buffer (yas/snippet-exit snippet)))
(push (yas/snippet-exit snippet) markers))
markers))
(defun yas/real-line-beginning () (defun yas/real-line-beginning ()
(let ((c (char-after (line-beginning-position))) (let ((c (char-after (line-beginning-position)))