Add ein:notebook-get-nearest-cell-ewoc-node

This commit is contained in:
Takafumi Arakaki 2012-05-10 19:55:49 +02:00
parent 2675facfe5
commit c95f505287
2 changed files with 10 additions and 7 deletions

View file

@ -56,13 +56,7 @@ Return the point of beginning of the input element of cell after
the point POS. Return `nil' if it cannot be found before the point
MAX. If END is non-`nil', end of the input element is returned."
(let* ((ewoc-node
(ein:aif (ein:notebook-get-current-ewoc-node pos)
(let ((ewoc-node it))
;; can be optimized using the argument `max'
(while (and ewoc-node
(not (ein:cell-ewoc-node-p ewoc-node)))
(setq ewoc-node (ewoc-next (ein:@notebook ewoc) ewoc-node)))
ewoc-node)))
(ein:notebook-get-nearest-cell-ewoc-node pos max))
(_ (ein:log 'debug "(null ewoc-node) = %s" (null ewoc-node)))
(cell (ein:aif ewoc-node (ein:$node-data (ewoc-data it))))
(_ (ein:log 'debug "(null cell) = %s" (null cell)))

View file

@ -302,6 +302,15 @@ Note that SLOT should not be quoted."
(defun ein:notebook-get-current-ewoc-node (&optional pos)
(ein:aand ein:notebook (ein:$notebook-ewoc it) (ewoc-locate it pos)))
(defun ein:notebook-get-nearest-cell-ewoc-node (&optional pos max)
(ein:aif (ein:notebook-get-current-ewoc-node pos)
(let ((ewoc-node it))
;; FIXME: can be optimized using the argument `max'
(while (and ewoc-node
(not (ein:cell-ewoc-node-p ewoc-node)))
(setq ewoc-node (ewoc-next (ein:@notebook ewoc) ewoc-node)))
ewoc-node)))
(defun ein:notebook-get-current-cell (&optional pos)
(let ((cell (ein:aand (ein:notebook-get-current-ewoc-node pos)
(ewoc-data it)