mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-14 05:23:04 +00:00
* Fix issue 80 (buffer needs widening before any indentation)
* Fix issue 81 (refactored "trouble-markers" fix in yas/indent-according-to-mode. Reapplied to $> indentation) * Probably fix issues 82 and 83 (could not reproduce, probably fixed by 80 and 81)
This commit is contained in:
parent
4cb1ab2ba7
commit
405b76b0d3
69
yasnippet.el
69
yasnippet.el
@ -2948,24 +2948,9 @@ Meant to be called in a narrowed buffer, does various passes"
|
|||||||
(goto-char parse-start)
|
(goto-char parse-start)
|
||||||
(yas/indent snippet)))
|
(yas/indent snippet)))
|
||||||
|
|
||||||
(defun yas/indent (snippet)
|
(defun yas/indent-according-to-mode (snippet-markers)
|
||||||
(save-excursion
|
"Indent current line according to mode, preserving
|
||||||
(while (re-search-forward "$>" nil t)
|
SNIPPET-MARKERS."
|
||||||
(delete-region (match-beginning 0) (match-end 0))
|
|
||||||
(when (not (eq yas/indent-line 'auto))
|
|
||||||
(indent-according-to-mode))))
|
|
||||||
(save-excursion
|
|
||||||
(cond ((eq yas/indent-line 'fixed)
|
|
||||||
(goto-char (point-min))
|
|
||||||
(while (and (zerop (forward-line))
|
|
||||||
(zerop (current-column)))
|
|
||||||
(indent-to-column column)))
|
|
||||||
((eq yas/indent-line 'auto)
|
|
||||||
(let ((end (set-marker (make-marker) (point-max)))
|
|
||||||
(indent-first-line-p yas/also-auto-indent-first-line)
|
|
||||||
(snippet-markers (yas/collect-snippet-markers snippet)))
|
|
||||||
(save-restriction
|
|
||||||
(widen)
|
|
||||||
;; XXX: Here seems to be the indent problem:
|
;; XXX: Here seems to be the indent problem:
|
||||||
;;
|
;;
|
||||||
;; `indent-according-to-mode' uses whatever
|
;; `indent-according-to-mode' uses whatever
|
||||||
@ -2979,9 +2964,41 @@ Meant to be called in a narrowed buffer, does various passes"
|
|||||||
;; This would also happen if we had used overlays with
|
;; This would also happen if we had used overlays with
|
||||||
;; the `front-advance' property set to nil.
|
;; the `front-advance' property set to nil.
|
||||||
;;
|
;;
|
||||||
;; This is why I have these `trouble-markers', which
|
;; This is why I have these `trouble-markers', they are the ones at
|
||||||
;; are restored after indentation happens.
|
;; they are the ones at the first non-whitespace char at the line
|
||||||
|
;; (i.e. at `yas/real-line-beginning'. After indentation takes place
|
||||||
|
;; we should be at the correct to restore them to. All other
|
||||||
|
;; non-trouble-markers have been *pushed* and don't need special
|
||||||
|
;; attention.
|
||||||
;;
|
;;
|
||||||
|
(goto-char (yas/real-line-beginning))
|
||||||
|
(let ((trouble-markers (remove-if-not #'(lambda (marker)
|
||||||
|
(= marker (point)))
|
||||||
|
snippet-markers)))
|
||||||
|
(save-restriction
|
||||||
|
(widen)
|
||||||
|
(indent-according-to-mode))
|
||||||
|
(mapc #'(lambda (marker)
|
||||||
|
(set-marker marker (point)))
|
||||||
|
trouble-markers)))
|
||||||
|
|
||||||
|
(defun yas/indent (snippet)
|
||||||
|
(let ((snippet-markers (yas/collect-snippet-markers snippet)))
|
||||||
|
;; Look for those $>
|
||||||
|
(save-excursion
|
||||||
|
(while (re-search-forward "$>" nil t)
|
||||||
|
(delete-region (match-beginning 0) (match-end 0))
|
||||||
|
(when (not (eq yas/indent-line 'auto))
|
||||||
|
(yas/indent-according-to-mode snippet-markers))))
|
||||||
|
;; Now do stuff for 'fixed and 'auto
|
||||||
|
(save-excursion
|
||||||
|
(cond ((eq yas/indent-line 'fixed)
|
||||||
|
(while (and (zerop (forward-line))
|
||||||
|
(zerop (current-column)))
|
||||||
|
(indent-to-column column)))
|
||||||
|
((eq yas/indent-line 'auto)
|
||||||
|
(let ((end (set-marker (make-marker) (point-max)))
|
||||||
|
(indent-first-line-p yas/also-auto-indent-first-line))
|
||||||
(while (and (zerop (if indent-first-line-p
|
(while (and (zerop (if indent-first-line-p
|
||||||
(prog1
|
(prog1
|
||||||
(forward-line 0)
|
(forward-line 0)
|
||||||
@ -2989,17 +3006,9 @@ Meant to be called in a narrowed buffer, does various passes"
|
|||||||
(forward-line 1)))
|
(forward-line 1)))
|
||||||
(not (eobp))
|
(not (eobp))
|
||||||
(<= (point) end))
|
(<= (point) end))
|
||||||
(goto-char (yas/real-line-beginning))
|
(yas/indent-according-to-mode snippet-markers))))
|
||||||
(let ((trouble-markers (remove-if-not #'(lambda (marker)
|
|
||||||
(= marker (point)))
|
|
||||||
snippet-markers)))
|
|
||||||
(indent-according-to-mode)
|
|
||||||
(mapc #'(lambda (marker)
|
|
||||||
(set-marker marker (point)))
|
|
||||||
trouble-markers)))
|
|
||||||
(set-marker end nil))))
|
|
||||||
(t
|
(t
|
||||||
nil))))
|
nil)))))
|
||||||
|
|
||||||
(defun yas/collect-snippet-markers (snippet)
|
(defun yas/collect-snippet-markers (snippet)
|
||||||
"Make a list of all the markers used by SNIPPET."
|
"Make a list of all the markers used by SNIPPET."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user