From c95f50528785202ea9c98184d94789acea9a4681 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Thu, 10 May 2012 19:55:49 +0200 Subject: [PATCH] Add ein:notebook-get-nearest-cell-ewoc-node --- ein-mumamo.el | 8 +------- ein-notebook.el | 9 +++++++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/ein-mumamo.el b/ein-mumamo.el index 701db89..dd6ac1c 100644 --- a/ein-mumamo.el +++ b/ein-mumamo.el @@ -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))) diff --git a/ein-notebook.el b/ein-notebook.el index 36c368f..c6507ad 100644 --- a/ein-notebook.el +++ b/ein-notebook.el @@ -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)