fixup: guess I need to close snippet-objects after all

This commit is contained in:
Joao Tavora 2013-10-19 17:20:25 +01:00
parent 76bc40fd03
commit 2db4102fda

View File

@ -453,26 +453,35 @@ can be:
(eq (snippet--object-end prev) (eq (snippet--object-end prev)
(snippet--object-start next))) (snippet--object-start next)))
(defun snippet--open-object (object) (defun snippet--open-object (object &optional close-instead)
(set-marker-insertion-type (snippet--object-start object) nil) (let ((stay (cons (snippet--object-start object)
(cl-loop for o = object then prev (cl-loop for o = object then prev
for prev = (snippet--object-prev o) for prev = (snippet--object-prev o)
while (and prev while (and prev
(snippet--objects-adjacent-p prev o) (snippet--objects-adjacent-p prev o)
(snippet--object-empty-p prev)) (snippet--object-empty-p prev))
do (set-marker-insertion-type (snippet--object-start prev) nil)) collect (snippet--object-start prev))))
(push (cons (snippet--object-end object)
(set-marker-insertion-type (snippet--object-end object) t) (cl-loop for o = object then next
(cl-loop for o = object then next for next = (snippet--object-next o)
for next = (snippet--object-next o) while (and next
while (and next (snippet--objects-adjacent-p o next)
(snippet--objects-adjacent-p o next) (snippet--object-empty-p next))
(snippet--object-empty-p next)) collect (snippet--object-end next)))))
do (set-marker-insertion-type (snippet--object-end next) t))) (when close-instead
(if (snippet--object-empty-p object)
(setq stay (append stay push)
push nil)
(cl-rotatef stay push)))
(mapc #'(lambda (m) (set-marker-insertion-type m nil)) stay)
(mapc #'(lambda (m) (set-marker-insertion-type m t)) push)))
(defun snippet--call-with-current-object (object fn) (defun snippet--call-with-current-object (object fn)
(snippet--open-object object) (unwind-protect
(funcall fn)) (progn
(snippet--open-object object)
(funcall fn))
(snippet--open-object object 'close)))
(defmacro snippet--with-current-object (object &rest body) (defmacro snippet--with-current-object (object &rest body)
(declare (indent defun) (debug t)) (declare (indent defun) (debug t))