diff options
author | David Aspinall <da@inf.ed.ac.uk> | 2010-10-01 15:52:08 +0000 |
---|---|---|
committer | David Aspinall <da@inf.ed.ac.uk> | 2010-10-01 15:52:08 +0000 |
commit | ac54baff3a890d738516e164a0bfc2191dbe4cde (patch) | |
tree | 1f6567e8e541b5370df0f1c467a2c94d0ec579b3 /lib | |
parent | 0bb355a0ed7db7130758a5e9685ee61ede255c2a (diff) |
span-make-modifying-removing-span: add utility
span-make-self-removing-span: rename from span-add-self-removing-span
Diffstat (limited to 'lib')
-rw-r--r-- | lib/span.el | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/span.el b/lib/span.el index 6b576b87..cbdf8406 100644 --- a/lib/span.el +++ b/lib/span.el @@ -219,12 +219,33 @@ Return nil if no such overlay belong to the list." ;; Handy overlay utils ;; -(defun span-add-self-removing-span (beg end &rest props) +(defun span-make-self-removing-span (beg end &rest props) + "Add a self-removing span from BEG to END with properties PROPS. +The span will remove itself after a timeout of 2 seconds." (let ((ol (make-overlay beg end))) (while props (overlay-put ol (car props) (cadr props)) (setq props (cddr props))) - (add-timeout 2 'delete-overlay ol))) + (add-timeout 2 'delete-overlay ol) + ol)) + +(defun span-delete-self-modification-hook (span &rest args) + "Hook for overlay modification-hooks, which deletes SPAN." + (if (span-live-p span) + (span-delete span))) + +(defun span-make-modifying-removing-span (beg end &rest props) + "Add a self-removing span from BEG to END with properties PROPS. +The span will remove itself after any edit within its range. +Return the span." + (let ((ol (make-overlay beg end))) + (while props + (overlay-put ol (car props) (cadr props)) + (setq props (cddr props))) + (span-set-property ol 'modification-hooks + (list 'span-delete-self-modification-hook)) + ol)) + (provide 'span) |